Jforrester has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392901 )
Change subject: Radically simplify this extension now there's only one config option ...................................................................... Radically simplify this extension now there's only one config option On or off. Pick your apples. Change-Id: I7677f0b597c33f236192aea1aaa347a36216fbb7 --- M README M WikiEditor.hooks.php M extension.json M i18n/en.json M i18n/qqq.json M modules/jquery.wikiEditor.js 6 files changed, 33 insertions(+), 123 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiEditor refs/changes/01/392901/1 diff --git a/README b/README index e50b695..9d4459f 100644 --- a/README +++ b/README @@ -1,20 +1,17 @@ -# WikiEditor provides enhancements to the MediaWiki edit page +WikiEditor provides enhancements to the MediaWiki edit page -# This extension requires MediaWiki 1.17+ because it makes use of ResourceLoader. +This extension requires MediaWiki 1.25+, because it makes use of ResourceLoader, static extension +loading, and other features. -# Example LocalSettings.php additions +For installation, once the code is copied into your extensions directory, you can load it for your +wiki by adding to LocalSettings.php the line: -require_once( "$IP/extensions/WikiEditor/WikiEditor.php" ); + wfLoadExtensions( "WikiEditor" ); -# Before configuring this extension, see WikiEditor.php and become familiar with the initial state and structure of the -# $wgWikiEditorFeatures configuration variable. Essentially it's an array of arrays, keyed by feature name, each -# containing global and user keys with boolean values. "global" indicates that it should be turned on for everyone -# always, while user indicates that users should be allowed to turn it on or off in their user preferences. +By default, when installed this extension will be available to all users, and logged-in users can +disable it from their preferences. If you wish all users to have it, and be unable to disable it, +add it to $wgHiddenPrefs in your LocalSettings.php: -# To enable a preference by default but still allow users to disable it in preferences, use something like... + $wgHiddenPrefs[] = 'usebetatoolbar'; -$wgDefaultUserOptions['usebetatoolbar'] = 1; - -# Release 1.21 removes the $wgWikiEditorToolbarClickTracking config variable -# and with it support for tracking clicks on WikiEditor features via the -# ClickTracking extension. +More can be found on the extension's page: https://www.mediawiki.org/wiki/Extension:WikiEditor diff --git a/WikiEditor.hooks.php b/WikiEditor.hooks.php index 1cba9db..ae4ccd0 100644 --- a/WikiEditor.hooks.php +++ b/WikiEditor.hooks.php @@ -11,70 +11,7 @@ // EventLogging. private static $statsId = false; - /* Protected Static Members */ - - protected static $features = [ - - /* Toolbar Features */ - - // 'toolbar' is the main wikieditor feature, including toolbars and dialogs. - // The legacy name preserves user preferences for disabling the feature. - 'toolbar' => [ - 'preferences' => [ - // Ideally this key would be 'wikieditor-toolbar' - 'usebetatoolbar' => [ - 'type' => 'toggle', - 'label-message' => 'wikieditor-toolbar-preference', - 'section' => 'editing/editor', - ], - ], - 'requirements' => [ - 'usebetatoolbar' => true, - ], - 'modules' => [ - 'ext.wikiEditor', - ], - 'stylemodules' => [ - 'ext.wikiEditor.styles', - ], - ], - ]; - /* Static Methods */ - - /** - * Checks if a certain option is enabled - * - * This method is public to allow other extensions that use WikiEditor to use the - * same configuration as WikiEditor itself - * - * @param string $name Name of the feature, should be a key of $features - * @return bool - */ - public static function isEnabled( $name ) { - global $wgWikiEditorFeatures, $wgUser; - - // Features with global set to true are always enabled - if ( !isset( $wgWikiEditorFeatures[$name] ) || $wgWikiEditorFeatures[$name]['global'] ) { - return true; - } - // Features with user preference control can have any number of preferences - // to be specific values to be enabled - if ( $wgWikiEditorFeatures[$name]['user'] ) { - if ( isset( self::$features[$name]['requirements'] ) ) { - foreach ( self::$features[$name]['requirements'] as $requirement => $value ) { - // Important! We really do want fuzzy evaluation here - if ( $wgUser->getOption( $requirement ) != $value ) { - return false; - } - } - } - return true; - } - // Features controlled by $wgWikiEditorFeatures with both global and user - // set to false are always disabled - return false; - } /** * Log stuff to EventLogging's Schema:Edit - see https://meta.wikimedia.org/wiki/Schema:Edit @@ -135,17 +72,10 @@ return true; } - // Add modules for enabled features - foreach ( self::$features as $name => $feature ) { - if ( !self::isEnabled( $name ) ) { - continue; - } - if ( isset( $feature['stylemodules'] ) ) { - $outputPage->addModuleStyles( $feature['stylemodules'] ); - } - if ( isset( $feature['modules'] ) ) { - $outputPage->addModules( $feature['modules'] ); - } + // Add modules if enabled + if ( $wgUser->getOption( 'usebetatoolbar' ) ) { + $outputPage->addModuleStyles( 'ext.wikiEditor.styles' ); + $outputPage->addModules( 'ext.wikiEditor' ); } $article = $editPage->getArticle(); @@ -220,7 +150,7 @@ * @return bool */ public static function EditPageBeforeEditToolbar( &$toolbar ) { - if ( self::isEnabled( 'toolbar' ) ) { + if ( $wgUser->getOption( 'usebetatoolbar' ) ) { $toolbar = Html::rawElement( 'div', [ 'class' => 'wikiEditor-oldToolbar' @@ -244,18 +174,14 @@ * @return bool */ public static function getPreferences( $user, &$defaultPreferences ) { - global $wgWikiEditorFeatures; + // Ideally this key would be 'wikieditor-toolbar' + $defaultPreferences['usebetatoolbar'] = [ + 'type' => 'toggle', + 'label-message' => 'wikieditor-toolbar-preference', + 'section' => 'editing/editor', + 'default' => true, + ]; - foreach ( self::$features as $name => $feature ) { - if ( - isset( $feature['preferences'] ) && - ( !isset( $wgWikiEditorFeatures[$name] ) || $wgWikiEditorFeatures[$name]['user'] ) - ) { - foreach ( $feature['preferences'] as $key => $options ) { - $defaultPreferences[$key] = $options; - } - } - } return true; } @@ -301,12 +227,7 @@ */ public static function makeGlobalVariablesScript( &$vars ) { // Build and export old-style wgWikiEditorEnabledModules object for back compat - $enabledModules = []; - foreach ( self::$features as $name => $feature ) { - $enabledModules[$name] = self::isEnabled( $name ); - } - - $vars['wgWikiEditorEnabledModules'] = $enabledModules; + $vars['wgWikiEditorEnabledModules'] = []; return true; } diff --git a/extension.json b/extension.json index cdb768a..e6b91e3 100644 --- a/extension.json +++ b/extension.json @@ -361,14 +361,8 @@ "localBasePath": "modules", "remoteExtPath": "WikiEditor/modules" }, - "config": { - "WikiEditorFeatures": { - "toolbar": { - "global": false, - "user": true - }, - "_merge_strategy": "array_plus_2d" - } + "DefaultUserOptions": { + "usebetatoolbar": true }, "AutoloadClasses": { "WikiEditorHooks": "WikiEditor.hooks.php" diff --git a/i18n/en.json b/i18n/en.json index 5af04fc..d5c9916 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5,7 +5,7 @@ ] }, "wikieditor": "Advanced wikitext editing interface", - "wikieditor-desc": "Provides an extendable wikitext editing interface and many feature-providing modules", + "wikieditor-desc": "Provides an advanced, extensible wikitext editing interface", "wikieditor-wikitext-tab": "Wikitext", "wikieditor-loading": "Loading...", "wikieditor-toolbar": "Editing toolbar", diff --git a/i18n/qqq.json b/i18n/qqq.json index 51f8b2c..c4365f5 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -28,8 +28,8 @@ "Quiddity" ] }, - "wikieditor": "An extension to allow for advanced editing features.\nhttps://www.mediawiki.org/wiki/Extension:WikiEditor", - "wikieditor-desc": "{{desc|name=Wiki Editor|url=https://www.mediawiki.org/wiki/Extension:WikiEditor}}\nI guess that \"feature-providing modules\" means the same as \"modules providing features\".", + "wikieditor": "An extension to provide an advanced, extensible wikitext editing interface.\nhttps://www.mediawiki.org/wiki/Extension:WikiEditor", + "wikieditor-desc": "{{desc|name=WikiEditor|url=https://www.mediawiki.org/wiki/Extension:WikiEditor}}", "wikieditor-wikitext-tab": "Caption of the tab containing the edit box", "wikieditor-loading": "Explanatory text for the temporary cover placed over the wikieditor while it's being assembled.\n{{Identical|Loading}}", "wikieditor-toolbar": "A customizable toolbar for the WikiEditor.\nFor more information, see https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization", diff --git a/modules/jquery.wikiEditor.js b/modules/jquery.wikiEditor.js index 02960fb..c1769a8 100644 --- a/modules/jquery.wikiEditor.js +++ b/modules/jquery.wikiEditor.js @@ -104,18 +104,16 @@ * is essentially to blacklist rather than whitelist are debatable, but at this point we've decided it's the more * "open-web" way to go. * - * @param {Object} module Module object, defaults to $.wikiEditor * @return {boolean} */ - isSupported: function ( module ) { + isSupported: function () { // Fallback to the wikiEditor browser map if no special map is provided in the module - var mod = module && 'browsers' in module ? module : $.wikiEditor; // Check for and make use of cached value and early opportunities to bail - if ( typeof mod.supported === 'undefined' ) { + if ( typeof $.wikiEditor.supported === 'undefined' ) { // Run a browser support test and then cache and return the result - mod.supported = $.client.test( mod.browsers ); + $.wikiEditor.supported = $.client.test( $.wikiEditor.browsers ); } - return mod.supported; + return $.wikiEditor.supported; }, /** -- To view, visit https://gerrit.wikimedia.org/r/392901 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7677f0b597c33f236192aea1aaa347a36216fbb7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikiEditor Gerrit-Branch: master Gerrit-Owner: Jforrester <jforres...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits