r33565 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33564‎ | r33565 | r33566 >
Date:20:40, 18 April 2008
Author:simetrical
Status:old
Tags:
Comment:
Users moving a page can now have all subpages automatically moved as well. Done by request of the people in #wikibooks; this is apparently a much-desired thing there (for, I guess, obvious reasons :) ). This took longer than I thought and is somewhat hackish in places, so it could maybe use a bit of polish.
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,8 +1581,10 @@
15821582 'talkexists',
15831583 'movedto',
15841584 'movetalk',
1585 - 'talkpagemoved',
1586 - 'talkpagenotmoved',
 1585+ 'move-subpages',
 1586+ 'movepage-page-exists',
 1587+ 'movepage-page-unmoved',
 1588+ 'movepage-page-moved',
15871589 '1movedto2',
15881590 '1movedto2_redir',
15891591 'movelogpage',
Index: trunk/phase3/includes/SpecialMovepage.php
@@ -30,9 +30,7 @@
3131
3232 $f = new MovePageForm( $par );
3333
34 - if ( 'success' == $action ) {
35 - $f->showSuccess();
36 - } else if ( 'submit' == $action && $wgRequest->wasPosted()
 34+ if ( 'submit' == $action && $wgRequest->wasPosted()
3735 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
3836 $f->doSubmit();
3937 } else {
@@ -46,7 +44,7 @@
4745 */
4846 class MovePageForm {
4947 var $oldTitle, $newTitle, $reason; # Text input
50 - var $moveTalk, $deleteAndMove;
 48+ var $moveTalk, $deleteAndMove, $moveSubpages;
5149
5250 private $watch = false;
5351
@@ -61,12 +59,13 @@
6260 } else {
6361 $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
6462 }
 63+ $this->moveSubpages = $wgRequest->getBool( 'wpMovesubpages', false );
6564 $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
6665 $this->watch = $wgRequest->getCheck( 'wpWatch' );
6766 }
6867
6968 function showForm( $err, $hookErr = '' ) {
70 - global $wgOut, $wgUser;
 69+ global $wgOut, $wgUser, $wgNamespacesWithSubpages;
7170
7271 $ot = Title::newFromURL( $this->oldTitle );
7372 if( is_null( $ot ) ) {
@@ -144,8 +143,6 @@
145144 $wgOut->addHTML( $errMsg );
146145 }
147146
148 - $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
149 -
150147 $wgOut->addHTML(
151148 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
152149 Xml::openElement( 'fieldset' ) .
@@ -178,17 +175,31 @@
179176 </tr>"
180177 );
181178
182 - if ( $considerTalk ) {
 179+ if( $considerTalk ) {
183180 $wgOut->addHTML( "
184181 <tr>
185182 <td></td>
186183 <td class='mw-input'>" .
187 - Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) .
 184+ Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk',
 185+ 'wpMovetalk', $this->moveTalk ? ' checked="checked"' : '').
188186 "</td>
189187 </tr>"
190188 );
191189 }
192190
 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+
193204 $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
194205 $wgOut->addHTML( "
195206 <tr>
@@ -264,28 +275,100 @@
265276
266277 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
267278
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();
 279+ $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
273280
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 - }
 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()) );
282312 } else {
283 - # Stay silent on the subject of talk.
284 - $talkmoved = '';
 313+ $conds['page_namespace'] = $ot->getNamespace();
285314 }
286315 } else {
287 - $talkmoved = 'notalkpage';
 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+ }
288324 }
289325
 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+
290373 # Deal with watches
291374 if( $this->watch ) {
292375 $wgUser->addWatch( $ot );
@@ -294,51 +377,8 @@
295378 $wgUser->removeWatch( $ot );
296379 $wgUser->removeWatch( $nt );
297380 }
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 );
307381 }
308382
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 -
343383 function showLogFragment( $title, &$out ) {
344384 $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'move' ) ) );
345385 LogEventsList::showLogExtract( $out, 'move', $title->getPrefixedText() );
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2345,8 +2345,10 @@
23462346 Please merge them manually.'''",
23472347 'movedto' => 'moved to',
23482348 'movetalk' => 'Move associated talk page',
2349 -'talkpagemoved' => 'The corresponding talk page was also moved.',
2350 -'talkpagenotmoved' => 'The corresponding talk page was <strong>not</strong> moved.',
 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.',
23512353 '1movedto2' => '[[$1]] moved to [[$2]]',
23522354 '1movedto2_redir' => '[[$1]] moved to [[$2]] over redirect',
23532355 'movelogpage' => 'Move log',
Index: trunk/phase3/RELEASE-NOTES
@@ -87,6 +87,7 @@
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
9192
9293 === Bug fixes in 1.13 ===
9394

Follow-up revisions

RevisionCommit summaryAuthorDate
r33578Revert r33565 pending some cleanup...brion23:53, 18 April 2008
r35213Re-commit cleaned-up version of r33565 (move subpages along with page)....simetrical01:11, 23 May 2008

Status & tagging log