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