Merge "Add top help link to MediaWiki.org in several pages via indicator"
[lhc/web/wiklou.git] / includes / specials / SpecialMovepage.php
1 <?php
2 /**
3 * Implements Special:Movepage
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that allows users to change page titles
26 *
27 * @ingroup SpecialPage
28 */
29 class MovePageForm extends UnlistedSpecialPage {
30 /** @var Title */
31 protected $oldTitle;
32
33 /** @var Title */
34 protected $newTitle;
35
36
37 /** @var string Text input */
38 protected $reason;
39
40 // Checks
41
42 /** @var bool */
43 protected $moveTalk;
44
45 /** @var bool */
46 protected $deleteAndMove;
47
48 /** @var bool */
49 protected $moveSubpages;
50
51 /** @var bool */
52 protected $fixRedirects;
53
54 /** @var bool */
55 protected $leaveRedirect;
56
57 /** @var bool */
58 protected $moveOverShared;
59
60 private $watch = false;
61
62 public function __construct() {
63 parent::__construct( 'Movepage' );
64 }
65
66 public function execute( $par ) {
67 $this->checkReadOnly();
68
69 $this->setHeaders();
70 $this->outputHeader();
71
72 $request = $this->getRequest();
73 $target = !is_null( $par ) ? $par : $request->getVal( 'target' );
74
75 // Yes, the use of getVal() and getText() is wanted, see bug 20365
76
77 $oldTitleText = $request->getVal( 'wpOldTitle', $target );
78 $this->oldTitle = Title::newFromText( $oldTitleText );
79
80 if ( is_null( $this->oldTitle ) ) {
81 throw new ErrorPageError( 'notargettitle', 'notargettext' );
82 }
83 if ( !$this->oldTitle->exists() ) {
84 throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
85 }
86
87 $newTitleTextMain = $request->getText( 'wpNewTitleMain' );
88 $newTitleTextNs = $request->getInt( 'wpNewTitleNs', $this->oldTitle->getNamespace() );
89 // Backwards compatibility for forms submitting here from other sources
90 // which is more common than it should be..
91 $newTitleText_bc = $request->getText( 'wpNewTitle' );
92 $this->newTitle = strlen( $newTitleText_bc ) > 0
93 ? Title::newFromText( $newTitleText_bc )
94 : Title::makeTitleSafe( $newTitleTextNs, $newTitleTextMain );
95
96 $user = $this->getUser();
97
98 # Check rights
99 $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $user );
100 if ( count( $permErrors ) ) {
101 // Auto-block user's IP if the account was "hard" blocked
102 $user->spreadAnyEditBlock();
103 throw new PermissionsError( 'move', $permErrors );
104 }
105
106 $def = !$request->wasPosted();
107
108 $this->reason = $request->getText( 'wpReason' );
109 $this->moveTalk = $request->getBool( 'wpMovetalk', $def );
110 $this->fixRedirects = $request->getBool( 'wpFixRedirects', $def );
111 $this->leaveRedirect = $request->getBool( 'wpLeaveRedirect', $def );
112 $this->moveSubpages = $request->getBool( 'wpMovesubpages', false );
113 $this->deleteAndMove = $request->getBool( 'wpDeleteAndMove' ) && $request->getBool( 'wpConfirm' );
114 $this->moveOverShared = $request->getBool( 'wpMoveOverSharedFile', false );
115 $this->watch = $request->getCheck( 'wpWatch' ) && $user->isLoggedIn();
116
117 if ( 'submit' == $request->getVal( 'action' ) && $request->wasPosted()
118 && $user->matchEditToken( $request->getVal( 'wpEditToken' ) )
119 ) {
120 $this->doSubmit();
121 } else {
122 $this->showForm( array() );
123 }
124 }
125
126 /**
127 * Show the form
128 *
129 * @param array $err Error messages. Each item is an error message.
130 * It may either be a string message name or array message name and
131 * parameters, like the second argument to OutputPage::wrapWikiMsg().
132 */
133 function showForm( $err ) {
134 global $wgContLang;
135
136 $this->getSkin()->setRelevantTitle( $this->oldTitle );
137
138 $oldTitleLink = Linker::link( $this->oldTitle );
139
140 $out = $this->getOutput();
141 $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
142 $out->addModules( 'mediawiki.special.movePage' );
143 $out->addHelpLink( 'Help:Moving a page' );
144
145 $newTitle = $this->newTitle;
146
147 if ( !$newTitle ) {
148 # Show the current title as a default
149 # when the form is first opened.
150 $newTitle = $this->oldTitle;
151 } elseif ( !count( $err ) ) {
152 # If a title was supplied, probably from the move log revert
153 # link, check for validity. We can then show some diagnostic
154 # information and save a click.
155 $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
156 if ( is_array( $newerr ) ) {
157 $err = $newerr;
158 }
159 }
160
161 $user = $this->getUser();
162
163 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
164 && $newTitle->quickUserCan( 'delete', $user )
165 ) {
166 $out->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
167 $movepagebtn = $this->msg( 'delete_and_move' )->text();
168 $submitVar = 'wpDeleteAndMove';
169 $confirm = true;
170 $err = array();
171 } else {
172 if ( $this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
173 $out->wrapWikiMsg(
174 "<div class=\"error mw-moveuserpage-warning\">\n$1\n</div>",
175 'moveuserpage-warning'
176 );
177 } elseif ( $this->oldTitle->getNamespace() == NS_CATEGORY ) {
178 $out->wrapWikiMsg(
179 "<div class=\"error mw-movecategorypage-warning\">\n$1\n</div>",
180 'movecategorypage-warning'
181 );
182 }
183
184 $out->addWikiMsg( $this->getConfig()->get( 'FixDoubleRedirects' ) ?
185 'movepagetext' :
186 'movepagetext-noredirectfixer'
187 );
188 $movepagebtn = $this->msg( 'movepagebtn' )->text();
189 $submitVar = 'wpMove';
190 $confirm = false;
191 }
192
193 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'file-exists-sharedrepo'
194 && $user->isAllowed( 'reupload-shared' )
195 ) {
196 $out->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
197 $submitVar = 'wpMoveOverSharedFile';
198 $err = array();
199 }
200
201 $oldTalk = $this->oldTitle->getTalkPage();
202 $oldTitleSubpages = $this->oldTitle->hasSubpages();
203 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
204
205 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
206 !count( $this->oldTitle->getUserPermissionsErrors( 'move-subpages', $user ) );
207
208 # We also want to be able to move assoc. subpage talk-pages even if base page
209 # has no associated talk page, so || with $oldTitleTalkSubpages.
210 $considerTalk = !$this->oldTitle->isTalkPage() &&
211 ( $oldTalk->exists()
212 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
213
214 $dbr = wfGetDB( DB_SLAVE );
215 if ( $this->getConfig()->get( 'FixDoubleRedirects' ) ) {
216 $hasRedirects = $dbr->selectField( 'redirect', '1',
217 array(
218 'rd_namespace' => $this->oldTitle->getNamespace(),
219 'rd_title' => $this->oldTitle->getDBkey(),
220 ), __METHOD__ );
221 } else {
222 $hasRedirects = false;
223 }
224
225 if ( $considerTalk ) {
226 $out->addWikiMsg( 'movepagetalktext' );
227 }
228
229 if ( count( $err ) ) {
230 $out->addHTML( "<div class='error'>\n" );
231 $action_desc = $this->msg( 'action-move' )->plain();
232 $out->addWikiMsg( 'permissionserrorstext-withaction', count( $err ), $action_desc );
233
234 if ( count( $err ) == 1 ) {
235 $errMsg = $err[0];
236 $errMsgName = array_shift( $errMsg );
237
238 if ( $errMsgName == 'hookaborted' ) {
239 $out->addHTML( "<p>{$errMsg[0]}</p>\n" );
240 } else {
241 $out->addWikiMsgArray( $errMsgName, $errMsg );
242 }
243 } else {
244 $errStr = array();
245
246 foreach ( $err as $errMsg ) {
247 if ( $errMsg[0] == 'hookaborted' ) {
248 $errStr[] = $errMsg[1];
249 } else {
250 $errMsgName = array_shift( $errMsg );
251 $errStr[] = $this->msg( $errMsgName, $errMsg )->parse();
252 }
253 }
254
255 $out->addHTML( '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n" );
256 }
257 $out->addHTML( "</div>\n" );
258 }
259
260 if ( $this->oldTitle->isProtected( 'move' ) ) {
261 # Is the title semi-protected?
262 if ( $this->oldTitle->isSemiProtected( 'move' ) ) {
263 $noticeMsg = 'semiprotectedpagemovewarning';
264 $classes[] = 'mw-textarea-sprotected';
265 } else {
266 # Then it must be protected based on static groups (regular)
267 $noticeMsg = 'protectedpagemovewarning';
268 $classes[] = 'mw-textarea-protected';
269 }
270 $out->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
271 $out->addWikiMsg( $noticeMsg );
272 LogEventsList::showLogExtract(
273 $out,
274 'protect',
275 $this->oldTitle,
276 '',
277 array( 'lim' => 1 )
278 );
279 $out->addHTML( "</div>\n" );
280 }
281
282 // Byte limit (not string length limit) for wpReason and wpNewTitleMain
283 // is enforced in the mediawiki.special.movePage module
284
285 $immovableNamespaces = array();
286
287 foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) {
288 if ( !MWNamespace::isMovable( $nsId ) ) {
289 $immovableNamespaces[] = $nsId;
290 }
291 }
292
293 $handler = ContentHandler::getForTitle( $this->oldTitle );
294
295 $out->addHTML(
296 Xml::openElement(
297 'form',
298 array(
299 'method' => 'post',
300 'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
301 'id' => 'movepage'
302 )
303 ) .
304 Xml::openElement( 'fieldset' ) .
305 Xml::element( 'legend', null, $this->msg( 'move-page-legend' )->text() ) .
306 Xml::openElement( 'table', array( 'id' => 'mw-movepage-table' ) )
307 );
308
309 $out->addHTML(
310 "<tr>
311 <td class='mw-label'>" .
312 $this->msg( 'movearticle' )->escaped() .
313 "</td>
314 <td class='mw-input'>
315 <strong>{$oldTitleLink}</strong>
316 </td>
317 </tr>
318 <tr>
319 <td class='mw-label'>" .
320 Xml::label( $this->msg( 'newtitle' )->text(), 'wpNewTitleMain' ) .
321 "</td>
322 <td class='mw-input'>" .
323 Html::namespaceSelector(
324 array(
325 'selected' => $newTitle->getNamespace(),
326 'exclude' => $immovableNamespaces
327 ),
328 array( 'name' => 'wpNewTitleNs', 'id' => 'wpNewTitleNs' )
329 ) .
330 Xml::input(
331 'wpNewTitleMain',
332 60,
333 $wgContLang->recodeForEdit( $newTitle->getText() ),
334 array(
335 'type' => 'text',
336 'id' => 'wpNewTitleMain',
337 'maxlength' => 255
338 )
339 ) .
340 Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
341 "</td>
342 </tr>
343 <tr>
344 <td class='mw-label'>" .
345 Xml::label( $this->msg( 'movereason' )->text(), 'wpReason' ) .
346 "</td>
347 <td class='mw-input'>" .
348 Xml::input( 'wpReason', 60, $this->reason, array(
349 'type' => 'text',
350 'id' => 'wpReason',
351 'maxlength' => 200,
352 ) ) .
353 "</td>
354 </tr>"
355 );
356
357 if ( $considerTalk ) {
358 $out->addHTML( "
359 <tr>
360 <td></td>
361 <td class='mw-input'>" .
362 Xml::checkLabel(
363 $this->msg( 'movetalk' )->text(),
364 'wpMovetalk',
365 'wpMovetalk',
366 $this->moveTalk
367 ) .
368 "</td>
369 </tr>"
370 );
371 }
372
373 if ( $user->isAllowed( 'suppressredirect' ) ) {
374 if ( $handler->supportsRedirects() ) {
375 $isChecked = $this->leaveRedirect;
376 $options = array();
377 } else {
378 $isChecked = false;
379 $options = array(
380 'disabled' => 'disabled'
381 );
382 }
383 $out->addHTML( "
384 <tr>
385 <td></td>
386 <td class='mw-input'>" .
387 Xml::checkLabel(
388 $this->msg( 'move-leave-redirect' )->text(),
389 'wpLeaveRedirect',
390 'wpLeaveRedirect',
391 $isChecked,
392 $options
393 ) .
394 "</td>
395 </tr>"
396 );
397 }
398
399 if ( $hasRedirects ) {
400 $out->addHTML( "
401 <tr>
402 <td></td>
403 <td class='mw-input'>" .
404 Xml::checkLabel(
405 $this->msg( 'fix-double-redirects' )->text(),
406 'wpFixRedirects',
407 'wpFixRedirects',
408 $this->fixRedirects
409 ) .
410 "</td>
411 </tr>"
412 );
413 }
414
415 if ( $canMoveSubpage ) {
416 $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
417 $out->addHTML( "
418 <tr>
419 <td></td>
420 <td class='mw-input'>" .
421 Xml::check(
422 'wpMovesubpages',
423 # Don't check the box if we only have talk subpages to
424 # move and we aren't moving the talk page.
425 $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ),
426 array( 'id' => 'wpMovesubpages' )
427 ) . '&#160;' .
428 Xml::tags(
429 'label',
430 array( 'for' => 'wpMovesubpages' ),
431 $this->msg(
432 ( $this->oldTitle->hasSubpages()
433 ? 'move-subpages'
434 : 'move-talk-subpages' )
435 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
436 ) .
437 "</td>
438 </tr>"
439 );
440 }
441
442 $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
443 || $user->isWatched( $this->oldTitle ) );
444 # Don't allow watching if user is not logged in
445 if ( $user->isLoggedIn() ) {
446 $out->addHTML( "
447 <tr>
448 <td></td>
449 <td class='mw-input'>" .
450 Xml::checkLabel(
451 $this->msg( 'move-watch' )->text(),
452 'wpWatch',
453 'watch',
454 $watchChecked
455 ) .
456 "</td>
457 </tr>"
458 );
459 }
460
461 if ( $confirm ) {
462 $out->addHTML( "
463 <tr>
464 <td></td>
465 <td class='mw-input'>" .
466 Xml::checkLabel(
467 $this->msg( 'delete_and_move_confirm' )->text(),
468 'wpConfirm',
469 'wpConfirm'
470 ) .
471 "</td>
472 </tr>"
473 );
474 }
475
476 $out->addHTML( "
477 <tr>
478 <td></td>
479 <td class='mw-submit'>" .
480 Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
481 "</td>
482 </tr>"
483 );
484
485 $out->addHTML(
486 Xml::closeElement( 'table' ) .
487 Html::hidden( 'wpEditToken', $user->getEditToken() ) .
488 Xml::closeElement( 'fieldset' ) .
489 Xml::closeElement( 'form' ) .
490 "\n"
491 );
492
493 $this->showLogFragment( $this->oldTitle );
494 $this->showSubpages( $this->oldTitle );
495 }
496
497 function doSubmit() {
498 $user = $this->getUser();
499
500 if ( $user->pingLimiter( 'move' ) ) {
501 throw new ThrottledError;
502 }
503
504 $ot = $this->oldTitle;
505 $nt = $this->newTitle;
506
507 # don't allow moving to pages with # in
508 if ( !$nt || $nt->hasFragment() ) {
509 $this->showForm( array( array( 'badtitletext' ) ) );
510
511 return;
512 }
513
514 # Show a warning if the target file exists on a shared repo
515 if ( $nt->getNamespace() == NS_FILE
516 && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
517 && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
518 && wfFindFile( $nt )
519 ) {
520 $this->showForm( array( array( 'file-exists-sharedrepo' ) ) );
521
522 return;
523 }
524
525 # Delete to make way if requested
526 if ( $this->deleteAndMove ) {
527 $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
528 if ( count( $permErrors ) ) {
529 # Only show the first error
530 $this->showForm( $permErrors );
531
532 return;
533 }
534
535 $reason = $this->msg( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
536
537 // Delete an associated image if there is
538 if ( $nt->getNamespace() == NS_FILE ) {
539 $file = wfLocalFile( $nt );
540 if ( $file->exists() ) {
541 $file->delete( $reason, false, $user );
542 }
543 }
544
545 $error = ''; // passed by ref
546 $page = WikiPage::factory( $nt );
547 $deleteStatus = $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
548 if ( !$deleteStatus->isGood() ) {
549 $this->showForm( $deleteStatus->getErrorsArray() );
550
551 return;
552 }
553 }
554
555 $handler = ContentHandler::getForTitle( $ot );
556
557 if ( !$handler->supportsRedirects() ) {
558 $createRedirect = false;
559 } elseif ( $user->isAllowed( 'suppressredirect' ) ) {
560 $createRedirect = $this->leaveRedirect;
561 } else {
562 $createRedirect = true;
563 }
564
565 # Do the actual move.
566 $mp = new MovePage( $ot, $nt );
567 $valid = $mp->isValidMove();
568 if ( !$valid->isOK() ) {
569 $this->showForm( $valid->getErrorsArray() );
570 return;
571 }
572
573 $permStatus = $mp->checkPermissions( $user, $this->reason );
574 if ( !$permStatus->isOK() ) {
575 $this->showForm( $permStatus->getErrorsArray() );
576 return;
577 }
578
579 $status = $mp->move( $user, $this->reason, $createRedirect );
580 if ( !$status->isOK() ) {
581 $this->showForm( $status->getErrorsArray() );
582 return;
583 }
584
585 if ( $this->getConfig()->get( 'FixDoubleRedirects' ) && $this->fixRedirects ) {
586 DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
587 }
588
589 $out = $this->getOutput();
590 $out->setPageTitle( $this->msg( 'pagemovedsub' ) );
591
592 $oldLink = Linker::link(
593 $ot,
594 null,
595 array( 'id' => 'movepage-oldlink' ),
596 array( 'redirect' => 'no' )
597 );
598 $newLink = Linker::linkKnown(
599 $nt,
600 null,
601 array( 'id' => 'movepage-newlink' )
602 );
603 $oldText = $ot->getPrefixedText();
604 $newText = $nt->getPrefixedText();
605
606 if ( $ot->exists() ) {
607 //NOTE: we assume that if the old title exists, it's because it was re-created as
608 // a redirect to the new title. This is not safe, but what we did before was
609 // even worse: we just determined whether a redirect should have been created,
610 // and reported that it was created if it should have, without any checks.
611 // Also note that isRedirect() is unreliable because of bug 37209.
612 $msgName = 'movepage-moved-redirect';
613 } else {
614 $msgName = 'movepage-moved-noredirect';
615 }
616
617 $out->addHTML( $this->msg( 'movepage-moved' )->rawParams( $oldLink,
618 $newLink )->params( $oldText, $newText )->parseAsBlock() );
619 $out->addWikiMsg( $msgName );
620
621 Hooks::run( 'SpecialMovepageAfterMove', array( &$this, &$ot, &$nt ) );
622
623 # Now we move extra pages we've been asked to move: subpages and talk
624 # pages. First, if the old page or the new page is a talk page, we
625 # can't move any talk pages: cancel that.
626 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
627 $this->moveTalk = false;
628 }
629
630 if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
631 $this->moveSubpages = false;
632 }
633
634 # Next make a list of id's. This might be marginally less efficient
635 # than a more direct method, but this is not a highly performance-cri-
636 # tical code path and readable code is more important here.
637 #
638 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
639 # 4 might get confused. If so, consider rewriting as a UNION.
640 #
641 # If the target namespace doesn't allow subpages, moving with subpages
642 # would mean that you couldn't move them back in one operation, which
643 # is bad.
644 # @todo FIXME: A specific error message should be given in this case.
645
646 // @todo FIXME: Use Title::moveSubpages() here
647 $dbr = wfGetDB( DB_MASTER );
648 if ( $this->moveSubpages && (
649 MWNamespace::hasSubpages( $nt->getNamespace() ) || (
650 $this->moveTalk
651 && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
652 )
653 ) ) {
654 $conds = array(
655 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
656 . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
657 );
658 $conds['page_namespace'] = array();
659 if ( MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
660 $conds['page_namespace'][] = $ot->getNamespace();
661 }
662 if ( $this->moveTalk &&
663 MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
664 ) {
665 $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
666 }
667 } elseif ( $this->moveTalk ) {
668 $conds = array(
669 'page_namespace' => $ot->getTalkPage()->getNamespace(),
670 'page_title' => $ot->getDBkey()
671 );
672 } else {
673 # Skip the query
674 $conds = null;
675 }
676
677 $extraPages = array();
678 if ( !is_null( $conds ) ) {
679 $extraPages = TitleArray::newFromResult(
680 $dbr->select( 'page',
681 array( 'page_id', 'page_namespace', 'page_title' ),
682 $conds,
683 __METHOD__
684 )
685 );
686 }
687
688 $extraOutput = array();
689 $count = 1;
690 foreach ( $extraPages as $oldSubpage ) {
691 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
692 # Already did this one.
693 continue;
694 }
695
696 $newPageName = preg_replace(
697 '#^' . preg_quote( $ot->getDBkey(), '#' ) . '#',
698 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
699 $oldSubpage->getDBkey()
700 );
701
702 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
703 // Moving a subpage from a subject namespace to a talk namespace or vice-versa
704 $newNs = $nt->getNamespace();
705 } elseif ( $oldSubpage->isTalkPage() ) {
706 $newNs = $nt->getTalkPage()->getNamespace();
707 } else {
708 $newNs = $nt->getSubjectPage()->getNamespace();
709 }
710
711 # Bug 14385: we need makeTitleSafe because the new page names may
712 # be longer than 255 characters.
713 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
714 if ( !$newSubpage ) {
715 $oldLink = Linker::linkKnown( $oldSubpage );
716 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink )
717 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
718 continue;
719 }
720
721 # This was copy-pasted from Renameuser, bleh.
722 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
723 $link = Linker::linkKnown( $newSubpage );
724 $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
725 } else {
726 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
727
728 if ( $success === true ) {
729 if ( $this->fixRedirects ) {
730 DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
731 }
732 $oldLink = Linker::link(
733 $oldSubpage,
734 null,
735 array(),
736 array( 'redirect' => 'no' )
737 );
738
739 $newLink = Linker::linkKnown( $newSubpage );
740 $extraOutput[] = $this->msg( 'movepage-page-moved' )
741 ->rawParams( $oldLink, $newLink )->escaped();
742 ++$count;
743
744 $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
745 if ( $count >= $maximumMovedPages ) {
746 $extraOutput[] = $this->msg( 'movepage-max-pages' )
747 ->numParams( $maximumMovedPages )->escaped();
748 break;
749 }
750 } else {
751 $oldLink = Linker::linkKnown( $oldSubpage );
752 $newLink = Linker::link( $newSubpage );
753 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )
754 ->rawParams( $oldLink, $newLink )->escaped();
755 }
756 }
757 }
758
759 if ( $extraOutput !== array() ) {
760 $out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
761 }
762
763 # Deal with watches (we don't watch subpages)
764 WatchAction::doWatchOrUnwatch( $this->watch, $ot, $user );
765 WatchAction::doWatchOrUnwatch( $this->watch, $nt, $user );
766 }
767
768 function showLogFragment( $title ) {
769 $moveLogPage = new LogPage( 'move' );
770 $out = $this->getOutput();
771 $out->addHTML( Xml::element( 'h2', null, $moveLogPage->getName()->text() ) );
772 LogEventsList::showLogExtract( $out, 'move', $title );
773 }
774
775 function showSubpages( $title ) {
776 if ( !MWNamespace::hasSubpages( $title->getNamespace() ) ) {
777 return;
778 }
779
780 $subpages = $title->getSubpages();
781 $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
782
783 $out = $this->getOutput();
784 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
785
786 # No subpages.
787 if ( $count == 0 ) {
788 $out->addWikiMsg( 'movenosubpage' );
789
790 return;
791 }
792
793 $out->addWikiMsg( 'movesubpagetext', $this->getLanguage()->formatNum( $count ) );
794 $out->addHTML( "<ul>\n" );
795
796 foreach ( $subpages as $subpage ) {
797 $link = Linker::link( $subpage );
798 $out->addHTML( "<li>$link</li>\n" );
799 }
800 $out->addHTML( "</ul>\n" );
801 }
802
803 protected function getGroupName() {
804 return 'pagetools';
805 }
806 }