Revision: 43524
Author:   werdna
Date:     2008-11-15 01:30:10 +0000 (Sat, 15 Nov 2008)

Log Message:
-----------
Configure extension:
* Add filesystem and in-process caching.
* Tweak some display, message names.
* Ensure that all data presented on Special:Configure is up-to-date by 
bypassing cache.

Modified Paths:
--------------
    trunk/extensions/Configure/Configure.css
    trunk/extensions/Configure/Configure.handler-db.php
    trunk/extensions/Configure/Configure.handler-files.php
    trunk/extensions/Configure/Configure.handler.php
    trunk/extensions/Configure/Configure.obj.php
    trunk/extensions/Configure/Configure.page.php
    trunk/extensions/Configure/Configure.php
    trunk/extensions/Configure/Configure.settings.i18n.php

Modified: trunk/extensions/Configure/Configure.css
===================================================================
--- trunk/extensions/Configure/Configure.css    2008-11-15 01:29:52 UTC (rev 
43523)
+++ trunk/extensions/Configure/Configure.css    2008-11-15 01:30:10 UTC (rev 
43524)
@@ -57,6 +57,10 @@
        width: 100%;
 }
 
+td.configure-left-column {
+       width: 20%;
+}
+
 /**
  * tables borders
  */

Modified: trunk/extensions/Configure/Configure.handler-db.php
===================================================================
--- trunk/extensions/Configure/Configure.handler-db.php 2008-11-15 01:29:52 UTC 
(rev 43523)
+++ trunk/extensions/Configure/Configure.handler-db.php 2008-11-15 01:30:10 UTC 
(rev 43524)
@@ -53,19 +53,61 @@
        protected function getCache() {
                return wfGetMainCache();
        }
+       
+       /**
+        * Checks if it's cached on the filesystem.
+        */
+       protected function getFSCached() {
+               global $wgConfigureFileSystemCache, 
$wgConfigureFileSystemCacheExpiry;
+               
+               $expiry = $wgConfigureFileSystemCacheExpiry;
+               
+               if (!($path = $wgConfigureFileSystemCache))
+                       return null;
+                       
+               if (!file_exists($path))
+                       return null;
+                       
+               $mtime = filemtime($path);
+               
+               if (time() > $mtime + $expiry) ## Regenerate every five minutes 
or so
+                       return null;
+                       
+               ## Suppress errors, if there's an error, it'll just be null and 
we'll do it again.
+               $data = @unserialize( file_get_contents( $path ) );
+               
+               return $data;
+       }
+       
+       /**
+        * Cache the data to the filesystem.
+        */
+       protected function cacheToFS( $data ) {
+               global $wgConfigureFileSystemCache;
+               
+               file_put_contents( $wgConfigureFileSystemCache, 
serialize($data) );
+       }
 
        /**
         * Load the current configuration the database (i.e. cv_is_latest == 1)
         * directory
         */
-       public function getCurrent(){
+       public function getCurrent( $useCache = true ){
+               static $ipCached = null;
+               
+               if ($ipCached && $useCache) ## In-process caching...
+                       return $ipCached;
+       
+               ## Check filesystem cache
+               if (($cached = $this->getFSCached()) && $useCache) {
+                       $this->cacheToFS($cached);
+                       return $ipCached = $cached;
+               }
+       
                $cacheKey = $this->cacheKey( 'configure', 'current' );
                $cached = $this->getCache()->get( $cacheKey );
-               if( is_array( $cached ) ){
-                       #var_dump( $cached ); die;
-                       return $cached;
-               } else {
-                       #var_dump( $this->getCache() ); die;
+               if( is_array( $cached ) && $useCache ){
+                       return $ipCached = $cached;
                }
                
                try {
@@ -83,7 +125,9 @@
                                $arr[$row->cv_wiki][$row->cs_name] = 
unserialize( $row->cs_value );
                        }
                        $this->getCache()->set( $cacheKey, $arr, 3600 );
-                       return $arr;
+                       $this->cacheToFS($arr);
+                       
+                       return $ipCached = $arr;
                } catch( MWException $e ) {
                        return array();
                }

Modified: trunk/extensions/Configure/Configure.handler-files.php
===================================================================
--- trunk/extensions/Configure/Configure.handler-files.php      2008-11-15 
01:29:52 UTC (rev 43523)
+++ trunk/extensions/Configure/Configure.handler-files.php      2008-11-15 
01:30:10 UTC (rev 43524)
@@ -30,7 +30,7 @@
         * Load the configuration from the conf-now.ser file in the $this->mDir
         * directory
         */
-       public function getCurrent(){
+       public function getCurrent( $useCache = true ){
                $file = $this->getFileName();
                if( !file_exists( $file ) )
                        # maybe the first time the user use this extensions, do 
not override

Modified: trunk/extensions/Configure/Configure.handler.php
===================================================================
--- trunk/extensions/Configure/Configure.handler.php    2008-11-15 01:29:52 UTC 
(rev 43523)
+++ trunk/extensions/Configure/Configure.handler.php    2008-11-15 01:30:10 UTC 
(rev 43524)
@@ -16,7 +16,7 @@
        /**
         * Load the current configuration
         */
-       public function getCurrent();
+       public function getCurrent( $useCache = true );
 
        /**
         * Return the old configuration from $ts timestamp

Modified: trunk/extensions/Configure/Configure.obj.php
===================================================================
--- trunk/extensions/Configure/Configure.obj.php        2008-11-15 01:29:52 UTC 
(rev 43523)
+++ trunk/extensions/Configure/Configure.obj.php        2008-11-15 01:30:10 UTC 
(rev 43524)
@@ -35,9 +35,9 @@
         * Load the configuration from the conf-now.ser file in the $this->mDir
         * directory
         */
-       public function initialise(){
+       public function initialise( $useCache = true ){
                parent::initialise();
-               $this->mConf = $this->mHandler->getCurrent();
+               $this->mConf = $this->mHandler->getCurrent( $useCache );
                $this->mOldSettings = $this->settings;
 
                # We'll need to invert the order of keys as SiteConfiguration 
uses

Modified: trunk/extensions/Configure/Configure.page.php
===================================================================
--- trunk/extensions/Configure/Configure.page.php       2008-11-15 01:29:52 UTC 
(rev 43523)
+++ trunk/extensions/Configure/Configure.page.php       2008-11-15 01:30:10 UTC 
(rev 43524)
@@ -19,6 +19,9 @@
        public function __construct( $name, $right ) {
                wfLoadExtensionMessages( 'Configure' );
                $this->mConfSettings = ConfigurationSettings::singleton( 
$this->getSettingMask() );
+               ## Reload data WITHOUT CACHE
+               global $wgConf;
+               $wgConf->initialise( false /* Skip cache */ );
                parent::__construct( $name, $right );
        }
 
@@ -994,9 +997,9 @@
                $msg = isset( $params['msg'] ) ? $params['msg'] : 
'configure-setting-' . $conf;
                $showLink = isset( $params['link'] ) ? $params['link'] : true;
 
-               $align = array();
-               $align['align'] = $wgContLang->isRtl() ? 'right' : 'left';
-               $align['valign'] = 'top';
+               $attribs = array();
+               $attribs['align'] = $wgContLang->isRtl() ? 'right' : 'left';
+               $attribs['valign'] = 'top';
                $msgVal = wfMsgExt( $msg, array( 'parseinline' ) );
                $rawVal = Xml::element( 'tt', null, "\$$conf" );
                if( wfEmptyMsg( $msg, $msgVal ) )
@@ -1009,11 +1012,13 @@
                } else {
                        $link = $msgVal;
                }
-               $td1 = Xml::openElement( 'td', $align ) . $link . '</td>';
+               $attribs['class'] = 'configure-left-column';
+               $td1 = Xml::openElement( 'td', $attribs ) . $link . '</td>';
+               $attribs['class'] = 'configure-right-column';
                if( $this->isSettingAvailable( $conf ) )
-                       $td2 = Xml::openElement( 'td', $align ) . 
$this->buildInput( $conf, $params ) . '</td>';
+                       $td2 = Xml::openElement( 'td', $attribs ) . 
$this->buildInput( $conf, $params ) . '</td>';
                else
-                       $td2 = Xml::openElement( 'td', $align ) . 
+                       $td2 = Xml::openElement( 'td', $attribs ) . 
                                wfMsgExt( 'configure-setting-not-available', 
array( 'parseinline' ) ) . '</td>';
 
                return '<tr>' . $td1 . $td2 . "</tr>\n";

Modified: trunk/extensions/Configure/Configure.php
===================================================================
--- trunk/extensions/Configure/Configure.php    2008-11-15 01:29:52 UTC (rev 
43523)
+++ trunk/extensions/Configure/Configure.php    2008-11-15 01:30:10 UTC (rev 
43524)
@@ -39,6 +39,14 @@
 $wgConfigureDatabase = 'config';
 
 /**
+ * Path for file-system cache
+ */
+$wgConfigureFileSystemCache = false;
+
+/** Expiry */
+$wgConfigureFileSystemCacheExpiry = 180;
+
+/**
  * Allow foreign wiki configuration? either:
  * - true: allow any wiki
  * - false: don't allow any wiki
@@ -97,7 +105,7 @@
 /**
  * Styles versions, you shouldn't change it
  */
-$wgConfigureStyleVersion = '6';
+$wgConfigureStyleVersion = '7';
 
 ## Adding new rights...
 $wgAvailableRights[] = 'configure';

Modified: trunk/extensions/Configure/Configure.settings.i18n.php
===================================================================
--- trunk/extensions/Configure/Configure.settings.i18n.php      2008-11-15 
01:29:52 UTC (rev 43523)
+++ trunk/extensions/Configure/Configure.settings.i18n.php      2008-11-15 
01:30:10 UTC (rev 43524)
@@ -464,7 +464,7 @@
        'configure-setting-wgUploadDirectory' => "The file system path of the 
upload directory",
        'configure-setting-wgUploadNavigationUrl' => "URL for the upload 
navigation link",
        'configure-setting-wgUploadPath' => "The URL of the upload directory",
-       'configure-setting-wgVariantArticlePath' => "Used for interwiki links",
+       'configure-setting-wgVariantArticlePath' => "Path for language-variant 
articles",
        'configure-setting-wgAllowCategorizedRecentChanges' => "Allow to filter 
the recentchanges by a category or one of its sub(subsubsub...)categories",
        'configure-setting-wgPutIPinRC' => "Log IP addresses in the 
recentchanges table",
        'configure-setting-wgRCChangedSizeThreshold' => "Highlight character 
count difference lower than this",



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to