[Mediawiki-l] PHP code to create/edit pages/sections

Kelly Jones kelly.terry.jones at gmail.com
Tue Jul 24 01:25:07 UTC 2007


On 7/22/07, Kelly Jones <kelly.terry.jones at 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!

-- 
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.



More information about the MediaWiki-l mailing list