Petar.petkovic has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/390224 )

Change subject: [WIP] Add new core tags
......................................................................

[WIP] Add new core tags

Add tags to types of edits that get automatic edit summaries:
- Making a page a redirect
- Blanking of the page
- Removing nearly all (more than 90%) content
- Rolling back an edit

Bug: T167656
Change-Id: Ie7f637fcec5ee659c1086e28e8ba21f470c45160
---
M includes/changetags/ChangeTags.php
M includes/content/ContentHandler.php
M includes/page/WikiPage.php
M languages/i18n/en.json
M languages/i18n/qqq.json
5 files changed, 158 insertions(+), 58 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/24/390224/1

diff --git a/includes/changetags/ChangeTags.php 
b/includes/changetags/ChangeTags.php
index fa98124..9451784 100644
--- a/includes/changetags/ChangeTags.php
+++ b/includes/changetags/ChangeTags.php
@@ -35,7 +35,13 @@
        /**
         * @var string[]
         */
-       private static $coreTags = [ 'mw-contentmodelchange' ];
+       private static $coreTags = [
+               'mw-contentmodelchange',
+               'redirect',
+               'blank',
+               'replace',
+               'rollback'
+       ];
 
        /**
         * Creates HTML for the given tags
diff --git a/includes/content/ContentHandler.php 
b/includes/content/ContentHandler.php
index 0509e29..b9c5452 100644
--- a/includes/content/ContentHandler.php
+++ b/includes/content/ContentHandler.php
@@ -755,6 +755,66 @@
        }
 
        /**
+        * Return type of change if one exists for the given edit.
+        *
+        * @param Content $oldContent The previous text of the page.
+        * @param Content $newContent The submitted text of the page.
+        * @param int $flags Bit mask: a bit mask of flags submitted for the 
edit.
+        *
+        * @return string|null String key representing type of change, or null.
+        */
+       private function getChangeType( Content $oldContent = null, Content 
$newContent = null,
+               $flags ) {
+               /**
+                * @var $ot Title
+                * @var $rt Title
+                */
+               $ot = !is_null( $oldContent ) ? 
$oldContent->getRedirectTarget() : null;
+               $rt = !is_null( $newContent ) ? 
$newContent->getRedirectTarget() : null;
+
+               // We check for the type of change in the given edit, and 
return string key accordingly
+
+               // Redirect
+               if ( is_object( $rt ) &&
+                       ( !is_object( $ot )
+                               || !$rt->equals( $ot )
+                               || $ot->getFragment() != $rt->getFragment()
+                       ) ) {
+                       return 'redirect';
+               }
+
+               // New page created
+               if ( $flags & EDIT_NEW && $newContent->getSize() > 0 ) {
+                       return 'newpage';
+               }
+
+               // Blanking of a page
+               if ( !empty( $oldContent ) && $oldContent->getSize() > 0 && 
$newContent->getSize() == 0 ) {
+                       return 'blank';
+               }
+
+               // Removing more than 90% of the article
+               if ( !empty( $oldContent )
+                       && $oldContent->getSize() > 10 * $newContent->getSize()
+                       && $newContent->getSize() < 500
+               ) {
+                       return 'replace';
+               }
+
+               // New blank article
+               if ( $flags & EDIT_NEW && $newContent->isEmpty() ) {
+                       return 'newblank';
+               }
+
+               // Content model changed
+               if ( $oldContent && $oldContent->getModel() !== 
$newContent->getModel() ) {
+                       return 'mw-contentmodelchange';
+               }
+
+               return null;
+       }
+
+       /**
         * Return an applicable auto-summary if one exists for the given edit.
         *
         * @since 1.21
@@ -767,23 +827,17 @@
         */
        public function getAutosummary( Content $oldContent = null, Content 
$newContent = null,
                $flags ) {
+               $changeType = $this->getChangeType( $oldContent, $newContent, 
$flags );
+
+               // There's no applicable auto-summary for our case, so our 
auto-summary is empty.
+               if ( !$changeType ) {
+                       return '';
+               }
+
                // Decide what kind of auto-summary is needed.
-
-               // Redirect auto-summaries
-
-               /**
-                * @var $ot Title
-                * @var $rt Title
-                */
-
-               $ot = !is_null( $oldContent ) ? 
$oldContent->getRedirectTarget() : null;
-               $rt = !is_null( $newContent ) ? 
$newContent->getRedirectTarget() : null;
-
-               if ( is_object( $rt ) ) {
-                       if ( !is_object( $ot )
-                               || !$rt->equals( $ot )
-                               || $ot->getFragment() != $rt->getFragment()
-                       ) {
+               switch ( $changeType ) {
+                       case 'redirect':
+                               $rt = !is_null( $newContent ) ? 
$newContent->getRedirectTarget() : null;
                                $truncatedtext = $newContent->getTextForSummary(
                                        250
                                        - strlen( wfMessage( 'autoredircomment' 
)->inContentLanguage()->text() )
@@ -791,45 +845,66 @@
 
                                return wfMessage( 'autoredircomment', 
$rt->getFullText() )
                                        ->rawParams( $truncatedtext 
)->inContentLanguage()->text();
-                       }
+                       case 'newpage':
+                               // If they're making a new article, give its 
text, truncated, in the summary.
+                               $truncatedtext = $newContent->getTextForSummary(
+                                       200 - strlen( wfMessage( 'autosumm-new' 
)->inContentLanguage()->text() ) );
+
+                               return wfMessage( 'autosumm-new' )->rawParams( 
$truncatedtext )
+                                       ->inContentLanguage()->text();
+                       case 'blank':
+                               return wfMessage( 'autosumm-blank' 
)->inContentLanguage()->text();
+                       case 'replace':
+                               $truncatedtext = $newContent->getTextForSummary(
+                                       200 - strlen( wfMessage( 
'autosumm-replace' )->inContentLanguage()->text() ) );
+
+                               return wfMessage( 'autosumm-replace' 
)->rawParams( $truncatedtext )
+                                       ->inContentLanguage()->text();
+                       case 'newblank':
+                               return wfMessage( 'autosumm-newblank' 
)->inContentLanguage()->text();
+                       default:
+                               return '';
+               }
+       }
+
+       /**
+        * Return an applicable tag if one exists for the given edit or return 
null.
+        *
+        * @param Content $oldContent The previous text of the page.
+        * @param Content $newContent The submitted text of the page.
+        * @param int $flags Bit mask: a bit mask of flags submitted for the 
edit.
+        *
+        * @return string|null An appropriate tag, or null.
+        */
+       public function getChangeTag( Content $oldContent = null, Content 
$newContent = null,
+               $flags ) {
+               $changeType = $this->getChangeType( $oldContent, $newContent, 
$flags );
+
+               // ChangeTags::$coreTags uses the same keys as ones returned 
from $this->getChangeType()
+               // to simplify logic around tags.
+               // Not all change types are tagged, so we check against the 
list of defined tags.
+               if ( in_array( $changeType, ChangeTags::listDefinedTags() ) ) {
+                       return $changeType;
                }
 
-               // New page auto-summaries
-               if ( $flags & EDIT_NEW && $newContent->getSize() > 0 ) {
-                       // If they're making a new article, give its text, 
truncated, in
-                       // the summary.
+               return null;
+       }
 
-                       $truncatedtext = $newContent->getTextForSummary(
-                               200 - strlen( wfMessage( 'autosumm-new' 
)->inContentLanguage()->text() ) );
-
-                       return wfMessage( 'autosumm-new' )->rawParams( 
$truncatedtext )
-                               ->inContentLanguage()->text();
-               }
-
-               // Blanking auto-summaries
-               if ( !empty( $oldContent ) && $oldContent->getSize() > 0 && 
$newContent->getSize() == 0 ) {
-                       return wfMessage( 'autosumm-blank' 
)->inContentLanguage()->text();
-               } elseif ( !empty( $oldContent )
-                       && $oldContent->getSize() > 10 * $newContent->getSize()
-                       && $newContent->getSize() < 500
-               ) {
-                       // Removing more than 90% of the article
-
-                       $truncatedtext = $newContent->getTextForSummary(
-                               200 - strlen( wfMessage( 'autosumm-replace' 
)->inContentLanguage()->text() ) );
-
-                       return wfMessage( 'autosumm-replace' )->rawParams( 
$truncatedtext )
-                               ->inContentLanguage()->text();
-               }
-
-               // New blank article auto-summary
-               if ( $flags & EDIT_NEW && $newContent->isEmpty() ) {
-                       return wfMessage( 'autosumm-newblank' 
)->inContentLanguage()->text();
-               }
-
-               // If we reach this point, there's no applicable auto-summary 
for our
-               // case, so our auto-summary is empty.
-               return '';
+       /**
+        * Return an applicable auto-summary and tag if those exist for the 
given edit.
+        *
+        * @param Content $oldContent The previous text of the page.
+        * @param Content $newContent The submitted text of the page.
+        * @param int $flags Bit mask: a bit mask of flags submitted for the 
edit.
+        *
+        * @return array Associative array mapping summary and tag.
+        */
+       public function getAutosummaryAndChangeTag( Content $oldContent = null,
+               Content $newContent = null, $flags ) {
+               return [
+                       'summary' => $this->getAutosummary( $oldContent, 
$newContent, $flags ),
+                       'tag' => $this->getChangeTag( $oldContent, $newContent, 
$flags )
+               ];
        }
 
        /**
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 95b7be2..7c2ea7f 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -1617,14 +1617,15 @@
                $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();
-                       $summary = $handler->getAutosummary( $old_content, 
$content, $flags );
+                       // extract() puts auto-summary into $summary variable, 
and tag into $tag variable
+                       extract( $handler->getAutosummaryAndChangeTag( 
$old_content, $content, $flags ) );
+                       // If there is no applicable tag, null is returned, so 
we need the check
+                       if ( $tag ) {
+                               $tags[] = $tag;
+                       }
                }
 
                // Avoid statsd noise and wasted cycles check the edit stash 
(T136678)
@@ -3079,6 +3080,8 @@
        ) {
                $resultDetails = null;
 
+               $tags[] = 'rollback';
+
                // Check permissions
                $editErrors = $this->mTitle->getUserPermissionsErrors( 'edit', 
$user );
                $rollbackErrors = $this->mTitle->getUserPermissionsErrors( 
'rollback', $user );
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index b463d95..df57d95 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -3861,6 +3861,14 @@
        "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",
+       "tag-redirect": "Redirect",
+       "tag-redirect-description": "This edit makes page a redirect",
+       "tag-blank": "Blanking",
+       "tag-blank-description": "This edit blanked the page",
+       "tag-replace": "Replaced",
+       "tag-replace-description": "This edit removed more than 90% of content",
+       "tag-rollback": "Rollback",
+       "tag-rollback-description": "This edit rolled back the changes to 
previous revision",
        "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",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index 862f64c..a82f23f 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -4055,6 +4055,14 @@
        "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",
+       "tag-redirect": "Change tag for edits that make the page a redirect 
(either redirect creation or editing an existing page)",
+       "tag-redirect-description": "Description for \"redirect\" change tag",
+       "tag-blank": "Change tag for edits that blank the page with existing 
content",
+       "tag-blank-description": "Description for \"blank\" change tag",
+       "tag-replace": "Change tag for edits removing more than 90% of the 
content",
+       "tag-replace-description": "Description for \"replace\" change tag",
+       "tag-rollback": "Change tag for rolling back an edit",
+       "tag-rollback-description": "Description for \"rollback\" 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]].",

-- 
To view, visit https://gerrit.wikimedia.org/r/390224
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7f637fcec5ee659c1086e28e8ba21f470c45160
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Petar.petkovic <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to