cache: Add in-process caching to MessageBlobStore
[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 $this->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 $file->load( File::READ_LATEST );
541 if ( $file->exists() ) {
542 $file->delete( $reason, false, $user );
543 }
544 }
545
546 $error = ''; // passed by ref
547 $page = WikiPage::factory( $nt );
548 $deleteStatus = $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
549 if ( !$deleteStatus->isGood() ) {
550 $this->showForm( $deleteStatus->getErrorsArray() );
551
552 return;
553 }
554 }
555
556 $handler = ContentHandler::getForTitle( $ot );
557
558 if ( !$handler->supportsRedirects() ) {
559 $createRedirect = false;
560 } elseif ( $user->isAllowed( 'suppressredirect' ) ) {
561 $createRedirect = $this->leaveRedirect;
562 } else {
563 $createRedirect = true;
564 }
565
566 # Do the actual move.
567 $mp = new MovePage( $ot, $nt );
568 $valid = $mp->isValidMove();
569 if ( !$valid->isOK() ) {
570 $this->showForm( $valid->getErrorsArray() );
571 return;
572 }
573
574 $permStatus = $mp->checkPermissions( $user, $this->reason );
575 if ( !$permStatus->isOK() ) {
576 $this->showForm( $permStatus->getErrorsArray() );
577 return;
578 }
579
580 $status = $mp->move( $user, $this->reason, $createRedirect );
581 if ( !$status->isOK() ) {
582 $this->showForm( $status->getErrorsArray() );
583 return;
584 }
585
586 if ( $this->getConfig()->get( 'FixDoubleRedirects' ) && $this->fixRedirects ) {
587 DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
588 }
589
590 $out = $this->getOutput();
591 $out->setPageTitle( $this->msg( 'pagemovedsub' ) );
592
593 $oldLink = Linker::link(
594 $ot,
595 null,
596 array( 'id' => 'movepage-oldlink' ),
597 array( 'redirect' => 'no' )
598 );
599 $newLink = Linker::linkKnown(
600 $nt,
601 null,
602 array( 'id' => 'movepage-newlink' )
603 );
604 $oldText = $ot->getPrefixedText();
605 $newText = $nt->getPrefixedText();
606
607 if ( $ot->exists() ) {
608 //NOTE: we assume that if the old title exists, it's because it was re-created as
609 // a redirect to the new title. This is not safe, but what we did before was
610 // even worse: we just determined whether a redirect should have been created,
611 // and reported that it was created if it should have, without any checks.
612 // Also note that isRedirect() is unreliable because of bug 37209.
613 $msgName = 'movepage-moved-redirect';
614 } else {
615 $msgName = 'movepage-moved-noredirect';
616 }
617
618 $out->addHTML( $this->msg( 'movepage-moved' )->rawParams( $oldLink,
619 $newLink )->params( $oldText, $newText )->parseAsBlock() );
620 $out->addWikiMsg( $msgName );
621
622 Hooks::run( 'SpecialMovepageAfterMove', array( &$this, &$ot, &$nt ) );
623
624 # Now we move extra pages we've been asked to move: subpages and talk
625 # pages. First, if the old page or the new page is a talk page, we
626 # can't move any talk pages: cancel that.
627 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
628 $this->moveTalk = false;
629 }
630
631 if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
632 $this->moveSubpages = false;
633 }
634
635 # Next make a list of id's. This might be marginally less efficient
636 # than a more direct method, but this is not a highly performance-cri-
637 # tical code path and readable code is more important here.
638 #
639 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
640 # 4 might get confused. If so, consider rewriting as a UNION.
641 #
642 # If the target namespace doesn't allow subpages, moving with subpages
643 # would mean that you couldn't move them back in one operation, which
644 # is bad.
645 # @todo FIXME: A specific error message should be given in this case.
646
647 // @todo FIXME: Use Title::moveSubpages() here
648 $dbr = wfGetDB( DB_MASTER );
649 if ( $this->moveSubpages && (
650 MWNamespace::hasSubpages( $nt->getNamespace() ) || (
651 $this->moveTalk
652 && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
653 )
654 ) ) {
655 $conds = array(
656 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
657 . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
658 );
659 $conds['page_namespace'] = array();
660 if ( MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
661 $conds['page_namespace'][] = $ot->getNamespace();
662 }
663 if ( $this->moveTalk &&
664 MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
665 ) {
666 $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
667 }
668 } elseif ( $this->moveTalk ) {
669 $conds = array(
670 'page_namespace' => $ot->getTalkPage()->getNamespace(),
671 'page_title' => $ot->getDBkey()
672 );
673 } else {
674 # Skip the query
675 $conds = null;
676 }
677
678 $extraPages = array();
679 if ( !is_null( $conds ) ) {
680 $extraPages = TitleArray::newFromResult(
681 $dbr->select( 'page',
682 array( 'page_id', 'page_namespace', 'page_title' ),
683 $conds,
684 __METHOD__
685 )
686 );
687 }
688
689 $extraOutput = array();
690 $count = 1;
691 foreach ( $extraPages as $oldSubpage ) {
692 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
693 # Already did this one.
694 continue;
695 }
696
697 $newPageName = preg_replace(
698 '#^' . preg_quote( $ot->getDBkey(), '#' ) . '#',
699 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
700 $oldSubpage->getDBkey()
701 );
702
703 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
704 // Moving a subpage from a subject namespace to a talk namespace or vice-versa
705 $newNs = $nt->getNamespace();
706 } elseif ( $oldSubpage->isTalkPage() ) {
707 $newNs = $nt->getTalkPage()->getNamespace();
708 } else {
709 $newNs = $nt->getSubjectPage()->getNamespace();
710 }
711
712 # Bug 14385: we need makeTitleSafe because the new page names may
713 # be longer than 255 characters.
714 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
715 if ( !$newSubpage ) {
716 $oldLink = Linker::linkKnown( $oldSubpage );
717 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink )
718 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
719 continue;
720 }
721
722 # This was copy-pasted from Renameuser, bleh.
723 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
724 $link = Linker::linkKnown( $newSubpage );
725 $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
726 } else {
727 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
728
729 if ( $success === true ) {
730 if ( $this->fixRedirects ) {
731 DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
732 }
733 $oldLink = Linker::link(
734 $oldSubpage,
735 null,
736 array(),
737 array( 'redirect' => 'no' )
738 );
739
740 $newLink = Linker::linkKnown( $newSubpage );
741 $extraOutput[] = $this->msg( 'movepage-page-moved' )
742 ->rawParams( $oldLink, $newLink )->escaped();
743 ++$count;
744
745 $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
746 if ( $count >= $maximumMovedPages ) {
747 $extraOutput[] = $this->msg( 'movepage-max-pages' )
748 ->numParams( $maximumMovedPages )->escaped();
749 break;
750 }
751 } else {
752 $oldLink = Linker::linkKnown( $oldSubpage );
753 $newLink = Linker::link( $newSubpage );
754 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )
755 ->rawParams( $oldLink, $newLink )->escaped();
756 }
757 }
758 }
759
760 if ( $extraOutput !== array() ) {
761 $out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
762 }
763
764 # Deal with watches (we don't watch subpages)
765 WatchAction::doWatchOrUnwatch( $this->watch, $ot, $user );
766 WatchAction::doWatchOrUnwatch( $this->watch, $nt, $user );
767 }
768
769 function showLogFragment( $title ) {
770 $moveLogPage = new LogPage( 'move' );
771 $out = $this->getOutput();
772 $out->addHTML( Xml::element( 'h2', null, $moveLogPage->getName()->text() ) );
773 LogEventsList::showLogExtract( $out, 'move', $title );
774 }
775
776 function showSubpages( $title ) {
777 if ( !MWNamespace::hasSubpages( $title->getNamespace() ) ) {
778 return;
779 }
780
781 $subpages = $title->getSubpages();
782 $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
783
784 $out = $this->getOutput();
785 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
786
787 # No subpages.
788 if ( $count == 0 ) {
789 $out->addWikiMsg( 'movenosubpage' );
790
791 return;
792 }
793
794 $out->addWikiMsg( 'movesubpagetext', $this->getLanguage()->formatNum( $count ) );
795 $out->addHTML( "<ul>\n" );
796
797 foreach ( $subpages as $subpage ) {
798 $link = Linker::link( $subpage );
799 $out->addHTML( "<li>$link</li>\n" );
800 }
801 $out->addHTML( "</ul>\n" );
802 }
803
804 protected function getGroupName() {
805 return 'pagetools';
806 }
807 }