Replace use of &$this
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 157946c..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;
        }
 
@@ -1947,18 +1963,6 @@ class Parser {
                return $attribs;
        }
 
-       /**
-        * Replace unusual escape codes in a URL with their equivalent characters
-        *
-        * @deprecated since 1.24, use normalizeLinkUrl
-        * @param string $url
-        * @return string
-        */
-       public static function replaceUnusualEscapes( $url ) {
-               wfDeprecated( __METHOD__, '1.24' );
-               return self::normalizeLinkUrl( $url );
-       }
-
        /**
         * Replace unusual escape codes in a URL with their equivalent characters
         *
@@ -2213,7 +2217,7 @@ class Parser {
                                continue;
                        }
 
-                       $origLink = $m[1];
+                       $origLink = ltrim( $m[1], ' ' );
 
                        # Don't allow internal links to pages containing
                        # PROTO: where PROTO is a valid URL protocol; these
@@ -2498,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();
 
@@ -2812,6 +2819,9 @@ class Parser {
                        case 'contentlanguage':
                                global $wgLanguageCode;
                                return $wgLanguageCode;
+                       case 'pagelanguage':
+                               $value = $pageLang->getCode();
+                               break;
                        case 'cascadingsources':
                                $value = CoreParserFunctions::cascadingsources( $this );
                                break;
@@ -2819,7 +2829,7 @@ class Parser {
                                $ret = null;
                                Hooks::run(
                                        'ParserGetVariableValueSwitch',
-                                       [ &$this, &$this->mVarCache, &$index, &$ret, &$frame ]
+                                       [ &$parser, &$this->mVarCache, &$index, &$ret, &$frame ]
                                );
 
                                return $ret;
@@ -3363,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 = [];
@@ -3872,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>';
@@ -4975,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 ) {