Index: trunk/phase3/includes/Title.php |
— | — | @@ -3100,17 +3100,14 @@ |
3101 | 3101 | |
3102 | 3102 | $pageid = $this->getArticleID(); |
3103 | 3103 | $protected = $this->isProtected(); |
3104 | | - if ( $nt->exists() ) { |
3105 | | - $err = $this->moveOverExistingRedirect( $nt, $reason, $createRedirect ); |
3106 | | - $pageCountChange = ( $createRedirect ? 0 : -1 ); |
3107 | | - } else { # Target didn't exist, do normal move. |
3108 | | - $err = $this->moveToNewTitle( $nt, $reason, $createRedirect ); |
3109 | | - $pageCountChange = ( $createRedirect ? 1 : 0 ); |
3110 | | - } |
| 3104 | + $pageCountChange = ( $createRedirect ? 1 : 0 ) - ( $nt->exists() ? 1 : 0 ); |
3111 | 3105 | |
| 3106 | + // Do the actual move |
| 3107 | + $err = $this->moveToInternal( $nt, $reason, $createRedirect ); |
3112 | 3108 | if ( is_array( $err ) ) { |
3113 | 3109 | return $err; |
3114 | 3110 | } |
| 3111 | + |
3115 | 3112 | $redirid = $this->getArticleID(); |
3116 | 3113 | |
3117 | 3114 | // Refresh the sortkey for this row. Be careful to avoid resetting |
— | — | @@ -3210,64 +3207,73 @@ |
3211 | 3208 | } |
3212 | 3209 | |
3213 | 3210 | /** |
3214 | | - * Move page to a title which is at present a redirect to the |
3215 | | - * source page |
| 3211 | + * Move page to a title which is either a redirect to the |
| 3212 | + * source page or nonexistent |
3216 | 3213 | * |
3217 | | - * @param $nt \type{Title} the page to move to, which should currently |
3218 | | - * be a redirect |
| 3214 | + * @param $nt \type{Title} the page to move to, which should |
| 3215 | + * be a redirect or nonexistent |
3219 | 3216 | * @param $reason \type{\string} The reason for the move |
3220 | | - * @param $createRedirect \type{\bool} Whether to leave a redirect at the old title. |
3221 | | - * Ignored if the user doesn't have the suppressredirect right |
| 3217 | + * @param $createRedirect \type{\bool} Whether to leave a |
| 3218 | + * redirect at the old title. Ignored if the user doesn't |
| 3219 | + * have the suppressredirect right |
3222 | 3220 | */ |
3223 | | - private function moveOverExistingRedirect( &$nt, $reason = '', $createRedirect = true ) { |
3224 | | - global $wgUseSquid, $wgUser, $wgContLang; |
| 3221 | + private function moveToInternal( &$nt, $reason = '', $createRedirect = true ) { |
| 3222 | + global $wgUser, $wgContLang; |
3225 | 3223 | |
3226 | | - $comment = wfMsgForContent( '1movedto2_redir', $this->getPrefixedText(), $nt->getPrefixedText() ); |
| 3224 | + $moveOverRedirect = $nt->exists(); |
3227 | 3225 | |
| 3226 | + $commentMsg = ( $moveOverRedirect ? '1movedto2_redir' : '1movedto2' ); |
| 3227 | + $comment = wfMsgForContent( $commentMsg, $this->getPrefixedText(), $nt->getPrefixedText() ); |
| 3228 | + |
3228 | 3229 | if ( $reason ) { |
3229 | 3230 | $comment .= wfMsgForContent( 'colon-separator' ) . $reason; |
3230 | 3231 | } |
3231 | 3232 | # Truncate for whole multibyte characters. +5 bytes for ellipsis |
3232 | 3233 | $comment = $wgContLang->truncate( $comment, 250 ); |
3233 | 3234 | |
3234 | | - $now = wfTimestampNow(); |
3235 | | - $newid = $nt->getArticleID(); |
3236 | 3235 | $oldid = $this->getArticleID(); |
3237 | 3236 | $latest = $this->getLatestRevID(); |
3238 | 3237 | |
3239 | 3238 | $dbw = wfGetDB( DB_MASTER ); |
3240 | 3239 | |
3241 | | - $rcts = $dbw->timestamp( $nt->getEarliestRevTime() ); |
3242 | | - $newns = $nt->getNamespace(); |
3243 | | - $newdbk = $nt->getDBkey(); |
| 3240 | + if ( $moveOverRedirect ) { |
| 3241 | + $rcts = $dbw->timestamp( $nt->getEarliestRevTime() ); |
3244 | 3242 | |
3245 | | - # Delete the old redirect. We don't save it to history since |
3246 | | - # by definition if we've got here it's rather uninteresting. |
3247 | | - # We have to remove it so that the next step doesn't trigger |
3248 | | - # a conflict on the unique namespace+title index... |
3249 | | - $dbw->delete( 'page', array( 'page_id' => $newid ), __METHOD__ ); |
3250 | | - if ( !$dbw->cascadingDeletes() ) { |
3251 | | - $dbw->delete( 'revision', array( 'rev_page' => $newid ), __METHOD__ ); |
3252 | | - global $wgUseTrackbacks; |
3253 | | - if ( $wgUseTrackbacks ) { |
3254 | | - $dbw->delete( 'trackbacks', array( 'tb_page' => $newid ), __METHOD__ ); |
| 3243 | + $newid = $nt->getArticleID(); |
| 3244 | + $newns = $nt->getNamespace(); |
| 3245 | + $newdbk = $nt->getDBkey(); |
| 3246 | + |
| 3247 | + # Delete the old redirect. We don't save it to history since |
| 3248 | + # by definition if we've got here it's rather uninteresting. |
| 3249 | + # We have to remove it so that the next step doesn't trigger |
| 3250 | + # a conflict on the unique namespace+title index... |
| 3251 | + $dbw->delete( 'page', array( 'page_id' => $newid ), __METHOD__ ); |
| 3252 | + if ( !$dbw->cascadingDeletes() ) { |
| 3253 | + $dbw->delete( 'revision', array( 'rev_page' => $newid ), __METHOD__ ); |
| 3254 | + global $wgUseTrackbacks; |
| 3255 | + if ( $wgUseTrackbacks ) { |
| 3256 | + $dbw->delete( 'trackbacks', array( 'tb_page' => $newid ), __METHOD__ ); |
| 3257 | + } |
| 3258 | + $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ ); |
| 3259 | + $dbw->delete( 'imagelinks', array( 'il_from' => $newid ), __METHOD__ ); |
| 3260 | + $dbw->delete( 'categorylinks', array( 'cl_from' => $newid ), __METHOD__ ); |
| 3261 | + $dbw->delete( 'templatelinks', array( 'tl_from' => $newid ), __METHOD__ ); |
| 3262 | + $dbw->delete( 'externallinks', array( 'el_from' => $newid ), __METHOD__ ); |
| 3263 | + $dbw->delete( 'langlinks', array( 'll_from' => $newid ), __METHOD__ ); |
| 3264 | + $dbw->delete( 'redirect', array( 'rd_from' => $newid ), __METHOD__ ); |
3255 | 3265 | } |
3256 | | - $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ ); |
3257 | | - $dbw->delete( 'imagelinks', array( 'il_from' => $newid ), __METHOD__ ); |
3258 | | - $dbw->delete( 'categorylinks', array( 'cl_from' => $newid ), __METHOD__ ); |
3259 | | - $dbw->delete( 'templatelinks', array( 'tl_from' => $newid ), __METHOD__ ); |
3260 | | - $dbw->delete( 'externallinks', array( 'el_from' => $newid ), __METHOD__ ); |
3261 | | - $dbw->delete( 'langlinks', array( 'll_from' => $newid ), __METHOD__ ); |
3262 | | - $dbw->delete( 'redirect', array( 'rd_from' => $newid ), __METHOD__ ); |
| 3266 | + // If the target page was recently created, it may have an entry in recentchanges still |
| 3267 | + $dbw->delete( 'recentchanges', |
| 3268 | + array( 'rc_timestamp' => $rcts, 'rc_namespace' => $newns, 'rc_title' => $newdbk, 'rc_new' => 1 ), |
| 3269 | + __METHOD__ |
| 3270 | + ); |
3263 | 3271 | } |
3264 | | - // If the redirect was recently created, it may have an entry in recentchanges still |
3265 | | - $dbw->delete( 'recentchanges', |
3266 | | - array( 'rc_timestamp' => $rcts, 'rc_namespace' => $newns, 'rc_title' => $newdbk, 'rc_new' => 1 ), |
3267 | | - __METHOD__ |
3268 | | - ); |
3269 | 3272 | |
3270 | 3273 | # Save a null revision in the page's history notifying of the move |
3271 | 3274 | $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true ); |
| 3275 | + if ( !is_object( $nullRevision ) ) { |
| 3276 | + throw new MWException( 'No valid null revision produced in ' . __METHOD__ ); |
| 3277 | + } |
3272 | 3278 | $nullRevId = $nullRevision->insertOn( $dbw ); |
3273 | 3279 | |
3274 | 3280 | $article = new Article( $this ); |
— | — | @@ -3276,7 +3282,7 @@ |
3277 | 3283 | # Change the name of the target page: |
3278 | 3284 | $dbw->update( 'page', |
3279 | 3285 | /* SET */ array( |
3280 | | - 'page_touched' => $dbw->timestamp( $now ), |
| 3286 | + 'page_touched' => $dbw->timestamp(), |
3281 | 3287 | 'page_namespace' => $nt->getNamespace(), |
3282 | 3288 | 'page_title' => $nt->getDBkey(), |
3283 | 3289 | 'page_latest' => $nullRevId, |
— | — | @@ -3318,103 +3324,17 @@ |
3319 | 3325 | |
3320 | 3326 | # Log the move |
3321 | 3327 | $log = new LogPage( 'move' ); |
3322 | | - $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) ); |
| 3328 | + $logType = ( $moveOverRedirect ? 'move_redir' : 'move' ); |
| 3329 | + $log->addEntry( $logType, $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) ); |
3323 | 3330 | |
3324 | | - # Purge squid |
3325 | | - if ( $wgUseSquid ) { |
3326 | | - $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() ); |
3327 | | - $u = new SquidUpdate( $urls ); |
3328 | | - $u->doUpdate(); |
3329 | | - } |
3330 | | - |
3331 | | - } |
3332 | | - |
3333 | | - /** |
3334 | | - * Move page to non-existing title. |
3335 | | - * |
3336 | | - * @param $nt \type{Title} the new Title |
3337 | | - * @param $reason \type{\string} The reason for the move |
3338 | | - * @param $createRedirect \type{\bool} Whether to create a redirect from the old title to the new title |
3339 | | - * Ignored if the user doesn't have the suppressredirect right |
3340 | | - */ |
3341 | | - private function moveToNewTitle( &$nt, $reason = '', $createRedirect = true ) { |
3342 | | - global $wgUser, $wgContLang; |
3343 | | - |
3344 | | - $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() ); |
3345 | | - if ( $reason ) { |
3346 | | - $comment .= wfMsgExt( 'colon-separator', |
3347 | | - array( 'escapenoentities', 'content' ) ); |
3348 | | - $comment .= $reason; |
3349 | | - } |
3350 | | - # Truncate for whole multibyte characters. +5 bytes for ellipsis |
3351 | | - $comment = $wgContLang->truncate( $comment, 250 ); |
3352 | | - |
3353 | | - $oldid = $this->getArticleID(); |
3354 | | - $latest = $this->getLatestRevId(); |
3355 | | - |
3356 | | - $dbw = wfGetDB( DB_MASTER ); |
3357 | | - $now = $dbw->timestamp(); |
3358 | | - |
3359 | | - # Save a null revision in the page's history notifying of the move |
3360 | | - $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true ); |
3361 | | - if ( !is_object( $nullRevision ) ) { |
3362 | | - throw new MWException( 'No valid null revision produced in ' . __METHOD__ ); |
3363 | | - } |
3364 | | - $nullRevId = $nullRevision->insertOn( $dbw ); |
3365 | | - |
3366 | | - $article = new Article( $this ); |
3367 | | - wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) ); |
3368 | | - |
3369 | | - # Rename page entry |
3370 | | - $dbw->update( 'page', |
3371 | | - /* SET */ array( |
3372 | | - 'page_touched' => $now, |
3373 | | - 'page_namespace' => $nt->getNamespace(), |
3374 | | - 'page_title' => $nt->getDBkey(), |
3375 | | - 'page_latest' => $nullRevId, |
3376 | | - ), |
3377 | | - /* WHERE */ array( 'page_id' => $oldid ), |
3378 | | - __METHOD__ |
3379 | | - ); |
3380 | | - $nt->resetArticleID( $oldid ); |
3381 | | - |
3382 | | - if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) { |
3383 | | - # Insert redirect |
3384 | | - $mwRedir = MagicWord::get( 'redirect' ); |
3385 | | - $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n"; |
3386 | | - $redirectArticle = new Article( $this ); |
3387 | | - $newid = $redirectArticle->insertOn( $dbw ); |
3388 | | - $redirectRevision = new Revision( array( |
3389 | | - 'page' => $newid, |
3390 | | - 'comment' => $comment, |
3391 | | - 'text' => $redirectText ) ); |
3392 | | - $redirectRevision->insertOn( $dbw ); |
3393 | | - $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 ); |
3394 | | - |
3395 | | - wfRunHooks( 'NewRevisionFromEditComplete', array( $redirectArticle, $redirectRevision, false, $wgUser ) ); |
3396 | | - |
3397 | | - # Record the just-created redirect's linking to the page |
3398 | | - $dbw->insert( 'pagelinks', |
3399 | | - array( |
3400 | | - 'pl_from' => $newid, |
3401 | | - 'pl_namespace' => $nt->getNamespace(), |
3402 | | - 'pl_title' => $nt->getDBkey() ), |
3403 | | - __METHOD__ ); |
3404 | | - $redirectSuppressed = false; |
| 3331 | + # Purge caches for old and new titles |
| 3332 | + if ( $moveOverRedirect ) { |
| 3333 | + # A simple purge is enough when moving over a redirect |
| 3334 | + $nt->purgeSquid(); |
3405 | 3335 | } else { |
3406 | | - $this->resetArticleID( 0 ); |
3407 | | - $redirectSuppressed = true; |
| 3336 | + # Purge caches as per article creation, including any pages that link to this title |
| 3337 | + Article::onArticleCreate( $nt ); |
3408 | 3338 | } |
3409 | | - |
3410 | | - # Log the move |
3411 | | - $log = new LogPage( 'move' ); |
3412 | | - $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) ); |
3413 | | - |
3414 | | - # Purge caches as per article creation |
3415 | | - Article::onArticleCreate( $nt ); |
3416 | | - |
3417 | | - # Purge old title from squid |
3418 | | - # The new title, and links to the new title, are purged in Article::onArticleCreate() |
3419 | 3339 | $this->purgeSquid(); |
3420 | 3340 | } |
3421 | 3341 | |