On 05/01/07, Erhard Rainer mediawikimailinglist@erhard-rainer.com wrote:
I'm using an extension for parsing an external document. This works fine, but now I want to insert the content of a variable as a new article. So I took a look at maintenance\importTextFile.php as recommended and tried to write a new article using
Yeah, don't *call* the maintenance script. :)
For an extension, this is quite simple to achieve, at least in MediaWiki 1.7.0 and upwards. You'll need a Title object representing the page to be edited.
Assuming $text is the text to be inserted, and $title is the Title object:
if( !$title->exists() ) { $article = new Article( $title ); $article->doEdit( $text ); }
Article::doEdit() will accept other parameters; see the documentation. It handles saving the text, performing link table and search engine updates, and a whole host of other stuff.
Pre-1.7, well, it's a similar procedure, but broken up into a lot more steps; one has to create the Article object, use the insertOn method, create a Revision, insert that, update the Article, call link table updates...
Rob Church