WikiLink.m

From Knot Atlas
Revision as of 00:20, 16 August 2005 by Scott (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
BeginPackage["Mediawiki`",{"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.";\

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.";

Begin["`Private`"];

mediawikiConnection=.;

SetJarPath[jarPath_String]:=(InstallJava[];
    AddToClassPath[jarPath<>"commons-httpclient-3.0-rc2.jar",jarPath<>"commons-codec-1.3.jar",
      jarPath<>"commons-logging.jar",jarPath<>"jdom.jar", 
      jarPath<>"mediawiki.jar"];)

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

CreateWikiConnection[baseURL_String,username_String, password_String]:=
  (InstallJava[];
    mediawikiConnection=
      JavaNew["mediawiki.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]:=
  If[WikiConnectionValidQ[],mediawikiConnection@setPageText[name, contents],
    Message[WikiSetPageText::invalid]]

End[];

EndPackage[];