Hi MediaWiki-User and Developer,
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
require_once( 'importTextFile.inc' ); .... insertNewArticle( $title, $text, $user, $comment, $rc );
after testing if the article exists and the user is allowed to write new articles.
But I receive the following message:
Fatal error: Call to a member function exists() on a non-object in importTextFile.inc on line 24
What does this mean? Or is there a other way to create new articles using an extension.
Thanks in advanced
Erhard Rainer
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
Hello,
Assuming $text is the text to be inserted, and $title is the Title object:
if( !$title->>exists() ) { $article = new Article( $title ); $article->doEdit( $text ); }
now I get "Fatal error: Call to a member function exists() on a non-object".
Article::doEdit() will accept other parameters; see the documentation.
Where can I find documentations of functions like doEdit()?
TIA Erhard
mailto:mediawikimailinglist@erhard-rainer.com
On 06/01/07, Erhard Rainer mediawikimailinglist@erhard-rainer.com wrote:
now I get "Fatal error: Call to a member function exists() on a non-object".
Well, Title needs to be an object; you need to use one of the Title factory functions, e.g.
$title = Title::newFromText( 'Some page' );
It might also be a good idea to check that the title was created, using is_object() too.
Where can I find documentations of functions like doEdit()?
Either in the code itself or via http://svn.wikimedia.org/doc.
Rob Church
mediawiki-l@lists.wikimedia.org