r33578 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33577‎ | r33578 | r33579 >
Date:23:53, 18 April 2008
Author:brion
Status:old
Tags:
Comment:
Revert r33565 pending some cleanup...

A few notes:

* This seems to drop the 'action=success' page in favor of dumping all the output directly on the POST response. That's probably necessary, but tends to cause annoyances with back/forward navigation (warnings about re-POSTing data etc)

* The subpage checkbox is shown on the form based only on the target page's namespace. This means it'll show for the vast majority of, say, talk pages which don't have any subpages. To be consistent with the talk namespace, it should be kept hidden if there aren't any.

* Subpages may exist for a talk namespace while not existing for the article namespace. When moving an article with its talk, and the talk has archive subpages, it would probably make sense to do the moves -- but no check will show here due to the check only on the article space.

* There's a couple copy-pasted instances of $something ? ' checked="checked"' : '' ... since these are passed to a function looking for a boolean, they should just use the boolean $something. :)

* I see some unnecessary uses of =& ... this is a PHP 4-ism and not needed here.

* This query's kind of creepy:

SELECT /* MovePageForm::doSubmit WikiSysop */
page_id,page_namespace,page_title FROM `page` WHERE 0 = 1

* Generally speaking, there may be a _lot_ of subpages. English Wikipedia Main_Page will net you 169 total including itself, talk, and all subpages. How safe is it to move potentially thousands in one request here?
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/SpecialMovepage.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1581,10 +1581,8 @@
15821582 'talkexists',
15831583 'movedto',
15841584 'movetalk',
1585 - 'move-subpages',
1586 - 'movepage-page-exists',
1587 - 'movepage-page-unmoved',
1588 - 'movepage-page-moved',
 1585+ 'talkpagemoved',
 1586+ 'talkpagenotmoved',
15891587 '1movedto2',
15901588 '1movedto2_redir',
15911589 'movelogpage',
Index: trunk/phase3/includes/SpecialMovepage.php
@@ -30,7 +30,9 @@
3131
3232 $f = new MovePageForm( $par );
3333
34 - if ( 'submit' == $action && $wgRequest->wasPosted()
 34+ if ( 'success' == $action ) {
 35+ $f->showSuccess();
 36+ } else if ( 'submit' == $action && $wgRequest->wasPosted()
3537 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
3638 $f->doSubmit();
3739 } else {
@@ -44,7 +46,7 @@
4547 */
4648 class MovePageForm {
4749 var $oldTitle, $newTitle, $reason; # Text input
48 - var $moveTalk, $deleteAndMove, $moveSubpages;
 50+ var $moveTalk, $deleteAndMove;
4951
5052 private $watch = false;
5153
@@ -59,13 +61,12 @@
6062 } else {
6163 $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
6264 }
63 - $this->moveSubpages = $wgRequest->getBool( 'wpMovesubpages', false );
6465 $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
6566 $this->watch = $wgRequest->getCheck( 'wpWatch' );
6667 }
6768
6869 function showForm( $err, $hookErr = '' ) {
69 - global $wgOut, $wgUser, $wgNamespacesWithSubpages;
 70+ global $wgOut, $wgUser;
7071
7172 $ot = Title::newFromURL( $this->oldTitle );
7273 if( is_null( $ot ) ) {
@@ -143,6 +144,8 @@
144145 $wgOut->addHTML( $errMsg );
145146 }
146147
 148+ $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
 149+
147150 $wgOut->addHTML(
148151 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
149152 Xml::openElement( 'fieldset' ) .
@@ -175,31 +178,17 @@
176179 </tr>"
177180 );
178181
179 - if( $considerTalk ) {
 182+ if ( $considerTalk ) {
180183 $wgOut->addHTML( "
181184 <tr>
182185 <td></td>
183186 <td class='mw-input'>" .
184 - Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk',
185 - 'wpMovetalk', $this->moveTalk ? ' checked="checked"' : '').
 187+ Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) .
186188 "</td>
187189 </tr>"
188190 );
189191 }
190192
191 - if( isset( $wgNamespacesWithSubpages[$ot->getNamespace()] ) ) {
192 - $wgOut->addHTML( "
193 - <tr>
194 - <td></td>
195 - <td class=\"mw-input\">" .
196 - Xml::checkLabel( wfMsgHtml( 'move-subpages' ),
197 - 'wpMovesubpages', 'wpMovesubpages',
198 - $this->moveSubpages ? ' checked="checked"' : '' ) .
199 - "</td>
200 - </tr>"
201 - );
202 - }
203 -
204193 $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
205194 $wgOut->addHTML( "
206195 <tr>
@@ -275,100 +264,28 @@
276265
277266 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
278267
279 - $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
 268+ # Move the talk page if relevant, if it exists, and if we've been told to
 269+ $ott = $ot->getTalkPage();
 270+ if( $ott->exists() ) {
 271+ if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
 272+ $ntt = $nt->getTalkPage();
280273
281 - $oldUrl = $ot->getFullUrl( 'redirect=no' );
282 - $newUrl = $nt->getFullUrl();
283 - $oldText = $ot->getPrefixedText();
284 - $newText = $nt->getPrefixedText();
285 - $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
286 - $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
287 -
288 - $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
289 -
290 - # Now we move extra pages we've been asked to move: subpages and talk
291 - # pages. First, if the old page or the new page is a talk page, we
292 - # can't move any talk pages: cancel that.
293 - if( $ot->isTalkPage() || $nt->isTalkPage() ) {
294 - $this->moveTalk = false;
295 - }
296 -
297 - # Next make a list of id's. This might be marginally less efficient
298 - # than a more direct method, but this is not a highly performance-cri-
299 - # tical code path and readable code is more important here.
300 - #
301 - # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
302 - # 4 might get confused. If so, consider rewriting as a UNION.
303 - $dbr = wfGetDB( DB_SLAVE );
304 - if( $this->moveSubpages ) {
305 - $conds = array(
306 - 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
307 - .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
308 - );
309 - if( $this->moveTalk ) {
310 - $conds['page_namespace'] = array( $ot->getNamespace(),
311 - MWNamespace::getTalk($ot->getNamespace()) );
 274+ # Attempt the move
 275+ $error = $ott->moveTo( $ntt, true, $this->reason );
 276+ if ( $error === true ) {
 277+ $talkmoved = 1;
 278+ wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) );
 279+ } else {
 280+ $talkmoved = $error;
 281+ }
312282 } else {
313 - $conds['page_namespace'] = $ot->getNamespace();
 283+ # Stay silent on the subject of talk.
 284+ $talkmoved = '';
314285 }
315286 } else {
316 - if( $this->moveTalk ) {
317 - $conds = array(
318 - 'page_namespace' => MWNamespace::getTalk($ot->getNamespace()),
319 - 'page_title' => $ot->getDBKey()
320 - );
321 - } else {
322 - $conds = '0 = 1';
323 - }
 287+ $talkmoved = 'notalkpage';
324288 }
325289
326 - $extrapages = $dbr->select(
327 - 'page',
328 - array( 'page_id', 'page_namespace', 'page_title' ),
329 - $conds,
330 - __METHOD__
331 - );
332 -
333 - $extraOutput = '';
334 - $skin =& $wgUser->getSkin();
335 - foreach( $extrapages as $row ) {
336 - if( $row->page_id == $ot->getArticleId() ) {
337 - # Already did this one.
338 - continue;
339 - }
340 -
341 - $oldPage = Title::newFromRow( $row );
342 - $newPageName = preg_replace(
343 - '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
344 - $nt->getDBKey(),
345 - $oldPage->getDBKey()
346 - );
347 - # The following line is an atrocious hack. Kill it.
348 - $newNs = $nt->getNamespace() + ($oldPage->getNamespace() & 1);
349 - $newPage = Title::makeTitle( $newNs, $newPageName );
350 -
351 - # This was copy-pasted from Renameuser, bleh.
352 - if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) {
353 - $link = $skin->makeKnownLinkObj( $newPage );
354 - $extraOutput .= '<li>' . wfMsgHtml( 'movepage-page-exists', $link ) . '</li>';
355 - } else {
356 - $success = $oldPage->moveTo( $newPage, true, $this->reason );
357 - if( $success === true ) {
358 - $oldLink = $skin->makeKnownLinkObj( $oldPage, '', 'redirect=no' );
359 - $newLink = $skin->makeKnownLinkObj( $newPage );
360 - $extraOutput .= '<li>' . wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink ) . '</li>';
361 - } else {
362 - $oldLink = $skin->makeKnownLinkObj( $oldPage );
363 - $newLink = $skin->makeLinkObj( $newPage );
364 - $extraOutput .= '<li>' . wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink ) . '</li>';
365 - }
366 - }
367 - }
368 -
369 - if( $extraOutput !== '' ) {
370 - $wgOut->addHTML( "<ul>$extraOutput</ul>" );
371 - }
372 -
373290 # Deal with watches
374291 if( $this->watch ) {
375292 $wgUser->addWatch( $ot );
@@ -377,8 +294,51 @@
378295 $wgUser->removeWatch( $ot );
379296 $wgUser->removeWatch( $nt );
380297 }
 298+
 299+ # Give back result to user.
 300+ $titleObj = SpecialPage::getTitleFor( 'Movepage' );
 301+ $success = $titleObj->getFullURL(
 302+ 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
 303+ '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
 304+ '&talkmoved='.$talkmoved );
 305+
 306+ $wgOut->redirect( $success );
381307 }
382308
 309+ function showSuccess() {
 310+ global $wgOut, $wgRequest, $wgUser;
 311+
 312+ $old = Title::newFromText( $wgRequest->getVal( 'oldtitle' ) );
 313+ $new = Title::newFromText( $wgRequest->getVal( 'newtitle' ) );
 314+
 315+ if( is_null( $old ) || is_null( $new ) ) {
 316+ throw new ErrorPageError( 'badtitle', 'badtitletext' );
 317+ }
 318+
 319+ $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
 320+
 321+ $talkmoved = $wgRequest->getVal( 'talkmoved' );
 322+ $oldUrl = $old->getFullUrl( 'redirect=no' );
 323+ $newUrl = $new->getFullUrl();
 324+ $oldText = $old->getPrefixedText();
 325+ $newText = $new->getPrefixedText();
 326+ $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
 327+ $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
 328+
 329+ $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
 330+
 331+ if ( $talkmoved == 1 ) {
 332+ $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
 333+ } elseif( 'articleexists' == $talkmoved ) {
 334+ $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
 335+ } else {
 336+ if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
 337+ $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
 338+ }
 339+ }
 340+ $wgOut->addWikiText( $s );
 341+ }
 342+
383343 function showLogFragment( $title, &$out ) {
384344 $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'move' ) ) );
385345 LogEventsList::showLogExtract( $out, 'move', $title->getPrefixedText() );
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2345,10 +2345,8 @@
23462346 Please merge them manually.'''",
23472347 'movedto' => 'moved to',
23482348 'movetalk' => 'Move associated talk page',
2349 -'move-subpages' => 'Move all subpages, if applicable',
2350 -'movepage-page-exists' => 'The page $1 already exists and cannot be automatically overwritten.',
2351 -'movepage-page-moved' => 'The page $1 has been moved to $2.',
2352 -'movepage-page-unmoved' => 'The page $1 could not be moved to $2.',
 2349+'talkpagemoved' => 'The corresponding talk page was also moved.',
 2350+'talkpagenotmoved' => 'The corresponding talk page was <strong>not</strong> moved.',
23532351 '1movedto2' => '[[$1]] moved to [[$2]]',
23542352 '1movedto2_redir' => '[[$1]] moved to [[$2]] over redirect',
23552353 'movelogpage' => 'Move log',
Index: trunk/phase3/RELEASE-NOTES
@@ -87,7 +87,6 @@
8888 text from Special:UserLogin title (new message 'nav-login-createaccount')
8989 * Say "log in / create account" if an anonymous user can create an account,
9090 otherwise just "log in", consistently across skins
91 -* Users moving a page can now have all subpages automatically moved as well
9291
9392 === Bug fixes in 1.13 ===
9493

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r33565Users moving a page can now have all subpages automatically moved as well. D...simetrical20:40, 18 April 2008

Status & tagging log