From b4f144057ed582a49eee60a3261d87fb595b1228 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Tue, 7 Apr 2020 11:50:44 +0100 Subject: [PATCH] Tag WikiEditor edits with a hidden tag Bug: T249038 Change-Id: Ia4267bc430ba0f12cce496ebf6f8c1773ae355a6 --- extension.json | 5 ++- i18n/en.json | 4 ++- i18n/qqq.json | 4 ++- includes/Hooks.php | 66 +++++++++++++++++++++++++++++++++------ modules/ext.wikiEditor.js | 4 +-- 5 files changed, 68 insertions(+), 15 deletions(-) diff --git a/extension.json b/extension.json index f73c29b6..ebcb3c5a 100644 --- a/extension.json +++ b/extension.json @@ -26,7 +26,10 @@ "EditPage::showEditForm:fields": "WikiEditorHooks", "EditPage::attemptSave": "WikiEditorHooks", "EditPage::attemptSave:after": "WikiEditorHooks", - "EditPageGetPreviewContent": "WikiEditorHooks" + "EditPageGetPreviewContent": "WikiEditorHooks", + "ListDefinedTags": "WikiEditorHooks", + "ChangeTagsListActive": "WikiEditorHooks", + "RecentChange_save": "WikiEditorHooks" }, "HookHandlers": { "WikiEditorHooks": { diff --git a/i18n/en.json b/i18n/en.json index dc956e28..2b0c571a 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -197,5 +197,7 @@ "wikieditor-toolbar-help-content-signature-result": "Username (talk)", "wikieditor-toolbar-help-content-indent-description": "Indent", "wikieditor-toolbar-help-content-indent-syntax": "Normal text
:Indented text
::Indented text", - "wikieditor-toolbar-help-content-indent-result": "Normal text
Indented text
Indented text
" + "wikieditor-toolbar-help-content-indent-result": "Normal text
Indented text
Indented text
", + "tag-wikieditor": "-", + "tag-wikieditor-description": "Edit made using [[mw:Special:MyLanguage/Extension:WikiEditor|WikiEditor]] (2010 wikitext editor)" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 19ec6628..f7077b0e 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -227,5 +227,7 @@ "wikieditor-toolbar-help-content-signature-result": "{{RawHtml|phab=T294760}}\n\nHTML example used in the help section \"discussion\" of the toolbar.\n\nParameters:\n* $1 - The \"User\" namespace name\n* $2 - The \"User talk\" namespace name", "wikieditor-toolbar-help-content-indent-description": "{{RawHtml|phab=T294760}}\n\n{{Identical|Indent}}", "wikieditor-toolbar-help-content-indent-syntax": "{{RawHtml|phab=T294760}}\n\nSyntax example used in the help section \"discussion\" of the toolbar", - "wikieditor-toolbar-help-content-indent-result": "{{RawHtml|phab=T294760}}\n\nHTML example used in the help section \"discussion\" of the toolbar" + "wikieditor-toolbar-help-content-indent-result": "{{RawHtml|phab=T294760}}\n\nHTML example used in the help section \"discussion\" of the toolbar", + "tag-wikieditor": "{{ignored}}Short description of the wikieditor tag.\n\nShown on lists of changes (history, recentchanges, etc.) for each edit made using WikiEditor.\n\nSee also:\n* {{msg-mw|Tag-wikieditor-description}}", + "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}}" } diff --git a/includes/Hooks.php b/includes/Hooks.php index f7873132..c82aa6dd 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -17,11 +17,14 @@ use EventLogging; use ExtensionRegistry; use Html; use MediaWiki\Cache\CacheKeyHelper; +use MediaWiki\ChangeTags\Hook\ChangeTagsListActiveHook; +use MediaWiki\ChangeTags\Hook\ListDefinedTagsHook; use MediaWiki\Hook\EditPage__attemptSave_afterHook; use MediaWiki\Hook\EditPage__attemptSaveHook; use MediaWiki\Hook\EditPage__showEditForm_fieldsHook; use MediaWiki\Hook\EditPage__showEditForm_initialHook; use MediaWiki\Hook\EditPageGetPreviewContentHook; +use MediaWiki\Hook\RecentChange_saveHook; use MediaWiki\MediaWikiServices; use MediaWiki\Preferences\Hook\GetPreferencesHook; use MediaWiki\User\UserEditTracker; @@ -29,6 +32,8 @@ use MediaWiki\User\UserOptionsLookup; use MessageLocalizer; use MWCryptRand; use OutputPage; +use RecentChange; +use RequestContext; use ResourceLoaderContext; use Status; use User; @@ -44,12 +49,18 @@ class Hooks implements GetPreferencesHook, EditPage__attemptSaveHook, EditPage__attemptSave_afterHook, - EditPageGetPreviewContentHook + EditPageGetPreviewContentHook, + ListDefinedTagsHook, + ChangeTagsListActiveHook, + RecentChange_saveHook { /** @var string|bool ID used for grouping entries all of a session's entries together in EventLogging. */ private static $statsId = false; + /** @var string[] */ + private static $tags = [ 'wikieditor' ]; + /** @var Config */ private $config; @@ -276,6 +287,14 @@ class Hooks implements * @param OutputPage $outputPage object. */ public function onEditPage__showEditForm_fields( $editPage, $outputPage ) { + $outputPage->addHTML( + Html::hidden( + 'wikieditorUsed', + '', + [ 'id' => 'wikieditorUsed' ] + ) + ); + if ( $editPage->contentModel !== CONTENT_MODEL_WIKITEXT || !ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' ) ) { return; @@ -304,14 +323,6 @@ class Hooks implements ) ); } - - $outputPage->addHTML( - Html::hidden( - 'wikieditorJavascriptSupport', - '', - [ 'id' => 'wikieditorJavascriptSupport' ] - ) - ); } /** @@ -443,7 +454,7 @@ class Hooks implements if ( $status->isOK() ) { $action = 'saveSuccess'; - if ( $request->getRawVal( 'wikieditorJavascriptSupport' ) === 'yes' ) { + if ( $request->getRawVal( 'wikieditorUsed' ) === 'yes' ) { $this->doVisualEditorFeatureUseLogging( 'mwSave', 'source-has-js', $article, $statsId ); @@ -512,6 +523,41 @@ class Hooks implements $this->doVisualEditorFeatureUseLogging( 'preview', 'preview-nonlive', $article, $editingStatsId ); } } + + /** + * @param string[] &$tags + * @return bool|void + */ + public function onChangeTagsListActive( &$tags ) { + $this->registerTags( $tags ); + } + + /** + * @param string[] &$tags + * @return bool|void + */ + public function onListDefinedTags( &$tags ) { + $this->registerTags( $tags ); + } + + /** + * @param string[] &$tags + */ + protected function registerTags( &$tags ) { + $tags = array_merge( $tags, static::$tags ); + } + + /** + * @param RecentChange $recentChange + * @return bool|void + */ + public function onRecentChange_save( $recentChange ) { + $request = RequestContext::getMain()->getRequest(); + if ( $request->getRawVal( 'wikieditorUsed' ) === 'yes' ) { + $recentChange->addTags( 'wikieditor' ); + } + return true; + } } /** diff --git a/modules/ext.wikiEditor.js b/modules/ext.wikiEditor.js index e5ea2291..4adb962d 100644 --- a/modules/ext.wikiEditor.js +++ b/modules/ext.wikiEditor.js @@ -152,8 +152,8 @@ $editingSessionIdInput = $( '#editingStatsId' ), origText = $textarea.val(); - // Tracking Javascript support: T263505 - $( '#wikieditorJavascriptSupport' ).val( 'yes' ); + // T263505, T249038 + $( '#wikieditorUsed' ).val( 'yes' ); if ( $editingSessionIdInput.length ) { editingSessionId = $editingSessionIdInput.val();