From f9aaf2823038c936ac86c58a293ebbbb7ccaa5ba Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Tue, 13 Sep 2016 00:10:08 -0700 Subject: [PATCH] Add a change tag for edits that change the content model of a page And adjust the 'tags-source-extension' message to indicate that tags are not just defined by extensions, but the software in general. The extension related functions will be renamed in a follow-up patchset. Bug: T145344 Change-Id: Id4391bc100287b8e469636949eaf7845bbd1d67c --- includes/changetags/ChangeTags.php | 27 +++++++++++++++++---------- includes/page/WikiPage.php | 11 ++++++++++- languages/i18n/en.json | 4 +++- languages/i18n/qqq.json | 4 +++- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index a6e4e78ddc..2b4e96e709 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -29,6 +29,11 @@ class ChangeTags { */ const MAX_DELETE_USES = 5000; + /** + * @var string[] + */ + private static $coreTags = [ 'mw-contentmodelchange' ]; + /** * Creates HTML for the given tags * @@ -1126,25 +1131,26 @@ class ChangeTags { } /** - * Lists those tags which extensions report as being "active". + * Lists those tags which core or extensions report as being "active". * * @return array * @since 1.25 */ public static function listExtensionActivatedTags() { + // core active tags + $tags = self::$coreTags; if ( !Hooks::isRegistered( 'ChangeTagsListActive' ) ) { - return []; + return $tags; } return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'active-tags' ), WANObjectCache::TTL_MINUTE * 5, - function ( $oldValue, &$ttl, array &$setOpts ) { + function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) { $setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) ); // Ask extensions which tags they consider active - $extensionActive = []; - Hooks::run( 'ChangeTagsListActive', [ &$extensionActive ] ); - return $extensionActive; + Hooks::run( 'ChangeTagsListActive', [ &$tags ] ); + return $tags; }, [ 'checkKeys' => [ wfMemcKey( 'active-tags' ) ], @@ -1201,7 +1207,7 @@ class ChangeTags { } /** - * Lists tags defined by extensions using the ListDefinedTags hook. + * Lists tags defined by core or extensions using the ListDefinedTags hook. * Extensions need only define those tags they deem to be in active use. * * Tries memcached first. @@ -1210,16 +1216,17 @@ class ChangeTags { * @since 1.25 */ public static function listExtensionDefinedTags() { + // core defined tags + $tags = self::$coreTags; if ( !Hooks::isRegistered( 'ListDefinedTags' ) ) { - return []; + return $tags; } return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'valid-tags-hook' ), WANObjectCache::TTL_MINUTE * 5, - function ( $oldValue, &$ttl, array &$setOpts ) { + function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) { $setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) ); - $tags = []; Hooks::run( 'ListDefinedTags', [ &$tags ] ); return array_filter( array_unique( $tags ) ); }, diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 86ec37e958..c57d0efe47 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -1599,10 +1599,15 @@ class WikiPage implements Page, IDBAccessObject { */ public function doEditContent( Content $content, $summary, $flags = 0, $baseRevId = false, - User $user = null, $serialFormat = null, $tags = null + User $user = null, $serialFormat = null, $tags = [] ) { global $wgUser, $wgUseAutomaticEditSummaries; + // Old default parameter for $tags was null + if ( $tags === null ) { + $tags = []; + } + // Low-level sanity check if ( $this->mTitle->getText() === '' ) { throw new MWException( 'Something is trying to edit an article with an empty title' ); @@ -1642,6 +1647,10 @@ class WikiPage implements Page, IDBAccessObject { $old_revision = $this->getRevision(); // current revision $old_content = $this->getContent( Revision::RAW ); // current revision's content + if ( $old_content && $old_content->getModel() !== $content->getModel() ) { + $tags[] = 'mw-contentmodelchange'; + } + // Provide autosummaries if one is not provided and autosummaries are enabled if ( $wgUseAutomaticEditSummaries && ( $flags & EDIT_AUTOSUMMARY ) && $summary == '' ) { $handler = $content->getContentHandler(); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 558a452b32..7998bdf9b5 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3663,6 +3663,8 @@ "tag-filter": "[[Special:Tags|Tag]] filter:", "tag-filter-submit": "Filter", "tag-list-wrapper": "([[Special:Tags|{{PLURAL:$1|Tag|Tags}}]]: $2)", + "tag-mw-contentmodelchange": "content model change", + "tag-mw-contentmodelchange-description": "Edits that [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:ChangeContentModel change the content model] of a page", "tags-title": "Tags", "tags-intro": "This page lists the tags that the software may mark an edit with, and their meaning.", "tags-tag": "Tag name", @@ -3674,7 +3676,7 @@ "tags-actions-header": "Actions", "tags-active-yes": "Yes", "tags-active-no": "No", - "tags-source-extension": "Defined by an extension", + "tags-source-extension": "Defined by the software", "tags-source-manual": "Applied manually by users and bots", "tags-source-none": "No longer in use", "tags-edit": "edit", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index bd8a90450c..7fe220b79e 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3847,6 +3847,8 @@ "tag-filter": "Caption of a filter shown on lists of changes (e.g. [[Special:Log]], [[Special:Contributions]], [[Special:Newpages]], [[Special:Recentchanges]], [[Special:Recentchangeslinked]], page histories)", "tag-filter-submit": "Caption of the submit button displayed next to the tag filter on lists of changes (e.g. [[Special:Log]], [[Special:Contributions]], [[Special:Newpages]], [[Special:Recentchanges]], [[Special:Recentchangeslinked]], page histories)\n\n{{Identical|Filter}}", "tag-list-wrapper": "Wrapper for the list of tags shown on recent changes, watchlists, history pages and diffs.\n\nParameters:\n* $1 - number of distinct tags for given edit\n* $2 - comma-separated list of tags for given edit", + "tag-mw-contentmodelchange": "Change tag for edits that change the content model of a page", + "tag-mw-contentmodelchange-description": "Description for \"content model change\" change tag", "tags-title": "The title of [[Special:Tags]].\n{{Identical|Tag}}", "tags-intro": "Explanation on top of [[Special:Tags]]. For more information on tags see [[mw:Manual:Tags|MediaWiki]].", "tags-tag": "Caption of a column in [[Special:Tags]]. For more information on tags see [[mw:Manual:Tags|MediaWiki]].", @@ -3858,7 +3860,7 @@ "tags-actions-header": "Caption of a column in [[Special:Tags]]. The column contains action links like \"delete\". For more information on tags see [[mw:Manual:Tags|MediaWiki]].\n{{Identical|Action}}", "tags-active-yes": "Table cell contents if given tag is \"active\".\n\nSee also:\n* {{msg-mw|Tags-active-no}}\n{{Identical|Yes}}", "tags-active-no": "Table cell contents if given tag is not \"active\".\n\nSee also:\n* {{msg-mw|Tags-active-yes}}\n{{Identical|No}}", - "tags-source-extension": "Table cell contents if given tag can be applied automatically by a software [[mw:Manual:Extensions|extension]].\n\nSee also:\n* {{msg-mw|Tags-source-manual}}\n* {{msg-mw|Tags-source-none}}", + "tags-source-extension": "Table cell contents if given tag can be applied automatically by the MediaWiki software.\n\nSee also:\n* {{msg-mw|Tags-source-manual}}\n* {{msg-mw|Tags-source-none}}", "tags-source-manual": "\"Applied\" is not past tense, but an adjective that describes an action that sometimes happens, as in the sentence: \"(this tag is usually) applied by users and bots\".\n\nTable cell contents if given tag can be applied by users or bots.\n\nSee also:\n* {{msg-mw|Tags-source-extension}}\n* {{msg-mw|Tags-source-none}}", "tags-source-none": "Table cell contents if given tag is no longer in use. (It was applied in the past, but it is currently not applied.)\n\nSee also:\n* {{msg-mw|Tags-source-extension}}\n* {{msg-mw|Tags-source-manual}}", "tags-edit": "Used on [[Special:Tags]]. Verb. Used as display text on a link to create/edit a description.\n{{Identical|Edit}}", -- 2.20.1