Merge "Respect beta feature in new wikitext editor"

This commit is contained in:
jenkins-bot 2017-09-29 05:37:46 +00:00 committed by Gerrit Code Review
commit 76671dc662
2 changed files with 28 additions and 14 deletions

View file

@ -3,7 +3,7 @@
class CodeMirrorHooks {
/**
* Checks, if CodeMirror should be loaded on this page or not.
* Checks if CodeMirror is enabled for this user
*
* @param IContextSource $context The current ContextSource object
* @staticvar null|boolean $isEnabled Saves, if CodeMirror should be loaded on this page or not
@ -16,10 +16,9 @@ class CodeMirrorHooks {
// Check, if we already checked, if page action is editing, if not, do it now
if ( $isEnabled === null ) {
if ( !$wgCodeMirrorBetaFeature ) {
$isEnabled = in_array( Action::getActionName( $context ), [ 'edit', 'submit' ] );
$isEnabled = true;
} else {
$isEnabled = in_array( Action::getActionName( $context ), [ 'edit', 'submit' ] ) &&
$wgCodeMirrorBetaFeature &&
$isEnabled = $wgCodeMirrorBetaFeature &&
ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) &&
BetaFeatures::isFeatureEnabled(
$context->getUser(), 'codemirror-syntax-highlight' );
@ -29,6 +28,18 @@ class CodeMirrorHooks {
return $isEnabled;
}
/**
* Checks if CodeMirror for textarea wikitext editor should be loaded on this page or not.
*
* @param IContextSource $context The current ContextSource object
* @staticvar null|boolean $isEnabled Saves, if CodeMirror should be loaded on this page or not
* @return bool
*/
private static function isCodeMirrorOnPage( IContextSource $context ) {
return in_array( Action::getActionName( $context ), [ 'edit', 'submit' ] ) &&
self::isCodeMirrorEnabled( $context );
}
/**
* BeforePageDisplay hook handler
*
@ -38,9 +49,10 @@ class CodeMirrorHooks {
* @param Skin &$skin
*/
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
if ( self::isCodeMirrorEnabled( $out->getContext() ) ) {
if ( self::isCodeMirrorOnPage( $out->getContext() ) ) {
$out->addModules( 'ext.CodeMirror' );
}
$out->addJsConfigVars( 'wgCodeMirrorEnabled', self::isCodeMirrorEnabled( $out->getContext() ) );
}
/**

View file

@ -1,12 +1,14 @@
( function ( ve, mw ) {
mw.libs.ve.targetLoader.addPlugin( function () {
var i, target, index;
for ( i in ve.init.mw ) {
target = ve.init.mw[ i ];
if ( target === ve.init.mw.DesktopArticleTarget ) {
index = target.static.actionGroups[ 1 ].include.indexOf( 'changeDirectionality' );
target.static.actionGroups[ 1 ].include.splice( index, 0, 'codeMirror' );
if ( mw.config.get( 'wgCodeMirrorEnabled' ) ) {
mw.libs.ve.targetLoader.addPlugin( function () {
var i, target, index;
for ( i in ve.init.mw ) {
target = ve.init.mw[ i ];
if ( target === ve.init.mw.DesktopArticleTarget ) {
index = target.static.actionGroups[ 1 ].include.indexOf( 'changeDirectionality' );
target.static.actionGroups[ 1 ].include.splice( index, 0, 'codeMirror' );
}
}
}
} );
} );
}
}( ve, mediaWiki ) );