WikiLink.m

From Knot Atlas
Revision as of 09:16, 24 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"<>
\

      "CreateWikiConnection[URL, username, password, poolSize] creates a pool of connections, enabling asynchronous use of WikiSetPageText.";\

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"<>
\

      "WikiSetPageText[pagename, text, summary, Asynchronous->True] returns immediately, performing the request asynchronously. To use this option, you must have specified a connection pool size when executing CreateWikiConnection.";\

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

Asynchronous;

Begin["`Private`"];

mediawikiConnection=.;mediawikiConnectionPool=.;

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<>"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];)

CreateWikiConnection[baseURL_String,username_String, password_String, 
    poolSize_Integer]:=
  Module[{},
    InstallJava[];
    mediawikiConnection=
      JavaNew["wikilink.MediawikiConnection",baseURL, username, password];
    mediawikiConnectionPool=
      JavaNew["wikilink.MediawikiConnectionPool",baseURL, username, password, 
        poolSize];
    ]

WikiConnectionValidQ[]:=JavaObjectQ[mediawikiConnection]

WikiConnectionPoolValidQ[]:=JavaObjectQ[mediawikiConnectionPool]

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

WikiSetPageText::poolinvalid="You must call CreateWikiConnection, specifying a connection pool size, before using WikiSetPageText with Asynchronous->True";

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

Options[WikiSetPageText]={Asynchronous\[Rule]False};

WikiSetPageText[name_String,contents_String, summary_String,opts___]:=
  If[WikiConnectionValidQ[],
    If[(Asynchronous/.{opts})/.Options[WikiSetPageText],
      If[WikiConnectionPoolValidQ[],
        mediawikiConnectionPool@scheduleSetPageText[name, contents, summary],
        Message[WikiSetPageText::poolinvalid];
        ],
      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[];
(*
  • )