Replace &$this with $this in MediaWiki/core hook system
authordivadsn <divad.nnamtdeis@gmail.com>
Sun, 25 Dec 2016 23:55:27 +0000 (23:55 +0000)
committerFlorianschmidtwelzow <florian.schmidt.stargatewissen@gmail.com>
Mon, 26 Dec 2016 14:26:21 +0000 (14:26 +0000)
Bug: T153505
Change-Id: Ie287adf8b1d384aa651c659a9d385877379a0f11

includes/page/Article.php
includes/page/CategoryPage.php
includes/page/ImagePage.php
includes/page/WikiPage.php

index 6e3bace..4bcb655 100644 (file)
@@ -388,9 +388,12 @@ class Article implements Page {
                $this->mContentObject = $content;
                $this->mRevIdFetched = $this->mRevision->getId();
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $articlePage = $this;
+
                ContentHandler::runLegacyHooks(
                        'ArticleAfterFetchContentObject',
-                       [ &$this, &$this->mContentObject ],
+                       [ &$articlePage, &$this->mContentObject ],
                        '1.21'
                );
 
@@ -525,7 +528,9 @@ class Article implements Page {
                while ( !$outputDone && ++$pass ) {
                        switch ( $pass ) {
                                case 1:
-                                       Hooks::run( 'ArticleViewHeader', [ &$this, &$outputDone, &$useParserCache ] );
+                                       // Avoid PHP 7.1 warning of passing $this by reference
+                                       $articlePage = $this;
+                                       Hooks::run( 'ArticleViewHeader', [ &$articlePage, &$outputDone, &$useParserCache ] );
                                        break;
                                case 2:
                                        # Early abort if the page doesn't exist
@@ -863,9 +868,12 @@ class Article implements Page {
                $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
 
                if ( isset( $this->mRedirectedFrom ) ) {
+                       // Avoid PHP 7.1 warning of passing $this by reference
+                       $articlePage = $this;
+
                        // This is an internally redirected page view.
                        // We'll need a backlink to the source page for navigation.
-                       if ( Hooks::run( 'ArticleViewRedirect', [ &$this ] ) ) {
+                       if ( Hooks::run( 'ArticleViewRedirect', [ &$articlePage ] ) ) {
                                $redir = Linker::linkKnown(
                                        $this->mRedirectedFrom,
                                        null,
@@ -1295,7 +1303,10 @@ class Article implements Page {
         * @param int $oldid Revision ID of this article revision
         */
        public function setOldSubtitle( $oldid = 0 ) {
-               if ( !Hooks::run( 'DisplayOldSubtitle', [ &$this, &$oldid ] ) ) {
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $articlePage = $this;
+
+               if ( !Hooks::run( 'DisplayOldSubtitle', [ &$articlePage, &$oldid ] ) ) {
                        return;
                }
 
@@ -1858,7 +1869,9 @@ class Article implements Page {
                                && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
                        // Extension may have reason to disable file caching on some pages.
                        if ( $cacheable ) {
-                               $cacheable = Hooks::run( 'IsFileCacheable', [ &$this ] );
+                               // Avoid PHP 7.1 warning of passing $this by reference
+                               $articlePage = $this;
+                               $cacheable = Hooks::run( 'IsFileCacheable', [ &$articlePage ] );
                        }
                }
 
index 6d2be51..ccc50f7 100644 (file)
@@ -54,7 +54,10 @@ class CategoryPage extends Article {
                        return;
                }
 
-               if ( !Hooks::run( 'CategoryPageView', [ &$this ] ) ) {
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $categoryPage = $this;
+
+               if ( !Hooks::run( 'CategoryPageView', [ &$categoryPage ] ) ) {
                        return;
                }
 
index db3ec14..b60b010 100644 (file)
@@ -69,6 +69,7 @@ class ImagePage extends Article {
                $this->fileLoaded = true;
 
                $this->displayImg = $img = false;
+
                Hooks::run( 'ImagePageFindFile', [ $this, &$img, &$this->displayImg ] );
                if ( !$img ) { // not set by hook?
                        $img = wfFindFile( $this->getTitle() );
@@ -335,7 +336,10 @@ class ImagePage extends Article {
                        $filename = wfEscapeWikiText( $this->displayImg->getName() );
                        $linktext = $filename;
 
-                       Hooks::run( 'ImageOpenShowImageInlineBefore', [ &$this, &$out ] );
+                       // Use of &$this in hooks triggers warnings in PHP 7.1
+                       $imagePage = $this;
+
+                       Hooks::run( 'ImageOpenShowImageInlineBefore', [ &$imagePage, &$out ] );
 
                        if ( $this->displayImg->allowInlineDisplay() ) {
                                # image
index 45540b5..0f1efe7 100644 (file)
@@ -316,7 +316,10 @@ class WikiPage implements Page, IDBAccessObject {
        protected function pageData( $dbr, $conditions, $options = [] ) {
                $fields = self::selectFields();
 
-               Hooks::run( 'ArticlePageDataBefore', [ &$this, &$fields ] );
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $wikiPage = $this;
+
+               Hooks::run( 'ArticlePageDataBefore', [ &$wikiPage, &$fields ] );
 
                $row = $dbr->selectRow( 'page', $fields, $conditions, __METHOD__, $options );
 
@@ -1121,7 +1124,10 @@ class WikiPage implements Page, IDBAccessObject {
         * @return bool
         */
        public function doPurge( $flags = self::PURGE_ALL ) {
-               if ( !Hooks::run( 'ArticlePurge', [ &$this ] ) ) {
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $wikiPage = $this;
+
+               if ( !Hooks::run( 'ArticlePurge', [ &$wikiPage ] ) ) {
                        return false;
                }
 
@@ -1649,9 +1655,12 @@ class WikiPage implements Page, IDBAccessObject {
                $user = $user ?: $wgUser;
                $flags = $this->checkFlags( $flags );
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $wikiPage = $this;
+
                // Trigger pre-save hook (using provided edit summary)
                $hookStatus = Status::newGood( [] );
-               $hook_args = [ &$this, &$user, &$content, &$summary,
+               $hook_args = [ &$wikiPage, &$user, &$content, &$summary,
                                                        $flags & EDIT_MINOR, null, null, &$flags, &$hookStatus ];
                // Check if the hook rejected the attempted save
                if ( !Hooks::run( 'PageContentSave', $hook_args )
@@ -1878,8 +1887,10 @@ class WikiPage implements Page, IDBAccessObject {
                                                        'oldrevision' => $meta['oldRevision']
                                                ]
                                        );
+                                       // Avoid PHP 7.1 warning of passing $this by reference
+                                       $wikiPage = $this;
                                        // Trigger post-save hook
-                                       $params = [ &$this, &$user, $content, $summary, $flags & EDIT_MINOR,
+                                       $params = [ &$wikiPage, &$user, $content, $summary, $flags & EDIT_MINOR,
                                                null, null, &$flags, $revision, &$status, $meta['baseRevId'],
                                                $meta['undidRevId'] ];
                                        ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $params );
@@ -1999,8 +2010,10 @@ class WikiPage implements Page, IDBAccessObject {
                                ) {
                                        // Update links, etc.
                                        $this->doEditUpdates( $revision, $user, [ 'created' => true ] );
+                                       // Avoid PHP 7.1 warning of passing $this by reference
+                                       $wikiPage = $this;
                                        // Trigger post-create hook
-                                       $params = [ &$this, &$user, $content, $summary,
+                                       $params = [ &$wikiPage, &$user, $content, $summary,
                                                $flags & EDIT_MINOR, null, null, &$flags, $revision ];
                                        ContentHandler::runLegacyHooks( 'ArticleInsertComplete', $params, '1.21' );
                                        Hooks::run( 'PageContentInsertComplete', $params );
@@ -2277,9 +2290,12 @@ class WikiPage implements Page, IDBAccessObject {
                        }
                }
 
-               Hooks::run( 'ArticleEditUpdates', [ &$this, &$editInfo, $options['changed'] ] );
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $wikiPage = $this;
+
+               Hooks::run( 'ArticleEditUpdates', [ &$wikiPage, &$editInfo, $options['changed'] ] );
 
-               if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', [ &$this ] ) ) {
+               if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', [ &$wikiPage ] ) ) {
                        // Flush old entries from the `recentchanges` table
                        if ( mt_rand( 0, 9 ) == 0 ) {
                                JobQueueGroup::singleton()->lazyPush( RecentChangesUpdateJob::newPurgeJob() );
@@ -2323,9 +2339,12 @@ class WikiPage implements Page, IDBAccessObject {
                        if ( !$recipient ) {
                                wfDebug( __METHOD__ . ": invalid username\n" );
                        } else {
+                               // Avoid PHP 7.1 warning of passing $this by reference
+                               $wikiPage = $this;
+
                                // Allow extensions to prevent user notification
                                // when a new message is added to their talk page
-                               if ( Hooks::run( 'ArticleEditUpdateNewTalk', [ &$this, $recipient ] ) ) {
+                               if ( Hooks::run( 'ArticleEditUpdateNewTalk', [ &$wikiPage, $recipient ] ) ) {
                                        if ( User::isIP( $shortTitle ) ) {
                                                // An anonymous user
                                                $recipient->setNewtalk( true, $revision );
@@ -2454,7 +2473,10 @@ class WikiPage implements Page, IDBAccessObject {
                $nullRevision = null;
 
                if ( $id ) { // Protection of existing page
-                       if ( !Hooks::run( 'ArticleProtect', [ &$this, &$user, $limit, $reason ] ) ) {
+                       // Avoid PHP 7.1 warning of passing $this by reference
+                       $wikiPage = $this;
+
+                       if ( !Hooks::run( 'ArticleProtect', [ &$wikiPage, &$user, $limit, $reason ] ) ) {
                                return Status::newGood();
                        }
 
@@ -2541,9 +2563,12 @@ class WikiPage implements Page, IDBAccessObject {
                                __METHOD__
                        );
 
+                       // Avoid PHP 7.1 warning of passing $this by reference
+                       $wikiPage = $this;
+
                        Hooks::run( 'NewRevisionFromEditComplete',
                                [ $this, $nullRevision, $latest, $user ] );
-                       Hooks::run( 'ArticleProtectComplete', [ &$this, &$user, $limit, $reason ] );
+                       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
                        $cascade = false;
@@ -2823,9 +2848,12 @@ class WikiPage implements Page, IDBAccessObject {
                        return $status;
                }
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $wikiPage = $this;
+
                $user = is_null( $user ) ? $wgUser : $user;
                if ( !Hooks::run( 'ArticleDelete',
-                       [ &$this, &$user, &$reason, &$error, &$status, $suppress ]
+                       [ &$wikiPage, &$user, &$reason, &$error, &$status, $suppress ]
                ) ) {
                        if ( $status->isOK() ) {
                                // Hook aborted but didn't set a fatal status