Last modified: 2010-05-15 15:59:47 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 13204 - Hook: TitleMoveComplete, Wrong Page ID present
Hook: TitleMoveComplete, Wrong Page ID present
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
All All
: Normal minor (vote)
: ---
Assigned To: Nobody - You can work on this!
Depends on:
  Show dependency treegraph
Reported: 2008-02-29 23:51 UTC by Darien Hager
Modified: 2010-05-15 15:59 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Description Darien Hager 2008-02-29 23:51:06 UTC
According to:

The first two arguments are title objects, corresponding to the old Title (which now refers to the just-generated redirect page) and the "New" title which points back to the original page.

The old-title object has the correct mArticleID corresponding to the new redirect page.

By contrast, the new-title object's mArticleID is zero. Instead, it should refer to the original page which has just completed being retitled.
Comment 1 Roan Kattouw 2008-03-01 09:27:27 UTC
Try to use $title->getArticleID() rather than accessing mArticleID directly. The former will load the ID from the database if it's zero.
Comment 2 Brion Vibber 2008-03-02 21:49:19 UTC
mArticleID is a private member and should never be directly accessed; IDs are often lazy-initialized.
Comment 3 Darien Hager 2008-03-03 18:19:25 UTC
Please, this is not an invalid issue--I know it may be lazily loaded and am using what appears to be the correct API calls.

Here's the problem: I can get the ID from the hook function signature's fourth argument, but I am having problems instantiating any valid Article object for it which does not break just like the one that is passed as the first argument.

public function testRename(&$title, &$newtitle, &$user, $corePageId, $newRedirId)
	// $corePageId is set correctly, but I need a valid Article object, not an integer.
	$id = $title->getArticleID();
	$newid = $newtitle->getArticleID();
	die("testing, debug stop");

Output is:
string '30' (length=2)

int 0

testing, debug stop

As you can see, the ID was not loaded. This assertion also fails:
$temptitle = Title::newFromID($corePageId); // (Doesn't work even with GAID_FOR_UPDATE as second arg)
assert($fixedNewTitle->getArticleID() > 0);

Is it possible the hook is called before the move/rename is truly complete?
Comment 4 Roan Kattouw 2008-03-03 18:23:27 UTC
Can't you just construct an article object with

$articleObj = new Article($newtitle);

(In reply to comment #3)
> Is it possible the hook is called before the move/rename is truly complete?
What I think is happening is that the article ID was loaded before the move, and isn't reloaded.

Comment 5 Darien Hager 2008-03-03 18:48:29 UTC
The Title object (I misspoke in my last post identifying an input as an Article) is still broken.
public function testRename(&$oldTitle, &$newTitle, &$user, $contentArticleId, $redirArticleId)
	// This var_dump() ought to match the value of $contentArticleId.
	$temp = new Article($newTitle);

Here's the output. The error message is little extra-fancy since XDebug is installed.

int 0

  public 'mComment' => string '' (length=0)
  public 'mContent' => null
  public 'mContentLoaded' => boolean false
  public 'mCounter' => int -1
  public 'mForUpdate' => boolean false
  public 'mGoodAdjustment' => int 0
  public 'mLatest' => boolean false
  public 'mMinorEdit' => null
  public 'mOldId' => null
  public 'mRedirectedFrom' => null
  public 'mRedirectUrl' => boolean false
  public 'mRevIdFetched' => int 0
  public 'mRevision' => null
  public 'mTimestamp' => string '' (length=0)
  public 'mTitle' => &
      public 'mTextform' => string 'Test Page32' (length=11)
      public 'mUrlform' => string 'Test_Page32' (length=11)
      public 'mDbkeyform' => string 'Test_Page32' (length=11)
      public 'mUserCaseDBKey' => string 'Test_Page32' (length=11)
      public 'mNamespace' => int 0
      public 'mInterwiki' => string '' (length=0)
      public 'mFragment' => string '' (length=0)
      public 'mArticleID' => int 0
      public 'mLatestID' => boolean false
      public 'mRestrictions' => 
      public 'mCascadeRestriction' => null
      public 'mRestrictionsExpiry' => null
      public 'mHasCascadingRestrictions' => null
      public 'mCascadeRestrictionSources' => null
      public 'mRestrictionsLoaded' => boolean false
      public 'mPrefixedText' => string 'Test Page32' (length=11)
      public 'mDefaultNamespace' => int 0
      public 'mWatched' => null
      public 'mOldRestrictions' => boolean false
      public 'mCascadeSources' => 
      public 'mCascadingRestrictions' => 
          'edit' => 
          'move' => 
  public 'mTotalAdjustment' => int 0
  public 'mTouched' => string '19700101000000' (length=14)
  public 'mUser' => int -1
  public 'mUserText' => string '' (length=0)
  public 'mDataLoaded' => boolean false
  public 'mCurID' => int -1
  public 'mIsRedirect' => boolean false

( ! ) Fatal error: Call to undefined method Article::getArticleID() in /var/www/accounts/aa74ce4ceb83430cba264edc09dc3e98/b6a0ae9602634a6f8cb5ba843e07da68/etelos/wikihelp.php on line 112
Call Stack
#	Time	Memory	Function	Location
1	0.0485	80084	{main}( )	../index.php:0
2	0.1078	3942832	MediaWiki->initialize( object(Title)[6], object(OutputPage)[7], object(User)[17], object(WebRequest)[3] )	../index.php:89
3	0.1346	5665612	MediaWiki->initializeSpecialCases( object(Title)[6], object(OutputPage)[7], object(WebRequest)[3] )	../Wiki.php:45
4	0.1373	5926160	SpecialPage::executePath( object(Title)[6], ??? )	../Wiki.php:201
5	0.1409	5945660	SpecialPage->execute( null )	../SpecialPage.php:459
6	0.1977	7937328	wfSpecialMovepage( null, object(UnlistedSpecialPage)[8] )	../SpecialPage.php:653
7	0.2068	8255308	MovePageForm->doSubmit( )	../SpecialMovepage.php:37
8	0.2103	8483908	Title->moveTo( object(Title)[112], bool, string(0) )	../SpecialMovepage.php:219
9	0.2790	10221192 wfRunHooks( string(17), array(5) )	../Title.php:2226
10	0.2791	10221220 call_user_func_array ( array(2), array(5) )	../Hooks.php:113
11	0.2792	10221220 testWikiClass->testRename( object(Title)[111], object(Title)[112], object(User)[17], string(2), string(2) )	../Hooks.php:0

By the way, does Bugzilla support any particular quoting facility other than attachments? 
Comment 6 Darien Hager 2008-03-03 18:52:07 UTC
I'm sorry, I need caffeine. Of COURSE that doesn't work.

When I don't screw up, it prints Zero where that Fatal error was. 
Comment 7 Roan Kattouw 2008-03-03 19:19:27 UTC
On second thought, I think something entirely different is going on.

The move hasn't been committed to the database yet, so the Title and Article classes sincerely believe their target doesn't exist yet and report ID=0. If I'm right about this (not sure, can another dev confirm/deny this please?) you can still get the page ID of the moved page by fetching the source page ID (the ID of the old title), as page IDs don't change when moving pages.
Comment 8 Darien Hager 2008-03-03 19:52:07 UTC
Nope, I've been doing step-through debugging and problems manifest even when the database changes are already committed. That is page.page_title has changed.

As for the page ID of the old title, I can get that from the function parameters... The problem is I can't seem to do anything useful with it. Or rather, the fact that I cannot get it from anywhere else (e.g. from the valid title string) is a canary in the coal mine for larger problems.

$myTitle = Title::newFromID($correctId);
$myArticle = new Article($myTitle);
assert(arty->getID() != 0);//Failed, is integer zero
assert($arty->getLatest()); //Failed, is boolean false
Comment 9 Brion Vibber 2008-03-03 19:57:17 UTC
I seem to remember a fix for this floating by. Can you try with trunk (1.13 SVN) or 1.12 branch and see if it's fixed?

Can check out 1.12 prerelease with:
svn co
Comment 10 Darien Hager 2008-03-04 02:28:30 UTC
It still happens with the 1.11.2 release... I'll see if I can find time to try it with one of the SVN copies.

I'm actually doing some additional customizations and DB changes, so I can't just drop the new sources on. (And it seems the database schema changes in any event...)
Comment 11 Darien Hager 2008-03-06 00:07:52 UTC
By the way, has anyone else been able to replicate this problem?
Comment 12 Aaron Schulz 2008-12-13 21:28:42 UTC
Tested on 1.14a with var_dump(). Works OK.

Note You need to log in before you can comment on or make changes to this bug.