(bug 5167) Add {{SUBPAGENAME}} variable
[lhc/web/wiklou.git] / includes / Parser.php
index c4fed1d..8165de7 100644 (file)
@@ -51,7 +51,7 @@ define( 'EXT_LINK_URL_CLASS', '[^][<>"\\x00-\\x20\\x7F]' );
 define( 'EXT_LINK_TEXT_CLASS', '[^\]\\x00-\\x1F\\x7F]' );
 define( 'EXT_IMAGE_FNAME_CLASS', '[A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]' );
 define( 'EXT_IMAGE_EXTENSIONS', 'gif|png|jpg|jpeg' );
-define( 'EXT_LINK_BRACKETED',  '/\[(\b(' . wfUrlProtocols() . ')'.EXT_LINK_URL_CLASS.'+)( *)('.EXT_LINK_TEXT_CLASS.'*?)\]/S' );
+define( 'EXT_LINK_BRACKETED',  '/\[(\b(' . wfUrlProtocols() . ')'.EXT_LINK_URL_CLASS.'+) *('.EXT_LINK_TEXT_CLASS.'*?)\]/S' );
 define( 'EXT_IMAGE_REGEX',
        '/^('.HTTP_PROTOCOLS.')'.  # Protocol
        '('.EXT_LINK_URL_CLASS.'+)\\/'.  # Hostname and path
@@ -73,7 +73,7 @@ define( 'EXT_IMAGE_REGEX',
  *   performs brace substitution on MediaWiki messages
  *
  * Globals used:
- *    objects:   $wgLang
+ *    objects:   $wgLang, $wgContLang
  *
  * NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
  *
@@ -236,11 +236,11 @@ class Parser
 
                $this->replaceLinkHolders( $text );
 
-               # the position of the convert() call should not be changed. it
-               # assumes that the links are all replaces and the only thing left
+               # the position of the parserConvert() call should not be changed. it
+               # assumes that the links are all replaced and the only thing left
                # is the <nowiki> mark.
-               $text = $wgContLang->convert($text);
-               $this->mOutput->setTitleText($wgContLang->getParsedTitle());
+               # Side-effects: this calls $this->mOutput->setTitleText()
+               $text = $wgContLang->parserConvert( $text, $this );
 
                $text = $this->unstripNoWiki( $text, $this->mStripState );
 
@@ -270,6 +270,9 @@ class Parser
                return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
        }
 
+       function &getTitle() { return $this->mTitle; }
+       function getOptions() { return $this->mOptions; }
+
        /**
         * Replaces all occurrences of <$tag>content</$tag> in the text
         * with a random marker and returns the new text. the output parameter
@@ -1085,7 +1088,6 @@ class Parser
                while ( $i<count( $bits ) ) {
                        $url = $bits[$i++];
                        $protocol = $bits[$i++];
-                       $spaces = $bits[$i++];
                        $text = $bits[$i++];
                        $trail = $bits[$i++];
 
@@ -1143,13 +1145,7 @@ class Parser
                        # This means that users can paste URLs directly into the text
                        # Funny characters like &ouml; aren't valid in URLs anyway
                        # This was changed in August 2004
-                       if ( strlen ( $spaces ) < 2 ) {
-                               # Normal case
-                               $s .= $sk->makeExternalLink( $url, $text, false, $linktype ) . $dtrail . $trail;
-                       } else {
-                               # Fix for [url  text] (notice the two blanks)
-                               $s .= '[' . $sk->makeExternalLink( $url, $url, false, "free" ) . $spaces . $text . ']' . $dtrail . $trail;
-                       }
+                       $s .= $sk->makeExternalLink( $url, $text, false, $linktype ) . $dtrail . $trail;
 
                        # Register link in the output object
                        $this->mOutput->addExternalLink( $url );
@@ -2026,6 +2022,8 @@ class Parser
                                return $this->mTitle->getPrefixedText();
                        case MAG_FULLPAGENAMEE:
                                return $this->mTitle->getPrefixedURL();
+                       case MAG_SUBPAGENAME:
+                               return $this->mTitle->getSubpageText();
                        case MAG_REVISIONID:
                                return $this->mRevisionId;
                        case MAG_NAMESPACE:
@@ -3024,6 +3022,8 @@ class Parser
                        # strip out HTML
                        $canonized_headline = preg_replace( '/<.*?' . '>/','',$canonized_headline );
                        $tocline = trim( $canonized_headline );
+                       # Save headline for section edit hint before it's escaped
+                       $headline_hint = trim( $canonized_headline ); 
                        $canonized_headline = Sanitizer::escapeId( $tocline );
                        $refers[$headlineCount] = $canonized_headline;
 
@@ -3052,7 +3052,7 @@ class Parser
                                if( $istemplate )
                                        $head[$headlineCount] .= $sk->editSectionLinkForOther($templatetitle, $templatesection);
                                else
-                                       $head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1);
+                                       $head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint);
                        }
 
                        # give headline the correct <h#> tag
@@ -3435,8 +3435,11 @@ class Parser
 
        /**
         * Create an HTML-style tag, e.g. <yourtag>special text</yourtag>
-        * Callback will be called with the text within
-        * Transform and return the text within
+        * The callback should have the following form:
+        *    function myParserHook( $text, $params, &$parser ) { ... }
+        *
+        * Transform and return $text. Use $parser for any required context, e.g. use
+        * $parser->getTitle() and $parser->getOptions() not $wgTitle or $wgOut->mParserOptions
         *
         * @access public
         *