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!