The static declaration must come after the visibility declaration
[lhc/web/wiklou.git] / includes / parser / Parser.php
index b31288f..3a79c54 100644 (file)
@@ -246,6 +246,13 @@ class Parser {
                }
        }
 
+       /**
+        * Allow extensions to clean up when the parser is cloned
+        */
+       function __clone() {
+               wfRunHooks( 'ParserCloned', array( $this ) );
+       }
+
        /**
         * Do various kinds of initialisation on the first call of the parser
         */
@@ -405,9 +412,7 @@ class Parser {
                if ( !( $options->getDisableContentConversion()
                                || isset( $this->mDoubleUnderscores['nocontentconvert'] ) ) )
                {
-                       # Run convert unconditionally in 1.18-compatible mode
-                       global $wgBug34832TransitionalRollback;
-                       if ( $wgBug34832TransitionalRollback || !$this->mOptions->getInterfaceMessage() ) {
+                       if ( !$this->mOptions->getInterfaceMessage() ) {
                                # The position of the convert() call should not be changed. it
                                # assumes that the links are all replaced and the only thing left
                                # is the <nowiki> mark.
@@ -542,7 +547,7 @@ class Parser {
         * Also removes comments.
         * @return mixed|string
         */
-       function preprocess( $text, Title $title, ParserOptions $options, $revid = null ) {
+       function preprocess( $text, Title $title = null, ParserOptions $options, $revid = null ) {
                wfProfileIn( __METHOD__ );
                $this->startParse( $title, $options, self::OT_PREPROCESS, true );
                if ( $revid !== null ) {
@@ -601,7 +606,7 @@ class Parser {
         *
         * @return string
         */
-       static public function getRandomString() {
+       public static function getRandomString() {
                return wfRandomString( 16 );
        }
 
@@ -774,12 +779,7 @@ class Parser {
         * Get the language object for language conversion
         */
        function getConverterLanguage() {
-               global $wgBug34832TransitionalRollback, $wgContLang;
-               if ( $wgBug34832TransitionalRollback ) {
-                       return $wgContLang;
-               } else {
-                       return $this->getTargetLanguage();
-               }
+               return $this->getTargetLanguage();
        }
 
        /**
@@ -1307,7 +1307,8 @@ class Parser {
                if ( $text === false ) {
                        # Not an image, make a link
                        $text = Linker::makeExternalLink( $url,
-                               $this->getConverterLanguage()->markNoConversion($url), true, 'free',
+                               $this->getConverterLanguage()->markNoConversion( $url, true ),
+                               true, 'free',
                                $this->getExternalLinkAttribs( $url ) );
                        # Register it in the output object...
                        # Replace unnecessary URL escape codes with their equivalent characters
@@ -1606,7 +1607,25 @@ class Parser {
                wfProfileOut( __METHOD__ );
                return $s;
        }
-
+       /**
+        * Get the rel attribute for a particular external link.
+        *
+        * @since 1.21
+        * @param $url String|bool optional URL, to extract the domain from for rel =>
+        *   nofollow if appropriate
+        * @param $title Title optional Title, for wgNoFollowNsExceptions lookups
+        * @return string|null rel attribute for $url
+        */
+       public static function getExternalLinkRel( $url = false, $title = null ) {
+               global $wgNoFollowLinks, $wgNoFollowNsExceptions, $wgNoFollowDomainExceptions;
+               $ns = $title ? $title->getNamespace() : false;
+               if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) &&
+                               !wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) )
+               {
+                       return 'nofollow';
+               }
+               return null;
+       }
        /**
         * Get an associative array of additional HTML attributes appropriate for a
         * particular external link.  This currently may include rel => nofollow
@@ -1619,13 +1638,8 @@ class Parser {
         */
        function getExternalLinkAttribs( $url = false ) {
                $attribs = array();
-               global $wgNoFollowLinks, $wgNoFollowNsExceptions, $wgNoFollowDomainExceptions;
-               $ns = $this->mTitle->getNamespace();
-               if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) &&
-                               !wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) )
-               {
-                       $attribs['rel'] = 'nofollow';
-               }
+               $attribs['rel'] = self::getExternalLinkRel( $url, $this->mTitle );
+
                if ( $this->mOptions->getExternalLinkTarget() ) {
                        $attribs['target'] = $this->mOptions->getExternalLinkTarget();
                }
@@ -3617,7 +3631,7 @@ class Parser {
 
                        if ( $rev ) {
                                $content = $rev->getContent();
-                               $text = $content->getWikitextForTransclusion();
+                               $text = $content ? $content->getWikitextForTransclusion() : null;
 
                                if ( $text === false || $text === null ) {
                                        $text = false;
@@ -4478,14 +4492,14 @@ class Parser {
                        '~~~' => $sigText
                ) );
 
-               # Context links: [[|name]] and [[name (context)|]]
+               # Context links ("pipe tricks"): [[|name]] and [[name (context)|]]
                $tc = '[' . Title::legalChars() . ']';
                $nc = '[ _0-9A-Za-z\x80-\xff-]'; # Namespaces can use non-ascii!
 
-               $p1 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\))\\|]]/";           # [[ns:page (context)|]]
-               $p4 = "/\[\[(:?$nc+:|:|)($tc+?)( ?($tc+))\\|]]/";           # [[ns:page(context)|]]
-               $p3 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\)|)((?:, |,)$tc+|)\\|]]/"; # [[ns:page (context), context|]]
-               $p2 = "/\[\[\\|($tc+)]]/";                                      # [[|page]]
+               $p1 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\))\\|]]/";                   # [[ns:page (context)|]]
+               $p4 = "/\[\[(:?$nc+:|:|)($tc+?)( ?($tc+))\\|]]/";                           # [[ns:page(context)|]] (double-width brackets, added in r40257)
+               $p3 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\)|)((?:, |,)$tc+|)\\|]]/";         # [[ns:page (context), context|]] (using either single or double-width comma)
+               $p2 = "/\[\[\\|($tc+)]]/";                                              # [[|page]] (reverse pipe trick: add context from page title)
 
                # try $p1 first, to turn "[[A, B (C)|]]" into "[[A, B (C)|A, B]]"
                $text = preg_replace( $p1, '[[\\1\\2\\3|\\2]]', $text );
@@ -4675,11 +4689,7 @@ class Parser {
                        global $wgTitle;
                        $title = $wgTitle;
                }
-               if ( !$title ) {
-                       # It's not uncommon having a null $wgTitle in scripts. See r80898
-                       # Create a ghost title in such case
-                       $title = Title::newFromText( 'Dwimmerlaik' );
-               }
+
                $text = $this->preprocess( $text, $title, $options );
 
                $executing = false;
@@ -4978,13 +4988,17 @@ class Parser {
                                                $alt = $this->stripAltText( $match, false );
                                        }
                                        elseif( $match = $magicWordLink->matchVariableStartToEnd( $parameterMatch ) ){
-                                               $link = strip_tags($this->replaceLinkHoldersText($match));
+                                               $linkValue = strip_tags( $this->replaceLinkHoldersText( $match ) );
                                                $chars = self::EXT_LINK_URL_CLASS;
                                                $prots = $this->mUrlProtocols;
                                                //check to see if link matches an absolute url, if not then it must be a wiki link.
-                                               if(!preg_match( "/^($prots)$chars+$/u", $link)){
-                                                       $localLinkTitle = Title::newFromText($link);
-                                                       $link = $localLinkTitle->getLocalURL();
+                                               if ( preg_match( "/^($prots)$chars+$/u", $linkValue ) ) {
+                                                       $link = $linkValue;
+                                               } else {
+                                                       $localLinkTitle = Title::newFromText( $linkValue );
+                                                       if ( $localLinkTitle !== null ) {
+                                                               $link = $localLinkTitle->getLocalURL();
+                                                       }
                                                }
                                        }
                                        else {