WikiLink.m

From Knot Atlas
Revision as of 23:07, 26 August 2005 by Scott (talk | contribs)
Jump to navigationJump to search

(*

*)
(*******************************************************************
This file was generated automatically by the Mathematica front end.
It contains Initialization cells from a Notebook file, which
typically will have the same name as this file except ending in
".nb" instead of ".m".

This file is intended to be loaded into the Mathematica kernel using
the package loading commands Get or Needs.  Doing so is equivalent
to using the Evaluate Initialization Cells menu command in the front
end.

DO NOT EDIT THIS FILE.  This entire file is regenerated
automatically each time the parent Notebook file is saved in the
Mathematica front end.  Any changes you make to this file will be
overwritten.
***********************************************************************)











BeginPackage["WikiLink`",{"JLink`"}];

SetJarPath::usage="You'll need to call this, specifying the path to the jar files needed by this package. Hopefully, they're in the same place as the package itself.";

CreateWikiConnection::usage="CreateWikiConnection[URL, username, password] initialises a connection to a mediawiki server. The URL should typically end in \"index.php\". The username and password are optional.\n";\

WikiGetPageText::usage="WikiGetPageText[pagename] returns the raw text of the specified page.";\

WikiSetPageText::usage=
    "WikiSetPageText[pagename, text] overwrites the contents of the specificied page with the given text.\n"<>\
"WikiSetPageText[pagename, text, summary] overwrites the contents of the specificied page with the given text and notes summary in the change log.\n";\

WikiUploadFile::usage="WikiUploadFile[name, description] uploads the specified file to the wiki.";

Begin["`Private`"];

mediawikiConnection=.;

SetJarPath[path_String]:=
  Module[{},
    Print[
      "Be careful here to provide the path in a format your operating system understands!"]\
;
    InstallJava[];
    AddToClassPath[path<>"commons-httpclient-3.0-rc2.jar",path<>"commons-codec-1.3.jar",
      path<>"commons-logging.jar",path<>"commons-lang-2.1.jar",
      path<>"jdom.jar", path<>"wikilink.jar"];
    ]

CreateWikiConnection[baseURL_String]:=
  (InstallJava[];
    mediawikiConnection=JavaNew["wikilink.MediawikiConnection",baseURL];)

CreateWikiConnection[baseURL_String,username_String, password_String]:=
  (InstallJava[];
    mediawikiConnection=
      JavaNew["wikilink.MediawikiConnection",baseURL, username, password];)

WikiConnectionValidQ[]:=JavaObjectQ[mediawikiConnection]

WikiGetPageText::invalid=WikiSetPageText::invalid="You must call CreateWikiConnection before using WikiGetPageText or WikiSetPageText";

WikiGetPageText[name_String]:=
  If[WikiConnectionValidQ[],mediawikiConnection@getPageText[name],
    Message[WikiGetPageText::invalid]]

WikiSetPageText[name_String,contents_String, summary_String]:=
  If[WikiConnectionValidQ[],
    mediawikiConnection@setPageText[name, contents, summary],
    Message[WikiSetPageText::invalid]
    ]

WikiSetPageText[name_String,contents_String,opts___]:=
  WikiSetPageText[name,contents,"",opts]

WikiUploadFile[name_String,description_String]:=
  If[WikiConnectionValidQ[],mediawikiConnection@uploadFile[name,description],
    Message[WikiUploadFile::invalid]]

End[];

EndPackage[];
(*
  • )