Last modified: 2010-05-15 15:59:47 UTC
According to: http://www.mediawiki.org/wiki/Manual:Hooks/TitleMoveComplete 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.
Try to use $title->getArticleID() rather than accessing mArticleID directly. The former will load the ID from the database if it's zero.
mArticleID is a private member and should never be directly accessed; IDs are often lazy-initialized.
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. Example: _______________________________________ 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(); var_dump($id); var_dump($newid); 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?
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.
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. var_dump($newTitle->getArticleID()); $temp = new Article($newTitle); var_dump($temp); var_dump($temp->getArticleID()); die("debugstop"); } _______________________________________ Here's the output. The error message is little extra-fancy since XDebug is installed. _______________________________________ int 0 object(Article)[119] 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' => & object(Title)[112] 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' => array empty 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' => array empty public 'mCascadingRestrictions' => array 'edit' => array ... 'move' => array ... 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?
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.
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.
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 __________
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 http://svn.wikimedia.org/svnroot/mediawiki/branches/REL1_12/phase3
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...)
By the way, has anyone else been able to replicate this problem?
Tested on 1.14a with var_dump(). Works OK.