MediaWiki  REL1_31
MovePage.php
Go to the documentation of this file.
1 <?php
2 
23 
30 class MovePage {
31 
35  protected $oldTitle;
36 
40  protected $newTitle;
41 
42  public function __construct( Title $oldTitle, Title $newTitle ) {
43  $this->oldTitle = $oldTitle;
44  $this->newTitle = $newTitle;
45  }
46 
47  public function checkPermissions( User $user, $reason ) {
48  $status = new Status();
49 
50  $errors = wfMergeErrorArrays(
51  $this->oldTitle->getUserPermissionsErrors( 'move', $user ),
52  $this->oldTitle->getUserPermissionsErrors( 'edit', $user ),
53  $this->newTitle->getUserPermissionsErrors( 'move-target', $user ),
54  $this->newTitle->getUserPermissionsErrors( 'edit', $user )
55  );
56 
57  // Convert into a Status object
58  if ( $errors ) {
59  foreach ( $errors as $error ) {
60  call_user_func_array( [ $status, 'fatal' ], $error );
61  }
62  }
63 
64  if ( EditPage::matchSummarySpamRegex( $reason ) !== false ) {
65  // This is kind of lame, won't display nice
66  $status->fatal( 'spamprotectiontext' );
67  }
68 
69  $tp = $this->newTitle->getTitleProtection();
70  if ( $tp !== false && !$user->isAllowed( $tp['permission'] ) ) {
71  $status->fatal( 'cantmove-titleprotected' );
72  }
73 
74  Hooks::run( 'MovePageCheckPermissions',
75  [ $this->oldTitle, $this->newTitle, $user, $reason, $status ]
76  );
77 
78  return $status;
79  }
80 
88  public function isValidMove() {
90  $status = new Status();
91 
92  if ( $this->oldTitle->equals( $this->newTitle ) ) {
93  $status->fatal( 'selfmove' );
94  }
95  if ( !$this->oldTitle->isMovable() ) {
96  $status->fatal( 'immobile-source-namespace', $this->oldTitle->getNsText() );
97  }
98  if ( $this->newTitle->isExternal() ) {
99  $status->fatal( 'immobile-target-namespace-iw' );
100  }
101  if ( !$this->newTitle->isMovable() ) {
102  $status->fatal( 'immobile-target-namespace', $this->newTitle->getNsText() );
103  }
104 
105  $oldid = $this->oldTitle->getArticleID();
106 
107  if ( strlen( $this->newTitle->getDBkey() ) < 1 ) {
108  $status->fatal( 'articleexists' );
109  }
110  if (
111  ( $this->oldTitle->getDBkey() == '' ) ||
112  ( !$oldid ) ||
113  ( $this->newTitle->getDBkey() == '' )
114  ) {
115  $status->fatal( 'badarticleerror' );
116  }
117 
118  # The move is allowed only if (1) the target doesn't exist, or
119  # (2) the target is a redirect to the source, and has no history
120  # (so we can undo bad moves right after they're done).
121  if ( $this->newTitle->getArticleID() && !$this->isValidMoveTarget() ) {
122  $status->fatal( 'articleexists' );
123  }
124 
125  // Content model checks
126  if ( !$wgContentHandlerUseDB &&
127  $this->oldTitle->getContentModel() !== $this->newTitle->getContentModel() ) {
128  // can't move a page if that would change the page's content model
129  $status->fatal(
130  'bad-target-model',
131  ContentHandler::getLocalizedName( $this->oldTitle->getContentModel() ),
132  ContentHandler::getLocalizedName( $this->newTitle->getContentModel() )
133  );
134  } elseif (
135  !ContentHandler::getForTitle( $this->oldTitle )->canBeUsedOn( $this->newTitle )
136  ) {
137  $status->fatal(
138  'content-not-allowed-here',
139  ContentHandler::getLocalizedName( $this->oldTitle->getContentModel() ),
140  $this->newTitle->getPrefixedText()
141  );
142  }
143 
144  // Image-specific checks
145  if ( $this->oldTitle->inNamespace( NS_FILE ) ) {
146  $status->merge( $this->isValidFileMove() );
147  }
148 
149  if ( $this->newTitle->inNamespace( NS_FILE ) && !$this->oldTitle->inNamespace( NS_FILE ) ) {
150  $status->fatal( 'nonfile-cannot-move-to-file' );
151  }
152 
153  // Hook for extensions to say a title can't be moved for technical reasons
154  Hooks::run( 'MovePageIsValidMove', [ $this->oldTitle, $this->newTitle, $status ] );
155 
156  return $status;
157  }
158 
164  protected function isValidFileMove() {
165  $status = new Status();
166  $file = wfLocalFile( $this->oldTitle );
167  $file->load( File::READ_LATEST );
168  if ( $file->exists() ) {
169  if ( $this->newTitle->getText() != wfStripIllegalFilenameChars( $this->newTitle->getText() ) ) {
170  $status->fatal( 'imageinvalidfilename' );
171  }
172  if ( !File::checkExtensionCompatibility( $file, $this->newTitle->getDBkey() ) ) {
173  $status->fatal( 'imagetypemismatch' );
174  }
175  }
176 
177  if ( !$this->newTitle->inNamespace( NS_FILE ) ) {
178  $status->fatal( 'imagenocrossnamespace' );
179  }
180 
181  return $status;
182  }
183 
191  protected function isValidMoveTarget() {
192  # Is it an existing file?
193  if ( $this->newTitle->inNamespace( NS_FILE ) ) {
194  $file = wfLocalFile( $this->newTitle );
195  $file->load( File::READ_LATEST );
196  if ( $file->exists() ) {
197  wfDebug( __METHOD__ . ": file exists\n" );
198  return false;
199  }
200  }
201  # Is it a redirect with no history?
202  if ( !$this->newTitle->isSingleRevRedirect() ) {
203  wfDebug( __METHOD__ . ": not a one-rev redirect\n" );
204  return false;
205  }
206  # Get the article text
207  $rev = Revision::newFromTitle( $this->newTitle, false, Revision::READ_LATEST );
208  if ( !is_object( $rev ) ) {
209  return false;
210  }
211  $content = $rev->getContent();
212  # Does the redirect point to the source?
213  # Or is it a broken self-redirect, usually caused by namespace collisions?
214  $redirTitle = $content ? $content->getRedirectTarget() : null;
215 
216  if ( $redirTitle ) {
217  if ( $redirTitle->getPrefixedDBkey() !== $this->oldTitle->getPrefixedDBkey() &&
218  $redirTitle->getPrefixedDBkey() !== $this->newTitle->getPrefixedDBkey() ) {
219  wfDebug( __METHOD__ . ": redirect points to other page\n" );
220  return false;
221  } else {
222  return true;
223  }
224  } else {
225  # Fail safe (not a redirect after all. strange.)
226  wfDebug( __METHOD__ . ": failsafe: database says " . $this->newTitle->getPrefixedDBkey() .
227  " is a redirect, but it doesn't contain a valid redirect.\n" );
228  return false;
229  }
230  }
231 
240  public function move( User $user, $reason, $createRedirect, array $changeTags = [] ) {
242 
243  Hooks::run( 'TitleMove', [ $this->oldTitle, $this->newTitle, $user ] );
244 
245  // If it is a file, move it first.
246  // It is done before all other moving stuff is done because it's hard to revert.
247  $dbw = wfGetDB( DB_MASTER );
248  if ( $this->oldTitle->getNamespace() == NS_FILE ) {
249  $file = wfLocalFile( $this->oldTitle );
250  $file->load( File::READ_LATEST );
251  if ( $file->exists() ) {
252  $status = $file->move( $this->newTitle );
253  if ( !$status->isOK() ) {
254  return $status;
255  }
256  }
257  // Clear RepoGroup process cache
258  RepoGroup::singleton()->clearCache( $this->oldTitle );
259  RepoGroup::singleton()->clearCache( $this->newTitle ); # clear false negative cache
260  }
261 
262  $dbw->startAtomic( __METHOD__ );
263 
264  Hooks::run( 'TitleMoveStarting', [ $this->oldTitle, $this->newTitle, $user ] );
265 
266  $pageid = $this->oldTitle->getArticleID( Title::GAID_FOR_UPDATE );
267  $protected = $this->oldTitle->isProtected();
268 
269  // Do the actual move; if this fails, it will throw an MWException(!)
270  $nullRevision = $this->moveToInternal( $user, $this->newTitle, $reason, $createRedirect,
271  $changeTags );
272 
273  // Refresh the sortkey for this row. Be careful to avoid resetting
274  // cl_timestamp, which may disturb time-based lists on some sites.
275  // @todo This block should be killed, it's duplicating code
276  // from LinksUpdate::getCategoryInsertions() and friends.
277  $prefixes = $dbw->select(
278  'categorylinks',
279  [ 'cl_sortkey_prefix', 'cl_to' ],
280  [ 'cl_from' => $pageid ],
281  __METHOD__
282  );
283  if ( $this->newTitle->getNamespace() == NS_CATEGORY ) {
284  $type = 'subcat';
285  } elseif ( $this->newTitle->getNamespace() == NS_FILE ) {
286  $type = 'file';
287  } else {
288  $type = 'page';
289  }
290  foreach ( $prefixes as $prefixRow ) {
291  $prefix = $prefixRow->cl_sortkey_prefix;
292  $catTo = $prefixRow->cl_to;
293  $dbw->update( 'categorylinks',
294  [
295  'cl_sortkey' => Collation::singleton()->getSortKey(
296  $this->newTitle->getCategorySortkey( $prefix ) ),
297  'cl_collation' => $wgCategoryCollation,
298  'cl_type' => $type,
299  'cl_timestamp=cl_timestamp' ],
300  [
301  'cl_from' => $pageid,
302  'cl_to' => $catTo ],
303  __METHOD__
304  );
305  }
306 
307  $redirid = $this->oldTitle->getArticleID();
308 
309  if ( $protected ) {
310  # Protect the redirect title as the title used to be...
311  $res = $dbw->select(
312  'page_restrictions',
313  [ 'pr_type', 'pr_level', 'pr_cascade', 'pr_user', 'pr_expiry' ],
314  [ 'pr_page' => $pageid ],
315  __METHOD__,
316  'FOR UPDATE'
317  );
318  $rowsInsert = [];
319  foreach ( $res as $row ) {
320  $rowsInsert[] = [
321  'pr_page' => $redirid,
322  'pr_type' => $row->pr_type,
323  'pr_level' => $row->pr_level,
324  'pr_cascade' => $row->pr_cascade,
325  'pr_user' => $row->pr_user,
326  'pr_expiry' => $row->pr_expiry
327  ];
328  }
329  $dbw->insert( 'page_restrictions', $rowsInsert, __METHOD__, [ 'IGNORE' ] );
330 
331  // Build comment for log
332  $comment = wfMessage(
333  'prot_1movedto2',
334  $this->oldTitle->getPrefixedText(),
335  $this->newTitle->getPrefixedText()
336  )->inContentLanguage()->text();
337  if ( $reason ) {
338  $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
339  }
340 
341  // reread inserted pr_ids for log relation
342  $insertedPrIds = $dbw->select(
343  'page_restrictions',
344  'pr_id',
345  [ 'pr_page' => $redirid ],
346  __METHOD__
347  );
348  $logRelationsValues = [];
349  foreach ( $insertedPrIds as $prid ) {
350  $logRelationsValues[] = $prid->pr_id;
351  }
352 
353  // Update the protection log
354  $logEntry = new ManualLogEntry( 'protect', 'move_prot' );
355  $logEntry->setTarget( $this->newTitle );
356  $logEntry->setComment( $comment );
357  $logEntry->setPerformer( $user );
358  $logEntry->setParameters( [
359  '4::oldtitle' => $this->oldTitle->getPrefixedText(),
360  ] );
361  $logEntry->setRelations( [ 'pr_id' => $logRelationsValues ] );
362  $logEntry->setTags( $changeTags );
363  $logId = $logEntry->insert();
364  $logEntry->publish( $logId );
365  }
366 
367  // Update *_from_namespace fields as needed
368  if ( $this->oldTitle->getNamespace() != $this->newTitle->getNamespace() ) {
369  $dbw->update( 'pagelinks',
370  [ 'pl_from_namespace' => $this->newTitle->getNamespace() ],
371  [ 'pl_from' => $pageid ],
372  __METHOD__
373  );
374  $dbw->update( 'templatelinks',
375  [ 'tl_from_namespace' => $this->newTitle->getNamespace() ],
376  [ 'tl_from' => $pageid ],
377  __METHOD__
378  );
379  $dbw->update( 'imagelinks',
380  [ 'il_from_namespace' => $this->newTitle->getNamespace() ],
381  [ 'il_from' => $pageid ],
382  __METHOD__
383  );
384  }
385 
386  # Update watchlists
387  $oldtitle = $this->oldTitle->getDBkey();
388  $newtitle = $this->newTitle->getDBkey();
389  $oldsnamespace = MWNamespace::getSubject( $this->oldTitle->getNamespace() );
390  $newsnamespace = MWNamespace::getSubject( $this->newTitle->getNamespace() );
391  if ( $oldsnamespace != $newsnamespace || $oldtitle != $newtitle ) {
392  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
393  $store->duplicateAllAssociatedEntries( $this->oldTitle, $this->newTitle );
394  }
395 
396  Hooks::run(
397  'TitleMoveCompleting',
398  [ $this->oldTitle, $this->newTitle,
399  $user, $pageid, $redirid, $reason, $nullRevision ]
400  );
401 
402  $dbw->endAtomic( __METHOD__ );
403 
404  $params = [
407  &$user,
408  $pageid,
409  $redirid,
410  $reason,
411  $nullRevision
412  ];
413  // Keep each single hook handler atomic
416  $dbw,
417  __METHOD__,
418  // Hold onto $user to avoid HHVM bug where it no longer
419  // becomes a reference (T118683)
420  function () use ( $params, &$user ) {
421  Hooks::run( 'TitleMoveComplete', $params );
422  }
423  )
424  );
425 
426  return Status::newGood();
427  }
428 
444  private function moveToInternal( User $user, &$nt, $reason = '', $createRedirect = true,
445  array $changeTags = []
446  ) {
447  if ( $nt->exists() ) {
448  $moveOverRedirect = true;
449  $logType = 'move_redir';
450  } else {
451  $moveOverRedirect = false;
452  $logType = 'move';
453  }
454 
455  if ( $moveOverRedirect ) {
456  $overwriteMessage = wfMessage(
457  'delete_and_move_reason',
458  $this->oldTitle->getPrefixedText()
459  )->inContentLanguage()->text();
460  $newpage = WikiPage::factory( $nt );
461  $errs = [];
462  $status = $newpage->doDeleteArticleReal(
463  $overwriteMessage,
464  /* $suppress */ false,
465  $nt->getArticleID(),
466  /* $commit */ false,
467  $errs,
468  $user,
469  $changeTags,
470  'delete_redir'
471  );
472 
473  if ( !$status->isGood() ) {
474  throw new MWException( 'Failed to delete page-move revision: ' . $status );
475  }
476 
477  $nt->resetArticleID( false );
478  }
479 
480  if ( $createRedirect ) {
481  if ( $this->oldTitle->getNamespace() == NS_CATEGORY
482  && !wfMessage( 'category-move-redirect-override' )->inContentLanguage()->isDisabled()
483  ) {
484  $redirectContent = new WikitextContent(
485  wfMessage( 'category-move-redirect-override' )
486  ->params( $nt->getPrefixedText() )->inContentLanguage()->plain() );
487  } else {
488  $contentHandler = ContentHandler::getForTitle( $this->oldTitle );
489  $redirectContent = $contentHandler->makeRedirectContent( $nt,
490  wfMessage( 'move-redirect-text' )->inContentLanguage()->plain() );
491  }
492 
493  // NOTE: If this page's content model does not support redirects, $redirectContent will be null.
494  } else {
495  $redirectContent = null;
496  }
497 
498  // Figure out whether the content model is no longer the default
499  $oldDefault = ContentHandler::getDefaultModelFor( $this->oldTitle );
500  $contentModel = $this->oldTitle->getContentModel();
501  $newDefault = ContentHandler::getDefaultModelFor( $nt );
502  $defaultContentModelChanging = ( $oldDefault !== $newDefault
503  && $oldDefault === $contentModel );
504 
505  // T59084: log_page should be the ID of the *moved* page
506  $oldid = $this->oldTitle->getArticleID();
507  $logTitle = clone $this->oldTitle;
508 
509  $logEntry = new ManualLogEntry( 'move', $logType );
510  $logEntry->setPerformer( $user );
511  $logEntry->setTarget( $logTitle );
512  $logEntry->setComment( $reason );
513  $logEntry->setParameters( [
514  '4::target' => $nt->getPrefixedText(),
515  '5::noredir' => $redirectContent ? '0' : '1',
516  ] );
517 
518  $formatter = LogFormatter::newFromEntry( $logEntry );
519  $formatter->setContext( RequestContext::newExtraneousContext( $this->oldTitle ) );
520  $comment = $formatter->getPlainActionText();
521  if ( $reason ) {
522  $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
523  }
524 
525  $dbw = wfGetDB( DB_MASTER );
526 
527  $oldpage = WikiPage::factory( $this->oldTitle );
528  $oldcountable = $oldpage->isCountable();
529 
530  $newpage = WikiPage::factory( $nt );
531 
532  # Save a null revision in the page's history notifying of the move
533  $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true, $user );
534  if ( !is_object( $nullRevision ) ) {
535  throw new MWException( 'No valid null revision produced in ' . __METHOD__ );
536  }
537 
538  $nullRevId = $nullRevision->insertOn( $dbw );
539  $logEntry->setAssociatedRevId( $nullRevId );
540 
541  # Change the name of the target page:
542  $dbw->update( 'page',
543  /* SET */ [
544  'page_namespace' => $nt->getNamespace(),
545  'page_title' => $nt->getDBkey(),
546  ],
547  /* WHERE */ [ 'page_id' => $oldid ],
548  __METHOD__
549  );
550 
551  if ( !$redirectContent ) {
552  // Clean up the old title *before* reset article id - T47348
553  WikiPage::onArticleDelete( $this->oldTitle );
554  }
555 
556  $this->oldTitle->resetArticleID( 0 ); // 0 == non existing
557  $nt->resetArticleID( $oldid );
558  $newpage->loadPageData( WikiPage::READ_LOCKING ); // T48397
559 
560  $newpage->updateRevisionOn( $dbw, $nullRevision );
561 
562  Hooks::run( 'NewRevisionFromEditComplete',
563  [ $newpage, $nullRevision, $nullRevision->getParentId(), $user ] );
564 
565  $newpage->doEditUpdates( $nullRevision, $user,
566  [ 'changed' => false, 'moved' => true, 'oldcountable' => $oldcountable ] );
567 
568  // If the default content model changes, we need to populate rev_content_model
569  if ( $defaultContentModelChanging ) {
570  $dbw->update(
571  'revision',
572  [ 'rev_content_model' => $contentModel ],
573  [ 'rev_page' => $nt->getArticleID(), 'rev_content_model IS NULL' ],
574  __METHOD__
575  );
576  }
577 
579 
580  # Recreate the redirect, this time in the other direction.
581  if ( $redirectContent ) {
582  $redirectArticle = WikiPage::factory( $this->oldTitle );
583  $redirectArticle->loadFromRow( false, WikiPage::READ_LOCKING ); // T48397
584  $newid = $redirectArticle->insertOn( $dbw );
585  if ( $newid ) { // sanity
586  $this->oldTitle->resetArticleID( $newid );
587  $redirectRevision = new Revision( [
588  'title' => $this->oldTitle, // for determining the default content model
589  'page' => $newid,
590  'user_text' => $user->getName(),
591  'user' => $user->getId(),
592  'comment' => $comment,
593  'content' => $redirectContent ] );
594  $redirectRevId = $redirectRevision->insertOn( $dbw );
595  $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
596 
597  Hooks::run( 'NewRevisionFromEditComplete',
598  [ $redirectArticle, $redirectRevision, false, $user ] );
599 
600  $redirectArticle->doEditUpdates( $redirectRevision, $user, [ 'created' => true ] );
601 
602  // make a copy because of log entry below
603  $redirectTags = $changeTags;
604  if ( in_array( 'mw-new-redirect', ChangeTags::getSoftwareTags() ) ) {
605  $redirectTags[] = 'mw-new-redirect';
606  }
607  ChangeTags::addTags( $redirectTags, null, $redirectRevId, null );
608  }
609  }
610 
611  # Log the move
612  $logid = $logEntry->insert();
613 
614  $logEntry->setTags( $changeTags );
615  $logEntry->publish( $logid );
616 
617  return $nullRevision;
618  }
619 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:247
MovePage\checkPermissions
checkPermissions(User $user, $reason)
Definition: MovePage.php:47
File\checkExtensionCompatibility
static checkExtensionCompatibility(File $old, $new)
Checks if file extensions are compatible.
Definition: File.php:249
WikiPage\onArticleCreate
static onArticleCreate(Title $title)
The onArticle*() functions are supposed to be a kind of hooks which should be called whenever any of ...
Definition: WikiPage.php:3363
RepoGroup\singleton
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:59
wfMergeErrorArrays
wfMergeErrorArrays()
Merge arrays in the style of getUserPermissionsErrors, with duplicate removal e.g.
Definition: GlobalFunctions.php:211
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
MovePage\__construct
__construct(Title $oldTitle, Title $newTitle)
Definition: MovePage.php:42
wfMessage
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MovePage\isValidMoveTarget
isValidMoveTarget()
Checks if $this can be moved to a given Title.
Definition: MovePage.php:191
plain
either a plain
Definition: hooks.txt:2056
MovePage\$oldTitle
Title $oldTitle
Definition: MovePage.php:35
MovePage\move
move(User $user, $reason, $createRedirect, array $changeTags=[])
Definition: MovePage.php:240
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
Definition: DeferredUpdates.php:76
MovePage\isValidMove
isValidMove()
Does various sanity checks that the move is valid.
Definition: MovePage.php:88
NS_FILE
const NS_FILE
Definition: Defines.php:80
$params
$params
Definition: styleTest.css.php:40
RequestContext\newExtraneousContext
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
Definition: RequestContext.php:604
ContentHandler\getForTitle
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
Definition: ContentHandler.php:240
$res
$res
Definition: database.txt:21
$wgContentHandlerUseDB
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
Definition: DefaultSettings.php:8581
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:55
php
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:37
IDBAccessObject\READ_LOCKING
const READ_LOCKING
Constants for object loading bitfield flags (higher => higher QoS)
Definition: IDBAccessObject.php:62
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
Collation\singleton
static singleton()
Definition: Collation.php:34
Revision
Definition: Revision.php:41
Revision\newFromTitle
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition: Revision.php:133
ContentHandler\getDefaultModelFor
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
Definition: ContentHandler.php:178
MWException
MediaWiki exception.
Definition: MWException.php:26
wfStripIllegalFilenameChars
wfStripIllegalFilenameChars( $name)
Replace all invalid characters with '-'.
Definition: GlobalFunctions.php:3027
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:115
MovePage
Handles the backend logic of moving a page from one title to another.
Definition: MovePage.php:30
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2812
WikiPage\onArticleDelete
static onArticleDelete(Title $title)
Clears caches when article is deleted.
Definition: WikiPage.php:3394
ChangeTags\getSoftwareTags
static getSoftwareTags( $all=false)
Loads defined core tags, checks for invalid types (if not array), and filters for supported and enabl...
Definition: ChangeTags.php:53
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:88
DB_MASTER
const DB_MASTER
Definition: defines.php:26
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:33
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:994
AtomicSectionUpdate
Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
Definition: AtomicSectionUpdate.php:9
ContentHandler\getLocalizedName
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
Definition: ContentHandler.php:355
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
EditPage\matchSummarySpamRegex
static matchSummarySpamRegex( $text)
Check given input text against $wgSummarySpamRegex, and return the text of the first match.
Definition: EditPage.php:2374
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define.
Definition: Title.php:54
MovePage\moveToInternal
moveToInternal(User $user, &$nt, $reason='', $createRedirect=true, array $changeTags=[])
Move page to a title which is either a redirect to the source page or nonexistent.
Definition: MovePage.php:444
MovePage\$newTitle
Title $newTitle
Definition: MovePage.php:40
$status
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. '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 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object '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:1255
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1777
Title
Represents a title within MediaWiki.
Definition: Title.php:39
as
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:22
MovePage\isValidFileMove
isValidFileMove()
Sanity checks for when a file is being moved.
Definition: MovePage.php:164
ManualLogEntry
Class for creating log entries manually, to inject them into the database.
Definition: LogEntry.php:432
$wgCategoryCollation
$wgCategoryCollation
Specify how category names should be sorted, when listed on a category page.
Definition: DefaultSettings.php:7637
Revision\newNullRevision
static newNullRevision( $dbw, $pageId, $summary, $minor, $user=null)
Create a new null-revision for insertion into a page's history.
Definition: Revision.php:1159
MediaWikiServices
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:25
MWNamespace\getSubject
static getSubject( $index)
Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA,...
Definition: MWNamespace.php:143
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
wfLocalFile
wfLocalFile( $title)
Get an object referring to a locally registered file.
Definition: GlobalFunctions.php:2864
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
ChangeTags\addTags
static addTags( $tags, $rc_id=null, $rev_id=null, $log_id=null, $params=null, RecentChange $rc=null)
Add tags to a change given its rc_id, rev_id and/or log_id.
Definition: ChangeTags.php:220
LogFormatter\newFromEntry
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Definition: LogFormatter.php:50
$type
$type
Definition: testCompression.php:48