SpecialMovepage: Correctly apply target namespace to subpages
[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
144 $newTitle = $this->newTitle;
145
146 if ( !$newTitle ) {
147 # Show the current title as a default
148 # when the form is first opened.
149 $newTitle = $this->oldTitle;
150 } elseif ( !count( $err ) ) {
151 # If a title was supplied, probably from the move log revert
152 # link, check for validity. We can then show some diagnostic
153 # information and save a click.
154 $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
155 if ( is_array( $newerr ) ) {
156 $err = $newerr;
157 }
158 }
159
160 $user = $this->getUser();
161
162 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
163 && $newTitle->quickUserCan( 'delete', $user )
164 ) {
165 $out->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
166 $movepagebtn = $this->msg( 'delete_and_move' )->text();
167 $submitVar = 'wpDeleteAndMove';
168 $confirm = true;
169 $err = array();
170 } else {
171 if ( $this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
172 $out->wrapWikiMsg(
173 "<div class=\"error mw-moveuserpage-warning\">\n$1\n</div>",
174 'moveuserpage-warning'
175 );
176 } elseif ( $this->oldTitle->getNamespace() == NS_CATEGORY ) {
177 $out->wrapWikiMsg(
178 "<div class=\"error mw-movecategorypage-warning\">\n$1\n</div>",
179 'movecategorypage-warning'
180 );
181 }
182
183 $out->addWikiMsg( $this->getConfig()->get( 'FixDoubleRedirects' ) ?
184 'movepagetext' :
185 'movepagetext-noredirectfixer'
186 );
187 $movepagebtn = $this->msg( 'movepagebtn' )->text();
188 $submitVar = 'wpMove';
189 $confirm = false;
190 }
191
192 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'file-exists-sharedrepo'
193 && $user->isAllowed( 'reupload-shared' )
194 ) {
195 $out->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
196 $submitVar = 'wpMoveOverSharedFile';
197 $err = array();
198 }
199
200 $oldTalk = $this->oldTitle->getTalkPage();
201 $oldTitleSubpages = $this->oldTitle->hasSubpages();
202 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
203
204 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
205 !count( $this->oldTitle->getUserPermissionsErrors( 'move-subpages', $user ) );
206
207 # We also want to be able to move assoc. subpage talk-pages even if base page
208 # has no associated talk page, so || with $oldTitleTalkSubpages.
209 $considerTalk = !$this->oldTitle->isTalkPage() &&
210 ( $oldTalk->exists()
211 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
212
213 $dbr = wfGetDB( DB_SLAVE );
214 if ( $this->getConfig()->get( 'FixDoubleRedirects' ) ) {
215 $hasRedirects = $dbr->selectField( 'redirect', '1',
216 array(
217 'rd_namespace' => $this->oldTitle->getNamespace(),
218 'rd_title' => $this->oldTitle->getDBkey(),
219 ), __METHOD__ );
220 } else {
221 $hasRedirects = false;
222 }
223
224 if ( $considerTalk ) {
225 $out->addWikiMsg( 'movepagetalktext' );
226 }
227
228 if ( count( $err ) ) {
229 $out->addHTML( "<div class='error'>\n" );
230 $action_desc = $this->msg( 'action-move' )->plain();
231 $out->addWikiMsg( 'permissionserrorstext-withaction', count( $err ), $action_desc );
232
233 if ( count( $err ) == 1 ) {
234 $errMsg = $err[0];
235 $errMsgName = array_shift( $errMsg );
236
237 if ( $errMsgName == 'hookaborted' ) {
238 $out->addHTML( "<p>{$errMsg[0]}</p>\n" );
239 } else {
240 $out->addWikiMsgArray( $errMsgName, $errMsg );
241 }
242 } else {
243 $errStr = array();
244
245 foreach ( $err as $errMsg ) {
246 if ( $errMsg[0] == 'hookaborted' ) {
247 $errStr[] = $errMsg[1];
248 } else {
249 $errMsgName = array_shift( $errMsg );
250 $errStr[] = $this->msg( $errMsgName, $errMsg )->parse();
251 }
252 }
253
254 $out->addHTML( '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n" );
255 }
256 $out->addHTML( "</div>\n" );
257 }
258
259 if ( $this->oldTitle->isProtected( 'move' ) ) {
260 # Is the title semi-protected?
261 if ( $this->oldTitle->isSemiProtected( 'move' ) ) {
262 $noticeMsg = 'semiprotectedpagemovewarning';
263 $classes[] = 'mw-textarea-sprotected';
264 } else {
265 # Then it must be protected based on static groups (regular)
266 $noticeMsg = 'protectedpagemovewarning';
267 $classes[] = 'mw-textarea-protected';
268 }
269 $out->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
270 $out->addWikiMsg( $noticeMsg );
271 LogEventsList::showLogExtract(
272 $out,
273 'protect',
274 $this->oldTitle,
275 '',
276 array( 'lim' => 1 )
277 );
278 $out->addHTML( "</div>\n" );
279 }
280
281 // Byte limit (not string length limit) for wpReason and wpNewTitleMain
282 // is enforced in the mediawiki.special.movePage module
283
284 $immovableNamespaces = array();
285
286 foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) {
287 if ( !MWNamespace::isMovable( $nsId ) ) {
288 $immovableNamespaces[] = $nsId;
289 }
290 }
291
292 $handler = ContentHandler::getForTitle( $this->oldTitle );
293
294 $out->addHTML(
295 Xml::openElement(
296 'form',
297 array(
298 'method' => 'post',
299 'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
300 'id' => 'movepage'
301 )
302 ) .
303 Xml::openElement( 'fieldset' ) .
304 Xml::element( 'legend', null, $this->msg( 'move-page-legend' )->text() ) .
305 Xml::openElement( 'table', array( 'id' => 'mw-movepage-table' ) )
306 );
307
308 $out->addHTML(
309 "<tr>
310 <td class='mw-label'>" .
311 $this->msg( 'movearticle' )->escaped() .
312 "</td>
313 <td class='mw-input'>
314 <strong>{$oldTitleLink}</strong>
315 </td>
316 </tr>
317 <tr>
318 <td class='mw-label'>" .
319 Xml::label( $this->msg( 'newtitle' )->text(), 'wpNewTitleMain' ) .
320 "</td>
321 <td class='mw-input'>" .
322 Html::namespaceSelector(
323 array(
324 'selected' => $newTitle->getNamespace(),
325 'exclude' => $immovableNamespaces
326 ),
327 array( 'name' => 'wpNewTitleNs', 'id' => 'wpNewTitleNs' )
328 ) .
329 Xml::input(
330 'wpNewTitleMain',
331 60,
332 $wgContLang->recodeForEdit( $newTitle->getText() ),
333 array(
334 'type' => 'text',
335 'id' => 'wpNewTitleMain',
336 'maxlength' => 255
337 )
338 ) .
339 Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
340 "</td>
341 </tr>
342 <tr>
343 <td class='mw-label'>" .
344 Xml::label( $this->msg( 'movereason' )->text(), 'wpReason' ) .
345 "</td>
346 <td class='mw-input'>" .
347 Xml::input( 'wpReason', 60, $this->reason, array(
348 'type' => 'text',
349 'id' => 'wpReason',
350 'maxlength' => 200,
351 ) ) .
352 "</td>
353 </tr>"
354 );
355
356 if ( $considerTalk ) {
357 $out->addHTML( "
358 <tr>
359 <td></td>
360 <td class='mw-input'>" .
361 Xml::checkLabel(
362 $this->msg( 'movetalk' )->text(),
363 'wpMovetalk',
364 'wpMovetalk',
365 $this->moveTalk
366 ) .
367 "</td>
368 </tr>"
369 );
370 }
371
372 if ( $user->isAllowed( 'suppressredirect' ) ) {
373 if ( $handler->supportsRedirects() ) {
374 $isChecked = $this->leaveRedirect;
375 $options = array();
376 } else {
377 $isChecked = false;
378 $options = array(
379 'disabled' => 'disabled'
380 );
381 }
382 $out->addHTML( "
383 <tr>
384 <td></td>
385 <td class='mw-input'>" .
386 Xml::checkLabel(
387 $this->msg( 'move-leave-redirect' )->text(),
388 'wpLeaveRedirect',
389 'wpLeaveRedirect',
390 $isChecked,
391 $options
392 ) .
393 "</td>
394 </tr>"
395 );
396 }
397
398 if ( $hasRedirects ) {
399 $out->addHTML( "
400 <tr>
401 <td></td>
402 <td class='mw-input'>" .
403 Xml::checkLabel(
404 $this->msg( 'fix-double-redirects' )->text(),
405 'wpFixRedirects',
406 'wpFixRedirects',
407 $this->fixRedirects
408 ) .
409 "</td>
410 </tr>"
411 );
412 }
413
414 if ( $canMoveSubpage ) {
415 $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
416 $out->addHTML( "
417 <tr>
418 <td></td>
419 <td class='mw-input'>" .
420 Xml::check(
421 'wpMovesubpages',
422 # Don't check the box if we only have talk subpages to
423 # move and we aren't moving the talk page.
424 $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ),
425 array( 'id' => 'wpMovesubpages' )
426 ) . '&#160;' .
427 Xml::tags(
428 'label',
429 array( 'for' => 'wpMovesubpages' ),
430 $this->msg(
431 ( $this->oldTitle->hasSubpages()
432 ? 'move-subpages'
433 : 'move-talk-subpages' )
434 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
435 ) .
436 "</td>
437 </tr>"
438 );
439 }
440
441 $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
442 || $user->isWatched( $this->oldTitle ) );
443 # Don't allow watching if user is not logged in
444 if ( $user->isLoggedIn() ) {
445 $out->addHTML( "
446 <tr>
447 <td></td>
448 <td class='mw-input'>" .
449 Xml::checkLabel(
450 $this->msg( 'move-watch' )->text(),
451 'wpWatch',
452 'watch',
453 $watchChecked
454 ) .
455 "</td>
456 </tr>"
457 );
458 }
459
460 if ( $confirm ) {
461 $out->addHTML( "
462 <tr>
463 <td></td>
464 <td class='mw-input'>" .
465 Xml::checkLabel(
466 $this->msg( 'delete_and_move_confirm' )->text(),
467 'wpConfirm',
468 'wpConfirm'
469 ) .
470 "</td>
471 </tr>"
472 );
473 }
474
475 $out->addHTML( "
476 <tr>
477 <td></td>
478 <td class='mw-submit'>" .
479 Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
480 "</td>
481 </tr>"
482 );
483
484 $out->addHTML(
485 Xml::closeElement( 'table' ) .
486 Html::hidden( 'wpEditToken', $user->getEditToken() ) .
487 Xml::closeElement( 'fieldset' ) .
488 Xml::closeElement( 'form' ) .
489 "\n"
490 );
491
492 $this->showLogFragment( $this->oldTitle );
493 $this->showSubpages( $this->oldTitle );
494 }
495
496 function doSubmit() {
497 $user = $this->getUser();
498
499 if ( $user->pingLimiter( 'move' ) ) {
500 throw new ThrottledError;
501 }
502
503 $ot = $this->oldTitle;
504 $nt = $this->newTitle;
505
506 # don't allow moving to pages with # in
507 if ( !$nt || $nt->hasFragment() ) {
508 $this->showForm( array( array( 'badtitletext' ) ) );
509
510 return;
511 }
512
513 # Show a warning if the target file exists on a shared repo
514 if ( $nt->getNamespace() == NS_FILE
515 && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
516 && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
517 && wfFindFile( $nt )
518 ) {
519 $this->showForm( array( array( 'file-exists-sharedrepo' ) ) );
520
521 return;
522 }
523
524 # Delete to make way if requested
525 if ( $this->deleteAndMove ) {
526 $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
527 if ( count( $permErrors ) ) {
528 # Only show the first error
529 $this->showForm( $permErrors );
530
531 return;
532 }
533
534 $reason = $this->msg( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
535
536 // Delete an associated image if there is
537 if ( $nt->getNamespace() == NS_FILE ) {
538 $file = wfLocalFile( $nt );
539 if ( $file->exists() ) {
540 $file->delete( $reason, false );
541 }
542 }
543
544 $error = ''; // passed by ref
545 $page = WikiPage::factory( $nt );
546 $deleteStatus = $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
547 if ( !$deleteStatus->isGood() ) {
548 $this->showForm( $deleteStatus->getErrorsArray() );
549
550 return;
551 }
552 }
553
554 $handler = ContentHandler::getForTitle( $ot );
555
556 if ( !$handler->supportsRedirects() ) {
557 $createRedirect = false;
558 } elseif ( $user->isAllowed( 'suppressredirect' ) ) {
559 $createRedirect = $this->leaveRedirect;
560 } else {
561 $createRedirect = true;
562 }
563
564 # Do the actual move.
565 $mp = new MovePage( $ot, $nt );
566 $valid = $mp->isValidMove();
567 if ( !$valid->isOK() ) {
568 $this->showForm( $valid->getErrorsArray() );
569 return;
570 }
571
572 $permStatus = $mp->checkPermissions( $user, $this->reason );
573 if ( !$permStatus->isOK() ) {
574 $this->showForm( $permStatus->getErrorsArray() );
575 return;
576 }
577
578 $status = $mp->move( $user, $this->reason, $createRedirect );
579 if ( !$status->isOK() ) {
580 $this->showForm( $status->getErrorsArray() );
581 return;
582 }
583
584 if ( $this->getConfig()->get( 'FixDoubleRedirects' ) && $this->fixRedirects ) {
585 DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
586 }
587
588 $out = $this->getOutput();
589 $out->setPageTitle( $this->msg( 'pagemovedsub' ) );
590
591 $oldLink = Linker::link(
592 $ot,
593 null,
594 array( 'id' => 'movepage-oldlink' ),
595 array( 'redirect' => 'no' )
596 );
597 $newLink = Linker::linkKnown(
598 $nt,
599 null,
600 array( 'id' => 'movepage-newlink' )
601 );
602 $oldText = $ot->getPrefixedText();
603 $newText = $nt->getPrefixedText();
604
605 if ( $ot->exists() ) {
606 //NOTE: we assume that if the old title exists, it's because it was re-created as
607 // a redirect to the new title. This is not safe, but what we did before was
608 // even worse: we just determined whether a redirect should have been created,
609 // and reported that it was created if it should have, without any checks.
610 // Also note that isRedirect() is unreliable because of bug 37209.
611 $msgName = 'movepage-moved-redirect';
612 } else {
613 $msgName = 'movepage-moved-noredirect';
614 }
615
616 $out->addHTML( $this->msg( 'movepage-moved' )->rawParams( $oldLink,
617 $newLink )->params( $oldText, $newText )->parseAsBlock() );
618 $out->addWikiMsg( $msgName );
619
620 Hooks::run( 'SpecialMovepageAfterMove', array( &$this, &$ot, &$nt ) );
621
622 # Now we move extra pages we've been asked to move: subpages and talk
623 # pages. First, if the old page or the new page is a talk page, we
624 # can't move any talk pages: cancel that.
625 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
626 $this->moveTalk = false;
627 }
628
629 if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
630 $this->moveSubpages = false;
631 }
632
633 # Next make a list of id's. This might be marginally less efficient
634 # than a more direct method, but this is not a highly performance-cri-
635 # tical code path and readable code is more important here.
636 #
637 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
638 # 4 might get confused. If so, consider rewriting as a UNION.
639 #
640 # If the target namespace doesn't allow subpages, moving with subpages
641 # would mean that you couldn't move them back in one operation, which
642 # is bad.
643 # @todo FIXME: A specific error message should be given in this case.
644
645 // @todo FIXME: Use Title::moveSubpages() here
646 $dbr = wfGetDB( DB_MASTER );
647 if ( $this->moveSubpages && (
648 MWNamespace::hasSubpages( $nt->getNamespace() ) || (
649 $this->moveTalk
650 && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
651 )
652 ) ) {
653 $conds = array(
654 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
655 . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
656 );
657 $conds['page_namespace'] = array();
658 if ( MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
659 $conds['page_namespace'][] = $ot->getNamespace();
660 }
661 if ( $this->moveTalk &&
662 MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
663 ) {
664 $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
665 }
666 } elseif ( $this->moveTalk ) {
667 $conds = array(
668 'page_namespace' => $ot->getTalkPage()->getNamespace(),
669 'page_title' => $ot->getDBkey()
670 );
671 } else {
672 # Skip the query
673 $conds = null;
674 }
675
676 $extraPages = array();
677 if ( !is_null( $conds ) ) {
678 $extraPages = TitleArray::newFromResult(
679 $dbr->select( 'page',
680 array( 'page_id', 'page_namespace', 'page_title' ),
681 $conds,
682 __METHOD__
683 )
684 );
685 }
686
687 $extraOutput = array();
688 $count = 1;
689 foreach ( $extraPages as $oldSubpage ) {
690 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
691 # Already did this one.
692 continue;
693 }
694
695 $newPageName = preg_replace(
696 '#^' . preg_quote( $ot->getDBkey(), '#' ) . '#',
697 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
698 $oldSubpage->getDBkey()
699 );
700
701 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
702 // Moving a subpage from a subject namespace to a talk namespace or vice-versa
703 $newNs = $nt->getNamespace();
704 } elseif ( $oldSubpage->isTalkPage() ) {
705 $newNs = $nt->getTalkPage()->getNamespace();
706 } else {
707 $newNs = $nt->getSubjectPage()->getNamespace();
708 }
709
710 # Bug 14385: we need makeTitleSafe because the new page names may
711 # be longer than 255 characters.
712 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
713 if ( !$newSubpage ) {
714 $oldLink = Linker::linkKnown( $oldSubpage );
715 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink )
716 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
717 continue;
718 }
719
720 # This was copy-pasted from Renameuser, bleh.
721 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
722 $link = Linker::linkKnown( $newSubpage );
723 $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
724 } else {
725 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
726
727 if ( $success === true ) {
728 if ( $this->fixRedirects ) {
729 DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
730 }
731 $oldLink = Linker::link(
732 $oldSubpage,
733 null,
734 array(),
735 array( 'redirect' => 'no' )
736 );
737
738 $newLink = Linker::linkKnown( $newSubpage );
739 $extraOutput[] = $this->msg( 'movepage-page-moved' )
740 ->rawParams( $oldLink, $newLink )->escaped();
741 ++$count;
742
743 $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
744 if ( $count >= $maximumMovedPages ) {
745 $extraOutput[] = $this->msg( 'movepage-max-pages' )
746 ->numParams( $maximumMovedPages )->escaped();
747 break;
748 }
749 } else {
750 $oldLink = Linker::linkKnown( $oldSubpage );
751 $newLink = Linker::link( $newSubpage );
752 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )
753 ->rawParams( $oldLink, $newLink )->escaped();
754 }
755 }
756 }
757
758 if ( $extraOutput !== array() ) {
759 $out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
760 }
761
762 # Deal with watches (we don't watch subpages)
763 WatchAction::doWatchOrUnwatch( $this->watch, $ot, $user );
764 WatchAction::doWatchOrUnwatch( $this->watch, $nt, $user );
765 }
766
767 function showLogFragment( $title ) {
768 $moveLogPage = new LogPage( 'move' );
769 $out = $this->getOutput();
770 $out->addHTML( Xml::element( 'h2', null, $moveLogPage->getName()->text() ) );
771 LogEventsList::showLogExtract( $out, 'move', $title );
772 }
773
774 function showSubpages( $title ) {
775 if ( !MWNamespace::hasSubpages( $title->getNamespace() ) ) {
776 return;
777 }
778
779 $subpages = $title->getSubpages();
780 $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
781
782 $out = $this->getOutput();
783 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
784
785 # No subpages.
786 if ( $count == 0 ) {
787 $out->addWikiMsg( 'movenosubpage' );
788
789 return;
790 }
791
792 $out->addWikiMsg( 'movesubpagetext', $this->getLanguage()->formatNum( $count ) );
793 $out->addHTML( "<ul>\n" );
794
795 foreach ( $subpages as $subpage ) {
796 $link = Linker::link( $subpage );
797 $out->addHTML( "<li>$link</li>\n" );
798 }
799 $out->addHTML( "</ul>\n" );
800 }
801
802 protected function getGroupName() {
803 return 'pagetools';
804 }
805 }