Replace some usages of &$this in hook parameters
authorVictor Barbu <victorbarbu08@gmail.com>
Sun, 25 Dec 2016 19:32:22 +0000 (21:32 +0200)
committerFlorianschmidtwelzow <florian.schmidt.stargatewissen@gmail.com>
Wed, 28 Dec 2016 21:19:23 +0000 (21:19 +0000)
Affected classes:
- ApiBase
- ApiPageSet
- HistoryPager
- RawAction

Bug: T153505
Change-Id: I0862476a39a1c3206a84f79c1b8f7db41bc47959

includes/actions/HistoryAction.php
includes/actions/RawAction.php
includes/api/ApiBase.php
includes/api/ApiPageSet.php

index 767a163..e8aec1c 100644 (file)
@@ -428,7 +428,10 @@ class HistoryPager extends ReverseChronologicalPager {
                        $queryInfo['options'],
                        $this->tagFilter
                );
-               Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$this, &$queryInfo ] );
+
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $historyPager = $this;
+               Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$historyPager, &$queryInfo ] );
 
                return $queryInfo;
        }
index 5bf24f6..d8c8bc3 100644 (file)
@@ -108,7 +108,9 @@ class RawAction extends FormlessAction {
                        $response->statusHeader( 404 );
                }
 
-               if ( !Hooks::run( 'RawPageViewBeforeOutput', [ &$this, &$text ] ) ) {
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $rawAction = $this;
+               if ( !Hooks::run( 'RawPageViewBeforeOutput', [ &$rawAction, &$text ] ) ) {
                        wfDebug( __METHOD__ . ": RawPageViewBeforeOutput hook broke raw page output.\n" );
                }
 
index c1ad947..063d661 100644 (file)
@@ -1936,7 +1936,10 @@ abstract class ApiBase extends ContextSource {
         */
        public function getFinalDescription() {
                $desc = $this->getDescription();
-               Hooks::run( 'APIGetDescription', [ &$this, &$desc ] );
+
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $apiModule = $this;
+               Hooks::run( 'APIGetDescription', [ &$apiModule, &$desc ] );
                $desc = self::escapeWikiText( $desc );
                if ( is_array( $desc ) ) {
                        $desc = implode( "\n", $desc );
@@ -1984,7 +1987,9 @@ abstract class ApiBase extends ContextSource {
                        ] + ( isset( $params['token'] ) ? $params['token'] : [] );
                }
 
-               Hooks::run( 'APIGetAllowedParams', [ &$this, &$params, $flags ] );
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $apiModule = $this;
+               Hooks::run( 'APIGetAllowedParams', [ &$apiModule, &$params, $flags ] );
 
                return $params;
        }
@@ -2002,7 +2007,10 @@ abstract class ApiBase extends ContextSource {
                $path = $this->getModulePath();
 
                $desc = $this->getParamDescription();
-               Hooks::run( 'APIGetParamDescription', [ &$this, &$desc ] );
+
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $apiModule = $this;
+               Hooks::run( 'APIGetParamDescription', [ &$apiModule, &$desc ] );
 
                if ( !$desc ) {
                        $desc = [];
index 160ce87..d42e306 100644 (file)
@@ -174,7 +174,10 @@ class ApiPageSet extends ApiBase {
                        // populate this pageset with the generator output
                        if ( !$isDryRun ) {
                                $generator->executeGenerator( $this );
-                               Hooks::run( 'APIQueryGeneratorAfterExecute', [ &$generator, &$this ] );
+
+                               // Avoid PHP 7.1 warning of passing $this by reference
+                               $apiModule = $this;
+                               Hooks::run( 'APIQueryGeneratorAfterExecute', [ &$generator, &$apiModule ] );
                        } else {
                                // Prevent warnings from being reported on these parameters
                                $main = $this->getMain();