MediaWiki REL1_31
MovePage.php
Go to the documentation of this file.
1<?php
2
23
30class MovePage {
31
35 protected $oldTitle;
36
40 protected $newTitle;
41
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( Title::READ_LATEST /* T272386 */ )
122 && !$this->isValidMoveTarget()
123 ) {
124 $status->fatal( 'articleexists' );
125 }
126
127 // Content model checks
129 $this->oldTitle->getContentModel() !== $this->newTitle->getContentModel() ) {
130 // can't move a page if that would change the page's content model
131 $status->fatal(
132 'bad-target-model',
133 ContentHandler::getLocalizedName( $this->oldTitle->getContentModel() ),
134 ContentHandler::getLocalizedName( $this->newTitle->getContentModel() )
135 );
136 } elseif (
137 !ContentHandler::getForTitle( $this->oldTitle )->canBeUsedOn( $this->newTitle )
138 ) {
139 $status->fatal(
140 'content-not-allowed-here',
141 ContentHandler::getLocalizedName( $this->oldTitle->getContentModel() ),
142 $this->newTitle->getPrefixedText()
143 );
144 }
145
146 // Image-specific checks
147 if ( $this->oldTitle->inNamespace( NS_FILE ) ) {
148 $status->merge( $this->isValidFileMove() );
149 }
150
151 if ( $this->newTitle->inNamespace( NS_FILE ) && !$this->oldTitle->inNamespace( NS_FILE ) ) {
152 $status->fatal( 'nonfile-cannot-move-to-file' );
153 }
154
155 // Hook for extensions to say a title can't be moved for technical reasons
156 Hooks::run( 'MovePageIsValidMove', [ $this->oldTitle, $this->newTitle, $status ] );
157
158 return $status;
159 }
160
166 protected function isValidFileMove() {
167 $status = new Status();
168 $file = wfLocalFile( $this->oldTitle );
169 $file->load( File::READ_LATEST );
170 if ( $file->exists() ) {
171 if ( $this->newTitle->getText() != wfStripIllegalFilenameChars( $this->newTitle->getText() ) ) {
172 $status->fatal( 'imageinvalidfilename' );
173 }
174 if ( !File::checkExtensionCompatibility( $file, $this->newTitle->getDBkey() ) ) {
175 $status->fatal( 'imagetypemismatch' );
176 }
177 }
178
179 if ( !$this->newTitle->inNamespace( NS_FILE ) ) {
180 $status->fatal( 'imagenocrossnamespace' );
181 }
182
183 return $status;
184 }
185
193 protected function isValidMoveTarget() {
194 # Is it an existing file?
195 if ( $this->newTitle->inNamespace( NS_FILE ) ) {
196 $file = wfLocalFile( $this->newTitle );
197 $file->load( File::READ_LATEST );
198 if ( $file->exists() ) {
199 wfDebug( __METHOD__ . ": file exists\n" );
200 return false;
201 }
202 }
203 # Is it a redirect with no history?
204 if ( !$this->newTitle->isSingleRevRedirect() ) {
205 wfDebug( __METHOD__ . ": not a one-rev redirect\n" );
206 return false;
207 }
208 # Get the article text
209 $rev = Revision::newFromTitle( $this->newTitle, false, Revision::READ_LATEST );
210 if ( !is_object( $rev ) ) {
211 return false;
212 }
213 $content = $rev->getContent();
214 # Does the redirect point to the source?
215 # Or is it a broken self-redirect, usually caused by namespace collisions?
216 $redirTitle = $content ? $content->getRedirectTarget() : null;
217
218 if ( $redirTitle ) {
219 if ( $redirTitle->getPrefixedDBkey() !== $this->oldTitle->getPrefixedDBkey() &&
220 $redirTitle->getPrefixedDBkey() !== $this->newTitle->getPrefixedDBkey() ) {
221 wfDebug( __METHOD__ . ": redirect points to other page\n" );
222 return false;
223 } else {
224 return true;
225 }
226 } else {
227 # Fail safe (not a redirect after all. strange.)
228 wfDebug( __METHOD__ . ": failsafe: database says " . $this->newTitle->getPrefixedDBkey() .
229 " is a redirect, but it doesn't contain a valid redirect.\n" );
230 return false;
231 }
232 }
233
242 public function move( User $user, $reason, $createRedirect, array $changeTags = [] ) {
244
245 Hooks::run( 'TitleMove', [ $this->oldTitle, $this->newTitle, $user ] );
246
247 // If it is a file, move it first.
248 // It is done before all other moving stuff is done because it's hard to revert.
249 $dbw = wfGetDB( DB_MASTER );
250 if ( $this->oldTitle->getNamespace() == NS_FILE ) {
251 $file = wfLocalFile( $this->oldTitle );
252 $file->load( File::READ_LATEST );
253 if ( $file->exists() ) {
254 $status = $file->move( $this->newTitle );
255 if ( !$status->isOK() ) {
256 return $status;
257 }
258 }
259 // Clear RepoGroup process cache
260 RepoGroup::singleton()->clearCache( $this->oldTitle );
261 RepoGroup::singleton()->clearCache( $this->newTitle ); # clear false negative cache
262 }
263
264 $dbw->startAtomic( __METHOD__ );
265
266 Hooks::run( 'TitleMoveStarting', [ $this->oldTitle, $this->newTitle, $user ] );
267
268 $pageid = $this->oldTitle->getArticleID( Title::GAID_FOR_UPDATE );
269 $protected = $this->oldTitle->isProtected();
270
271 // Do the actual move; if this fails, it will throw an MWException(!)
272 $nullRevision = $this->moveToInternal( $user, $this->newTitle, $reason, $createRedirect,
273 $changeTags );
274
275 // Refresh the sortkey for this row. Be careful to avoid resetting
276 // cl_timestamp, which may disturb time-based lists on some sites.
277 // @todo This block should be killed, it's duplicating code
278 // from LinksUpdate::getCategoryInsertions() and friends.
279 $prefixes = $dbw->select(
280 'categorylinks',
281 [ 'cl_sortkey_prefix', 'cl_to' ],
282 [ 'cl_from' => $pageid ],
283 __METHOD__
284 );
285 if ( $this->newTitle->getNamespace() == NS_CATEGORY ) {
286 $type = 'subcat';
287 } elseif ( $this->newTitle->getNamespace() == NS_FILE ) {
288 $type = 'file';
289 } else {
290 $type = 'page';
291 }
292 foreach ( $prefixes as $prefixRow ) {
293 $prefix = $prefixRow->cl_sortkey_prefix;
294 $catTo = $prefixRow->cl_to;
295 $dbw->update( 'categorylinks',
296 [
297 'cl_sortkey' => Collation::singleton()->getSortKey(
298 $this->newTitle->getCategorySortkey( $prefix ) ),
299 'cl_collation' => $wgCategoryCollation,
300 'cl_type' => $type,
301 'cl_timestamp=cl_timestamp' ],
302 [
303 'cl_from' => $pageid,
304 'cl_to' => $catTo ],
305 __METHOD__
306 );
307 }
308
309 $redirid = $this->oldTitle->getArticleID();
310
311 if ( $protected ) {
312 # Protect the redirect title as the title used to be...
313 $res = $dbw->select(
314 'page_restrictions',
315 [ 'pr_type', 'pr_level', 'pr_cascade', 'pr_user', 'pr_expiry' ],
316 [ 'pr_page' => $pageid ],
317 __METHOD__,
318 'FOR UPDATE'
319 );
320 $rowsInsert = [];
321 foreach ( $res as $row ) {
322 $rowsInsert[] = [
323 'pr_page' => $redirid,
324 'pr_type' => $row->pr_type,
325 'pr_level' => $row->pr_level,
326 'pr_cascade' => $row->pr_cascade,
327 'pr_user' => $row->pr_user,
328 'pr_expiry' => $row->pr_expiry
329 ];
330 }
331 $dbw->insert( 'page_restrictions', $rowsInsert, __METHOD__, [ 'IGNORE' ] );
332
333 // Build comment for log
334 $comment = wfMessage(
335 'prot_1movedto2',
336 $this->oldTitle->getPrefixedText(),
337 $this->newTitle->getPrefixedText()
338 )->inContentLanguage()->text();
339 if ( $reason ) {
340 $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
341 }
342
343 // reread inserted pr_ids for log relation
344 $insertedPrIds = $dbw->select(
345 'page_restrictions',
346 'pr_id',
347 [ 'pr_page' => $redirid ],
348 __METHOD__
349 );
350 $logRelationsValues = [];
351 foreach ( $insertedPrIds as $prid ) {
352 $logRelationsValues[] = $prid->pr_id;
353 }
354
355 // Update the protection log
356 $logEntry = new ManualLogEntry( 'protect', 'move_prot' );
357 $logEntry->setTarget( $this->newTitle );
358 $logEntry->setComment( $comment );
359 $logEntry->setPerformer( $user );
360 $logEntry->setParameters( [
361 '4::oldtitle' => $this->oldTitle->getPrefixedText(),
362 ] );
363 $logEntry->setRelations( [ 'pr_id' => $logRelationsValues ] );
364 $logEntry->setTags( $changeTags );
365 $logId = $logEntry->insert();
366 $logEntry->publish( $logId );
367 }
368
369 // Update *_from_namespace fields as needed
370 if ( $this->oldTitle->getNamespace() != $this->newTitle->getNamespace() ) {
371 $dbw->update( 'pagelinks',
372 [ 'pl_from_namespace' => $this->newTitle->getNamespace() ],
373 [ 'pl_from' => $pageid ],
374 __METHOD__
375 );
376 $dbw->update( 'templatelinks',
377 [ 'tl_from_namespace' => $this->newTitle->getNamespace() ],
378 [ 'tl_from' => $pageid ],
379 __METHOD__
380 );
381 $dbw->update( 'imagelinks',
382 [ 'il_from_namespace' => $this->newTitle->getNamespace() ],
383 [ 'il_from' => $pageid ],
384 __METHOD__
385 );
386 }
387
388 # Update watchlists
389 $oldtitle = $this->oldTitle->getDBkey();
390 $newtitle = $this->newTitle->getDBkey();
391 $oldsnamespace = MWNamespace::getSubject( $this->oldTitle->getNamespace() );
392 $newsnamespace = MWNamespace::getSubject( $this->newTitle->getNamespace() );
393 if ( $oldsnamespace != $newsnamespace || $oldtitle != $newtitle ) {
394 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
395 $store->duplicateAllAssociatedEntries( $this->oldTitle, $this->newTitle );
396 }
397
398 Hooks::run(
399 'TitleMoveCompleting',
400 [ $this->oldTitle, $this->newTitle,
401 $user, $pageid, $redirid, $reason, $nullRevision ]
402 );
403
404 $dbw->endAtomic( __METHOD__ );
405
406 $params = [
409 &$user,
410 $pageid,
411 $redirid,
412 $reason,
413 $nullRevision
414 ];
415 // Keep each single hook handler atomic
416 DeferredUpdates::addUpdate(
418 $dbw,
419 __METHOD__,
420 // Hold onto $user to avoid HHVM bug where it no longer
421 // becomes a reference (T118683)
422 function () use ( $params, &$user ) {
423 Hooks::run( 'TitleMoveComplete', $params );
424 }
425 )
426 );
427
428 return Status::newGood();
429 }
430
446 private function moveToInternal( User $user, &$nt, $reason = '', $createRedirect = true,
447 array $changeTags = []
448 ) {
449 if ( $nt->exists() ) {
450 $moveOverRedirect = true;
451 $logType = 'move_redir';
452 } else {
453 $moveOverRedirect = false;
454 $logType = 'move';
455 }
456
457 if ( $moveOverRedirect ) {
458 $overwriteMessage = wfMessage(
459 'delete_and_move_reason',
460 $this->oldTitle->getPrefixedText()
461 )->inContentLanguage()->text();
462 $newpage = WikiPage::factory( $nt );
463 $errs = [];
464 $status = $newpage->doDeleteArticleReal(
465 $overwriteMessage,
466 /* $suppress */ false,
467 $nt->getArticleID(),
468 /* $commit */ false,
469 $errs,
470 $user,
471 $changeTags,
472 'delete_redir'
473 );
474
475 if ( !$status->isGood() ) {
476 throw new MWException( 'Failed to delete page-move revision: ' . $status );
477 }
478
479 $nt->resetArticleID( false );
480 }
481
482 if ( $createRedirect ) {
483 if ( $this->oldTitle->getNamespace() == NS_CATEGORY
484 && !wfMessage( 'category-move-redirect-override' )->inContentLanguage()->isDisabled()
485 ) {
486 $redirectContent = new WikitextContent(
487 wfMessage( 'category-move-redirect-override' )
488 ->params( $nt->getPrefixedText() )->inContentLanguage()->plain() );
489 } else {
490 $contentHandler = ContentHandler::getForTitle( $this->oldTitle );
491 $redirectContent = $contentHandler->makeRedirectContent( $nt,
492 wfMessage( 'move-redirect-text' )->inContentLanguage()->plain() );
493 }
494
495 // NOTE: If this page's content model does not support redirects, $redirectContent will be null.
496 } else {
497 $redirectContent = null;
498 }
499
500 // Figure out whether the content model is no longer the default
501 $oldDefault = ContentHandler::getDefaultModelFor( $this->oldTitle );
502 $contentModel = $this->oldTitle->getContentModel();
503 $newDefault = ContentHandler::getDefaultModelFor( $nt );
504 $defaultContentModelChanging = ( $oldDefault !== $newDefault
505 && $oldDefault === $contentModel );
506
507 // T59084: log_page should be the ID of the *moved* page
508 $oldid = $this->oldTitle->getArticleID();
509 $logTitle = clone $this->oldTitle;
510
511 $logEntry = new ManualLogEntry( 'move', $logType );
512 $logEntry->setPerformer( $user );
513 $logEntry->setTarget( $logTitle );
514 $logEntry->setComment( $reason );
515 $logEntry->setParameters( [
516 '4::target' => $nt->getPrefixedText(),
517 '5::noredir' => $redirectContent ? '0' : '1',
518 ] );
519
520 $formatter = LogFormatter::newFromEntry( $logEntry );
521 $formatter->setContext( RequestContext::newExtraneousContext( $this->oldTitle ) );
522 $comment = $formatter->getPlainActionText();
523 if ( $reason ) {
524 $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
525 }
526
527 $dbw = wfGetDB( DB_MASTER );
528
529 $oldpage = WikiPage::factory( $this->oldTitle );
530 $oldcountable = $oldpage->isCountable();
531
532 $newpage = WikiPage::factory( $nt );
533
534 # Save a null revision in the page's history notifying of the move
535 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true, $user );
536 if ( !is_object( $nullRevision ) ) {
537 throw new MWException( 'No valid null revision produced in ' . __METHOD__ );
538 }
539
540 $nullRevId = $nullRevision->insertOn( $dbw );
541 $logEntry->setAssociatedRevId( $nullRevId );
542
543 # Change the name of the target page:
544 $dbw->update( 'page',
545 /* SET */ [
546 'page_namespace' => $nt->getNamespace(),
547 'page_title' => $nt->getDBkey(),
548 ],
549 /* WHERE */ [ 'page_id' => $oldid ],
550 __METHOD__
551 );
552
553 if ( !$redirectContent ) {
554 // Clean up the old title *before* reset article id - T47348
555 WikiPage::onArticleDelete( $this->oldTitle );
556 }
557
558 $this->oldTitle->resetArticleID( 0 ); // 0 == non existing
559 $nt->resetArticleID( $oldid );
560 $newpage->loadPageData( WikiPage::READ_LOCKING ); // T48397
561
562 $newpage->updateRevisionOn( $dbw, $nullRevision );
563
564 Hooks::run( 'NewRevisionFromEditComplete',
565 [ $newpage, $nullRevision, $nullRevision->getParentId(), $user ] );
566
567 $newpage->doEditUpdates( $nullRevision, $user,
568 [ 'changed' => false, 'moved' => true, 'oldcountable' => $oldcountable ] );
569
570 // If the default content model changes, we need to populate rev_content_model
571 if ( $defaultContentModelChanging ) {
572 $dbw->update(
573 'revision',
574 [ 'rev_content_model' => $contentModel ],
575 [ 'rev_page' => $nt->getArticleID(), 'rev_content_model IS NULL' ],
576 __METHOD__
577 );
578 }
579
580 WikiPage::onArticleCreate( $nt );
581
582 # Recreate the redirect, this time in the other direction.
583 if ( $redirectContent ) {
584 $redirectArticle = WikiPage::factory( $this->oldTitle );
585 $redirectArticle->loadFromRow( false, WikiPage::READ_LOCKING ); // T48397
586 $newid = $redirectArticle->insertOn( $dbw );
587 if ( $newid ) { // sanity
588 $this->oldTitle->resetArticleID( $newid );
589 $redirectRevision = new Revision( [
590 'title' => $this->oldTitle, // for determining the default content model
591 'page' => $newid,
592 'user_text' => $user->getName(),
593 'user' => $user->getId(),
594 'comment' => $comment,
595 'content' => $redirectContent ] );
596 $redirectRevId = $redirectRevision->insertOn( $dbw );
597 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
598
599 Hooks::run( 'NewRevisionFromEditComplete',
600 [ $redirectArticle, $redirectRevision, false, $user ] );
601
602 $redirectArticle->doEditUpdates( $redirectRevision, $user, [ 'created' => true ] );
603
604 // make a copy because of log entry below
605 $redirectTags = $changeTags;
606 if ( in_array( 'mw-new-redirect', ChangeTags::getSoftwareTags() ) ) {
607 $redirectTags[] = 'mw-new-redirect';
608 }
609 ChangeTags::addTags( $redirectTags, null, $redirectRevId, null );
610 }
611 }
612
613 # Log the move
614 $logid = $logEntry->insert();
615
616 $logEntry->setTags( $changeTags );
617 $logEntry->publish( $logid );
618
619 return $nullRevision;
620 }
621}
$wgCategoryCollation
Specify how category names should be sorted, when listed on a category page.
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfMergeErrorArrays()
Merge arrays in the style of getUserPermissionsErrors, with duplicate removal e.g.
wfLocalFile( $title)
Get an object referring to a locally registered file.
wfStripIllegalFilenameChars( $name)
Replace all invalid characters with '-'.
Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
static getSoftwareTags( $all=false)
Loads defined core tags, checks for invalid types (if not array), and filters for supported and enabl...
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.
static singleton()
Definition Collation.php:34
static matchSummarySpamRegex( $text)
Check given input text against $wgSummarySpamRegex, and return the text of the first match.
static checkExtensionCompatibility(File $old, $new)
Checks if file extensions are compatible.
Definition File.php:249
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
MediaWiki exception.
Class for creating log entries manually, to inject them into the database.
Definition LogEntry.php:432
MediaWikiServices is the service locator for the application scope of MediaWiki.
Handles the backend logic of moving a page from one title to another.
Definition MovePage.php:30
checkPermissions(User $user, $reason)
Definition MovePage.php:47
isValidFileMove()
Sanity checks for when a file is being moved.
Definition MovePage.php:166
Title $oldTitle
Definition MovePage.php:35
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:446
isValidMove()
Does various sanity checks that the move is valid.
Definition MovePage.php:88
isValidMoveTarget()
Checks if $this can be moved to a given Title.
Definition MovePage.php:193
move(User $user, $reason, $createRedirect, array $changeTags=[])
Definition MovePage.php:242
Title $newTitle
Definition MovePage.php:40
__construct(Title $oldTitle, Title $newTitle)
Definition MovePage.php:42
static singleton()
Get a RepoGroup instance.
Definition RepoGroup.php:59
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:40
Represents a title within MediaWiki.
Definition Title.php:39
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:53
Content object for wiki text pages.
$res
Definition database.txt:21
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:1051
either a plain
Definition hooks.txt:2056
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;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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
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 local account $user
Definition hooks.txt:247
const NS_FILE
Definition Defines.php:80
const NS_CATEGORY
Definition Defines.php:88
you have access to all of the normal MediaWiki so you can get a DB use the cache
const DB_MASTER
Definition defines.php:29
$params