Replaced &$this with $this
authorawu42 <9922yalp@gmail.com>
Fri, 30 Dec 2016 16:55:28 +0000 (11:55 -0500)
committerawu42 <9922yalp@gmail.com>
Fri, 30 Dec 2016 16:55:28 +0000 (11:55 -0500)
Replaced &$this in includes/Title.php to avoid error in PHP 7.1

Bug: T153505
Change-Id: I76eaae609a817af42687d87bcf0d13da7ba01c05

includes/Title.php

index c4584bd..1125f23 100644 (file)
@@ -1681,8 +1681,9 @@ class Title implements LinkTarget {
 
                # Finally, add the fragment.
                $url .= $this->getFragmentForURL();
-
-               Hooks::run( 'GetFullURL', [ &$this, &$url, $query ] );
+               // Avoid PHP 7.1 warning from passing $this by reference
+               $titleRef = $this;
+               Hooks::run( 'GetFullURL', [ &$titleRef, &$url, $query ] );
                return $url;
        }
 
@@ -1728,7 +1729,9 @@ class Title implements LinkTarget {
                        $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
                        if ( $query == '' ) {
                                $url = str_replace( '$1', $dbkey, $wgArticlePath );
-                               Hooks::run( 'GetLocalURL::Article', [ &$this, &$url ] );
+                               // Avoid PHP 7.1 warning from passing $this by reference
+                               $titleRef = $this;
+                               Hooks::run( 'GetLocalURL::Article', [ &$titleRef, &$url ] );
                        } else {
                                global $wgVariantArticlePath, $wgActionPaths, $wgContLang;
                                $url = false;
@@ -1772,8 +1775,9 @@ class Title implements LinkTarget {
                                        $url = "{$wgScript}?title={$dbkey}&{$query}";
                                }
                        }
-
-                       Hooks::run( 'GetLocalURL::Internal', [ &$this, &$url, $query ] );
+                       // Avoid PHP 7.1 warning from passing $this by reference
+                       $titleRef = $this;
+                       Hooks::run( 'GetLocalURL::Internal', [ &$titleRef, &$url, $query ] );
 
                        // @todo FIXME: This causes breakage in various places when we
                        // actually expected a local URL and end up with dupe prefixes.
@@ -1781,7 +1785,9 @@ class Title implements LinkTarget {
                                $url = $wgServer . $url;
                        }
                }
-               Hooks::run( 'GetLocalURL', [ &$this, &$url, $query ] );
+               // Avoid PHP 7.1 warning from passing $this by reference
+               $titleRef = $this;
+               Hooks::run( 'GetLocalURL', [ &$titleRef, &$url, $query ] );
                return $url;
        }
 
@@ -1830,7 +1836,9 @@ class Title implements LinkTarget {
                $query = self::fixUrlQueryArgs( $query, $query2 );
                $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
                $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
-               Hooks::run( 'GetInternalURL', [ &$this, &$url, $query ] );
+               // Avoid PHP 7.1 warning from passing $this by reference
+               $titleRef = $this;
+               Hooks::run( 'GetInternalURL', [ &$titleRef, &$url, $query ] );
                return $url;
        }
 
@@ -1848,7 +1856,9 @@ class Title implements LinkTarget {
        public function getCanonicalURL( $query = '', $query2 = false ) {
                $query = self::fixUrlQueryArgs( $query, $query2 );
                $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
-               Hooks::run( 'GetCanonicalURL', [ &$this, &$url, $query ] );
+               // Avoid PHP 7.1 warning from passing $this by reference
+               $titleRef = $this;
+               Hooks::run( 'GetCanonicalURL', [ &$titleRef, &$url, $query ] );
                return $url;
        }
 
@@ -2052,18 +2062,22 @@ class Title implements LinkTarget {
        private function checkPermissionHooks( $action, $user, $errors, $rigor, $short ) {
                // Use getUserPermissionsErrors instead
                $result = '';
-               if ( !Hooks::run( 'userCan', [ &$this, &$user, $action, &$result ] ) ) {
+               // Avoid PHP 7.1 warning from passing $this by reference
+               $titleRef = $this;
+               if ( !Hooks::run( 'userCan', [ &$titleRef, &$user, $action, &$result ] ) ) {
                        return $result ? [] : [ [ 'badaccess-group0' ] ];
                }
                // Check getUserPermissionsErrors hook
-               if ( !Hooks::run( 'getUserPermissionsErrors', [ &$this, &$user, $action, &$result ] ) ) {
+               // Avoid PHP 7.1 warning from passing $this by reference
+               $titleRef = $this;
+               if ( !Hooks::run( 'getUserPermissionsErrors', [ &$titleRef, &$user, $action, &$result ] ) ) {
                        $errors = $this->resultToError( $errors, $result );
                }
                // Check getUserPermissionsErrorsExpensive hook
                if (
                        $rigor !== 'quick'
                        && !( $short && count( $errors ) > 0 )
-                       && !Hooks::run( 'getUserPermissionsErrorsExpensive', [ &$this, &$user, $action, &$result ] )
+                       && !Hooks::run( 'getUserPermissionsErrorsExpensive', [ &$titleRef, &$user, $action, &$result ] )
                ) {
                        $errors = $this->resultToError( $errors, $result );
                }