Replace use of &$this
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 1 Feb 2017 04:01:54 +0000 (23:01 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 1 Feb 2017 04:01:54 +0000 (23:01 -0500)
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

25 files changed:
docs/hooks.txt
includes/MagicWord.php
includes/changes/ChangesList.php
includes/changes/OldChangesList.php
includes/changes/RecentChange.php
includes/db/DatabaseOracle.php
includes/deferred/LinksUpdate.php
includes/diff/DifferenceEngine.php
includes/export/XmlDumpWriter.php
includes/filerepo/file/LocalFile.php
includes/libs/rdbms/database/Database.php
includes/libs/rdbms/database/DatabasePostgres.php
includes/libs/replacers/Replacer.php
includes/page/ImagePage.php
includes/page/WikiPage.php
includes/parser/DateFormatter.php
includes/parser/LinkHolderArray.php
includes/parser/Parser.php
includes/resourceloader/ResourceLoader.php
includes/skins/BaseTemplate.php
includes/specials/SpecialMovepage.php
includes/specials/SpecialWantedpages.php
includes/specials/pagers/ContribsPager.php
includes/specials/pagers/NewPagesPager.php
languages/Language.php

index 27773f6..1459b89 100644 (file)
@@ -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 ] );
                        }
                }
        }
index 5968e87..09317d7 100644 (file)
@@ -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
                );
 
index 77038ed..1e88e13 100644 (file)
@@ -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}";
        }
index 8eb06ce..d862ef4 100644 (file)
@@ -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;
                }
 
index 13a5fc7..772500f 100644 (file)
@@ -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'],
index c3502f6..d8ed7a9 100644 (file)
@@ -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 );
index 229a9a2..464c908 100644 (file)
@@ -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__
                );
index 559a5ec..5367199 100644 (file)
@@ -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(
                        '/<!--LINE (\d+)-->/',
-                       [ &$this, 'localiseLineNumbersCb' ],
+                       [ $this, 'localiseLineNumbersCb' ],
                        $text
                );
        }
index 5be166b..52bf0f0 100644 (file)
@@ -269,7 +269,9 @@ class XmlDumpWriter {
                        $out .= "      <sha1/>\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 .= "    </revision>\n";
 
index be0751f..8c088b9 100644 (file)
@@ -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 );
index 68d500b..d15d6f1 100644 (file)
@@ -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 );
                }
index 42113b0..75cc97c 100644 (file)
@@ -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';
                }
index 3b97835..655e771 100644 (file)
@@ -27,7 +27,7 @@ abstract class Replacer {
         * @return array
         */
        public function cb() {
-               return [ &$this, 'replace' ];
+               return [ $this, 'replace' ];
        }
 
        /**
index b60b010..c75cfdd 100644 (file)
@@ -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 ] );
index 1c1412a..232f6cc 100644 (file)
@@ -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;
        }
index 08e3c77..76ee525 100644 (file)
@@ -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;
index e7712f2..d2a0a1a 100644 (file)
@@ -613,7 +613,7 @@ class LinkHolderArray {
        public function replaceText( $text ) {
                $text = preg_replace_callback(
                        '/<!--(LINK|IWLINK) (.*?)-->/',
-                       [ &$this, 'replaceTextCallback' ],
+                       [ $this, 'replaceTextCallback' ],
                        $text );
 
                return $text;
index 3ec0596..1d55c98 100644 (file)
@@ -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 = '<span class="error">Invalid tag extension name: ' .
                                        htmlspecialchars( $name ) . '</span>';
@@ -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 ) {
index f0b48d5..a55cbc1 100644 (file)
@@ -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.
index 65eb9b7..eef421c 100644 (file)
@@ -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 ) ) {
index 298d6c4..0281b15 100644 (file)
@@ -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
index c37ecbd..8cea6cc 100644 (file)
@@ -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;
        }
index 367d073..0c3a211 100644 (file)
@@ -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;
        }
index e298f10..dafd244 100644 (file)
@@ -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 = [];
 
index 68727bb..a1cc4bc 100644 (file)
@@ -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 );
        }