Localisation updates for core and extension messages from translatewiki.net (2010...
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 22257f6..e14d54b 100644 (file)
@@ -129,7 +129,7 @@ class Parser {
                $this->mDefaultStripList = $this->mStripList = array();
                $this->mUrlProtocols = wfUrlProtocols();
                $this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'.
-                       '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x0a\\x0d]*?)\]/S';
+                       '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x00-\\x08\\x0a-\\x1F]*?)\]/S';
                $this->mVarCache = array();
                if ( isset( $conf['preprocessorClass'] ) ) {
                        $this->mPreprocessorClass = $conf['preprocessorClass'];
@@ -303,7 +303,7 @@ class Parser {
                 * to internalParse() which does all the real work.
                 */
 
-               global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion;
+               global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
                $fname = __METHOD__.'-' . wfGetCaller();
                wfProfileIn( __METHOD__ );
                wfProfileIn( $fname );
@@ -347,13 +347,11 @@ class Parser {
                /**
                 * The page doesn't get language converted if
                 * a) It's disabled
-                * b) Titles aren't converted
-                * c) Content isn't converted and this is not a talk page
-                * d) It's a conversion table
+                * b) Content isn't converted
+                * c) It's a conversion table
                 */
                if ( !( $wgDisableLangConversion
-                               || isset( $this->mDoubleUnderscores['notitleconvert'] )
-                               || ( isset( $this->mDoubleUnderscores['nocontentconvert'] ) && !$this->mTitle->isTalkPage() )
+                               || isset( $this->mDoubleUnderscores['nocontentconvert'] )
                                || $this->mTitle->isConversionTable() ) ) {
 
                        # The position of the convert() call should not be changed. it
@@ -363,12 +361,33 @@ class Parser {
                        $text = $wgContLang->convert( $text );
                }
 
-               # A title may have been set in a conversion rule.
-               # Note that if a user tries to set a title in a conversion
-               # rule but content conversion was not done, then the parser
-               # won't pick it up.  This is probably expected behavior.
-               if ( $wgContLang->getConvRuleTitle() ) {
-                       $this->mOutput->setTitleText( $wgContLang->getConvRuleTitle() );
+               /**
+                * A page get its title converted except:
+                * a) Language conversion is globally disabled
+                * b) Title convert is globally disabled
+                * c) The page is a redirect page
+                * d) User request with a "linkconvert" set to "no"
+                * e) A "nocontentconvert" magic word has been set
+                * f) A "notitleconvert" magic word has been set
+                * g) User sets "noconvertlink" in his/her preference
+                *
+                * Note that if a user tries to set a title in a conversion
+                * rule but content conversion was not done, then the parser
+                * won't pick it up.  This is probably expected behavior.
+                */
+               if ( !( $wgDisableLangConversion
+                               || $wgDisableTitleConversion
+                               || isset( $this->mDoubleUnderscores['nocontentconvert'] )
+                               || isset( $this->mDoubleUnderscores['notitleconvert'] )
+                               || $this->mOutput->getDisplayTitle() !== false ) ) 
+               {
+                       $convruletitle = $wgContLang->getConvRuleTitle();
+                       if ( $convruletitle ) {
+                               $this->mOutput->setTitleText( $convruletitle );
+                       } else {
+                               $titleText = $wgContLang->convertTitle( $title );
+                               $this->mOutput->setTitleText( $titleText );
+                       }
                }
 
                $text = $this->mStripState->unstripNoWiki( $text );
@@ -497,7 +516,7 @@ class Parser {
        /**
         * Process the wikitext for the ?preload= feature. (bug 5210)
         *
-        * <noinclude>, <includeonly> etc. are parsed as for template transclusion, 
+        * <noinclude>, <includeonly> etc. are parsed as for template transclusion,
         * comments, templates, arguments, tags hooks and parser functions are untouched.
         */
        public function getPreloadText( $text, $title, $options ) {
@@ -505,7 +524,7 @@ class Parser {
                $this->clearState();
                $this->setOutputType( self::OT_PLAIN );
                $this->mOptions = $options;
-               $this->setTitle( $title ); 
+               $this->setTitle( $title );
 
                $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES;
                $dom = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION );
@@ -914,9 +933,9 @@ class Parser {
                                $flag = 0;
                        } else {
                                $flag = Parser::PTD_FOR_INCLUSION;
+                       }
                        $dom = $this->preprocessToDom( $text, $flag );
                        $text = $frame->expand( $dom );
-                       }
                } else {
                        # if $frame is not provided, then use old-style replaceVariables
                        $text = $this->replaceVariables( $text );
@@ -1144,12 +1163,12 @@ class Parser {
                                        }
                                        # Count the number of occurrences of bold and italics mark-ups.
                                        # We are not counting sequences of five apostrophes.
-                                       if ( strlen( $arr[$i] ) == 2 ) { 
+                                       if ( strlen( $arr[$i] ) == 2 ) {
                                                $numitalics++;
-                                       } elseif ( strlen( $arr[$i] ) == 3 ) { 
+                                       } elseif ( strlen( $arr[$i] ) == 3 ) {
                                                $numbold++;
-                                       } elseif ( strlen( $arr[$i] ) == 5 ) { 
-                                               $numitalics++; 
+                                       } elseif ( strlen( $arr[$i] ) == 5 ) {
+                                               $numitalics++;
                                                $numbold++;
                                        }
                                }
@@ -1174,7 +1193,7 @@ class Parser {
                                                                $firstspace = $i;
                                                        }
                                                } elseif ( $x2 === ' ') {
-                                                       if ( $firstsingleletterword == -1 ) { 
+                                                       if ( $firstsingleletterword == -1 ) {
                                                                $firstsingleletterword = $i;
                                                        }
                                                } else {
@@ -1594,10 +1613,10 @@ class Parser {
                                # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up,
                                # the real problem is with the $e1 regex
                                # See bug 1300.
-                               # 
+                               #
                                # Still some problems for cases where the ] is meant to be outside punctuation,
                                # and no image is in sight. See bug 2095.
-                               # 
+                               #
                                if ( $text !== '' &&
                                        substr( $m[3], 0, 1 ) === ']' &&
                                        strpos( $text, '[' ) !== false
@@ -1808,7 +1827,7 @@ class Parser {
                        wfProfileIn( __METHOD__."-always_known" );
                        # Some titles, such as valid special pages or files in foreign repos, should
                        # be shown as bluelinks even though they're not included in the page table
-                       # 
+                       #
                        # FIXME: isAlwaysKnown() can be expensive for file links; we should really do
                        # batch file existence checks for NS_FILE and NS_MEDIA
                        if ( $iw == '' && $nt->isAlwaysKnown() ) {
@@ -1909,18 +1928,18 @@ class Parser {
        /**
         * getCommon() returns the length of the longest common substring
         * of both arguments, starting at the beginning of both.
-        * @private 
-        */ 
+        * @private
+        */
        function getCommon( $st1, $st2 ) {
                $fl = strlen( $st1 );
                $shorter = strlen( $st2 );
-               if ( $fl < $shorter ) { 
-                       $shorter = $fl; 
+               if ( $fl < $shorter ) {
+                       $shorter = $fl;
                }
 
                for ( $i = 0; $i < $shorter; ++$i ) {
-                       if ( $st1{$i} != $st2{$i} ) { 
-                               break; 
+                       if ( $st1{$i} != $st2{$i} ) {
+                               break;
                        }
                }
                return $i;
@@ -1928,22 +1947,22 @@ class Parser {
        /**
         * These next three functions open, continue, and close the list
         * element appropriate to the prefix character passed into them.
-        * @private 
+        * @private
         */
        function openList( $char ) {
                $result = $this->closeParagraph();
 
-               if ( '*' === $char ) { 
-                       $result .= '<ul><li>'; 
-               } elseif ( '#' === $char ) { 
-                       $result .= '<ol><li>'; 
-               } elseif ( ':' === $char ) { 
-                       $result .= '<dl><dd>'; 
+               if ( '*' === $char ) {
+                       $result .= '<ul><li>';
+               } elseif ( '#' === $char ) {
+                       $result .= '<ol><li>';
+               } elseif ( ':' === $char ) {
+                       $result .= '<dl><dd>';
                } elseif ( ';' === $char ) {
                        $result .= '<dl><dt>';
                        $this->mDTopen = true;
-               } else { 
-                       $result = '<!-- ERR 1 -->'; 
+               } else {
+                       $result = '<!-- ERR 1 -->';
                }
 
                return $result;
@@ -1955,12 +1974,12 @@ class Parser {
         * @private
         */
        function nextItem( $char ) {
-               if ( '*' === $char || '#' === $char ) { 
-                       return '</li><li>'; 
+               if ( '*' === $char || '#' === $char ) {
+                       return '</li><li>';
                } elseif ( ':' === $char || ';' === $char ) {
                        $close = '</dd>';
-                       if ( $this->mDTopen ) { 
-                               $close = '</dt>'; 
+                       if ( $this->mDTopen ) {
+                               $close = '</dt>';
                        }
                        if ( ';' === $char ) {
                                $this->mDTopen = true;
@@ -1979,10 +1998,10 @@ class Parser {
         * @private
         */
        function closeList( $char ) {
-               if ( '*' === $char ) { 
-                       $text = '</li></ul>'; 
-               } elseif ( '#' === $char ) { 
-                       $text = '</li></ol>'; 
+               if ( '*' === $char ) {
+                       $text = '</li></ul>';
+               } elseif ( '#' === $char ) {
+                       $text = '</li></ol>';
                } elseif ( ':' === $char ) {
                        if ( $this->mDTopen ) {
                                $this->mDTopen = false;
@@ -1990,8 +2009,8 @@ class Parser {
                        } else {
                                $text = '</dd></dl>';
                        }
-               } else {        
-                       return '<!-- ERR 3 -->'; 
+               } else {
+                       return '<!-- ERR 3 -->';
                }
                return $text."\n";
        }
@@ -2010,7 +2029,7 @@ class Parser {
                # Parsing through the text line by line.  The main thing
                # happening here is handling of block-level elements p, pre,
                # and making lists from lines starting with * # : etc.
-               # 
+               #
                $textLines = StringUtils::explode( "\n", $text );
 
                $lastPrefix = $output = '';
@@ -2509,6 +2528,13 @@ class Parser {
                                # *after* a revision ID has been assigned. This is for null edits.
                                $this->mOutput->setFlag( 'vary-revision' );
                                wfDebug( __METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n" );
+                               $value = substr( $this->getRevisionTimestamp(), 4, 2 );
+                               break;
+                       case 'revisionmonth1':
+                               # Let the edit saving system know we should parse the page
+                               # *after* a revision ID has been assigned. This is for null edits.
+                               $this->mOutput->setFlag( 'vary-revision' );
+                               wfDebug( __METHOD__ . ": {{REVISIONMONTH1}} used, setting vary-revision...\n" );
                                $value = intval( substr( $this->getRevisionTimestamp(), 4, 2 ) );
                                break;
                        case 'revisionyear':
@@ -2654,7 +2680,7 @@ class Parser {
        }
 
        /**
-        * initialise the magic variables (like CURRENTMONTHNAME) and substitution modifiers 
+        * initialise the magic variables (like CURRENTMONTHNAME) and substitution modifiers
         *
         * @private
         */
@@ -2778,14 +2804,14 @@ class Parser {
         * Will warn at most once the user per limitation type
         *
         * @param string $limitationType, should be one of:
-        *   'expensive-parserfunction' (corresponding messages: 
-        *       'expensive-parserfunction-warning', 
+        *   'expensive-parserfunction' (corresponding messages:
+        *       'expensive-parserfunction-warning',
         *       'expensive-parserfunction-category')
-        *   'post-expand-template-argument' (corresponding messages: 
-        *       'post-expand-template-argument-warning', 
+        *   'post-expand-template-argument' (corresponding messages:
+        *       'post-expand-template-argument-warning',
         *       'post-expand-template-argument-category')
-        *   'post-expand-template-inclusion' (corresponding messages: 
-        *       'post-expand-template-inclusion-warning', 
+        *   'post-expand-template-inclusion' (corresponding messages:
+        *       'post-expand-template-inclusion-warning',
         *       'post-expand-template-inclusion-category')
         * @params int $current, $max When an explicit limit has been
         *       exceeded, provide the values (optional)
@@ -2990,8 +3016,8 @@ class Parser {
                                $limit = $this->mOptions->getMaxTemplateDepth();
                                if ( $frame->depth >= $limit ) {
                                        $found = true;
-                                       $text = '<span class="error">' 
-                                               . wfMsgForContent( 'parser-template-recursion-depth-warning', $limit ) 
+                                       $text = '<span class="error">'
+                                               . wfMsgForContent( 'parser-template-recursion-depth-warning', $limit )
                                                . '</span>';
                                }
                        }
@@ -3001,9 +3027,9 @@ class Parser {
                if ( !$found && $title ) {
                        wfProfileIn( __METHOD__ . '-loadtpl' );
                        if ( !$title->isExternal() ) {
-                               if ( $title->getNamespace() == NS_SPECIAL 
-                                       && $this->mOptions->getAllowSpecialInclusion() 
-                                       && $this->ot['html'] ) 
+                               if ( $title->getNamespace() == NS_SPECIAL
+                                       && $this->mOptions->getAllowSpecialInclusion()
+                                       && $this->ot['html'] )
                                {
                                        $text = SpecialPage::capturePath( $title );
                                        if ( is_string( $text ) ) {
@@ -3093,7 +3119,7 @@ class Parser {
                        # Escape nowiki-style return values
                        $text = wfEscapeWikiText( $text );
                } elseif ( is_string( $text )
-                       && !$piece['lineStart'] 
+                       && !$piece['lineStart']
                        && preg_match( '/^(?:{\\||:|;|#|\*)/', $text ) )
                {
                        # Bug 529: if the template begins with a table or block-level
@@ -3104,8 +3130,16 @@ class Parser {
 
                if ( is_string( $text ) && !$this->incrementIncludeSize( 'post-expand', strlen( $text ) ) ) {
                        # Error, oversize inclusion
-                       $text = "[[$originalTitle]]" .
-                               $this->insertStripItem( '<!-- WARNING: template omitted, post-expand include size too large -->' );
+                       if ( $titleText !== false ) {
+                               # Make a working, properly escaped link if possible (bug 23588)
+                               $text = "[[:$titleText]]";
+                       } else {
+                               # This will probably not be a working link, but at least it may
+                               # provide some hint of where the problem is
+                               preg_replace( '/^:/', '', $originalTitle );
+                               $text = "[[:$originalTitle]]";
+                       }
+                       $text .= $this->insertStripItem( '<!-- WARNING: template omitted, post-expand include size too large -->' );
                        $this->limitationWarn( 'post-expand-template-inclusion' );
                }
 
@@ -3481,7 +3515,7 @@ class Parser {
                        $this->addTrackingCategory( 'hidden-category-category' );
                }
                # (bug 8068) Allow control over whether robots index a page.
-               # 
+               #
                # FIXME (bug 14899): __INDEX__ always overrides __NOINDEX__ here!  This
                # is not desirable, the last one on the page should win.
                if ( isset( $this->mDoubleUnderscores['noindex'] ) && $this->mTitle->canUseNoindex() ) {
@@ -3715,7 +3749,7 @@ class Parser {
                        if ( $wgHtml5 && $wgExperimentalHtmlIds ) {
                                # For reverse compatibility, provide an id that's
                                # HTML4-compatible, like we used to.
-                               # 
+                               #
                                # It may be worth noting, academically, that it's possible for
                                # the legacy anchor to conflict with a non-legacy headline
                                # anchor on the page.  In this case likely the "correct" thing
@@ -4021,7 +4055,7 @@ class Parser {
                $ts = date( 'YmdHis', $unixts );
                $tzMsg = date( 'T', $unixts );  # might vary on DST changeover!
 
-               # Allow translation of timezones trough wiki. date() can return
+               # Allow translation of timezones through wiki. date() can return
                # whatever crap the system uses, localised or not, so we cannot
                # ship premade translations.
                $key = 'timezone-' . strtolower( trim( $tzMsg ) );
@@ -4678,13 +4712,13 @@ class Parser {
                # came to also set the caption, ordinary text after the image -- which
                # makes no sense, because that just repeats the text multiple times in
                # screen readers.  It *also* came to set the title attribute.
-               # 
+               #
                # Now that we have an alt attribute, we should not set the alt text to
                # equal the caption: that's worse than useless, it just repeats the
                # text.  This is the framed/thumbnail case.  If there's no caption, we
                # use the unnamed parameter for alt text as well, just for the time be-
                # ing, if the unnamed param is set and the alt param is not.
-               # 
+               #
                # For the future, we need to figure out if we want to tweak this more,
                # e.g., introducing a title= parameter for the title; ignoring the un-
                # named parameter entirely for images without a caption; adding an ex-
@@ -4781,8 +4815,8 @@ class Parser {
        /**#@+
         * Accessor
         */
-       function getTags() { 
-               return array_merge( array_keys( $this->mTransparentTagHooks ), array_keys( $this->mTagHooks ) ); 
+       function getTags() {
+               return array_merge( array_keys( $this->mTransparentTagHooks ), array_keys( $this->mTagHooks ) );
        }
        /**#@-*/
 
@@ -4945,7 +4979,7 @@ class Parser {
 
                        # The cryptic '' timezone parameter tells to use the site-default
                        # timezone offset instead of the user settings.
-                       # 
+                       #
                        # Since this value will be saved into the parser cache, served
                        # to other users, and potentially even used inside links and such,
                        # it needs to be consistent for all visitors.
@@ -4992,7 +5026,7 @@ class Parser {
                if ( $this->mDefaultSort !== false ) {
                        return $this->mDefaultSort;
                } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ||
-                       !$wgCategoryPrefixedDefaultSortkey ) 
+                       !$wgCategoryPrefixedDefaultSortkey )
                {
                        return $this->mTitle->getText();
                } else {
@@ -5133,8 +5167,8 @@ class Parser {
                #  data in an array.
                $stripState = new StripState;
                $pos = 0;
-               while ( ( $start_pos = strpos( $text, $this->mUniqPrefix, $pos ) ) 
-                       && ( $end_pos = strpos( $text, self::MARKER_SUFFIX, $pos ) ) ) 
+               while ( ( $start_pos = strpos( $text, $this->mUniqPrefix, $pos ) )
+                       && ( $end_pos = strpos( $text, self::MARKER_SUFFIX, $pos ) ) )
                {
                        $end_pos += strlen( self::MARKER_SUFFIX );
                        $marker = substr( $text, $start_pos, $end_pos-$start_pos );