From 8935fb4f6642b16481265aa8d7e345d317e85aa8 Mon Sep 17 00:00:00 2001 From: Victor Barbu Date: Sun, 25 Dec 2016 21:32:22 +0200 Subject: [PATCH] Replace some usages of &$this in hook parameters Affected classes: - ApiBase - ApiPageSet - HistoryPager - RawAction Bug: T153505 Change-Id: I0862476a39a1c3206a84f79c1b8f7db41bc47959 --- includes/actions/HistoryAction.php | 5 ++++- includes/actions/RawAction.php | 4 +++- includes/api/ApiBase.php | 14 +++++++++++--- includes/api/ApiPageSet.php | 5 ++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 767a163e02..e8aec1cf6e 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -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; } diff --git a/includes/actions/RawAction.php b/includes/actions/RawAction.php index 5bf24f60e6..d8c8bc3213 100644 --- a/includes/actions/RawAction.php +++ b/includes/actions/RawAction.php @@ -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" ); } diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index c1ad9479e2..063d6613ce 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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 = []; diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 160ce87365..d42e306efa 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -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(); -- 2.20.1