I am trying to create a new article eventually from a form you would fill out. The contents of the form would then be part of the article which you could edit.
At this point all I want to do is create a new article with the name I specify. I am trying to use the Article and Title classes and use the function insertNewArticle(***) to accomplish this, but I keep getting database insert errors:
Here is my sample code:
$myTitle = new Title("Change Control Test");
$myArticle = new Article($myTitle);
$myArticle->onArticleCreate($myTitle);
$myArticle->insertNewArticle( "A test article", "Just Testing", FALSE, FALSE );
And the error:
A database error has occurred Query: INSERT INTO `cur` (cur_id,cur_namespace,cur_title,cur_text,cur_comment,cur_user,cur_timest amp,cur_minor_edit,cur_counter,cur_restrictions,cur_user_text,cur_is_red irect,cur_is_new,cur_random,cur_touched,inverse_timestamp) VALUES (NULL,'0','','A test article','Just Testing','1','20051013212242','0','0','','Mharris','0','1','0.0116757728 88','20051013212242','79948986787757') Function: Article::insertNewArticle Error: 1062 Duplicate entry '0-' for key 2 (localhost)
Backtrace:
* GlobalFunctions.php line 524 calls wfBacktrace() * Database.php line 383 calls wfDebugDieBacktrace() * Database.php line 333 calls Database::reportQueryError() * Database.php line 911 calls Database::query() * Article.php line 885 calls Database::insert() * ChangeControlExtension.php line 30 calls Article::insertNewArticle() * ChangeControlExtension.php line 45 calls ChangeControlPage::ChangeControlPage() * Setup.php line 381 calls wfChangeControlExtension() * index.php line 26 calls require_once()
What is the best way to create a new article from an extension? I am using mediaiwiki 1.4.10.
Thanks,
Mike
Harris, Mike wrote:
$myTitle = new Title("Change Control Test");
You might want to look at the existing code for how title objects are created. There are factory functions for this.
-- brion vibber (brion @ pobox.com)
Brion Vibber wrote:
Harris, Mike wrote:
$myTitle = new Title("Change Control Test");
You might want to look at the existing code for how title objects are created. There are factory functions for this.
I've been wondering for a while why the code above doesn't work. It looks much nicer than Title::newFromText(). Why can't we have sensible constructors for Title and User?
Of course, I'm the perpetrator of horrible entities such as Database::newFromParams(), but in my defence, I was just trying to fit in.
-- Tim Starling
Tim Starling wrote:
Brion Vibber wrote:
Harris, Mike wrote:
$myTitle = new Title("Change Control Test");
You might want to look at the existing code for how title objects are created. There are factory functions for this.
I've been wondering for a while why the code above doesn't work. It looks much nicer than Title::newFromText(). Why can't we have sensible constructors for Title and User?
Of course, I'm the perpetrator of horrible entities such as Database::newFromParams(), but in my defence, I was just trying to fit in.
It probably would be reasonable, but we'd need to change some stuff. It doesn't work now. :)
One of the reasons we use static factory methods in various places is to provide semantically clear alternatives when there are mutliple different ways; for instance on Titles things get handled differently depending on whether the source text is from a URL or from wiki text. Or... something like that.
That one's a little confusing; others are clearer, eg taking an id number versus a name, or whatever.
-- brion vibber (brion @ pobox.com)
Harris, Mike wrote:
I am trying to create a new article eventually from a form you would fill out. The contents of the form would then be part of the article which you could edit.
You are aware of [[m:Help:Inputbox]] http://meta.wikimedia.org/wiki/Help:Inputbox, correct?
At this point all I want to do is create a new article with the name I specify. I am trying to use the Article and Title classes and use the function insertNewArticle(***) to accomplish this, but I keep getting database insert errors:
Here is my sample code:
$myTitle = new Title("Change Control Test"); $myArticle = new Article($myTitle); $myArticle->onArticleCreate($myTitle); $myArticle->insertNewArticle( "A test article", "Just Testing", FALSE, FALSE );
Do you have code to check that the user is actually allowed to create the article? Article::insertNewArticle() doesn't do this (in 1.5 or 1.4).
And the error:
A database error has occurred Query: INSERT INTO `cur` (cur_id,cur_namespace,cur_title,cur_text,cur_comment,cur_user,cur_timest amp,cur_minor_edit,cur_counter,cur_restrictions,cur_user_text,cur_is_red irect,cur_is_new,cur_random,cur_touched,inverse_timestamp) VALUES (NULL,'0','','A test article','Just Testing','1','20051013212242','0','0','','Mharris','0','1','0.0116757728 88','20051013212242','79948986787757') Function: Article::insertNewArticle Error: 1062 Duplicate entry '0-' for key 2 (localhost)
The sound of the error would indicate that you already have an article by that name (ie, your extension should check if the article exists before working). I also noticed that the cur_title is '' (empty string), so the article will likely be inaccessable.
Backtrace:
- GlobalFunctions.php line 524 calls wfBacktrace()
- Database.php line 383 calls wfDebugDieBacktrace()
- Database.php line 333 calls Database::reportQueryError()
- Database.php line 911 calls Database::query()
- Article.php line 885 calls Database::insert()
- ChangeControlExtension.php line 30 calls
Article::insertNewArticle()
- ChangeControlExtension.php line 45 calls
ChangeControlPage::ChangeControlPage()
- Setup.php line 381 calls wfChangeControlExtension()
- index.php line 26 calls require_once()
Is ChangeControlExtension.php your thing?
What is the best way to create a new article from an extension? I am using mediaiwiki 1.4.10.
The EditPage class if you really feel like having kludges and hacks around.
-- Jamie ------------------------------------------------------------------- http://endeavour.zapto.org/astro73/ Thank you to JosephM for inviting me to Gmail! Have lots of invites. Gmail now has 2GB.
mediawiki-l@lists.wikimedia.org