Ability to disable gadget caching

Change-Id: Ic1653ae896ac0fd7c0165ecee76f807feea6edcf
This commit is contained in:
Max Semenik 2014-09-05 15:47:08 -07:00
parent 37e67b7deb
commit 1e5c7917a7
2 changed files with 43 additions and 25 deletions

View file

@ -52,3 +52,8 @@ $wgSpecialPageGroups['Gadgets'] = 'wiki';
$wgAPIListModules['gadgetcategories'] = 'ApiQueryGadgetCategories';
$wgAPIListModules['gadgets'] = 'ApiQueryGadgets';
/**
* Whether the gadget list should be cached or recomputed every time
*/
$wgGadgetsCaching = true;

View file

@ -354,7 +354,7 @@ class Gadget {
* @return Mixed: Array or false
*/
public static function loadStructuredList( $forceNewText = null ) {
global $wgMemc;
global $wgMemc, $wgGadgetsCaching;
static $gadgets = null;
if ( $gadgets !== null && $forceNewText === null ) {
@ -365,11 +365,13 @@ class Gadget {
$key = wfMemcKey( 'gadgets-definition', self::GADGET_CLASS_VERSION );
if ( $forceNewText === null ) {
// cached?
$gadgets = $wgMemc->get( $key );
if ( self::isValidList( $gadgets ) ) {
wfProfileOut( __METHOD__ );
return $gadgets;
if ( $wgGadgetsCaching ) {
// cached?
$gadgets = $wgMemc->get( $key );
if ( self::isValidList( $gadgets ) ) {
wfProfileOut( __METHOD__ );
return $gadgets;
}
}
$g = wfMessage( "gadgets-definition" )->inContentLanguage();
@ -383,26 +385,9 @@ class Gadget {
$g = $forceNewText;
}
$g = preg_replace( '/<!--.*?-->/s', '', $g );
$g = preg_split( '/(\r\n|\r|\n)+/', $g );
$gadgets = self::listFromDefinition( $g );
$gadgets = array();
$section = '';
foreach ( $g as $line ) {
$m = array();
if ( preg_match( '/^==+ *([^*:\s|]+?)\s*==+\s*$/', $line, $m ) ) {
$section = $m[1];
} else {
$gadget = self::newFromDefinition( $line );
if ( $gadget ) {
$gadgets[$section][$gadget->getName()] = $gadget;
$gadget->category = $section;
}
}
}
if ( !count( $gadgets ) ) {
if ( !count( $gadgets ) || !$wgGadgetsCaching ) {
// Don't cache in case we couldn't find any gadgets. Bug 37228
$gadgets = false;
wfProfileOut( __METHOD__ );
@ -417,6 +402,34 @@ class Gadget {
return $gadgets;
}
/**
* Generates a structured list of Gadget objects from a definition
*
* @param $definition
* @return array Array( category => Array( name => Gadget ) )
*/
private static function listFromDefinition( $definition ) {
$definition = preg_replace( '/<!--.*?-->/s', '', $definition );
$lines = preg_split( '/(\r\n|\r|\n)+/', $definition );
$gadgets = array();
$section = '';
foreach ( $lines as $line ) {
$m = array();
if ( preg_match( '/^==+ *([^*:\s|]+?)\s*==+\s*$/', $line, $m ) ) {
$section = $m[1];
} else {
$gadget = self::newFromDefinition( $line );
if ( $gadget ) {
$gadgets[$section][$gadget->getName()] = $gadget;
$gadget->category = $section;
}
}
}
return $gadgets;
}
}
/**