diff --git a/Gadgets.i18n.php b/Gadgets.i18n.php index 78061082..e396a26c 100644 --- a/Gadgets.i18n.php +++ b/Gadgets.i18n.php @@ -32,8 +32,6 @@ Local administrators can edit available gadgets using [[MediaWiki:Gadgets-defini 'gadgets-pagetext' => "Below is a list of special gadgets users can enable on their preferences page, as defined by [[MediaWiki:Gadgets-definition]]. This overview provides easy access to the system message pages that define each gadget's description and code.", 'gadgets-uses' => 'Uses', - 'gadgets-rights' => 'Requires the following rights', - 'gadgets-default' => 'Enabled by default', ); /** Amharic (አማርኛ) @@ -899,6 +897,7 @@ Esta visão geral proporciona um acesso fácil para as mensagens de sistema que * @author Illusion * @author Siebrand * @author Александр Сигачёв + * @author Ahonc */ $messages['ru'] = array( 'gadgets-desc' => 'Позволяет участникам выбирать в [[Special:Preferences|настройках]] CSS- и JavaScript-гаджеты, которые они хотят подключить', @@ -1164,4 +1163,3 @@ $messages['zh-hant'] = array( 'gadgets-uses' => '使用', ); - diff --git a/Gadgets.php b/Gadgets.php index 4366e704..1bedf0d1 100644 --- a/Gadgets.php +++ b/Gadgets.php @@ -38,23 +38,6 @@ $wgExtensionMessagesFiles['Gadgets'] = $dir . 'Gadgets.i18n.php'; $wgAutoloadClasses['SpecialGadgets'] = $dir . 'SpecialGadgets.php'; $wgSpecialPages['Gadgets'] = 'SpecialGadgets'; -class Gadget { - const CACHE_VERSION = 1; - /** - * This gadget option contains rights the user must have to use this gadget - */ - const RIGHTS = 666; - - /** - * This gadget should be enabled by default - */ - const ON_BY_DEFAULT = 667; - - var $name = ''; - var $modules = array(); - var $options = array(); -} - function wfGadgetsArticleSaveComplete( &$article, &$wgUser, &$text ) { //update cache if MediaWiki:Gadgets-definition was edited $title = $article->mTitle; @@ -94,10 +77,7 @@ function wfLoadGadgetsStructured( $forceNewText = NULL ) { if ( $forceNewText === NULL ) { //cached? $gadgets = $wgMemc->get( $key ); - if ( is_array( $gadgets ) && isset( $gadgets['version'] ) && $gadgets['version'] == Gadget::CACHE_VERSION ) { - unset( $gadgets['version'] ); - return $gadgets; - } + if ( is_array($gadgets) ) return $gadgets; $g = wfMsgForContentNoTrans( "gadgets-definition" ); if ( wfEmptyMsg( "gadgets-definition", $g ) ) { @@ -117,48 +97,29 @@ function wfLoadGadgetsStructured( $forceNewText = NULL ) { foreach ( $g as $line ) { if ( preg_match( '/^==+ *([^*:\s|]+?)\s*==+\s*$/', $line, $m ) ) { $section = $m[1]; - } else if ( preg_match( '/^\*+ *([a-zA-Z](?:[-_:.\w\d ]*[a-zA-Z0-9])?)\s*((\|[^|[]*)+)\s*(|\[(.*)\])\s*$/', $line, $m ) ) { - $gadget = new Gadget(); - + } + else if ( preg_match( '/^\*+ *([a-zA-Z](?:[-_:.\w\d ]*[a-zA-Z0-9])?)\s*((\|[^|]*)+)\s*$/', $line, $m ) ) { //NOTE: the gadget name is used as part of the name of a form field, // and must follow the rules defined in http://www.w3.org/TR/html4/types.html#type-cdata // Also, title-normalization applies. - $gadget->name = str_replace(' ', '_', $m[1] ); + $name = str_replace(' ', '_', $m[1] ); - $gadget->modules = preg_split( '/\s*\|\s*/', $m[2], -1, PREG_SPLIT_NO_EMPTY ); + $code = preg_split( '/\s*\|\s*/', $m[2], -1, PREG_SPLIT_NO_EMPTY ); - if( !empty( $m[5] ) && $gadget->modules ) - $gadget->options = wfProcessGadgetOptions( $m[5] ); - - if ( $gadget->modules ) { - $gadgets[$section][$gadget->name] = $gadget; + if ( $code ) { + $gadgets[$section][$name] = $code; } } } //cache for a while. gets purged automatically when MediaWiki:Gadgets-definition is edited - $gadgets['version'] = Gadget::CACHE_VERSION; - $wgMemc->set( $key, $gadgets, 60*60*24 ); + $wgMemc->set( $key, $gadgets, 60*60*24 ); $source = $forceNewText !== NULL ? 'input text' : 'MediaWiki:Gadgets-definition'; wfDebug( __METHOD__ . ": $source parsed, cache entry $key updated\n"); - unset( $gadgets['version'] ); return $gadgets; } -function wfProcessGadgetOptions( $options ) { - $out = array(); - foreach( preg_split( '/\s*\|\s*/', $options, -1, PREG_SPLIT_NO_EMPTY ) as $option ) { - if( preg_match( '/^rights\s*:\s*([\w\s,]+)$/', $option, $m ) ) { - $out[Gadget::RIGHTS] = preg_split( '/\s*,\s*/', $m[1], -1, PREG_SPLIT_NO_EMPTY ); - } elseif( preg_match( '/^default$/', $option ) ) { - $out[Gadget::ON_BY_DEFAULT] = true; - } - } - - return $out; -} - function wfGadgetsInitPreferencesForm( &$prefs, &$request ) { $gadgets = wfLoadGadgets(); if ( !$gadgets ) return true; @@ -171,18 +132,6 @@ function wfGadgetsInitPreferencesForm( &$prefs, &$request ) { return true; } -function wfGadgetAllowed( $options ) { - global $wgUser; - - if( isset( $options[Gadget::RIGHTS] ) ) - foreach( $options[Gadget::RIGHTS] as $right ) { - if( !in_array( $right, $wgUser->getRights() ) ) - return FALSE; - } - - return TRUE; -} - function wfGadgetsResetPreferences( &$prefs, &$user ) { $gadgets = wfLoadGadgets(); if ( !$gadgets ) return true; @@ -196,8 +145,6 @@ function wfGadgetsResetPreferences( &$prefs, &$user ) { } function wfGadgetsRenderPreferencesForm( &$prefs, &$out ) { - global $wgUser; - $gadgets = wfLoadGadgetsStructured(); if ( !$gadgets ) return true; @@ -210,39 +157,22 @@ function wfGadgetsRenderPreferencesForm( &$prefs, &$out ) { $msgOpt = array( 'parseinline' ); foreach ( $gadgets as $section => $entries ) { - $first = true; + if ( $section !== false && $section !== '' ) { + $ttext = wfMsgExt( "gadget-section-$section", $msgOpt ); + $out->addHtml( "\n