summaryrefslogtreecommitdiff
path: root/extensions/Gadgets/Gadgets_body.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /extensions/Gadgets/Gadgets_body.php
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'extensions/Gadgets/Gadgets_body.php')
-rw-r--r--extensions/Gadgets/Gadgets_body.php85
1 files changed, 45 insertions, 40 deletions
diff --git a/extensions/Gadgets/Gadgets_body.php b/extensions/Gadgets/Gadgets_body.php
index 1e043a82..24196dd3 100644
--- a/extensions/Gadgets/Gadgets_body.php
+++ b/extensions/Gadgets/Gadgets_body.php
@@ -21,8 +21,7 @@ class Gadget {
*/
const GADGET_CLASS_VERSION = 7;
- private $version = self::GADGET_CLASS_VERSION,
- $scripts = array(),
+ private $scripts = array(),
$styles = array(),
$dependencies = array(),
$name,
@@ -50,6 +49,11 @@ class Gadget {
// Also, title-normalization applies.
$gadget = new Gadget();
$gadget->name = trim( str_replace( ' ', '_', $m[1] ) );
+ // If the name is too long, then RL will throw an MWException when
+ // we try to register the module
+ if ( !ResourceLoader::isValidModuleName( $gadget->getModuleName() ) ) {
+ return false;
+ }
$gadget->definition = $definition;
$options = trim( $m[2], ' []' );
@@ -137,14 +141,6 @@ class Gadget {
}
/**
- * Checks whether this is an instance of an older version of this class deserialized from cache
- * @return Boolean
- */
- public function isOutdated() {
- return $this->version != self::GADGET_CLASS_VERSION;
- }
-
- /**
* Checks whether this gadget is enabled for given user
*
* @param $user User: user to check against
@@ -322,18 +318,14 @@ class Gadget {
if ( !is_array( $gadgets ) ) {
return false;
}
- // Check if we have 1) array of gadgets 2) the gadgets are up to date
+ // Check if we have an array of gadgets
// One check is enough
/**
* @var $g Gadget
*/
foreach ( $gadgets as $list ) {
foreach ( $list as $g ) {
- if ( !( $g instanceof Gadget ) || $g->isOutdated() ) {
- return false;
- } else {
- return true;
- }
+ return $g instanceof Gadget;
}
}
@@ -342,14 +334,14 @@ class Gadget {
/**
* Loads list of gadgets and returns it as associative array of sections with gadgets
- * e.g. array( 'sectionnname1' => array( $gadget1, $gadget2),
+ * e.g. array( 'sectionnname1' => array( $gadget1, $gadget2 ),
* 'sectionnname2' => array( $gadget3 ) );
* @param $forceNewText String: New text of MediaWiki:gadgets-definition. If specified, will
* force a purge of cache and recreation of the gadget list.
* @return Mixed: Array or false
*/
public static function loadStructuredList( $forceNewText = null ) {
- global $wgMemc;
+ global $wgMemc, $wgGadgetsCaching;
static $gadgets = null;
if ( $gadgets !== null && $forceNewText === null ) {
@@ -360,11 +352,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();
@@ -378,13 +372,38 @@ class Gadget {
$g = $forceNewText;
}
- $g = preg_replace( '/<!--.*?-->/s', '', $g );
- $g = preg_split( '/(\r\n|\r|\n)+/', $g );
+ $gadgets = self::listFromDefinition( $g );
+
+ if ( !count( $gadgets ) || !$wgGadgetsCaching ) {
+ // Don't cache in case we couldn't find any gadgets. Bug 37228
+ $gadgets = false;
+ wfProfileOut( __METHOD__ );
+ return $gadgets;
+ }
+
+ // cache for a while. gets purged automatically when MediaWiki:Gadgets-definition is edited
+ $wgMemc->set( $key, $gadgets, 60 * 60 * 24 );
+ $source = $forceNewText !== null ? 'input text' : 'MediaWiki:Gadgets-definition';
+ wfDebug( __METHOD__ . ": $source parsed, cache entry $key updated\n" );
+ wfProfileOut( __METHOD__ );
+
+ 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 ( $g as $line ) {
+ foreach ( $lines as $line ) {
$m = array();
if ( preg_match( '/^==+ *([^*:\s|]+?)\s*==+\s*$/', $line, $m ) ) {
$section = $m[1];
@@ -396,20 +415,6 @@ class Gadget {
}
}
}
-
- if ( !count( $gadgets ) ) {
- // Don't cache in case we couldn't find any gadgets. Bug 37228
- $gadgets = false;
- wfProfileOut( __METHOD__ );
- return $gadgets;
- }
-
- // cache for a while. gets purged automatically when MediaWiki:Gadgets-definition is edited
- $wgMemc->set( $key, $gadgets, 60 * 60 * 24 );
- $source = $forceNewText !== null ? 'input text' : 'MediaWiki:Gadgets-definition';
- wfDebug( __METHOD__ . ": $source parsed, cache entry $key updated\n" );
- wfProfileOut( __METHOD__ );
-
return $gadgets;
}
}