Reconcile differences between arguments in hooks.txt and at the call site

The interface generator script now flags any differences between the
argument list at the call site and the documented arguments. Resolve all
such differences.

* In AlternateEditPreview, $parserOutput is a reference, and a
  WMF-deployed extension replaces it.
* In DeleteUnknownPreferences, fix missing "$" in &$where
* In LocalisationCacheRecache, document the unused parameter, as is the
  convention elsewhere in the file.
* In NewRevisionFromEditComplete, make all callers pass a $tags
  variable, and document the fact that there are multiple callers.
* In PageContentInsertComplete, document legacy references
* In PageContentSave, document the fact that $flags and $status are
  references. I made them legacy references, since although replacement
  will have an effect, no extension relies on this and it is not
  documented on the Manual:Hooks page.
* In PageContentSaveComplete, document $wikiPage, $user, $flags and
  $status as legacy references. Replacement of $status was broken
  by If610c68f4912e89 (MW 1.32), but I confirmed that no extensions
  in CodeSearch are currently affected.
* In ParserGetVariableValueSwitch, document $frame as a legacy reference
* In WatchArticleComplete and UnwatchArticleComplete, SpecialEditWatchlist
  was passing $user by value where as the other callers were passing it
  by reference. Passed by reference. It was already marked legacy.

Bug: T240307

Change-Id: I33f69ebdb5242982fd7986d9877959d2d33149b9
This commit is contained in:
Tim Starling 2020-03-04 09:50:34 +11:00
parent fd5dde8b86
commit 30d5810572
6 changed files with 29 additions and 21 deletions

View file

@ -312,7 +312,7 @@ preview HTML.
$editPage: the EditPage object
&$content: the Content object for the text field from the edit page
&$previewHTML: Text to be placed into the page for the preview
$parserOutput: the ParserOutput object for the preview
&$parserOutput: the ParserOutput object for the preview
'AlternateUserMailer': Called before mail is sent so that mail could be logged
(or something else) instead of using PEAR or PHP's mail(). Return false to skip
@ -1210,7 +1210,7 @@ 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
&$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.
@ -2111,6 +2111,7 @@ cache.
$cache: The LocalisationCache object
$code: language code
&$alldata: The localisation data from core and extensions
[&]$unused: Used to be $purgeBlobs, removed in 1.34
'LocalisationCacheRecacheFallback': Called for each language when merging
fallback data into the cache.
@ -2360,14 +2361,15 @@ $row: the database row for this page (the recentchanges record and a few extras
(see Sanitizer::isReservedDataAttribute).
'NewRevisionFromEditComplete': Called when a revision was inserted due to an
edit.
edit, file upload, import or page move.
$wikiPage: the WikiPage edited
$rev: the new revision
$originalRevId: if the edit restores or repeats an earlier revision (such as a
rollback or a null revision), the ID of that earlier revision. False otherwise.
(Used to be called $baseID.)
$user: the editing user
&$tags: tags to apply to the edit and recent change
&$tags: tags to apply to the edit and recent change. This is empty, and
replacement is ignored, in the case of import or page move.
'OldChangesListRecentChangesLine': Customize entire recent changes line, or
return false to omit the line from RecentChanges and Watchlist special pages.
@ -2442,14 +2444,14 @@ $categories: associative array, keys are category names, values are category
$parserOutput: parserOutput instance being added in $out
'PageContentInsertComplete': After a new article is created.
$wikiPage: WikiPage created
$user: User creating the article
[&]$wikiPage: WikiPage created
[&]$user: User creating the article
$content: New content as a Content object
$summary: Edit summary/comment
$isMinor: Whether or not the edit was marked as minor
$isWatch: (No longer used)
$section: (No longer used)
$flags: Flags passed to WikiPage::doEditContent()
[&]$flags: Flags passed to WikiPage::doEditContent()
$revision: New Revision of the article
'PageContentLanguage': Allows changing the language in which the content of a
@ -2468,22 +2470,24 @@ $userLang: the user language (Language object)
$isminor: Boolean flag specifying if the edit was marked as minor.
$iswatch: Previously a watch flag. Currently unused, always null.
$section: Previously the section number being edited. Currently unused, always null.
$flags: All EDIT_… flags (including EDIT_MINOR) as an integer number. See WikiPage::doEditContent
[&]$flags: All EDIT_… flags (including EDIT_MINOR) as an integer number. See WikiPage::doEditContent
documentation for flags' definition.
$status: StatusValue object for the hook handlers resulting status. Either set $status->fatal() or
[&]$status: StatusValue object for the hook handlers resulting status. Either set $status->fatal() or
return false to abort the save action.
'PageContentSaveComplete': After an article has been updated.
$wikiPage: WikiPage modified
$user: User performing the modification
[&]$wikiPage: WikiPage modified
[&]$user: User performing the modification
$content: New content, as a Content object
$summary: Edit summary/comment
$isMinor: Whether or not the edit was marked as minor
$isWatch: (No longer used)
$section: (No longer used)
$flags: Flags passed to WikiPage::doEditContent()
[&]$flags: Flags passed to WikiPage::doEditContent()
$revision: New Revision of the article
$status: Status object about to be returned by doEditContent()
[&]$status: Status object about to be returned by doEditContent(). Since
MediaWiki 1.32, replacing the Status object by assigning through the reference
has had no effect.
$originalRevId: if the edit restores or repeats an earlier revision (such as a
rollback or a null revision), the ID of that earlier revision. False otherwise.
(Used to be called $baseRevId.)
@ -2596,7 +2600,7 @@ custom magic word
same magic word
&$magicWordId: index (string) of the magic word
&$ret: value of the magic word (the hook should set it)
$frame: PPFrame object to use for expanding any template variables
[&]$frame: PPFrame object to use for expanding any template variables
'ParserGetVariableValueTs': Use this to change the value of the time for the
{{LOCAL...}} magic word.

View file

@ -858,8 +858,9 @@ class MovePage {
$newpage->updateRevisionOn( $dbw, $nullRevision );
$fakeTags = [];
Hooks::run( 'NewRevisionFromEditComplete',
[ $newpage, $nullRevision, $nullRevision->getParentId(), $user ] );
[ $newpage, $nullRevision, $nullRevision->getParentId(), $user, &$fakeTags ] );
$newpage->doEditUpdates( $nullRevision, $user,
[ 'changed' => false, 'moved' => true, 'oldcountable' => $oldcountable ] );
@ -893,8 +894,9 @@ class MovePage {
$redirectRevId = $redirectRevision->insertOn( $dbw );
$redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
$fakeTags = [];
Hooks::run( 'NewRevisionFromEditComplete',
[ $redirectArticle, $redirectRevision, false, $user ] );
[ $redirectArticle, $redirectRevision, false, $user, &$fakeTags ] );
$redirectArticle->doEditUpdates( $redirectRevision, $user, [ 'created' => true ] );

View file

@ -1627,7 +1627,7 @@ class LocalFile extends File {
$nullRevision->insertOn( $dbw );
Hooks::run(
'NewRevisionFromEditComplete',
[ $wikiPage, $nullRevision, $nullRevision->getParentId(), $user ]
[ $wikiPage, $nullRevision, $nullRevision->getParentId(), $user, &$tags ]
);
$wikiPage->updateRevisionOn( $dbw, $nullRevision );
// Associate null revision id

View file

@ -2363,7 +2363,7 @@ class WikiPage implements Page, IDBAccessObject {
$wikiPage = $this;
Hooks::run( 'NewRevisionFromEditComplete',
[ $this, $nullRevision, $latest, $user ] );
[ $this, $nullRevision, $latest, $user, &$tags ] );
Hooks::run( 'ArticleProtectComplete', [ &$wikiPage, &$user, $limit, $reason ] );
} else { // Protection of non-existing page (also known as "title protection")
// Cascade protection is meaningless in this case

View file

@ -538,10 +538,11 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
Title::newFromTitleValue( $target ) :
Title::newFromText( $target );
$page = WikiPage::factory( $title );
$user = $this->getUser();
if ( $action === 'Watch' ) {
Hooks::run( 'WatchArticleComplete', [ $this->getUser(), &$page ] );
Hooks::run( 'WatchArticleComplete', [ &$user, &$page ] );
} else {
Hooks::run( 'UnwatchArticleComplete', [ $this->getUser(), &$page ] );
Hooks::run( 'UnwatchArticleComplete', [ &$user, &$page ] );
}
}
return true;

View file

@ -148,9 +148,10 @@ class ImportReporter extends ContextSource {
$page = WikiPage::factory( $title );
# Update page record
$page->updateRevisionOn( $dbw, $nullRevision );
$fakeTags = [];
Hooks::run(
'NewRevisionFromEditComplete',
[ $page, $nullRevision, $latest, $this->getUser() ]
[ $page, $nullRevision, $latest, $this->getUser(), &$fakeTags ]
);
}