performance tweak related to title conversion
authorZheng Zhu <zhengzhu@users.mediawiki.org>
Fri, 8 Oct 2004 04:27:07 +0000 (04:27 +0000)
committerZheng Zhu <zhengzhu@users.mediawiki.org>
Fri, 8 Oct 2004 04:27:07 +0000 (04:27 +0000)
includes/OutputPage.php
includes/Parser.php
includes/Title.php

index 2fb7fb8..0e8d533 100644 (file)
@@ -161,7 +161,8 @@ class OutputPage {
        function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
        function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
        function setPageTitle( $name ) {
-               global $action;
+               global $action, $wgContLang;
+               $name = $wgContLang->autoConvert($name);
                $this->mPagetitle = $name;
                if(!empty($action)) {
                        $taction =  $this->getPageTitleActionText();
@@ -356,12 +357,12 @@ class OutputPage {
                global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
                global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
                global $wgDebugRedirects, $wgMimeType, $wgProfiler;
+
                if( $this->mDoNothing ){
                        return;
                }
                $fname = 'OutputPage::output';
                wfProfileIn( $fname );
-
                $sk = $wgUser->getSkin();
 
                if ( '' != $this->mRedirect ) {
@@ -951,6 +952,7 @@ class OutputPage {
                                $text);
                        wfProfileOut( $fname.'-interwiki' );
                }
+
                wfProfileOut( $fname );
                return $colours;
        }
index 5977b7b..4b79b83 100644 (file)
@@ -16,6 +16,7 @@
  * Hence, we limit the number of inclusions of any given page, thus bringing any
  * attack back to O(N).
  */
+
 define( 'MAX_INCLUDE_REPEAT', 100 );
 define( 'MAX_INCLUDE_SIZE', 1000000 ); // 1 Million
 
@@ -136,7 +137,7 @@ class Parser
         * @return ParserOutput a ParserOutput
         */
        function parse( $text, &$title, $options, $linestart = true, $clearState = true ) {
-               global $wgUseTidy;
+               global $wgUseTidy, $wgContLang;
                $fname = 'Parser::parse';
                wfProfileIn( $fname );
 
@@ -150,6 +151,7 @@ class Parser
 
                $stripState = NULL;
                $text = $this->strip( $text, $this->mStripState );
+
                $text = $this->internalParse( $text, $linestart );
                $text = $this->unstrip( $text, $this->mStripState );
                # Clean up special characters, only run once, next-to-last before doBlockLevels
@@ -182,6 +184,9 @@ class Parser
                }
                # only once and last
                $text = $this->doBlockLevels( $text, $linestart );
+
+               $text = $wgContLang->convert($text);
+
                $text = $this->unstripNoWiki( $text, $this->mStripState );
                $this->mOutput->setText( $text );
                wfProfileOut( $fname );
@@ -658,8 +663,6 @@ class Parser
                $text = $this->removeHTMLtags( $text );
                $text = $this->replaceVariables( $text, $args );
 
-               $text = $wgContLang->convert($text);
-
                $text = preg_replace( '/(^|\n)-----*/', '\\1<hr />', $text );
 
                $text = $this->doHeadings( $text );
@@ -1061,9 +1064,13 @@ class Parser
         *
         * @access private
         */
+
        function replaceInternalLinks( $s ) {
                global $wgLang, $wgContLang, $wgLinkCache;
                static $fname = 'Parser::replaceInternalLinks' ;
+               # use a counter to prevent too much unknown links from
+               # being checked for different language variants.
+               static $convertCount;
                wfProfileIn( $fname );
 
                wfProfileIn( $fname.'-setup' );
@@ -1170,12 +1177,14 @@ class Parser
                        //if the article does not exist
                        global $wgContLang;
                        $variants = $wgContLang->getVariants();
-                       if(sizeof($variants) > 1) {
+
+                       if(sizeof($variants) > 1 && $convertCount < 200) {
                                $varnt = false; 
                                if($nt->getArticleID() == 0) {
                                        foreach ( $variants as $v ) {
                                                if($v == $wgContLang->getPreferredVariant())
                                                        continue;
+                                               $convertCount ++;
                                                $varlink = $wgContLang->autoConvert($link, $v);
                                                $varnt = Title::newFromText($varlink);
                                                if($varnt && $varnt->getArticleID()>0) {
@@ -1281,7 +1290,9 @@ class Parser
                                        continue;
                                }
                        }
-                       
+
+            $text = $wgContLang->convert($text);                       
+
                        if( ( $nt->getPrefixedText() === $this->mTitle->getPrefixedText() ) &&
                            ( strpos( $link, '#' ) === FALSE ) ) {
                                # Self-links are handled specially; generally de-link and change to bold.
index b1cad3c..9eb2552 100644 (file)
@@ -525,9 +525,7 @@ class Title {
                        $s = str_replace( '_', ' ', $s );
                        $this->mPrefixedText = $s;
                }
-               //convert to the desired language variant
-               $t = $wgContLang->convert($this->mPrefixedText);
-               return $t;
+               return $this->mPrefixedText;
        }
        
        /**
@@ -543,9 +541,7 @@ class Title {
                if( '' != $this->mFragment ) {
                        $text .= '#' . $this->mFragment;
                }
-               //convert to desired language variant
-               $t = $wgContLang->convert($text);
-               return $t;
+               return $text;
        }
 
        /**