https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113800

Revision: 113800
Author:   santhosh
Date:     2012-03-14 08:34:38 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
Impliment getModifiedTime for ResourceLoaderLanguageDataModule, using 
CACHE_ANYTHING, store md5 hash of the grammarforms
and compare the hash to see if it is modified.
(Code mostly written by Niklas)
Ping r112991

Modified Paths:
--------------
    
branches/jsgrammar/includes/resourceloader/ResourceLoaderLanguageDataModule.php

Modified: 
branches/jsgrammar/includes/resourceloader/ResourceLoaderLanguageDataModule.php
===================================================================
--- 
branches/jsgrammar/includes/resourceloader/ResourceLoaderLanguageDataModule.php 
    2012-03-14 07:18:14 UTC (rev 113799)
+++ 
branches/jsgrammar/includes/resourceloader/ResourceLoaderLanguageDataModule.php 
    2012-03-14 08:34:38 UTC (rev 113800)
@@ -53,28 +53,21 @@
         * @return array|int|Mixed
         */
        public function getModifiedTime( ResourceLoaderContext $context ) {
-               global $wgCacheEpoch;
+               $cache = wfGetCache( CACHE_ANYTHING );
+               $key = wfMemckey( 'rllangdatacache' );
 
-               /**
-                * @todo FIXME: This needs to change whenever the array created 
by
-                * $wgContLang->getGrammarForms() changes. Which gets its data 
from
-                * $wgGrammarForms, which (for standard installations) comes 
from LocalSettings
-                * and $wgCacheEpoch would cover that. However there's two 
three problems:
-                *
-                * 1) $wgCacheEpoch is not meant for this use.
-                * 2) If $wgInvalidateCacheOnLocalSettingsChange is set to 
false,
-                *    $wgCacheEpoch will not be raised if LocalSettings is 
modified (see #1).
-                * 3) $wgGrammarForms can be set from anywhere. For example on 
WMF it is set
-                *    by the WikimediaMessages extension. Other farms might set 
it form
-                *    their 'CommonSettings.php'-like file or something (see 
#1).
-                *
-                * Possible solutions:
-                * - Store grammarforms in the language object cache instead of 
directly
-                *   from the global everytime. Then use 
$wgContLang->getLastModified().
-                * - Somehow monitor the value of $wgGrammarForms.
-                */
+               $forms = $this->getSiteLangGrammarForms();
+               $hash = md5( serialize( $forms ) );
 
-               return $wgCacheEpoch;
+               $result = $cache->get( $key );
+               if ( is_array( $result ) ) {
+                       if ( $result['hash'] === $hash ) {
+                               return $result['timestamp'];
+                       }
+               }
+               $timestamp = wfTimestamp();
+               $cache->set( $key, array( 'hash' => $hash, 'timestamp' => 
$timestamp ) );
+               return $timestamp;
        }
 
        /**


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

Reply via email to