I want to write PHP code for a MediaWiki I own (I have command-line + admin access) that:
% Checks if a given article exists, and creates it if not.
% Checks if a given section exists in an article, and creates it if not.
% Edits a given section in a given article.
I want the edit to be done just as if a user had gone in and edited the page: it should create a history entry, update all the appropriate tables, update the page in the cache, etc.
Can I use MediaWiki's PHP functions/libraries to do this?
I realize I can use wget/curl/lynx/elinks to do this, but was looking for something more "internal".
On a related note, does MediaWiki come w/ any maintenance tools? Examples:
% Auto-fix all double redirects (if X -> Y -> Z, just edit X to redirect directly to Z).
% Find all instances of certain words (eg, spam), and revert to the previous version of each page that contains those words (crude anti-vandalism tool). Delete pages where there is no previous version.
% For commonly misspelled articles, find all instances of [[wrong spelling]] and change them to [[correct spelling]] (redirecting "wrong spelling" to "right spelling" sort of works, but it still leaves the link misspelled on many pages)
I realize SQL queries can do some of this, but they won't update the history, won't handle caching issues properly, etc. I'm looking for something that works within MediaWiki's framework, not an outside hack.
On Jul 22, 2007, at 8:33 PM, Kelly Jones wrote:
I want to write PHP code for a MediaWiki I own (I have command-line + admin access) that:
% Checks if a given article exists, and creates it if not.
From the shell or from a browser? In general, you can do a lot of the things you want by pulling the current version of an article from the database, manipulating it with liberal use of regular expressions, saving the new version to an XML file compatible with importDump, and importing it.
You can also skip the importDump part by using some of the interfaces available via other maintenance scripts. I've been doing a lot of this for my wiki project. I hope to make some code available after it's been worked over to make it less obviously hacky!
JH
% Checks if a given section exists in an article, and creates it if not.
% Edits a given section in a given article.
I want the edit to be done just as if a user had gone in and edited the page: it should create a history entry, update all the appropriate tables, update the page in the cache, etc.
Can I use MediaWiki's PHP functions/libraries to do this?
I realize I can use wget/curl/lynx/elinks to do this, but was looking for something more "internal".
On a related note, does MediaWiki come w/ any maintenance tools? Examples:
% Auto-fix all double redirects (if X -> Y -> Z, just edit X to redirect directly to Z).
% Find all instances of certain words (eg, spam), and revert to the previous version of each page that contains those words (crude anti-vandalism tool). Delete pages where there is no previous version.
% For commonly misspelled articles, find all instances of [[wrong spelling]] and change them to [[correct spelling]] (redirecting "wrong spelling" to "right spelling" sort of works, but it still leaves the link misspelled on many pages)
I realize SQL queries can do some of this, but they won't update the history, won't handle caching issues properly, etc. I'm looking for something that works within MediaWiki's framework, not an outside hack.
-- We're just a Bunch Of Regular Guys, a collective group that's trying to understand and assimilate technology. We feel that resistance to new ideas and technology is unwise and ultimately futile.
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
===================================== Jim Hu Associate Professor Dept. of Biochemistry and Biophysics 2128 TAMU Texas A&M Univ. College Station, TX 77843-2128 979-862-4054
Kelly Jones wrote:
I want to write PHP code for a MediaWiki I own (I have command-line + admin access) that:
% Checks if a given article exists, and creates it if not.
% Checks if a given section exists in an article, and creates it if not.
% Edits a given section in a given article.
I want the edit to be done just as if a user had gone in and edited the page: it should create a history entry, update all the appropriate tables, update the page in the cache, etc.
Can I use MediaWiki's PHP functions/libraries to do this?
I think using a mediawiki bot framework like pywikipedia would be easier.
I realize I can use wget/curl/lynx/elinks to do this, but was looking for something more "internal".
On a related note, does MediaWiki come w/ any maintenance tools? Examples:
% Auto-fix all double redirects (if X -> Y -> Z, just edit X to redirect directly to Z).
There's a pywikipedia script to do that.
% Find all instances of certain words (eg, spam), and revert to the previous version of each page that contains those words (crude anti-vandalism tool). Delete pages where there is no previous version.
run maintenance/cleanupSpam.php
% For commonly misspelled articles, find all instances of [[wrong spelling]] and change them to [[correct spelling]] (redirecting "wrong spelling" to "right spelling" sort of works, but it still leaves the link misspelled on many pages)
run pywikipedia to change the links.
I realize SQL queries can do some of this, but they won't update the history, won't handle caching issues properly, etc. I'm looking for something that works within MediaWiki's framework, not an outside hack.
On Jul 23, 2007, at 5:41 AM, Platonides wrote:
Kelly Jones wrote:
I want to write PHP code for a MediaWiki I own (I have command-line + admin access) that:
% Checks if a given article exists, and creates it if not.
% Checks if a given section exists in an article, and creates it if not.
% Edits a given section in a given article.
I want the edit to be done just as if a user had gone in and edited the page: it should create a history entry, update all the appropriate tables, update the page in the cache, etc.
Can I use MediaWiki's PHP functions/libraries to do this?
I think using a mediawiki bot framework like pywikipedia would be easier.
I've found that the pywikipedia bots are too slow for doing large scale work... but obviously they work on Wikipedia, so perhaps it's just that my server can't handle the self-inflicted http load.
I realize I can use wget/curl/lynx/elinks to do this, but was looking for something more "internal".
On a related note, does MediaWiki come w/ any maintenance tools? Examples:
% Auto-fix all double redirects (if X -> Y -> Z, just edit X to redirect directly to Z).
There's a pywikipedia script to do that.
% Find all instances of certain words (eg, spam), and revert to the previous version of each page that contains those words (crude anti-vandalism tool). Delete pages where there is no previous version.
run maintenance/cleanupSpam.php
% For commonly misspelled articles, find all instances of [[wrong spelling]] and change them to [[correct spelling]] (redirecting "wrong spelling" to "right spelling" sort of works, but it still leaves the link misspelled on many pages)
run pywikipedia to change the links.
I realize SQL queries can do some of this, but they won't update the history, won't handle caching issues properly, etc. I'm looking for something that works within MediaWiki's framework, not an outside hack.
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
===================================== Jim Hu Associate Professor Dept. of Biochemistry and Biophysics 2128 TAMU Texas A&M Univ. College Station, TX 77843-2128 979-862-4054
On 7/22/07, Kelly Jones kelly.terry.jones@gmail.com wrote:
I want to write PHP code for a MediaWiki I own (I have command-line + admin access) that:
% Checks if a given article exists, and creates it if not.
[...]
I want the edit to be done just as if a user had gone in and edited the page: it should create a history entry, update all the appropriate tables, update the page in the cache, etc.
Thanks to everyone who helped out here. It turns out this is fairly easy. This PHP command-line code (5 lines, excluding comments):
== CUT HERE ==
# Initialization require_once( './includes/WebStart.php' ); require_once( "includes/Wiki.php" ); $mediaWiki = new MediaWiki();
$article = new Article( $mediaWiki->checkInitialQueries("EditMe","",$wgOut,$wgRequest,$wgContLang) ); $article->doEdit("this is page text", "i made some changes");
== CUT HERE ==
will create the page "EditMe" with the text "this is page text" and history comment "i made some changes".
If the page already exists, the code above will edit it, replacing its current text with "this is page text" (and the history comment "i made some changes".
Because it uses MediaWiki's framework, it appears to update all the tables/caches/etc correctly.
It doesn't do everything I want (the Article::getSection() function is sadly deprecated), but it's a great start!
mediawiki-l@lists.wikimedia.org