Realtime Preview: add as a Beta Feature

For MW installations where BetaFeatures is not available, Realtime
Preview is enabled solely with the $wgWikiEditorRealtimePreview
configuration setting.

Bug: T304596
Change-Id: I880022883bf526a2aef237f4a75e790b0f9bd4e5
This commit is contained in:
MusikAnimal 2022-04-04 18:10:11 -04:00
parent 8954cb96cd
commit b8bdd64ee5
7 changed files with 47 additions and 5 deletions

View file

@ -8,6 +8,7 @@ $cfg['directory_list'] = array_merge(
'../../extensions/EventLogging',
'../../extensions/WikimediaEvents',
'../../extensions/ConfirmEdit',
'../../extensions/BetaFeatures',
]
);
@ -17,6 +18,7 @@ $cfg['exclude_analysis_directory_list'] = array_merge(
'../../extensions/EventLogging',
'../../extensions/WikimediaEvents',
'../../extensions/ConfirmEdit',
'../../extensions/BetaFeatures',
]
);

View file

@ -29,7 +29,8 @@
"EditPageGetPreviewContent": "WikiEditorHooks",
"ListDefinedTags": "WikiEditorHooks",
"ChangeTagsListActive": "WikiEditorHooks",
"RecentChange_save": "WikiEditorHooks"
"RecentChange_save": "WikiEditorHooks",
"GetBetaFeaturePreferences": "MediaWiki\\Extension\\WikiEditor\\Hooks::onGetBetaFeaturePreferences"
},
"HookHandlers": {
"WikiEditorHooks": {

View file

@ -200,5 +200,7 @@
"tag-wikieditor-description": "Edit made using [[mw:Special:MyLanguage/Extension:WikiEditor|WikiEditor]] (2010 wikitext editor)",
"wikieditor-realtimepreview-preview": "Preview",
"wikieditor-realtimepreview-error": "Preview not loading",
"wikieditor-realtimepreview-reload": "Reload"
"wikieditor-realtimepreview-reload": "Reload",
"wikieditor-realtimepreview-beta-label": "Realtime Preview",
"wikieditor-realtimepreview-beta-desc": "See how wikitext changes will appear to readers inside the [[mw:Special:MyLanguage/Extension:WikiEditor|2010 editor]]."
}

View file

@ -231,5 +231,7 @@
"tag-wikieditor-description": "Long description of the wikieditor tag ({{msg-mw|Tag-wikieditor}}).\n\nShown on [[Special:Tags]].\n\nSee also:\n* {{msg-mw|Tag-wikieditor}}",
"wikieditor-realtimepreview-preview": "Label for the toolbar button to enable/disable realtime preview.",
"wikieditor-realtimepreview-error": "Header text for realtime preview errors.",
"wikieditor-realtimepreview-reload": "Button text for the 'reload' button on realtime preview errors."
"wikieditor-realtimepreview-reload": "Button text for the 'reload' button on realtime preview errors.",
"wikieditor-realtimepreview-beta-label": "Used in [[Special:Preferences]].\n\nUsed as label for checkbox to enable Realtime Preview as a Beta Feature.\n\nThe description for this checkbox is: {{msg-mw|wikieditor-realtimepreview-beta-desc}}.",
"wikieditor-realtimepreview-beta-desc": "Used in [[Special:Preferences]].\n\nUsed as description for the checkbox to enable Realtime Preview as a Beta Feature.\n\nThe label for this checkbox is {{msg-mw|wikieditor-realtimepreview-beta-label}}."
}

View file

@ -18,6 +18,7 @@ use Html;
use MediaWiki\Cache\CacheKeyHelper;
use MediaWiki\ChangeTags\Hook\ChangeTagsListActiveHook;
use MediaWiki\ChangeTags\Hook\ListDefinedTagsHook;
use MediaWiki\Extension\BetaFeatures\BetaFeatures;
use MediaWiki\Extension\EventLogging\EventLogging;
use MediaWiki\Hook\EditPage__attemptSave_afterHook;
use MediaWiki\Hook\EditPage__attemptSaveHook;
@ -222,8 +223,14 @@ class Hooks implements
if ( $this->userOptionsLookup->getBoolOption( $user, 'usebetatoolbar' ) ) {
$outputPage->addModuleStyles( 'ext.wikiEditor.styles' );
$outputPage->addModules( 'ext.wikiEditor' );
// Optionally enable Realtime Preview.
if ( $this->config->get( 'WikiEditorRealtimePreview' ) ) {
// Optionally enable Realtime Preview, and behind a BetaFeature where applicable.
$betaFeaturesInstalled = ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' );
$user = $article->getContext()->getUser();
$betaFeatureEnabled = $betaFeaturesInstalled &&
BetaFeatures::isFeatureEnabled( $user, 'wikieditor-realtime-preview' );
if ( $this->config->get( 'WikiEditorRealtimePreview' ) &&
( $betaFeatureEnabled || !$betaFeaturesInstalled )
) {
$outputPage->addModules( 'ext.wikiEditor.realtimepreview' );
}
}
@ -568,4 +575,30 @@ class Hooks implements
}
return true;
}
/**
* @param User $user
* @param array &$prefs
* @return void
*/
public static function onGetBetaFeaturePreferences( $user, &$prefs ) {
$config = MediaWikiServices::getInstance()->getMainConfig();
if ( !$config->get( 'WikiEditorRealtimePreview' ) ) {
return;
}
$extensionAssetsPath = $config->get( 'ExtensionAssetsPath' );
$prefs['wikieditor-realtime-preview'] = [
'label-message' => 'wikieditor-realtimepreview-beta-label',
'desc-message' => 'wikieditor-realtimepreview-beta-desc',
'screenshot' => [
'ltr' => "$extensionAssetsPath/WikiEditor/modules/images/beta-feature-ltr.svg",
'rtl' => "$extensionAssetsPath/WikiEditor/modules/images/beta-feature-rtl.svg",
],
// @todo Update links once mw:Help:Extension:WikiEditor/Realtime_Preview is written.
'info-link' => 'https://meta.wikimedia.org/wiki/Special:MyLanguage/' .
'Community_Wishlist_Survey_2021/Real_Time_Preview_for_Wikitext',
'discussion-link' => 'https://meta.wikimedia.org/wiki/' .
'Talk:Community_Wishlist_Survey_2021/Real_Time_Preview_for_Wikitext',
];
}
}

View file

@ -0,0 +1 @@
<svg width="264" height="162" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#a)"><path fill="#fff" d="M0 0h264v162H0z"/><path d="m263.5 162.25-263-.5V.5h263v161.75Z" fill="#fff"/><path d="M11 22c0-8 6-14 14-14s14 6 14 14-6 14-14 14-14-6-14-14Zm27 23v-5H13v5h25Zm0 118V58H13v106h25M233 5h26v6h-26V5Zm-24 0h22v6h-22V5Zm-24 0h22v6h-22V5Zm-23 0h13v6h-13V5Zm15 0h6v6h-6V5Zm-23 0h6v6h-6V5Zm104 11v4h-92v-4h92Zm1-1h-94v6h94v-6Z" fill="#EAECF0"/><path d="M168 17h2v2h-2v-2Zm84 145.496V29H48v133l204 .496Z" fill="#EAECF0"/><path d="M48 29h204v11H48V29Z" fill="#C8CCD1"/><path d="M51 32h24.793v5H51v-5Zm33.223 0h9.918v5h-9.918v-5Zm16.86 0H111v5h-9.917v-5Z" fill="#fff"/><path d="m71.738 78.134-1.128 1.968-4.058-2.376a11.29 11.29 0 0 1-.792-.528 3.112 3.112 0 0 1-.623-.672c.24.56.36 1.16.36 1.8v4.656h-2.28V78.35c0-.32.016-.616.048-.888a3.2 3.2 0 0 1 .264-.84 3.545 3.545 0 0 1-.6.6 6.68 6.68 0 0 1-.746.504l-4.032 2.352-1.128-1.968 4.032-2.352c.269-.151.55-.28.84-.384.272-.112.56-.184.864-.216a4.147 4.147 0 0 1-1.703-.624L57 72.158l1.13-1.968 4.056 2.376c.288.176.544.36.768.552.24.192.448.416.624.672a3.91 3.91 0 0 1-.288-.864 5.986 5.986 0 0 1-.073-.936v-4.68h2.28v4.632c0 .32-.024.632-.072.936a3.092 3.092 0 0 1-.216.84c.17-.234.373-.444.6-.624.222-.176.47-.352.742-.528l4.032-2.328 1.128 1.968-4.032 2.328c-.27.16-.543.296-.815.408a2.79 2.79 0 0 1-.816.216c.542.064 1.086.264 1.63.6l4.056 2.376M82 90h4.286v2.143h-2.143v10.714h2.143V105H82V90Zm5.358 0h4.286v2.143H89.5v10.714h2.144V105h-4.286V90Zm43.001 0h4.286l.001 15h-4.286v-2.143h2.143V92.143h-2.144V90Zm-5.358 0h4.287l-.002 15H125v-2.143h2.144V92.143h-2.143V90Zm-58.658 23.777h-3.06l-.787 3.212h3.045l.8-3.212h.002Zm5.047-1.482-.194.855a.68.68 0 0 1-.323.473c-.172.103-.437.154-.8.154h-1.652l-.8 3.212h2.195c.267 0 .456.066.568.196.12.124.15.336.09.638l-.116.649h-3.005l-1.058 4.313h-1.136c-.122 0-.237-.02-.35-.061a.798.798 0 0 1-.258-.186.845.845 0 0 1-.154-.278.659.659 0 0 1 .013-.34l.865-3.448h-3.048l-.865 3.552c-.069.274-.21.47-.426.586-.226.119-.48.18-.735.175h-1.11l1.058-4.313h-1.783c-.258 0-.448-.062-.568-.185-.121-.124-.151-.34-.09-.649l.117-.649h2.595l.789-3.212h-2.932l.181-.844c.043-.22.15-.38.323-.484.172-.102.439-.154.8-.154h1.899l.89-3.583c.05-.22.18-.39.388-.514.205-.13.46-.199.722-.196h1.136l-1.058 4.293h3.06l1.047-4.293h1.123c.275 0 .49.069.645.206.155.137.206.316.155.535l-.89 3.552h2.697M57.343 58h54v6h-54v-6Zm20 57.001H142v3H77.343v-3Zm-20 20H142v3H57.343v-3Zm0-10H120.5v3H57.343v-3Zm20-50H142v3H77.343v-3Zm-20 10H117v3H57.343v-3ZM124 96H93.5v3H124v-3Zm-48 0H57.343v3H76v-3Z" fill="#A2A9B1"/><path fill="#54595D" d="M146 40h4v122h-4z"/><path d="M245 56.001h-39v30h39v-30Zm-26.348 13.043h1.402l8.701 8.604 4.725-2.834 7.117 5.943v.025h-31.148l9.203-11.738ZM240 105h-82v3h82v-3Zm-1 10h-81v3h81v-3Zm-4 10h-77v3h77v-3Zm8 10h-85v3h85v-3Zm-55-59.999h-30v3h30v-3Zm9 10h-39v3h39v-3Zm37 10h-76v3h76v-3ZM196.748 58H158v5.999h38.748V58Z" fill="#36C"/><path d="M0-.5h-.5v163h265V-.5H0Zm240.32 150.815-.32-.267-.32.267-11.68 9.733-11.68-9.733-.32-.267-.32.267-11.68 9.733-11.68-9.733-.32-.267-.32.267-11.68 9.733-11.68-9.733-.32-.267-.32.267-11.68 9.733-11.68-9.733-.32-.267-.32.267-11.68 9.733-11.68-9.733-.32-.267-.32.267-11.68 9.733-11.68-9.733-.32-.267-.32.267L84 160.048l-11.68-9.733-.32-.267-.32.267L60 160.048l-11.68-9.733-.32-.267-.32.267L36 160.048l-11.68-9.733-.32-.267-.32.267L12 160.048l-10.5-8.751V1.5h261v149.799l-10.5 8.749-11.68-9.733Z" fill="#fff" stroke="#E6E6E6"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h264v162H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -0,0 +1 @@
<svg width="264" height="162" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#a)"><path fill="#fff" d="M264 0H0v162h264z"/><path d="m.5 162.25 263-.5V.5H.5v161.75Z" fill="#fff"/><path d="M253 22c0-8-6-14-14-14s-14 6-14 14 6 14 14 14 14-6 14-14Zm-27 23v-5h25v5h-25ZM226 163V58h25v106h-25M31 5H5v6h26V5Zm24 0H33v6h22V5Zm24 0H57v6h22V5Zm23 0H89v6h13V5ZM87 5h-6v6h6V5Zm23 0h-6v6h6V5ZM6 16v4h92v-4H6Zm-1-1h94v6H5v-6Z" fill="#EAECF0"/><path d="M96 17h-2v2h2v-2ZM12 162.496V29h204v133l-204 .496Z" fill="#EAECF0"/><path d="M216 29H12v11h204V29Z" fill="#C8CCD1"/><path d="M213 32h-24.793v5H213v-5Zm-33.223 0h-9.917v5h9.917v-5Zm-16.86 0H153v5h9.917v-5ZM24 32h-8.5v5H24v-5Z" fill="#fff"/><path d="M46.5 32h-19v5h19v-5Z" fill="#36C"/><path d="m192.262 78.134 1.128 1.968 4.058-2.376c.271-.165.536-.341.792-.528.24-.192.45-.419.623-.672a4.52 4.52 0 0 0-.36 1.8v4.656h2.28V78.35c0-.32-.016-.616-.048-.888a3.216 3.216 0 0 0-.264-.84c.175.223.377.425.6.6.237.184.486.353.746.504l4.032 2.352 1.128-1.968-4.032-2.352a5.543 5.543 0 0 0-.84-.384 3.113 3.113 0 0 0-.864-.216 4.148 4.148 0 0 0 1.703-.624L207 72.158l-1.13-1.968-4.056 2.376c-.288.176-.544.36-.768.552-.24.192-.448.416-.624.672.129-.276.226-.566.288-.864.049-.31.073-.623.073-.936v-4.68h-2.28v4.632c0 .32.024.632.072.936.032.289.105.572.216.84a3.18 3.18 0 0 0-.6-.624 9.531 9.531 0 0 0-.742-.528l-4.032-2.328-1.128 1.968 4.032 2.328c.27.16.543.296.815.408.259.113.535.186.816.216-.542.064-1.086.264-1.63.6l-4.056 2.376M182 90h-4.286v2.143h2.143v10.714h-2.143V105H182V90Zm-5.358 0h-4.286v2.143h2.144v10.714h-2.144V105h4.286V90ZM133.641 90h-4.286l-.001 15h4.286v-2.143h-2.143V92.143h2.144V90ZM138.999 90h-4.287l.002 15H139v-2.143h-2.144V92.143h2.143V90ZM197.657 113.777h3.06l.787 3.212h-3.045l-.8-3.212h-.002Zm-5.047-1.482.194.855a.672.672 0 0 0 .323.473c.172.103.437.154.8.154h1.652l.8 3.212h-2.195c-.267 0-.456.066-.568.196-.12.124-.15.336-.09.638l.116.649h3.005l1.058 4.313h1.136c.122 0 .237-.02.35-.061a.806.806 0 0 0 .258-.186.848.848 0 0 0 .154-.278.654.654 0 0 0-.013-.34l-.865-3.448h3.048l.865 3.552c.069.274.21.47.426.586.226.119.479.18.735.175h1.11l-1.058-4.313h1.783c.258 0 .448-.062.568-.185.121-.124.151-.34.09-.649l-.117-.649h-2.595l-.789-3.212h2.932l-.181-.844a.686.686 0 0 0-.323-.484c-.172-.102-.439-.154-.8-.154h-1.899l-.89-3.583a.786.786 0 0 0-.388-.514 1.328 1.328 0 0 0-.722-.196h-1.136l1.058 4.293h-3.06l-1.047-4.293h-1.123c-.275 0-.49.069-.645.206-.155.137-.206.316-.155.535l.89 3.552h-2.697M206.657 58h-54v6h54v-6Zm-20 57.001H122v3h64.657v-3Zm20 20H122v3h84.657v-3Zm0-10H143.5v3h63.157v-3Zm-20-50H122v3h64.657v-3Zm20 10H147v3h59.657v-3ZM140 96h30.5v3H140v-3ZM188 96h18.657v3H188v-3Z" fill="#A2A9B1"/><path fill="#54595D" d="M118 40h-4v122h4z"/><path d="M19 56.001h39v30H19v-30Zm26.348 13.043h-1.402l-8.701 8.604-4.725-2.834-7.117 5.943v.025h31.148l-9.203-11.738ZM24 105h82v3H24v-3ZM25 115h81v3H25v-3ZM29 125h77v3H29v-3ZM21 135h85v3H21v-3ZM76 75.001h30v3H76v-3ZM67 85.001h39v3H67v-3ZM30 95.001h76v3H30v-3ZM67.252 58H106v5.999H67.252V58Z" fill="#36C"/><path d="M264-.5h.5v163H-.5V-.5H264ZM23.68 150.315l.32-.267.32.267L36 160.048l11.68-9.733.32-.267.32.267L60 160.048l11.68-9.733.32-.267.32.267L84 160.048l11.68-9.733.32-.267.32.267 11.68 9.733 11.68-9.733.32-.267.32.267 11.68 9.733 11.68-9.733.32-.267.32.267 11.68 9.733 11.68-9.733.32-.267.32.267 11.68 9.733 11.68-9.733.32-.267.32.267 11.68 9.733 11.68-9.733.32-.267.32.267 11.68 9.733 11.68-9.733.32-.267.32.267 11.68 9.733 10.5-8.751V1.5H1.5v149.799l10.5 8.749 11.68-9.733Z" fill="#fff" stroke="#E6E6E6"/></g><defs><clipPath id="a"><path fill="#fff" transform="matrix(-1 0 0 1 264 0)" d="M0 0h264v162H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 3.6 KiB