From 9d9b5af04d80f9780bb3eaa554792607a189227c Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 10 Aug 2011 18:32:22 +0000 Subject: [PATCH] Made moveToInternal() check result of Article::insertOn (related to bug 26223) --- includes/Title.php | 54 +++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index bea3c2284f..a6a9d7e19f 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1235,7 +1235,7 @@ class Title { */ private function checkQuickPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { $ns = $this->getNamespace(); - + if ( $action == 'create' ) { if ( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk', $ns ) ) || ( !$this->isTalkPage() && !$user->isAllowed( 'createpage', $ns ) ) ) { @@ -1256,9 +1256,9 @@ class Title { if ( !$user->isAllowed( 'move', $ns) ) { // User can't move anything - $userCanMove = in_array( 'move', User::getGroupPermissions( + $userCanMove = in_array( 'move', User::getGroupPermissions( array( 'user' ), $ns ), true ); - $autoconfirmedCanMove = in_array( 'move', User::getGroupPermissions( + $autoconfirmedCanMove = in_array( 'move', User::getGroupPermissions( array( 'autoconfirmed' ), $ns ), true ); if ( $user->isAnon() && ( $userCanMove || $autoconfirmedCanMove ) ) { @@ -1511,8 +1511,8 @@ class Title { if( $title_protection['pt_create_perm'] == 'sysop' ) { $title_protection['pt_create_perm'] = 'protect'; // B/C } - if( $title_protection['pt_create_perm'] == '' || - !$user->isAllowed( $title_protection['pt_create_perm'], + if( $title_protection['pt_create_perm'] == '' || + !$user->isAllowed( $title_protection['pt_create_perm'], $this->mNamespace ) ) { $errors[] = array( 'titleprotected', User::whoIs( $title_protection['pt_user'] ), $title_protection['pt_reason'] ); } @@ -2369,7 +2369,7 @@ class Title { $fconditions[] = $dbr->bitAnd('fa_deleted', $suppressedTextBits ) . ' != ' . $suppressedTextBits; } - + $n += $dbr->selectField( 'filearchive', 'COUNT(*)', $fconditions, @@ -3339,7 +3339,8 @@ class Title { $nt->resetArticleID( $oldid ); $article = new Article( $nt ); - wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) ); + wfRunHooks( 'NewRevisionFromEditComplete', + array( $article, $nullRevision, $latest, $wgUser ) ); $article->setCachedLastEditTime( $now ); # Recreate the redirect, this time in the other direction. @@ -3348,24 +3349,27 @@ class Title { $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n"; $redirectArticle = new Article( $this ); $newid = $redirectArticle->insertOn( $dbw ); - $redirectRevision = new Revision( array( - 'page' => $newid, - 'comment' => $comment, - 'text' => $redirectText ) ); - $redirectRevision->insertOn( $dbw ); - $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 ); - - wfRunHooks( 'NewRevisionFromEditComplete', array( $redirectArticle, $redirectRevision, false, $wgUser ) ); - - # Now, we record the link from the redirect to the new title. - # It should have no other outgoing links... - $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ ); - $dbw->insert( 'pagelinks', - array( - 'pl_from' => $newid, - 'pl_namespace' => $nt->getNamespace(), - 'pl_title' => $nt->getDBkey() ), - __METHOD__ ); + if ( $newid ) { // sanity + $redirectRevision = new Revision( array( + 'page' => $newid, + 'comment' => $comment, + 'text' => $redirectText ) ); + $redirectRevision->insertOn( $dbw ); + $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 ); + + wfRunHooks( 'NewRevisionFromEditComplete', + array( $redirectArticle, $redirectRevision, false, $wgUser ) ); + + # Now, we record the link from the redirect to the new title. + # It should have no other outgoing links... + $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ ); + $dbw->insert( 'pagelinks', + array( + 'pl_from' => $newid, + 'pl_namespace' => $nt->getNamespace(), + 'pl_title' => $nt->getDBkey() ), + __METHOD__ ); + } $redirectSuppressed = false; } else { $this->resetArticleID( 0 ); -- 2.20.1