Follow-up r94680 - fix unit tests.
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 5837c7f..dc039fd 100644 (file)
@@ -362,14 +362,16 @@ class Parser {
                $this->replaceLinkHolders( $text );
 
                /**
-                * The page doesn't get language converted if
+                * The input doesn't get language converted if
                 * a) It's disabled
                 * b) Content isn't converted
                 * c) It's a conversion table
+                * d) it is an interface message (which is in the user language)
                 */
                if ( !( $wgDisableLangConversion
                                || isset( $this->mDoubleUnderscores['nocontentconvert'] )
-                               || $this->mTitle->isConversionTable() ) ) {
+                               || $this->mTitle->isConversionTable()
+                               || $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
@@ -508,6 +510,22 @@ class Parser {
                return $text;
        }
 
+       /**
+        * Recursive parser entry point that can be called from an extension tag
+        * hook.
+        *
+        * @param $text String: text to be expanded
+        * @param $frame PPFrame: The frame to use for expanding any template variables
+        * @return String
+        */
+       public function recursivePreprocess( $text, $frame = false ) {
+               wfProfileIn( __METHOD__ );
+               $text = $this->replaceVariables( $text, $frame );
+               $text = $this->mStripState->unstripBoth( $text );
+               wfProfileOut( __METHOD__ );
+               return $text;
+       }
+
        /**
         * Process the wikitext for the ?preload= feature. (bug 5210)
         *
@@ -1212,7 +1230,7 @@ class Parser {
         */
        function doMagicLinks( $text ) {
                wfProfileIn( __METHOD__ );
-               $prots = $this->mUrlProtocols;
+               $prots = wfUrlProtocolsWithoutProtRel();
                $urlChar = self::EXT_LINK_URL_CLASS;
                $text = preg_replace_callback(
                        '!(?:                           # Start cases
@@ -1894,7 +1912,7 @@ class Parser {
                        # Don't allow internal links to pages containing
                        # PROTO: where PROTO is a valid URL protocol; these
                        # should be external links.
-                       if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
+                       if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
                                $s .= $prefix . '[[' . $line ;
                                wfProfileOut( __METHOD__."-misc" );
                                continue;
@@ -2642,6 +2660,15 @@ class Parser {
                global $wgContLang, $wgSitename, $wgServer;
                global $wgArticlePath, $wgScriptPath, $wgStylePath;
 
+               if ( is_null( $this->mTitle ) ) {
+                       // If no title set, bad things are going to happen
+                       // later. Title should always be set since this
+                       // should only be called in the middle of a parse
+                       // operation (but the unit-tests do funky stuff)
+                       throw new MWException( __METHOD__ . ' Should only be '
+                               . ' called while parsing (no title set)' );
+               }
+
                /**
                 * Some of these require message or data lookups and can be
                 * expensive to check many times.
@@ -2676,48 +2703,50 @@ class Parser {
                        date_default_timezone_set( $oldtz );
                }
 
+               $pageLang = $this->getFunctionLang();
+
                switch ( $index ) {
                        case 'currentmonth':
-                               $value = $wgContLang->formatNum( gmdate( 'm', $ts ) );
+                               $value = $pageLang->formatNum( gmdate( 'm', $ts ) );
                                break;
                        case 'currentmonth1':
-                               $value = $wgContLang->formatNum( gmdate( 'n', $ts ) );
+                               $value = $pageLang->formatNum( gmdate( 'n', $ts ) );
                                break;
                        case 'currentmonthname':
-                               $value = $wgContLang->getMonthName( gmdate( 'n', $ts ) );
+                               $value = $pageLang->getMonthName( gmdate( 'n', $ts ) );
                                break;
                        case 'currentmonthnamegen':
-                               $value = $wgContLang->getMonthNameGen( gmdate( 'n', $ts ) );
+                               $value = $pageLang->getMonthNameGen( gmdate( 'n', $ts ) );
                                break;
                        case 'currentmonthabbrev':
-                               $value = $wgContLang->getMonthAbbreviation( gmdate( 'n', $ts ) );
+                               $value = $pageLang->getMonthAbbreviation( gmdate( 'n', $ts ) );
                                break;
                        case 'currentday':
-                               $value = $wgContLang->formatNum( gmdate( 'j', $ts ) );
+                               $value = $pageLang->formatNum( gmdate( 'j', $ts ) );
                                break;
                        case 'currentday2':
-                               $value = $wgContLang->formatNum( gmdate( 'd', $ts ) );
+                               $value = $pageLang->formatNum( gmdate( 'd', $ts ) );
                                break;
                        case 'localmonth':
-                               $value = $wgContLang->formatNum( $localMonth );
+                               $value = $pageLang->formatNum( $localMonth );
                                break;
                        case 'localmonth1':
-                               $value = $wgContLang->formatNum( $localMonth1 );
+                               $value = $pageLang->formatNum( $localMonth1 );
                                break;
                        case 'localmonthname':
-                               $value = $wgContLang->getMonthName( $localMonthName );
+                               $value = $pageLang->getMonthName( $localMonthName );
                                break;
                        case 'localmonthnamegen':
-                               $value = $wgContLang->getMonthNameGen( $localMonthName );
+                               $value = $pageLang->getMonthNameGen( $localMonthName );
                                break;
                        case 'localmonthabbrev':
-                               $value = $wgContLang->getMonthAbbreviation( $localMonthName );
+                               $value = $pageLang->getMonthAbbreviation( $localMonthName );
                                break;
                        case 'localday':
-                               $value = $wgContLang->formatNum( $localDay );
+                               $value = $pageLang->formatNum( $localDay );
                                break;
                        case 'localday2':
-                               $value = $wgContLang->formatNum( $localDay2 );
+                               $value = $pageLang->formatNum( $localDay2 );
                                break;
                        case 'pagename':
                                $value = wfEscapeWikiText( $this->mTitle->getText() );
@@ -2842,68 +2871,68 @@ class Parser {
                                $value = ( wfUrlencode( $this->mTitle->getSubjectNsText() ) );
                                break;
                        case 'currentdayname':
-                               $value = $wgContLang->getWeekdayName( gmdate( 'w', $ts ) + 1 );
+                               $value = $pageLang->getWeekdayName( gmdate( 'w', $ts ) + 1 );
                                break;
                        case 'currentyear':
-                               $value = $wgContLang->formatNum( gmdate( 'Y', $ts ), true );
+                               $value = $pageLang->formatNum( gmdate( 'Y', $ts ), true );
                                break;
                        case 'currenttime':
-                               $value = $wgContLang->time( wfTimestamp( TS_MW, $ts ), false, false );
+                               $value = $pageLang->time( wfTimestamp( TS_MW, $ts ), false, false );
                                break;
                        case 'currenthour':
-                               $value = $wgContLang->formatNum( gmdate( 'H', $ts ), true );
+                               $value = $pageLang->formatNum( gmdate( 'H', $ts ), true );
                                break;
                        case 'currentweek':
                                # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
                                # int to remove the padding
-                               $value = $wgContLang->formatNum( (int)gmdate( 'W', $ts ) );
+                               $value = $pageLang->formatNum( (int)gmdate( 'W', $ts ) );
                                break;
                        case 'currentdow':
-                               $value = $wgContLang->formatNum( gmdate( 'w', $ts ) );
+                               $value = $pageLang->formatNum( gmdate( 'w', $ts ) );
                                break;
                        case 'localdayname':
-                               $value = $wgContLang->getWeekdayName( $localDayOfWeek + 1 );
+                               $value = $pageLang->getWeekdayName( $localDayOfWeek + 1 );
                                break;
                        case 'localyear':
-                               $value = $wgContLang->formatNum( $localYear, true );
+                               $value = $pageLang->formatNum( $localYear, true );
                                break;
                        case 'localtime':
-                               $value = $wgContLang->time( $localTimestamp, false, false );
+                               $value = $pageLang->time( $localTimestamp, false, false );
                                break;
                        case 'localhour':
-                               $value = $wgContLang->formatNum( $localHour, true );
+                               $value = $pageLang->formatNum( $localHour, true );
                                break;
                        case 'localweek':
                                # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
                                # int to remove the padding
-                               $value = $wgContLang->formatNum( (int)$localWeek );
+                               $value = $pageLang->formatNum( (int)$localWeek );
                                break;
                        case 'localdow':
-                               $value = $wgContLang->formatNum( $localDayOfWeek );
+                               $value = $pageLang->formatNum( $localDayOfWeek );
                                break;
                        case 'numberofarticles':
-                               $value = $wgContLang->formatNum( SiteStats::articles() );
+                               $value = $pageLang->formatNum( SiteStats::articles() );
                                break;
                        case 'numberoffiles':
-                               $value = $wgContLang->formatNum( SiteStats::images() );
+                               $value = $pageLang->formatNum( SiteStats::images() );
                                break;
                        case 'numberofusers':
-                               $value = $wgContLang->formatNum( SiteStats::users() );
+                               $value = $pageLang->formatNum( SiteStats::users() );
                                break;
                        case 'numberofactiveusers':
-                               $value = $wgContLang->formatNum( SiteStats::activeUsers() );
+                               $value = $pageLang->formatNum( SiteStats::activeUsers() );
                                break;
                        case 'numberofpages':
-                               $value = $wgContLang->formatNum( SiteStats::pages() );
+                               $value = $pageLang->formatNum( SiteStats::pages() );
                                break;
                        case 'numberofadmins':
-                               $value = $wgContLang->formatNum( SiteStats::numberingroup( 'sysop' ) );
+                               $value = $pageLang->formatNum( SiteStats::numberingroup( 'sysop' ) );
                                break;
                        case 'numberofedits':
-                               $value = $wgContLang->formatNum( SiteStats::edits() );
+                               $value = $pageLang->formatNum( SiteStats::edits() );
                                break;
                        case 'numberofviews':
-                               $value = $wgContLang->formatNum( SiteStats::views() );
+                               $value = $pageLang->formatNum( SiteStats::views() );
                                break;
                        case 'currenttimestamp':
                                $value = wfTimestamp( TS_MW, $ts );
@@ -2930,7 +2959,7 @@ class Parser {
                        case 'stylepath':
                                return $wgStylePath;
                        case 'directionmark':
-                               return $wgContLang->getDirMark();
+                               return $pageLang->getDirMark();
                        case 'contentlanguage':
                                global $wgLanguageCode;
                                return $wgLanguageCode;
@@ -4524,10 +4553,7 @@ class Parser {
        function cleanSig( $text, $parsing = false ) {
                if ( !$parsing ) {
                        global $wgTitle;
-                       $this->mOptions = new ParserOptions;
-                       $this->clearState();
-                       $this->setTitle( $wgTitle );
-                       $this->setOutputType = self::OT_PREPROCESS;
+                       $this->startParse( $wgTitle, new ParserOptions, self::OT_PREPROCESS, true );
                }
 
                # Option to disable this feature