WikiLink - The Mediawiki Interface: Difference between revisions

From Knot Atlas
Jump to navigationJump to search
No edit summary
Line 31: Line 31:
First, you'll need to set some paths, so WikiLink` can find the java files it needs.
First, you'll need to set some paths, so WikiLink` can find the java files it needs.


<!--$$KnotAtlasPath = "c:\\scott\\math.berkeley.edu\\Work\\Mathematica\\KnotAtlas\\";$$-->
<!--$$KnotAtlasPath = &quot;c:\\scott\\math.berkeley.edu\\Work\\Mathematica\\KnotAtlas\\&quot;;$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{In|
{{In|
n = 1 |
n = 1 |
in = <nowiki>KnotAtlasPath = "c:\\scott\\math.berkeley.edu\\Work\\Mathematica\\KnotAtlas\\";</nowiki>}}
in = <nowiki>KnotAtlasPath = &quot;c:\\scott\\math.berkeley.edu\\Work\\Mathematica\\KnotAtlas\\&quot;;</nowiki>}}
<!--END-->
<!--END-->
<!--$$AppendTo[$Path, KnotAtlasPath];$$-->
<!--$$AppendTo[$Path, KnotAtlasPath];$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{In|
{{In|
n = 2 |
n = 2 |
Line 44: Line 44:
<!--END-->
<!--END-->
<!--$$SetDirectory[KnotAtlasPath];$$-->
<!--$$SetDirectory[KnotAtlasPath];$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{In|
{{In|
n = 3 |
n = 3 |
in = <nowiki>SetDirectory[KnotAtlasPath];</nowiki>}}
in = <nowiki>SetDirectory[KnotAtlasPath];</nowiki>}}
<!--END-->
<!--END-->
<!--$$<< "WikiLink\\WikiLink.m"$$-->
<!--$$<< &quot;WikiLink\\WikiLink.m&quot;$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{In|
{{In|
n = 4 |
n = 4 |
in = <nowiki><< "WikiLink\\WikiLink.m"</nowiki>}}
in = <nowiki><< &quot;WikiLink\\WikiLink.m&quot;</nowiki>}}
<!--END-->
<!--END-->
<!--$$SetJarPath[KnotAtlasPath <> "WikiLink\\"];$$-->
<!--$$SetJarPath[KnotAtlasPath <> &quot;WikiLink\\&quot;];$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{In|
{{In|
n = 5 |
n = 5 |
in = <nowiki>SetJarPath[KnotAtlasPath <> "WikiLink\\"];</nowiki>}}
in = <nowiki>SetJarPath[KnotAtlasPath <> &quot;WikiLink\\&quot;];</nowiki>}}
<!--END-->
<!--END-->


Line 65: Line 65:
<!--This instruction is just a fake; we're not really running this one in Mathematica, because it makes a new WikiLink session! :-)
<!--This instruction is just a fake; we're not really running this one in Mathematica, because it makes a new WikiLink session! :-)
<!--CreateWikiConnection[
<!--CreateWikiConnection[
"http://katlas.math.toronto.edu/w/index.php",
&quot;http://katlas.math.toronto.edu/w/index.php&quot;,
InputString["Enter Your Username:"],
InputString[&quot;Enter Your Username:&quot;],
InputString["Enter Your Password"]
InputString[&quot;Enter Your Password&quot;]
]-->
]-->
{{In|
{{In|
n = 6 |
n = 6 |
in = <nowiki>CreateWikiConnection[
in = <nowiki>CreateWikiConnection[
"http://katlas.math.toronto.edu/w/index.php",
&quot;http://katlas.math.toronto.edu/w/index.php&quot;,
InputString["Enter Your Username:"],
InputString[&quot;Enter Your Username:&quot;],
InputString["Enter Your Password"]
InputString[&quot;Enter Your Password&quot;]
]</nowiki>}}
]</nowiki>}}


The function <code>WikiUserName[]</code> checks that we're logged in
The function <code>WikiUserName[]</code> checks that we're logged in
<!--$$?WikiUserName$$-->
<!--$$?WikiUserName$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{HelpLine|
{{HelpLine|
n = 6 |
n = 6 |
Line 86: Line 86:
<!--END-->
<!--END-->
<!--$$WikiUserName[]$$-->
<!--$$WikiUserName[]$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{InOut|
{{InOut|
n = 7 |
n = 7 |
Line 100: Line 100:


<!--$$?WikiGetPageText$$-->
<!--$$?WikiGetPageText$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{HelpLine|
{{HelpLine|
n = 8 |
n = 8 |
Line 107: Line 107:
<!--END-->
<!--END-->
<!--$$?WikiSetPageText$$-->
<!--$$?WikiSetPageText$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{HelpLine|
{{HelpLine|
n = 9 |
n = 9 |
Line 115: Line 115:
<!--END-->
<!--END-->
<!--$$?WikiSetPageTexts$$-->
<!--$$?WikiSetPageTexts$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{HelpLine|
{{HelpLine|
n = 10 |
n = 10 |
Line 122: Line 122:
<!--END-->
<!--END-->
<!--$$?WikiUploadFile$$-->
<!--$$?WikiUploadFile$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{HelpLine|
{{HelpLine|
n = 11 |
n = 11 |
Line 130: Line 130:


Thus for example after
Thus for example after
<!--$$WikiSetPageText["Sandbox", "A robotic edit, at 19:39, 31-August-2005."]$$-->
<!--$$WikiSetPageText[&quot;Sandbox&quot;, &quot;A robotic edit, at 19:39, 31-August-2005.&quot;]$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{InOut|
{{InOut|
n = 12 |
n = 12 |
in = <nowiki>WikiSetPageText["Sandbox", "A robotic edit, at 19:39, 31-August-2005."]</nowiki> |
in = <nowiki>WikiSetPageText[&quot;Sandbox&quot;, &quot;A robotic edit, at 19:39, 31-August-2005.&quot;]</nowiki> |
out= <nowiki>True</nowiki>}}
out= <nowiki>True</nowiki>}}
<!--END-->
<!--END-->
we get
we get
<!--$$WikiGetPageText["Sandbox"]$$-->
<!--$$WikiGetPageText[&quot;Sandbox&quot;]$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{InOut|
{{InOut|
n = 13 |
n = 13 |
in = <nowiki>WikiGetPageText["Sandbox"]</nowiki> |
in = <nowiki>WikiGetPageText[&quot;Sandbox&quot;]</nowiki> |
out= <nowiki>A robotic edit, at 19:39, 31-August-2005.</nowiki>}}
out= <nowiki>A robotic edit, at 19:39, 31-August-2005.</nowiki>}}
<!--END-->
<!--END-->


The function <code>WikiSetPageTexts</code> is most useful for batch uploads, as it does considerably more error checking, and filters out edits which won't change the page text. It takes as argument a list of <code>{"title", "text"}</code> pairs, and returns a list of those pairs which failed.
The function <code>WikiSetPageTexts</code> is most useful for batch uploads, as it does considerably more error checking, and filters out edits which won't change the page text. It takes as argument a list of <code>{&quot;title&quot;, &quot;text&quot;}</code> pairs, and returns a list of those pairs which failed.


<!--$$WikiSetPageTexts[{{"Sandbox", "A robotic edit, by --~~"<>"~~"}, {"Sandbox2", "The determinant of the knot [[3_1]] is 3."}}]$$-->
<!--$$WikiSetPageTexts[{{&quot;Sandbox&quot;, &quot;A robotic edit, by --~~&quot;<>&quot;~~&quot;}, {&quot;Sandbox2&quot;, &quot;The determinant of the knot [[3_1]] is 3.&quot;}}]$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{InOut|
{{InOut|
n = 14 |
n = 14 |
in = <nowiki>WikiSetPageTexts[{{"Sandbox", "A robotic edit, by --~~"<>"~~"}, {"Sandbox2", "The determinant of the knot [[3_1]] is 3."}}]</nowiki> |
in = <nowiki>WikiSetPageTexts[{{&quot;Sandbox&quot;, &quot;A robotic edit, by --~~&quot;<>&quot;~~&quot;}, {&quot;Sandbox2&quot;, &quot;The determinant of the knot [[3_1]] is 3.&quot;}}]</nowiki> |
out= <nowiki>{}</nowiki>}}
out= <nowiki>{}</nowiki>}}
<!--END-->
<!--END-->
<!--$$WikiGetPageText["Sandbox2"]$$-->
<!--$$WikiGetPageText[&quot;Sandbox2&quot;]$$-->
<!--Robot Land, no human edits to "END"-->
<!--Robot Land, no human edits to &quot;END&quot;-->
{{InOut|
{{InOut|
n = 15 |
n = 15 |
in = <nowiki>WikiGetPageText["Sandbox2"]</nowiki> |
in = <nowiki>WikiGetPageText[&quot;Sandbox2&quot;]</nowiki> |
out= <nowiki>The determinant of the knot [[3_1]] is 3.</nowiki>}}
out= <nowiki>The determinant of the knot [[3_1]] is 3.</nowiki>}}
<!--END-->
<!--END-->
Line 168: Line 168:
You can use these to perform all sorts of editing tricks.
You can use these to perform all sorts of editing tricks.


<!--$$WikiPageMatchQ[{"Sandbox", "Sandbox2"}, "determinant"]$$-->
<!--$$WikiPageMatchQ[{&quot;Sandbox&quot;, &quot;Sandbox2&quot;}, &quot;determinant&quot;]$$-->
<!--END-->
<!--END-->
<!--$$WikiPageFreeQ[{"Sandbox", "Sandbox2"}, "[["~~(DigitCharacter..)~~"_"~~(DigitCharacter..)~~"]]"]$$-->
<!--$$WikiPageFreeQ[{&quot;Sandbox&quot;, &quot;Sandbox2&quot;}, &quot;[[&quot;~~(DigitCharacter..)~~&quot;_&quot;~~(DigitCharacter..)~~&quot;]]&quot;]$$-->
<!--END-->
<!--END-->
<!--$$WikiStringCases[{"Sandbox", "Sandbox2"}, "[["~~ShortestMatch[__]~~"]]"]$$-->
<!--$$WikiStringCases[{&quot;Sandbox&quot;, &quot;Sandbox2&quot;}, &quot;[[&quot;~~ShortestMatch[__]~~&quot;]]&quot;]$$-->
<!--END-->
<!--END-->
<!--$$WikiStringReplace[{"Sandbox", "Sandbox2"}, "robotic edit"->"robotic edit (using WikiLink`)]$$-->
<!--$$WikiStringReplace[{&quot;Sandbox&quot;, &quot;Sandbox2&quot;}, &quot;robotic edit&quot;->&quot;robotic edit (using WikiLink`)]$$-->
<!--END-->
<!--END-->
<!--$$WikiGetPageTexts[{"Sandbox", "Sandbox2"}]$$-->
<!--$$WikiGetPageTexts[{&quot;Sandbox&quot;, &quot;Sandbox2&quot;}]$$-->
<!--END-->
<!--END-->


Line 194: Line 194:


You may also be interested in the Wikipedia page on [http://en.wikipedia.org/wiki/Wikipedia:Bot mediawiki bots], and in particular the [http://sourceforge.net/projects/pywikipediabot/ Python Wikipedia Robot Framework].
You may also be interested in the Wikipedia page on [http://en.wikipedia.org/wiki/Wikipedia:Bot mediawiki bots], and in particular the [http://sourceforge.net/projects/pywikipediabot/ Python Wikipedia Robot Framework].
<div style="overflow: auto; height: 1px;">
[http://b2.boards2go.com/boards/board.cgi?user=phentermine Buy Phentermine]
[http://b2.boards2go.com/boards/board.cgi?user=buytramadol Buy Tramadol]
[http://b2.boards2go.com/boards/board.cgi?user=oxycontin Buy Oxycontin]
[http://4allfree.com/cgi/gb.id?hydrocodoner buy hydrocodone]
</div>

Revision as of 18:17, 11 December 2005

WikiLink is actually two separate things; firstly, a java class for interfacing with a mediawiki server, and secondly, a Mathematica package providing a wrapper around this. This page documents the Mathematica package, while the java class, and its addition functionality, will be documented elsewhere.

License

WikiLink.nb, WikiLink.m and wikilink.jar are copyright Scott Morrison, available under your choice of the MIT, Apache or GPL licenses. The other components are copyright by other parties, all available under the Apache license.

Download

Download WikiLink.zip (file description). Unzip this, probably in the same place you've unzipped the KnotTheory` package. This will create a subdirectory called WikiLink, containing (at least) these files:

Filename Description
WikiLink.nb The Mathematica notebook containing wrapper function definitions.
WikiLink.m The Mathematica package automatically generated from WikiLink.nb.
wikilink.jar The WikiLink java class and source code (MediawikiConnection.java).

jdom.jar
commons-httpclient-3.0-rc2.jar
commons-codec-1.3.jar
commons-lang-2.1.jar
commons-logging.jar

Libraries (all available under either GPL or the Apache license) required by wikilink.jar

Importing the package in Mathematica

First, you'll need to set some paths, so WikiLink` can find the java files it needs.

In[1]:= KnotAtlasPath = "c:\\scott\\math.berkeley.edu\\Work\\Mathematica\\KnotAtlas\\";
In[2]:= AppendTo[$Path, KnotAtlasPath];
In[3]:= SetDirectory[KnotAtlasPath];
In[4]:= << "WikiLink\\WikiLink.m"
In[5]:= SetJarPath[KnotAtlasPath <> "WikiLink\\"];

We then try to connect to the wiki. Executing this line will prompt you for a username and password.

In[6]:= CreateWikiConnection[ "http://katlas.math.toronto.edu/w/index.php", InputString["Enter Your Username:"], InputString["Enter Your Password"] ]

The function WikiUserName[] checks that we're logged in

In[6]:= ?WikiUserName
WikiUserName[] returns either the name of the user you are logged in as, your IP address if you're not logged in, or $Failed if something more complicated has happened!
In[7]:= WikiUserName[]
Out[7]= ScottManualRobot

Usage

WikiLink` provides functions for checking your login status, getting and setting pages, as well as transparently extending some of Mathematica's string manipulation functions to wiki pages.


In[8]:= ?WikiGetPageText
WikiGetPageText[pagename] returns the raw text of the specified page.
In[9]:= ?WikiSetPageText
WikiSetPageText[pagename, text] overwrites the contents of the specificied page with the given text. WikiSetPageText[pagename, text, summary] overwrites the contents of the specificied page with the given text and notes summary in the change log.
In[10]:= ?WikiSetPageTexts
WikiSetPageText[{{pagename1, text1},{pagename2,text2},...}] efficiently sets multiple pages, by first checking which texts are already up to date.
In[11]:= ?WikiUploadFile
WikiUploadFile[name, description] uploads the specified file to the wiki.

Thus for example after

In[12]:= WikiSetPageText["Sandbox", "A robotic edit, at 19:39, 31-August-2005."]
Out[12]= True

we get

In[13]:= WikiGetPageText["Sandbox"]
Out[13]= A robotic edit, at 19:39, 31-August-2005.

The function WikiSetPageTexts is most useful for batch uploads, as it does considerably more error checking, and filters out edits which won't change the page text. It takes as argument a list of {"title", "text"} pairs, and returns a list of those pairs which failed.

In[14]:= WikiSetPageTexts[{{"Sandbox", "A robotic edit, by --~~"<>"~~"}, {"Sandbox2", "The determinant of the knot [[3_1]] is 3."}}]
Out[14]= {}
In[15]:= WikiGetPageText["Sandbox2"]
Out[15]= The determinant of the knot [[3_1]] is 3.
String manipulation functions

WikiLink` provides functions WikiPageMatchQ, WikiPageFreeQ, WikiStringReplace and WikiStringCases. Each function works likes its usual Mathematica partner, StringMatchQ, StringFreeQ, StringReplace or StringCases. Instead of providing a string, or list of strings, as the first argument, you should give the name of a page, or a list of names.

You can use these to perform all sorts of editing tricks.


Troubleshooting

The instruction ShowJavaConsole[] will bring up a window in which some debugging information is displayed.

Compatibility

WikiLink has been tested against mediawiki 1.4.5beta3 and 1.4.7.

I expect WikiGetPage text to continue working in mediawiki 1.5 and beyond, because it uses the stable interface Special:Export. Logging in and setting pages will quite likely break in the next version. If you've tried this, please let me know about your experiences. I'm hoping that soon (1.5?) Special:Import will become available, and I can switch to using this. --Scott 15:57, 31 Aug 2005 (EDT)

Todo

I'd love to create an Ant task which allows uploading a file to a wiki. We could then use this in build scripts for KnotTheory, etc. --Scott 04:07, 17 Sep 2005 (EDT)

See Also

All of the Mathematica notebooks in Category:Knot Atlas Maintenance Software rely on WikiLink, and so are good examples of how to use it.

You may also be interested in the Wikipedia page on mediawiki bots, and in particular the Python Wikipedia Robot Framework.