MediaWiki  master
SpecialMovepage.php
Go to the documentation of this file.
1 <?php
25 
33  protected $oldTitle = null;
34 
36  protected $newTitle;
37 
39  protected $reason;
40 
41  // Checks
42 
44  protected $moveTalk;
45 
47  protected $deleteAndMove;
48 
50  protected $moveSubpages;
51 
53  protected $fixRedirects;
54 
56  protected $leaveRedirect;
57 
59  protected $moveOverShared;
60 
61  private $watch = false;
62 
63  public function __construct() {
64  parent::__construct( 'Movepage' );
65  }
66 
67  public function doesWrites() {
68  return true;
69  }
70 
71  public function execute( $par ) {
73 
74  $this->checkReadOnly();
75 
76  $this->setHeaders();
77  $this->outputHeader();
78 
79  $request = $this->getRequest();
80  $target = $par ?? $request->getVal( 'target' );
81 
82  // Yes, the use of getVal() and getText() is wanted, see T22365
83 
84  $oldTitleText = $request->getVal( 'wpOldTitle', $target );
85  $this->oldTitle = Title::newFromText( $oldTitleText );
86 
87  if ( !$this->oldTitle ) {
88  // Either oldTitle wasn't passed, or newFromText returned null
89  throw new ErrorPageError( 'notargettitle', 'notargettext' );
90  }
91  if ( !$this->oldTitle->exists() ) {
92  throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
93  }
94 
95  $newTitleTextMain = $request->getText( 'wpNewTitleMain' );
96  $newTitleTextNs = $request->getInt( 'wpNewTitleNs', $this->oldTitle->getNamespace() );
97  // Backwards compatibility for forms submitting here from other sources
98  // which is more common than it should be..
99  $newTitleText_bc = $request->getText( 'wpNewTitle' );
100  $this->newTitle = strlen( $newTitleText_bc ) > 0
101  ? Title::newFromText( $newTitleText_bc )
102  : Title::makeTitleSafe( $newTitleTextNs, $newTitleTextMain );
103 
104  $user = $this->getUser();
105 
106  # Check rights
107  $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $user );
108  if ( count( $permErrors ) ) {
109  // Auto-block user's IP if the account was "hard" blocked
110  DeferredUpdates::addCallableUpdate( function () use ( $user ) {
111  $user->spreadAnyEditBlock();
112  } );
113  throw new PermissionsError( 'move', $permErrors );
114  }
115 
116  $def = !$request->wasPosted();
117 
118  $this->reason = $request->getText( 'wpReason' );
119  $this->moveTalk = $request->getBool( 'wpMovetalk', $def );
120  $this->fixRedirects = $request->getBool( 'wpFixRedirects', $def );
121  $this->leaveRedirect = $request->getBool( 'wpLeaveRedirect', $def );
122  $this->moveSubpages = $request->getBool( 'wpMovesubpages' );
123  $this->deleteAndMove = $request->getBool( 'wpDeleteAndMove' );
124  $this->moveOverShared = $request->getBool( 'wpMoveOverSharedFile' );
125  $this->watch = $request->getCheck( 'wpWatch' ) && $user->isLoggedIn();
126 
127  if ( $request->getVal( 'action' ) == 'submit' && $request->wasPosted()
128  && $user->matchEditToken( $request->getVal( 'wpEditToken' ) )
129  ) {
130  $this->doSubmit();
131  } else {
132  $this->showForm( [] );
133  }
134  }
135 
144  function showForm( $err, $isPermError = false ) {
145  $this->getSkin()->setRelevantTitle( $this->oldTitle );
146 
147  $out = $this->getOutput();
148  $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
149  $out->addModuleStyles( 'mediawiki.special' );
150  $out->addModules( 'mediawiki.special.movePage' );
151  $this->addHelpLink( 'Help:Moving a page' );
152 
153  $out->addWikiMsg( $this->getConfig()->get( 'FixDoubleRedirects' ) ?
154  'movepagetext' :
155  'movepagetext-noredirectfixer'
156  );
157 
158  if ( $this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
159  $out->wrapWikiMsg(
160  "<div class=\"warningbox mw-moveuserpage-warning\">\n$1\n</div>",
161  'moveuserpage-warning'
162  );
163  } elseif ( $this->oldTitle->getNamespace() == NS_CATEGORY ) {
164  $out->wrapWikiMsg(
165  "<div class=\"warningbox mw-movecategorypage-warning\">\n$1\n</div>",
166  'movecategorypage-warning'
167  );
168  }
169 
170  $deleteAndMove = false;
171  $moveOverShared = false;
172 
173  $user = $this->getUser();
174 
176 
177  if ( !$newTitle ) {
178  # Show the current title as a default
179  # when the form is first opened.
181  } elseif ( !count( $err ) ) {
182  # If a title was supplied, probably from the move log revert
183  # link, check for validity. We can then show some diagnostic
184  # information and save a click.
185  $mp = new MovePage( $this->oldTitle, $newTitle );
186  $status = $mp->isValidMove();
187  $status->merge( $mp->checkPermissions( $user, null ) );
188  if ( $status->getErrors() ) {
189  $err = $status->getErrorsArray();
190  }
191  }
192 
193  if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
194  && $newTitle->quickUserCan( 'delete', $user )
195  ) {
196  $out->wrapWikiMsg(
197  "<div class='warningbox'>\n$1\n</div>\n",
198  [ 'delete_and_move_text', $newTitle->getPrefixedText() ]
199  );
200  $deleteAndMove = true;
201  $err = [];
202  }
203 
204  if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'file-exists-sharedrepo'
205  && $user->isAllowed( 'reupload-shared' )
206  ) {
207  $out->wrapWikiMsg(
208  "<div class='warningbox'>\n$1\n</div>\n",
209  [
210  'move-over-sharedrepo',
212  ]
213  );
214  $moveOverShared = true;
215  $err = [];
216  }
217 
218  $oldTalk = $this->oldTitle->getTalkPage();
219  $oldTitleSubpages = $this->oldTitle->hasSubpages();
220  $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
221 
222  $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
223  !count( $this->oldTitle->getUserPermissionsErrors( 'move-subpages', $user ) );
224 
225  # We also want to be able to move assoc. subpage talk-pages even if base page
226  # has no associated talk page, so || with $oldTitleTalkSubpages.
227  $considerTalk = !$this->oldTitle->isTalkPage() &&
228  ( $oldTalk->exists()
229  || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
230 
231  $dbr = wfGetDB( DB_REPLICA );
232  if ( $this->getConfig()->get( 'FixDoubleRedirects' ) ) {
233  $hasRedirects = $dbr->selectField( 'redirect', '1',
234  [
235  'rd_namespace' => $this->oldTitle->getNamespace(),
236  'rd_title' => $this->oldTitle->getDBkey(),
237  ], __METHOD__ );
238  } else {
239  $hasRedirects = false;
240  }
241 
242  if ( count( $err ) ) {
243  if ( $isPermError ) {
244  $action_desc = $this->msg( 'action-move' )->plain();
245  $errMsgHtml = $this->msg( 'permissionserrorstext-withaction',
246  count( $err ), $action_desc )->parseAsBlock();
247  } else {
248  $errMsgHtml = $this->msg( 'cannotmove', count( $err ) )->parseAsBlock();
249  }
250 
251  if ( count( $err ) == 1 ) {
252  $errMsg = $err[0];
253  $errMsgName = array_shift( $errMsg );
254 
255  if ( $errMsgName == 'hookaborted' ) {
256  $errMsgHtml .= "<p>{$errMsg[0]}</p>\n";
257  } else {
258  $errMsgHtml .= $this->msg( $errMsgName, $errMsg )->parseAsBlock();
259  }
260  } else {
261  $errStr = [];
262 
263  foreach ( $err as $errMsg ) {
264  if ( $errMsg[0] == 'hookaborted' ) {
265  $errStr[] = $errMsg[1];
266  } else {
267  $errMsgName = array_shift( $errMsg );
268  $errStr[] = $this->msg( $errMsgName, $errMsg )->parse();
269  }
270  }
271 
272  $errMsgHtml .= '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n";
273  }
274  $out->addHTML( Html::errorBox( $errMsgHtml ) );
275  }
276 
277  if ( $this->oldTitle->isProtected( 'move' ) ) {
278  # Is the title semi-protected?
279  if ( $this->oldTitle->isSemiProtected( 'move' ) ) {
280  $noticeMsg = 'semiprotectedpagemovewarning';
281  $classes[] = 'mw-textarea-sprotected';
282  } else {
283  # Then it must be protected based on static groups (regular)
284  $noticeMsg = 'protectedpagemovewarning';
285  $classes[] = 'mw-textarea-protected';
286  }
287  $out->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
288  $out->addWikiMsg( $noticeMsg );
290  $out,
291  'protect',
292  $this->oldTitle,
293  '',
294  [ 'lim' => 1 ]
295  );
296  $out->addHTML( "</div>\n" );
297  }
298 
299  // Length limit for wpReason and wpNewTitleMain is enforced in the
300  // mediawiki.special.movePage module
301 
302  $immovableNamespaces = [];
303  foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) {
304  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->isMovable( $nsId ) ) {
305  $immovableNamespaces[] = $nsId;
306  }
307  }
308 
309  $handler = ContentHandler::getForTitle( $this->oldTitle );
310 
311  $out->enableOOUI();
312  $fields = [];
313 
314  $fields[] = new OOUI\FieldLayout(
315  new MediaWiki\Widget\ComplexTitleInputWidget( [
316  'id' => 'wpNewTitle',
317  'namespace' => [
318  'id' => 'wpNewTitleNs',
319  'name' => 'wpNewTitleNs',
320  'value' => $newTitle->getNamespace(),
321  'exclude' => $immovableNamespaces,
322  ],
323  'title' => [
324  'id' => 'wpNewTitleMain',
325  'name' => 'wpNewTitleMain',
326  'value' => $newTitle->getText(),
327  // Inappropriate, since we're expecting the user to input a non-existent page's title
328  'suggestions' => false,
329  ],
330  'infusable' => true,
331  ] ),
332  [
333  'label' => $this->msg( 'newtitle' )->text(),
334  'align' => 'top',
335  ]
336  );
337 
338  // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
339  // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
340  // Unicode codepoints.
341  $fields[] = new OOUI\FieldLayout(
342  new OOUI\TextInputWidget( [
343  'name' => 'wpReason',
344  'id' => 'wpReason',
346  'infusable' => true,
347  'value' => $this->reason,
348  ] ),
349  [
350  'label' => $this->msg( 'movereason' )->text(),
351  'align' => 'top',
352  ]
353  );
354 
355  if ( $considerTalk ) {
356  $fields[] = new OOUI\FieldLayout(
357  new OOUI\CheckboxInputWidget( [
358  'name' => 'wpMovetalk',
359  'id' => 'wpMovetalk',
360  'value' => '1',
361  'selected' => $this->moveTalk,
362  ] ),
363  [
364  'label' => $this->msg( 'movetalk' )->text(),
365  'help' => new OOUI\HtmlSnippet( $this->msg( 'movepagetalktext' )->parseAsBlock() ),
366  'helpInline' => true,
367  'align' => 'inline',
368  'id' => 'wpMovetalk-field',
369  ]
370  );
371  }
372 
373  if ( $user->isAllowed( 'suppressredirect' ) ) {
374  if ( $handler->supportsRedirects() ) {
375  $isChecked = $this->leaveRedirect;
376  $isDisabled = false;
377  } else {
378  $isChecked = false;
379  $isDisabled = true;
380  }
381  $fields[] = new OOUI\FieldLayout(
382  new OOUI\CheckboxInputWidget( [
383  'name' => 'wpLeaveRedirect',
384  'id' => 'wpLeaveRedirect',
385  'value' => '1',
386  'selected' => $isChecked,
387  'disabled' => $isDisabled,
388  ] ),
389  [
390  'label' => $this->msg( 'move-leave-redirect' )->text(),
391  'align' => 'inline',
392  ]
393  );
394  }
395 
396  if ( $hasRedirects ) {
397  $fields[] = new OOUI\FieldLayout(
398  new OOUI\CheckboxInputWidget( [
399  'name' => 'wpFixRedirects',
400  'id' => 'wpFixRedirects',
401  'value' => '1',
402  'selected' => $this->fixRedirects,
403  ] ),
404  [
405  'label' => $this->msg( 'fix-double-redirects' )->text(),
406  'align' => 'inline',
407  ]
408  );
409  }
410 
411  if ( $canMoveSubpage ) {
412  $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
413  $fields[] = new OOUI\FieldLayout(
414  new OOUI\CheckboxInputWidget( [
415  'name' => 'wpMovesubpages',
416  'id' => 'wpMovesubpages',
417  'value' => '1',
418  # Don't check the box if we only have talk subpages to
419  # move and we aren't moving the talk page.
420  'selected' => $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ),
421  ] ),
422  [
423  'label' => new OOUI\HtmlSnippet(
424  $this->msg(
425  ( $this->oldTitle->hasSubpages()
426  ? 'move-subpages'
427  : 'move-talk-subpages' )
428  )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
429  ),
430  'align' => 'inline',
431  ]
432  );
433  }
434 
435  # Don't allow watching if user is not logged in
436  if ( $user->isLoggedIn() ) {
437  $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
438  || $user->isWatched( $this->oldTitle ) );
439  $fields[] = new OOUI\FieldLayout(
440  new OOUI\CheckboxInputWidget( [
441  'name' => 'wpWatch',
442  'id' => 'watch', # ew
443  'value' => '1',
444  'selected' => $watchChecked,
445  ] ),
446  [
447  'label' => $this->msg( 'move-watch' )->text(),
448  'align' => 'inline',
449  ]
450  );
451  }
452 
453  $hiddenFields = '';
454  if ( $moveOverShared ) {
455  $hiddenFields .= Html::hidden( 'wpMoveOverSharedFile', '1' );
456  }
457 
458  if ( $deleteAndMove ) {
459  $fields[] = new OOUI\FieldLayout(
460  new OOUI\CheckboxInputWidget( [
461  'name' => 'wpDeleteAndMove',
462  'id' => 'wpDeleteAndMove',
463  'value' => '1',
464  ] ),
465  [
466  'label' => $this->msg( 'delete_and_move_confirm' )->text(),
467  'align' => 'inline',
468  ]
469  );
470  }
471 
472  $fields[] = new OOUI\FieldLayout(
473  new OOUI\ButtonInputWidget( [
474  'name' => 'wpMove',
475  'value' => $this->msg( 'movepagebtn' )->text(),
476  'label' => $this->msg( 'movepagebtn' )->text(),
477  'flags' => [ 'primary', 'progressive' ],
478  'type' => 'submit',
479  ] ),
480  [
481  'align' => 'top',
482  ]
483  );
484 
485  $fieldset = new OOUI\FieldsetLayout( [
486  'label' => $this->msg( 'move-page-legend' )->text(),
487  'id' => 'mw-movepage-table',
488  'items' => $fields,
489  ] );
490 
491  $form = new OOUI\FormLayout( [
492  'method' => 'post',
493  'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
494  'id' => 'movepage',
495  ] );
496  $form->appendContent(
497  $fieldset,
498  new OOUI\HtmlSnippet(
499  $hiddenFields .
500  Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
501  Html::hidden( 'wpEditToken', $user->getEditToken() )
502  )
503  );
504 
505  $out->addHTML(
506  new OOUI\PanelLayout( [
507  'classes' => [ 'movepage-wrapper' ],
508  'expanded' => false,
509  'padded' => true,
510  'framed' => true,
511  'content' => $form,
512  ] )
513  );
514 
515  $this->showLogFragment( $this->oldTitle );
516  $this->showSubpages( $this->oldTitle );
517  }
518 
519  function doSubmit() {
520  $user = $this->getUser();
521 
522  if ( $user->pingLimiter( 'move' ) ) {
523  throw new ThrottledError;
524  }
525 
526  $ot = $this->oldTitle;
527  $nt = $this->newTitle;
528 
529  # don't allow moving to pages with # in
530  if ( !$nt || $nt->hasFragment() ) {
531  $this->showForm( [ [ 'badtitletext' ] ] );
532 
533  return;
534  }
535 
536  # Show a warning if the target file exists on a shared repo
537  if ( $nt->getNamespace() == NS_FILE
538  && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
539  && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
540  && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $nt )
541  ) {
542  $this->showForm( [ [ 'file-exists-sharedrepo' ] ] );
543 
544  return;
545  }
546 
547  # Delete to make way if requested
548  if ( $this->deleteAndMove ) {
549  $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
550  if ( count( $permErrors ) ) {
551  # Only show the first error
552  $this->showForm( $permErrors, true );
553 
554  return;
555  }
556 
557  $page = WikiPage::factory( $nt );
558 
559  // Small safety margin to guard against concurrent edits
560  if ( $page->isBatchedDelete( 5 ) ) {
561  $this->showForm( [ [ 'movepage-delete-first' ] ] );
562 
563  return;
564  }
565 
566  $reason = $this->msg( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
567 
568  // Delete an associated image if there is
569  if ( $nt->getNamespace() == NS_FILE ) {
570  $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
571  ->newFile( $nt );
572  $file->load( File::READ_LATEST );
573  if ( $file->exists() ) {
574  $file->delete( $reason, false, $user );
575  }
576  }
577 
578  $error = ''; // passed by ref
579  $deleteStatus = $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
580  if ( !$deleteStatus->isGood() ) {
581  $this->showForm( $deleteStatus->getErrorsArray() );
582 
583  return;
584  }
585  }
586 
588 
589  if ( !$handler->supportsRedirects() ) {
590  $createRedirect = false;
591  } elseif ( $user->isAllowed( 'suppressredirect' ) ) {
592  $createRedirect = $this->leaveRedirect;
593  } else {
594  $createRedirect = true;
595  }
596 
597  # Do the actual move.
598  $mp = new MovePage( $ot, $nt );
599 
600  # check whether the requested actions are permitted / possible
601  $userPermitted = $mp->checkPermissions( $user, $this->reason )->isOK();
602  if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
603  $this->moveTalk = false;
604  }
605  if ( $this->moveSubpages ) {
606  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
607  $this->moveSubpages = $permissionManager->userCan( 'move-subpages', $user, $ot );
608  }
609 
610  $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
611  if ( !$status->isOK() ) {
612  $this->showForm( $status->getErrorsArray(), !$userPermitted );
613  return;
614  }
615 
616  if ( $this->getConfig()->get( 'FixDoubleRedirects' ) && $this->fixRedirects ) {
617  DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
618  }
619 
620  $out = $this->getOutput();
621  $out->setPageTitle( $this->msg( 'pagemovedsub' ) );
622 
623  $linkRenderer = $this->getLinkRenderer();
624  $oldLink = $linkRenderer->makeLink(
625  $ot,
626  null,
627  [ 'id' => 'movepage-oldlink' ],
628  [ 'redirect' => 'no' ]
629  );
630  $newLink = $linkRenderer->makeKnownLink(
631  $nt,
632  null,
633  [ 'id' => 'movepage-newlink' ]
634  );
635  $oldText = $ot->getPrefixedText();
636  $newText = $nt->getPrefixedText();
637 
638  if ( $ot->exists() ) {
639  // NOTE: we assume that if the old title exists, it's because it was re-created as
640  // a redirect to the new title. This is not safe, but what we did before was
641  // even worse: we just determined whether a redirect should have been created,
642  // and reported that it was created if it should have, without any checks.
643  // Also note that isRedirect() is unreliable because of T39209.
644  $msgName = 'movepage-moved-redirect';
645  } else {
646  $msgName = 'movepage-moved-noredirect';
647  }
648 
649  $out->addHTML( $this->msg( 'movepage-moved' )->rawParams( $oldLink,
650  $newLink )->params( $oldText, $newText )->parseAsBlock() );
651  $out->addWikiMsg( $msgName );
652 
653  // Avoid PHP 7.1 warning from passing $this by reference
654  $movePage = $this;
655  Hooks::run( 'SpecialMovepageAfterMove', [ &$movePage, &$ot, &$nt ] );
656 
657  /*
658  * Now we move extra pages we've been asked to move: subpages and talk
659  * pages.
660  *
661  * First, make a list of id's. This might be marginally less efficient
662  * than a more direct method, but this is not a highly performance-cri-
663  * tical code path and readable code is more important here.
664  *
665  * If the target namespace doesn't allow subpages, moving with subpages
666  * would mean that you couldn't move them back in one operation, which
667  * is bad.
668  * @todo FIXME: A specific error message should be given in this case.
669  */
670 
671  // @todo FIXME: Use Title::moveSubpages() here
672  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
673  $dbr = wfGetDB( DB_MASTER );
674  if ( $this->moveSubpages && (
675  $nsInfo->hasSubpages( $nt->getNamespace() ) || (
676  $this->moveTalk
677  && $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
678  )
679  ) ) {
680  $conds = [
681  'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
682  . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
683  ];
684  $conds['page_namespace'] = [];
685  if ( $nsInfo->hasSubpages( $nt->getNamespace() ) ) {
686  $conds['page_namespace'][] = $ot->getNamespace();
687  }
688  if ( $this->moveTalk &&
689  $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
690  ) {
691  $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
692  }
693  } elseif ( $this->moveTalk ) {
694  $conds = [
695  'page_namespace' => $ot->getTalkPage()->getNamespace(),
696  'page_title' => $ot->getDBkey()
697  ];
698  } else {
699  # Skip the query
700  $conds = null;
701  }
702 
703  $extraPages = [];
704  if ( !is_null( $conds ) ) {
705  $extraPages = TitleArray::newFromResult(
706  $dbr->select( 'page',
707  [ 'page_id', 'page_namespace', 'page_title' ],
708  $conds,
709  __METHOD__
710  )
711  );
712  }
713 
714  $extraOutput = [];
715  $count = 1;
716  foreach ( $extraPages as $oldSubpage ) {
717  if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
718  # Already did this one.
719  continue;
720  }
721 
722  $newPageName = preg_replace(
723  '#^' . preg_quote( $ot->getDBkey(), '#' ) . '#',
724  StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # T23234
725  $oldSubpage->getDBkey()
726  );
727 
728  if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
729  // Moving a subpage from a subject namespace to a talk namespace or vice-versa
730  $newNs = $nt->getNamespace();
731  } elseif ( $oldSubpage->isTalkPage() ) {
732  $newNs = $nt->getTalkPage()->getNamespace();
733  } else {
734  $newNs = $nt->getSubjectPage()->getNamespace();
735  }
736 
737  # T16385: we need makeTitleSafe because the new page names may
738  # be longer than 255 characters.
739  $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
740  if ( !$newSubpage ) {
741  $oldLink = $linkRenderer->makeKnownLink( $oldSubpage );
742  $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink )
743  ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
744  continue;
745  }
746 
747  $mp = new MovePage( $oldSubpage, $newSubpage );
748  # This was copy-pasted from Renameuser, bleh.
749  if ( $newSubpage->exists() && !$mp->isValidMove()->isOk() ) {
750  $link = $linkRenderer->makeKnownLink( $newSubpage );
751  $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
752  } else {
753  $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
754 
755  if ( $status->isOK() ) {
756  if ( $this->fixRedirects ) {
757  DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
758  }
759  $oldLink = $linkRenderer->makeLink(
760  $oldSubpage,
761  null,
762  [],
763  [ 'redirect' => 'no' ]
764  );
765 
766  $newLink = $linkRenderer->makeKnownLink( $newSubpage );
767  $extraOutput[] = $this->msg( 'movepage-page-moved' )
768  ->rawParams( $oldLink, $newLink )->escaped();
769  ++$count;
770 
771  $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
772  if ( $count >= $maximumMovedPages ) {
773  $extraOutput[] = $this->msg( 'movepage-max-pages' )
774  ->numParams( $maximumMovedPages )->escaped();
775  break;
776  }
777  } else {
778  $oldLink = $linkRenderer->makeKnownLink( $oldSubpage );
779  $newLink = $linkRenderer->makeLink( $newSubpage );
780  $extraOutput[] = $this->msg( 'movepage-page-unmoved' )
781  ->rawParams( $oldLink, $newLink )->escaped();
782  }
783  }
784  }
785 
786  if ( $extraOutput !== [] ) {
787  $out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
788  }
789 
790  # Deal with watches (we don't watch subpages)
791  WatchAction::doWatchOrUnwatch( $this->watch, $ot, $user );
792  WatchAction::doWatchOrUnwatch( $this->watch, $nt, $user );
793  }
794 
795  function showLogFragment( $title ) {
796  $moveLogPage = new LogPage( 'move' );
797  $out = $this->getOutput();
798  $out->addHTML( Xml::element( 'h2', null, $moveLogPage->getName()->text() ) );
800  }
801 
808  function showSubpages( $title ) {
809  $nsHasSubpages = MediaWikiServices::getInstance()->getNamespaceInfo()->
810  hasSubpages( $title->getNamespace() );
811  $subpages = $title->getSubpages();
812  $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
813 
814  $titleIsTalk = $title->isTalkPage();
815  $subpagesTalk = $title->getTalkPage()->getSubpages();
816  $countTalk = $subpagesTalk instanceof TitleArray ? $subpagesTalk->count() : 0;
817  $totalCount = $count + $countTalk;
818 
819  if ( !$nsHasSubpages && $countTalk == 0 ) {
820  return;
821  }
822 
823  $this->getOutput()->wrapWikiMsg(
824  '== $1 ==',
825  [ 'movesubpage', ( $titleIsTalk ? $count : $totalCount ) ]
826  );
827 
828  if ( $nsHasSubpages ) {
829  $this->showSubpagesList( $subpages, $count, 'movesubpagetext', true );
830  }
831 
832  if ( !$titleIsTalk && $countTalk > 0 ) {
833  $this->showSubpagesList( $subpagesTalk, $countTalk, 'movesubpagetalktext' );
834  }
835  }
836 
837  function showSubpagesList( $subpages, $pagecount, $wikiMsg, $noSubpageMsg = false ) {
838  $out = $this->getOutput();
839 
840  # No subpages.
841  if ( $pagecount == 0 && $noSubpageMsg ) {
842  $out->addWikiMsg( 'movenosubpage' );
843  return;
844  }
845 
846  $out->addWikiMsg( $wikiMsg, $this->getLanguage()->formatNum( $pagecount ) );
847  $out->addHTML( "<ul>\n" );
848 
849  $linkBatch = new LinkBatch( $subpages );
850  $linkBatch->setCaller( __METHOD__ );
851  $linkBatch->execute();
852  $linkRenderer = $this->getLinkRenderer();
853 
854  foreach ( $subpages as $subpage ) {
855  $link = $linkRenderer->makeLink( $subpage );
856  $out->addHTML( "<li>$link</li>\n" );
857  }
858  $out->addHTML( "</ul>\n" );
859  }
860 
869  public function prefixSearchSubpages( $search, $limit, $offset ) {
870  return $this->prefixSearchString( $search, $limit, $offset );
871  }
872 
873  protected function getGroupName() {
874  return 'pagetools';
875  }
876 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
Shortcut to construct a special page which is unlisted by default.
Handles the backend logic of moving a page from one title to another.
Definition: MovePage.php:32
string $reason
Text input.
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:984
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition: router.php:42
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter...
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
showSubpagesList( $subpages, $pagecount, $wikiMsg, $noSubpageMsg=false)
getOutput()
Get the OutputPage being used for this instance.
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1696
const COMMENT_CHARACTER_LIMIT
Maximum length of a comment in UTF-8 characters.
A helper class for throttling authentication attempts.
target page
The TitleArray class only exists to provide the newFromResult method at pre- sent.
Definition: TitleArray.php:33
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
const DB_MASTER
Definition: defines.php:26
Class to simplify the use of log pages.
Definition: LogPage.php:33
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3051
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:780
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:780
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
quickUserCan( $action, $user=null)
Can $user perform $action on this page? This skips potentially expensive cascading permission checks ...
Definition: Title.php:2184
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1263
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
prefixSearchString( $search, $limit, $offset)
Perform a regular substring search for prefixSearchSubpages.
An error page which can definitely be safely rendered using the OutputPage.
static doWatchOrUnwatch( $watch, Title $title, User $user)
Watch or unwatch a page.
Definition: WatchAction.php:89
showForm( $err, $isPermError=false)
Show the form.
static singleton()
Definition: RepoGroup.php:60
static fixRedirects( $reason, $redirTitle, $destTitle=false)
Insert jobs into the job queue to fix redirects to the given title.
const NS_CATEGORY
Definition: Defines.php:74
getSkin()
Shortcut to get the skin being used for this instance.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
showLogFragment( $title)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
static newFromResult( $res)
Definition: TitleArray.php:40
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1026
const NS_FILE
Definition: Defines.php:66
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
showSubpages( $title)
Show subpages of the page being moved.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:617
static errorBox( $html, $heading='')
Return an error box.
Definition: Html.php:736
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
getUser()
Shortcut to get the User executing this instance.
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:797
A special page that allows users to change page titles.
getConfig()
Shortcut to get main config object.
Show an error when a user tries to do something they do not have the necessary permissions for...
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
getLanguage()
Shortcut to get user&#39;s language.
msg( $key)
Wrapper around wfMessage that sets the current context.
const DB_REPLICA
Definition: defines.php:25
getRequest()
Get the WebRequest being used for this instance.
static makeName( $ns, $title, $fragment='', $interwiki='', $canonicalNamespace=false)
Make a prefixed DB key from a DB key and a namespace index.
Definition: Title.php:819
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2633
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getPageTitle( $subpage=false)
Get a self-referential title object.
Show an error when the user hits a rate limit.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:67
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319