From fb3ae6fbe31738a0c886dcbeab90ca39bff9c167 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 31 Jan 2017 23:01:54 -0500 Subject: [PATCH] Replace use of &$this Use of &$this doesn't work in PHP 7.1. For callbacks to methods like array_map() it's completely unnecessary, while for hooks we still need to pass a reference and so we need to copy $this into a local variable. Bug: T153505 Change-Id: I8bbb26e248cd6f213fd0e7460d6d6935a3f9e468 --- docs/hooks.txt | 8 +- includes/MagicWord.php | 4 +- includes/changes/ChangesList.php | 4 +- includes/changes/OldChangesList.php | 4 +- includes/changes/RecentChange.php | 4 +- includes/db/DatabaseOracle.php | 4 +- includes/deferred/LinksUpdate.php | 12 ++- includes/diff/DifferenceEngine.php | 7 +- includes/export/XmlDumpWriter.php | 4 +- includes/filerepo/file/LocalFile.php | 4 +- includes/libs/rdbms/database/Database.php | 2 +- .../libs/rdbms/database/DatabasePostgres.php | 4 +- includes/libs/replacers/Replacer.php | 2 +- includes/page/ImagePage.php | 2 +- includes/page/WikiPage.php | 2 +- includes/parser/DateFormatter.php | 2 +- includes/parser/LinkHolderArray.php | 2 +- includes/parser/Parser.php | 74 +++++++++++++------ includes/resourceloader/ResourceLoader.php | 9 ++- includes/skins/BaseTemplate.php | 8 +- includes/specials/SpecialMovepage.php | 4 +- includes/specials/SpecialWantedpages.php | 4 +- includes/specials/pagers/ContribsPager.php | 4 +- includes/specials/pagers/NewPagesPager.php | 4 +- languages/Language.php | 2 +- 25 files changed, 123 insertions(+), 57 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 27773f6c9b..1459b892c1 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -212,9 +212,13 @@ related to a particular event, like so: # ... function protect() { global $wgUser; - if ( Hooks::run( 'ArticleProtect', array( &$this, &$wgUser ) ) ) { + + // Avoid PHP 7.1 warning from passing $this by reference + $article = $this; + + if ( Hooks::run( 'ArticleProtect', [ &$article, &$wgUser ] ) ) { # protect the article - Hooks::run( 'ArticleProtectComplete', array( &$this, &$wgUser ) ); + Hooks::run( 'ArticleProtectComplete', [ &$article, &$wgUser ] ); } } } diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 5968e87903..09317d7b1f 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -526,7 +526,7 @@ class MagicWord { $this->mFound = false; $text = preg_replace_callback( $this->getRegex(), - [ &$this, 'pregRemoveAndRecord' ], + [ $this, 'pregRemoveAndRecord' ], $text ); @@ -541,7 +541,7 @@ class MagicWord { $this->mFound = false; $text = preg_replace_callback( $this->getRegexStart(), - [ &$this, 'pregRemoveAndRecord' ], + [ $this, 'pregRemoveAndRecord' ], $text ); diff --git a/includes/changes/ChangesList.php b/includes/changes/ChangesList.php index 77038edd7d..1e88e13636 100644 --- a/includes/changes/ChangesList.php +++ b/includes/changes/ChangesList.php @@ -444,8 +444,10 @@ class ChangesList extends ContextSource { # TODO: Deprecate the $s argument, it seems happily unused. $s = ''; + # Avoid PHP 7.1 warning from passing $this by reference + $changesList = $this; Hooks::run( 'ChangesListInsertArticleLink', - [ &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ] ); + [ &$changesList, &$articlelink, &$s, &$rc, $unpatrolled, $watched ] ); return "{$s} {$articlelink}"; } diff --git a/includes/changes/OldChangesList.php b/includes/changes/OldChangesList.php index 8eb06ced03..d862ef482f 100644 --- a/includes/changes/OldChangesList.php +++ b/includes/changes/OldChangesList.php @@ -50,7 +50,9 @@ class OldChangesList extends ChangesList { $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] ); } - if ( !Hooks::run( 'OldChangesListRecentChangesLine', [ &$this, &$html, $rc, &$classes ] ) ) { + // Avoid PHP 7.1 warning from passing $this by reference + $list = $this; + if ( !Hooks::run( 'OldChangesListRecentChangesLine', [ &$list, &$html, $rc, &$classes ] ) ) { return false; } diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 13a5fc7b80..772500fe74 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -329,7 +329,9 @@ class RecentChange { $this->mAttribs['rc_id'] = $dbw->insertId(); # Notify extensions - Hooks::run( 'RecentChange_save', [ &$this ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $rc = $this; + Hooks::run( 'RecentChange_save', [ &$rc ] ); if ( count( $this->tags ) ) { ChangeTags::addTags( $this->tags, $this->mAttribs['rc_id'], diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index c3502f60ad..d8ed7a949c 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -668,7 +668,7 @@ class DatabaseOracle extends Database { list( $startOpts, $useIndex, $tailOpts, $ignoreIndex ) = $this->makeSelectOptions( $selectOptions ); if ( is_array( $srcTable ) ) { - $srcTable = implode( ',', array_map( [ &$this, 'tableName' ], $srcTable ) ); + $srcTable = implode( ',', array_map( [ $this, 'tableName' ], $srcTable ) ); } else { $srcTable = $this->tableName( $srcTable ); } @@ -998,7 +998,7 @@ class DatabaseOracle extends Database { private function fieldInfoMulti( $table, $field ) { $field = strtoupper( $field ); if ( is_array( $table ) ) { - $table = array_map( [ &$this, 'tableNameInternal' ], $table ); + $table = array_map( [ $this, 'tableNameInternal' ], $table ); $tableWhere = 'IN ('; foreach ( $table as &$singleTable ) { $singleTable = $this->removeIdentifierQuotes( $singleTable ); diff --git a/includes/deferred/LinksUpdate.php b/includes/deferred/LinksUpdate.php index 229a9a258f..464c908b40 100644 --- a/includes/deferred/LinksUpdate.php +++ b/includes/deferred/LinksUpdate.php @@ -154,7 +154,9 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { $this->mRecursive = $recursive; - Hooks::run( 'LinksUpdateConstructed', [ &$this ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $linksUpdate = $this; + Hooks::run( 'LinksUpdateConstructed', [ &$linksUpdate ] ); } /** @@ -169,7 +171,9 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { $scopedLock = self::acquirePageLock( $this->getDB(), $this->mId ); } - Hooks::run( 'LinksUpdate', [ &$this ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $linksUpdate = $this; + Hooks::run( 'LinksUpdate', [ &$linksUpdate ] ); $this->doIncrementalUpdate(); // Commit and release the lock (if set) @@ -177,7 +181,9 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { // Run post-commit hooks without DBO_TRX $this->getDB()->onTransactionIdle( function () { - Hooks::run( 'LinksUpdateComplete', [ &$this, $this->ticket ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $linksUpdate = $this; + Hooks::run( 'LinksUpdateComplete', [ &$linksUpdate, $this->ticket ] ); }, __METHOD__ ); diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 559a5ec667..5367199f2f 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -762,8 +762,11 @@ class DifferenceEngine extends ContextSource { $difftext = $this->generateContentDiffBody( $this->mOldContent, $this->mNewContent ); + // Avoid PHP 7.1 warning from passing $this by reference + $diffEngine = $this; + // Save to cache for 7 days - if ( !Hooks::run( 'AbortDiffCache', [ &$this ] ) ) { + if ( !Hooks::run( 'AbortDiffCache', [ &$diffEngine ] ) ) { wfIncrStats( 'diff_cache.uncacheable' ); } elseif ( $key !== false && $difftext !== false ) { wfIncrStats( 'diff_cache.miss' ); @@ -982,7 +985,7 @@ class DifferenceEngine extends ContextSource { public function localiseLineNumbers( $text ) { return preg_replace_callback( '//', - [ &$this, 'localiseLineNumbersCb' ], + [ $this, 'localiseLineNumbersCb' ], $text ); } diff --git a/includes/export/XmlDumpWriter.php b/includes/export/XmlDumpWriter.php index 5be166b29d..52bf0f0910 100644 --- a/includes/export/XmlDumpWriter.php +++ b/includes/export/XmlDumpWriter.php @@ -269,7 +269,9 @@ class XmlDumpWriter { $out .= " \n"; } - Hooks::run( 'XmlDumpWriterWriteRevision', [ &$this, &$out, $row, $text ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $writer = $this; + Hooks::run( 'XmlDumpWriterWriteRevision', [ &$writer, &$out, $row, $text ] ); $out .= " \n"; diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index be0751ff9a..8c088b9221 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1070,7 +1070,9 @@ class LocalFile extends File { $opts['ORDER BY'] = "oi_timestamp $order"; $opts['USE INDEX'] = [ 'oldimage' => 'oi_name_timestamp' ]; - Hooks::run( 'LocalFile::getHistory', [ &$this, &$tables, &$fields, + // Avoid PHP 7.1 warning from passing $this by reference + $localFile = $this; + Hooks::run( 'LocalFile::getHistory', [ &$localFile, &$tables, &$fields, &$conds, &$opts, &$join_conds ] ); $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds ); diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 68d500ba6c..d15d6f1937 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -2314,7 +2314,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $selectOptions ); if ( is_array( $srcTable ) ) { - $srcTable = implode( ',', array_map( [ &$this, 'tableName' ], $srcTable ) ); + $srcTable = implode( ',', array_map( [ $this, 'tableName' ], $srcTable ) ); } else { $srcTable = $this->tableName( $srcTable ); } diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php index 42113b0851..75cc97c9d5 100644 --- a/includes/libs/rdbms/database/DatabasePostgres.php +++ b/includes/libs/rdbms/database/DatabasePostgres.php @@ -698,7 +698,7 @@ __INDEXATTR__; list( $startOpts, $useIndex, $tailOpts, $ignoreIndex ) = $this->makeSelectOptions( $selectOptions ); if ( is_array( $srcTable ) ) { - $srcTable = implode( ',', array_map( [ &$this, 'tableName' ], $srcTable ) ); + $srcTable = implode( ',', array_map( [ $this, 'tableName' ], $srcTable ) ); } else { $srcTable = $this->tableName( $srcTable ); } @@ -1257,7 +1257,7 @@ SQL; if ( isset( $options['FOR UPDATE'] ) ) { $postLimitTail .= ' FOR UPDATE OF ' . - implode( ', ', array_map( [ &$this, 'tableName' ], $options['FOR UPDATE'] ) ); + implode( ', ', array_map( [ $this, 'tableName' ], $options['FOR UPDATE'] ) ); } elseif ( isset( $noKeyOptions['FOR UPDATE'] ) ) { $postLimitTail .= ' FOR UPDATE'; } diff --git a/includes/libs/replacers/Replacer.php b/includes/libs/replacers/Replacer.php index 3b978357ed..655e771087 100644 --- a/includes/libs/replacers/Replacer.php +++ b/includes/libs/replacers/Replacer.php @@ -27,7 +27,7 @@ abstract class Replacer { * @return array */ public function cb() { - return [ &$this, 'replace' ]; + return [ $this, 'replace' ]; } /** diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index b60b0108a1..c75cfdd26d 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -336,7 +336,7 @@ class ImagePage extends Article { $filename = wfEscapeWikiText( $this->displayImg->getName() ); $linktext = $filename; - // Use of &$this in hooks triggers warnings in PHP 7.1 + // Avoid PHP 7.1 warning from passing $this by reference $imagePage = $this; Hooks::run( 'ImageOpenShowImageInlineBefore', [ &$imagePage, &$out ] ); diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 1c1412a81f..232f6cc82f 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -323,7 +323,7 @@ class WikiPage implements Page, IDBAccessObject { $row = $dbr->selectRow( 'page', $fields, $conditions, __METHOD__, $options ); - Hooks::run( 'ArticlePageDataAfter', [ &$this, &$row ] ); + Hooks::run( 'ArticlePageDataAfter', [ &$wikiPage, &$row ] ); return $row; } diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php index 08e3c77158..76ee525cb9 100644 --- a/includes/parser/DateFormatter.php +++ b/includes/parser/DateFormatter.php @@ -197,7 +197,7 @@ class DateFormatter { // Another horrible hack $this->mLinked = $linked; - $text = preg_replace_callback( $regex, [ &$this, 'replace' ], $text ); + $text = preg_replace_callback( $regex, [ $this, 'replace' ], $text ); unset( $this->mLinked ); } return $text; diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index e7712f2b74..d2a0a1a6d4 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -613,7 +613,7 @@ class LinkHolderArray { public function replaceText( $text ) { $text = preg_replace_callback( '//', - [ &$this, 'replaceTextCallback' ], + [ $this, 'replaceTextCallback' ], $text ); return $text; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 3ec059632e..1d55c980a1 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -330,7 +330,9 @@ class Parser { CoreTagHooks::register( $this ); $this->initialiseVariables(); - Hooks::run( 'ParserFirstCallInit', [ &$this ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + Hooks::run( 'ParserFirstCallInit', [ &$parser ] ); } /** @@ -381,7 +383,9 @@ class Parser { $this->mProfiler = new SectionProfiler(); - Hooks::run( 'ParserClearState', [ &$this ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + Hooks::run( 'ParserClearState', [ &$parser ] ); } /** @@ -435,11 +439,13 @@ class Parser { $this->mRevisionSize = null; } - Hooks::run( 'ParserBeforeStrip', [ &$this, &$text, &$this->mStripState ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + Hooks::run( 'ParserBeforeStrip', [ &$parser, &$text, &$this->mStripState ] ); # No more strip! - Hooks::run( 'ParserAfterStrip', [ &$this, &$text, &$this->mStripState ] ); + Hooks::run( 'ParserAfterStrip', [ &$parser, &$text, &$this->mStripState ] ); $text = $this->internalParse( $text ); - Hooks::run( 'ParserAfterParse', [ &$this, &$text, &$this->mStripState ] ); + Hooks::run( 'ParserAfterParse', [ &$parser, &$text, &$this->mStripState ] ); $text = $this->internalParseHalfParsed( $text, true, $linestart ); @@ -615,8 +621,10 @@ class Parser { * @return string UNSAFE half-parsed HTML */ public function recursiveTagParse( $text, $frame = false ) { - Hooks::run( 'ParserBeforeStrip', [ &$this, &$text, &$this->mStripState ] ); - Hooks::run( 'ParserAfterStrip', [ &$this, &$text, &$this->mStripState ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + Hooks::run( 'ParserBeforeStrip', [ &$parser, &$text, &$this->mStripState ] ); + Hooks::run( 'ParserAfterStrip', [ &$parser, &$text, &$this->mStripState ] ); $text = $this->internalParse( $text, false, $frame ); return $text; } @@ -663,8 +671,10 @@ class Parser { if ( $revid !== null ) { $this->mRevisionId = $revid; } - Hooks::run( 'ParserBeforeStrip', [ &$this, &$text, &$this->mStripState ] ); - Hooks::run( 'ParserAfterStrip', [ &$this, &$text, &$this->mStripState ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + Hooks::run( 'ParserBeforeStrip', [ &$parser, &$text, &$this->mStripState ] ); + Hooks::run( 'ParserAfterStrip', [ &$parser, &$text, &$this->mStripState ] ); $text = $this->replaceVariables( $text, $frame ); $text = $this->mStripState->unstripBoth( $text ); return $text; @@ -1259,8 +1269,11 @@ class Parser { $origText = $text; + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + # Hook to suspend the parser in this state - if ( !Hooks::run( 'ParserBeforeInternalParse', [ &$this, &$text, &$this->mStripState ] ) ) { + if ( !Hooks::run( 'ParserBeforeInternalParse', [ &$parser, &$text, &$this->mStripState ] ) ) { return $text; } @@ -1280,16 +1293,16 @@ class Parser { $text = $this->replaceVariables( $text ); } - Hooks::run( 'InternalParseBeforeSanitize', [ &$this, &$text, &$this->mStripState ] ); + Hooks::run( 'InternalParseBeforeSanitize', [ &$parser, &$text, &$this->mStripState ] ); $text = Sanitizer::removeHTMLtags( $text, - [ &$this, 'attributeStripCallback' ], + [ $this, 'attributeStripCallback' ], false, array_keys( $this->mTransparentTagHooks ), [], - [ &$this, 'addTrackingCategory' ] + [ $this, 'addTrackingCategory' ] ); - Hooks::run( 'InternalParseBeforeLinks', [ &$this, &$text, &$this->mStripState ] ); + Hooks::run( 'InternalParseBeforeLinks', [ &$parser, &$text, &$this->mStripState ] ); # Tables need to come after variable replacement for things to work # properly; putting them before other transformations should keep @@ -1328,8 +1341,11 @@ class Parser { private function internalParseHalfParsed( $text, $isMain = true, $linestart = true ) { $text = $this->mStripState->unstripGeneral( $text ); + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + if ( $isMain ) { - Hooks::run( 'ParserAfterUnstrip', [ &$this, &$text ] ); + Hooks::run( 'ParserAfterUnstrip', [ &$parser, &$text ] ); } # Clean up special characters, only run once, next-to-last before doBlockLevels @@ -1368,7 +1384,7 @@ class Parser { $text = $this->mStripState->unstripNoWiki( $text ); if ( $isMain ) { - Hooks::run( 'ParserBeforeTidy', [ &$this, &$text ] ); + Hooks::run( 'ParserBeforeTidy', [ &$parser, &$text ] ); } $text = $this->replaceTransparentTags( $text ); @@ -1409,7 +1425,7 @@ class Parser { } if ( $isMain ) { - Hooks::run( 'ParserAfterTidy', [ &$this, &$text ] ); + Hooks::run( 'ParserAfterTidy', [ &$parser, &$text ] ); } return $text; @@ -1447,7 +1463,7 @@ class Parser { (?: [0-9] $spdash? ){9} # 9 digits with opt. delimiters [0-9Xx] # check digit )\b - )!xu", [ &$this, 'magicLinkCallback' ], $text ); + )!xu", [ $this, 'magicLinkCallback' ], $text ); return $text; } @@ -2486,18 +2502,21 @@ class Parser { . ' called while parsing (no title set)' ); } + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + /** * Some of these require message or data lookups and can be * expensive to check many times. */ - if ( Hooks::run( 'ParserGetVariableValueVarCache', [ &$this, &$this->mVarCache ] ) ) { + if ( Hooks::run( 'ParserGetVariableValueVarCache', [ &$parser, &$this->mVarCache ] ) ) { if ( isset( $this->mVarCache[$index] ) ) { return $this->mVarCache[$index]; } } $ts = wfTimestamp( TS_UNIX, $this->mOptions->getTimestamp() ); - Hooks::run( 'ParserGetVariableValueTs', [ &$this, &$ts ] ); + Hooks::run( 'ParserGetVariableValueTs', [ &$parser, &$ts ] ); $pageLang = $this->getFunctionLang(); @@ -2810,7 +2829,7 @@ class Parser { $ret = null; Hooks::run( 'ParserGetVariableValueSwitch', - [ &$this, &$this->mVarCache, &$index, &$ret, &$frame ] + [ &$parser, &$this->mVarCache, &$index, &$ret, &$frame ] ); return $ret; @@ -3354,7 +3373,10 @@ class Parser { throw new MWException( "Tag hook for $function is not callable\n" ); } - $allArgs = [ &$this ]; + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + + $allArgs = [ &$parser ]; if ( $flags & self::SFH_OBJECT_ARGS ) { # Convert arguments to PPNodes and collect for appending to $allArgs $funcArgs = []; @@ -3863,7 +3885,9 @@ class Parser { throw new MWException( "Tag hook for $name is not callable\n" ); } - $output = call_user_func_array( $callback, [ &$this, $frame, $content, $attributes ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + $output = call_user_func_array( $callback, [ &$parser, $frame, $content, $attributes ] ); } else { $output = 'Invalid tag extension name: ' . htmlspecialchars( $name ) . ''; @@ -4966,7 +4990,9 @@ class Parser { } $ig->setAdditionalOptions( $params ); - Hooks::run( 'BeforeParserrenderImageGallery', [ &$this, &$ig ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $parser = $this; + Hooks::run( 'BeforeParserrenderImageGallery', [ &$parser, &$ig ] ); $lines = StringUtils::explode( "\n", $text ); foreach ( $lines as $line ) { diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index f0b48d544f..a55cbc1b2c 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -255,7 +255,10 @@ class ResourceLoader implements LoggerAwareInterface { $this->register( include "$IP/resources/ResourcesOOUI.php" ); // Register extension modules $this->register( $config->get( 'ResourceModules' ) ); - Hooks::run( 'ResourceLoaderRegisterModules', [ &$this ] ); + + // Avoid PHP 7.1 warning from passing $this by reference + $rl = $this; + Hooks::run( 'ResourceLoaderRegisterModules', [ &$rl ] ); if ( $config->get( 'EnableJavaScriptTest' ) === true ) { $this->registerTestModules(); @@ -404,7 +407,9 @@ class ResourceLoader implements LoggerAwareInterface { $testModules = []; $testModules['qunit'] = []; // Get other test suites (e.g. from extensions) - Hooks::run( 'ResourceLoaderTestModules', [ &$testModules, &$this ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $rl = $this; + Hooks::run( 'ResourceLoaderTestModules', [ &$testModules, &$rl ] ); // Add the testrunner (which configures QUnit) to the dependencies. // Since it must be ready before any of the test suites are executed. diff --git a/includes/skins/BaseTemplate.php b/includes/skins/BaseTemplate.php index 65eb9b776e..eef421c46e 100644 --- a/includes/skins/BaseTemplate.php +++ b/includes/skins/BaseTemplate.php @@ -112,7 +112,9 @@ abstract class BaseTemplate extends QuickTemplate { $toolbox['info']['id'] = 't-info'; } - Hooks::run( 'BaseTemplateToolbox', [ &$this, &$toolbox ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $template = $this; + Hooks::run( 'BaseTemplateToolbox', [ &$template, &$toolbox ] ); return $toolbox; } @@ -227,7 +229,9 @@ abstract class BaseTemplate extends QuickTemplate { ob_start(); // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox // can abort and avoid outputting double toolbox links - Hooks::run( 'SkinTemplateToolboxEnd', [ &$this, true ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $template = $this; + Hooks::run( 'SkinTemplateToolboxEnd', [ &$template, true ] ); $hookContents = ob_get_contents(); ob_end_clean(); if ( !trim( $hookContents ) ) { diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 298d6c4edb..0281b15a0e 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -630,7 +630,9 @@ class MovePageForm extends UnlistedSpecialPage { $newLink )->params( $oldText, $newText )->parseAsBlock() ); $out->addWikiMsg( $msgName ); - Hooks::run( 'SpecialMovepageAfterMove', [ &$this, &$ot, &$nt ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $movePage = $this; + Hooks::run( 'SpecialMovepageAfterMove', [ &$movePage, &$ot, &$nt ] ); # Now we move extra pages we've been asked to move: subpages and talk # pages. First, if the old page or the new page is a talk page, we diff --git a/includes/specials/SpecialWantedpages.php b/includes/specials/SpecialWantedpages.php index c37ecbd17a..8cea6ccb77 100644 --- a/includes/specials/SpecialWantedpages.php +++ b/includes/specials/SpecialWantedpages.php @@ -85,7 +85,9 @@ class WantedPagesPage extends WantedQueryPage { ] ]; // Replacement for the WantedPages::getSQL hook - Hooks::run( 'WantedPages::getQueryInfo', [ &$this, &$query ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $wantedPages = $this; + Hooks::run( 'WantedPages::getQueryInfo', [ &$wantedPages, &$query ] ); return $query; } diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index 367d07304f..0c3a21108b 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -200,7 +200,9 @@ class ContribsPager extends ReverseChronologicalPager { $this->tagFilter ); - Hooks::run( 'ContribsPager::getQueryInfo', [ &$this, &$queryInfo ] ); + // Avoid PHP 7.1 warning from passing $this by reference + $pager = $this; + Hooks::run( 'ContribsPager::getQueryInfo', [ &$pager, &$queryInfo ] ); return $queryInfo; } diff --git a/includes/specials/pagers/NewPagesPager.php b/includes/specials/pagers/NewPagesPager.php index e298f103a2..dafd244ee5 100644 --- a/includes/specials/pagers/NewPagesPager.php +++ b/includes/specials/pagers/NewPagesPager.php @@ -100,8 +100,10 @@ class NewPagesPager extends ReverseChronologicalPager { ]; $join_conds = [ 'page' => [ 'INNER JOIN', 'page_id=rc_cur_id' ] ]; + // Avoid PHP 7.1 warning from passing $this by reference + $pager = $this; Hooks::run( 'SpecialNewpagesConditions', - [ &$this, $this->opts, &$conds, &$tables, &$fields, &$join_conds ] ); + [ &$pager, $this->opts, &$conds, &$tables, &$fields, &$join_conds ] ); $options = []; diff --git a/languages/Language.php b/languages/Language.php index 68727bb233..a1cc4bc9f2 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -4508,7 +4508,7 @@ class Language { # such as action=raw much more expensive than they need to be. # This will hopefully cover most cases. $talk = preg_replace_callback( '/{{grammar:(.*?)\|(.*?)}}/i', - [ &$this, 'replaceGrammarInNamespace' ], $talk ); + [ $this, 'replaceGrammarInNamespace' ], $talk ); return str_replace( ' ', '_', $talk ); } -- 2.20.1