Setup.php-DateFormatter was using a lot of CPU time on the live site. Moved it to...
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 20 Apr 2005 15:42:08 +0000 (15:42 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 20 Apr 2005 15:42:08 +0000 (15:42 +0000)
includes/DateFormatter.php
includes/Parser.php
includes/Setup.php

index 4682f39..f135d32 100755 (executable)
@@ -111,6 +111,22 @@ class DateFormatter
                $this->rules[DF_NONE][DF_ISO2]  = DF_ISO1;
        }
        
+       /**
+        * @static
+        */
+       function &getInstance() {
+               global $wgDBname, $wgMemc;
+               static $dateFormatter = false;
+               if ( !$dateFormatter ) {
+                       $dateFormatter = $wgMemc->get( "$wgDBname:dateformatter" );
+                       if ( !$dateFormatter ) {
+                               $dateFormatter = new DateFormatter;
+                               $wgMemc->set( "$wgDBname:dateformatter", $dateFormatter, 3600 );
+                       }
+               }
+               return $dateFormatter;
+       }       
+       
        /**
         * @param $preference
         * @param $text
@@ -279,7 +295,8 @@ class DateFormatter
  * @todo document
  */
 function wfMainDateReplace( $matches ) {
-       global $wgDateFormatter;
-       return $wgDateFormatter->replace( $matches );
+       $df =& DateFormatter::getInstance();
+       return $df->replace( $matches );
 }
+
 ?>
index 456e3af..9ad6ed8 100644 (file)
@@ -76,7 +76,7 @@ define( 'EXT_IMAGE_REGEX',
  *   performs brace substitution on MediaWiki messages
  *
  * Globals used:
- *    objects:   $wgLang, $wgDateFormatter, $wgLinkCache
+ *    objects:   $wgLang, $wgLinkCache
  *
  * NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
  *
@@ -651,8 +651,8 @@ class Parser
 
                $text = $this->doHeadings( $text );
                if($this->mOptions->getUseDynamicDates()) {
-                       global $wgDateFormatter;
-                       $text = $wgDateFormatter->reformat( $this->mOptions->getDateFormat(), $text );
+                       $df =& DateFormatter::getInstance();
+                       $text = $df->reformat( $this->mOptions->getDateFormat(), $text );
                }
                $text = $this->doAllQuotes( $text );
                $text = $this->replaceInternalLinks( $text );
@@ -2997,7 +2997,7 @@ class ParserOptions
 {
        # All variables are private
        var $mUseTeX;                    # Use texvc to expand <math> tags
-       var $mUseDynamicDates;           # Use $wgDateFormatter to format dates
+       var $mUseDynamicDates;           # Use DateFormatter to format dates
        var $mInterwikiMagic;            # Interlanguage links are removed and returned in an array
        var $mAllowExternalImages;       # Allow external images inline
        var $mSkin;                      # Reference to the preferred skin
index 057181f..738abb4 100644 (file)
@@ -72,6 +72,10 @@ require_once( 'HistoryBlob.php' );
 require_once( 'ProxyTools.php' );
 require_once( 'ObjectCache.php' );
 
+if ( $wgUseDynamicDates ) {
+       require_once( 'DateFormatter.php' );
+}
+
 wfProfileOut( $fname.'-includes' );
 wfProfileIn( $fname.'-misc1' );
 
@@ -260,14 +264,6 @@ wfProfileIn( $fname.'-OutputPage' );
 $wgOut = new OutputPage();
 
 wfProfileOut( $fname.'-OutputPage' );
-wfProfileIn( $fname.'-DateFormatter' );
-
-if ( $wgUseDynamicDates ) {
-       require_once( 'DateFormatter.php' );
-       $wgDateFormatter = new DateFormatter;
-}
-
-wfProfileOut( $fname.'-DateFormatter' );
 wfProfileIn( $fname.'-BlockCache' );
 
 $wgBlockCache = new BlockCache( true );