WikiLink.m: Difference between revisions

From Knot Atlas
Jump to navigationJump to search
No edit summary
No edit summary
Line 33: Line 33:
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.";
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::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.";\
WikiGetPageText::usage="WikiGetPageText[pagename] returns the raw text of the specified page.";\


WikiSetPageText::usage=
WikiSetPageText::usage=
"WikiSetPageText[pagename, text] overwrites the contents of the specificied page with the given text.\n"<>
"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] 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.";
WikiUploadFile::usage="WikiUploadFile[name, description] uploads the specified file to the wiki.";

Asynchronous;


Begin["`Private`"];
Begin["`Private`"];


mediawikiConnection=.;mediawikiConnectionPool=.;
mediawikiConnection=.;


SetJarPath[jarPath_String]:=(InstallJava[];
SetJarPath[path_String]:=
Module[{},
AddToClassPath[jarPath<>"commons-httpclient-3.0-rc2.jar",jarPath<>"commons-codec-1.3.jar",
Print[
jarPath<>"commons-logging.jar",jarPath<>"jdom.jar",
"Be careful here to provide the path in a format your operating system understands!"]\
jarPath<>"wikilink.jar"];)
;
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]:=
CreateWikiConnection[baseURL_String]:=
Line 69: Line 66:
mediawikiConnection=
mediawikiConnection=
JavaNew["wikilink.MediawikiConnection",baseURL, username, password];)
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]
WikiConnectionValidQ[]:=JavaObjectQ[mediawikiConnection]

WikiConnectionPoolValidQ[]:=JavaObjectQ[mediawikiConnectionPool]


WikiGetPageText::invalid=WikiSetPageText::invalid="You must call CreateWikiConnection before using WikiGetPageText or WikiSetPageText";
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]:=
WikiGetPageText[name_String]:=
Line 93: Line 75:
Message[WikiGetPageText::invalid]]
Message[WikiGetPageText::invalid]]


WikiSetPageText[name_String,contents_String, summary_String]:=
Options[WikiSetPageText]={Asynchronous\[Rule]False};

WikiSetPageText[name_String,contents_String, summary_String,opts___]:=
If[WikiConnectionValidQ[],
If[WikiConnectionValidQ[],
mediawikiConnection@setPageText[name, contents, summary],
If[(Asynchronous/.{opts})/.Options[WikiSetPageText],
If[WikiConnectionPoolValidQ[],
mediawikiConnectionPool@scheduleSetPageText[name, contents, summary],
Message[WikiSetPageText::poolinvalid];
],
mediawikiConnection@setPageText[name, contents, summary]
],
Message[WikiSetPageText::invalid]
Message[WikiSetPageText::invalid]
]
]

Revision as of 22:07, 26 August 2005

(*

*)
(*******************************************************************
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[];
(*
  • )