jenkins-bot has submitted this change and it was merged.

Change subject: Allow filtering content model changes
......................................................................


Allow filtering content model changes

This adds the new_content_model and old_content_model variables. The
latter will be an empty string upon page creation when there is no old
revision.

This also required adjusting the null edit detection to not treat
content model changes as null, as well as some other internal
refactoring.

Bug: T145489
Change-Id: I7c3385056751421ba22efb7d8d064981420e8819
---
M AbuseFilter.class.php
M AbuseFilter.hooks.php
M i18n/en.json
M i18n/qqq.json
4 files changed, 27 insertions(+), 8 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php
index 60e2978..e1908b9 100644
--- a/AbuseFilter.class.php
+++ b/AbuseFilter.class.php
@@ -91,6 +91,8 @@
                        'edit_diff' => 'diff',
                        'new_size' => 'newsize',
                        'old_size' => 'oldsize',
+                       'new_content_model' => 'new-content-model',
+                       'old_content_model' => 'old-content-model',
                        'removed_lines' => 'removedlines',
                        'summary' => 'summary',
                        'article_articleid' => 'article-id',
diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php
index a9921dc..c162a7d 100644
--- a/AbuseFilter.hooks.php
+++ b/AbuseFilter.hooks.php
@@ -81,7 +81,7 @@
 
                $user = $context->getUser();
 
-               $oldtext = '';
+               $oldcontent = null;
 
                if ( ( $title instanceof Title ) && $title->canExist() && 
$title->exists() ) {
                        // Make sure we load the latest text saved in database 
(bug 31656)
@@ -99,9 +99,11 @@
                        AFComputedVariable::$articleCache[$articleCacheKey] = 
$page;
 
                        // Don't trigger for null edits.
-                       if ( $content && isset( $oldcontent ) && 
$content->equals( $oldcontent ) ) {
+                       if ( $content && $oldcontent ) {
                                // Compare Content objects if available
-                               return Status::newGood();
+                               if ( $content->equals( $oldcontent ) ) {
+                                       return Status::newGood();
+                               }
                        } elseif ( strcmp( $oldtext, $text ) == 0 ) {
                                // Otherwise, compare strings
                                return Status::newGood();
@@ -112,7 +114,7 @@
 
                // Load vars for filters to check
                $vars = self::newVariableHolderForEdit(
-                       $user, $title, $page, $summary, $oldtext, $text
+                       $user, $title, $page, $summary, $content, $oldcontent, 
$text
                );
 
                $filter_result = AbuseFilter::filterAction( $vars, $title );
@@ -133,13 +135,15 @@
         * @param Title $title
         * @param WikiPage|null $page
         * @param string $summary
-        * @param string $oldtext
+        * @param Content $newcontent
+        * @param Content|null $oldcontent
         * @param string $text
         * @return AbuseFilterVariableHolder
         * @throws MWException
         */
        private static function newVariableHolderForEdit(
-               User $user, Title $title, $page, $summary, $oldtext, $text
+               User $user, Title $title, $page, $summary, Content $newcontent,
+               $oldcontent = null, $text
        ) {
                $vars = new AbuseFilterVariableHolder();
                $vars->addHolders(
@@ -148,6 +152,15 @@
                );
                $vars->setVar( 'action', 'edit' );
                $vars->setVar( 'summary', $summary );
+               if ( $oldcontent instanceof Content ) {
+                       $oldmodel = $oldcontent->getModel();
+                       $oldtext = AbuseFilter::contentToString( $oldcontent );
+               } else {
+                       $oldmodel = '';
+                       $oldtext = '';
+               }
+               $vars->setVar( 'old_content_model', $oldmodel );
+               $vars->setVar( 'new_content_model', $newcontent->getModel() );
                $vars->setVar( 'old_wikitext', $oldtext );
                $vars->setVar( 'new_wikitext', $text );
                // TODO: set old_content and new_content vars, use them
@@ -900,9 +913,9 @@
                // Cache any resulting filter matches.
                // Do this outside the synchronous stash lock to avoid any 
chance of slowdown.
                DeferredUpdates::addCallableUpdate(
-                       function () use ( $user, $page, $summary, $oldtext, 
$text ) {
+                       function () use ( $user, $page, $summary, $content, 
$oldcontent, $text ) {
                                $vars = self::newVariableHolderForEdit(
-                                       $user, $page->getTitle(), $page, 
$summary, $oldtext, $text
+                                       $user, $page->getTitle(), $page, 
$summary, $content, $oldcontent, $text
                                );
                                AbuseFilter::filterAction( $vars, 
$page->getTitle(), 'default', $user, 'stash' );
                        },
diff --git a/i18n/en.json b/i18n/en.json
index b44967b..5fc586b 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -243,6 +243,8 @@
        "abusefilter-edit-builder-vars-diff": "Unified diff of changes made by 
edit",
        "abusefilter-edit-builder-vars-newsize": "New page size",
        "abusefilter-edit-builder-vars-oldsize": "Old page size",
+       "abusefilter-edit-builder-vars-old-content-model": "Old content model",
+       "abusefilter-edit-builder-vars-new-content-model": "New content model",
        "abusefilter-edit-builder-vars-removedlines": "Lines removed in edit",
        "abusefilter-edit-builder-vars-summary": "Edit summary/reason",
        "abusefilter-edit-builder-vars-article-id": "Page ID",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 4dad310..0b60ff1 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -274,6 +274,8 @@
        "abusefilter-edit-builder-vars-diff": "Abuse filter syntax option in a 
dropdown from the group {{msg-mw|abusefilter-edit-builder-group-vars}}.",
        "abusefilter-edit-builder-vars-newsize": "New size of the page. Abuse 
filter syntax option in a dropdown from the group 
{{msg-mw|abusefilter-edit-builder-group-vars}}.",
        "abusefilter-edit-builder-vars-oldsize": "Old size of the page. Abuse 
filter syntax option in a dropdown from the group 
{{msg-mw|abusefilter-edit-builder-group-vars}}.",
+       "abusefilter-edit-builder-vars-old-content-model": "Old content model 
of the page. Abuse filter syntax option in a dropdown from the group 
{{msg-mw|abusefilter-edit-builder-group-vars}}.",
+       "abusefilter-edit-builder-vars-new-content-model": "New content model 
of the page. Abuse filter syntax option in a dropdown from the group 
{{msg-mw|abusefilter-edit-builder-group-vars}}.",
        "abusefilter-edit-builder-vars-removedlines": "Abuse filter syntax 
option in a dropdown from the group 
{{msg-mw|abusefilter-edit-builder-group-vars}}.",
        "abusefilter-edit-builder-vars-summary": "Abuse filter syntax option in 
a dropdown from the group {{msg-mw|abusefilter-edit-builder-group-vars}}.",
        "abusefilter-edit-builder-vars-article-id": "Abuse filter syntax option 
in a dropdown from the group 
{{msg-mw|Abusefilter-edit-builder-group-vars}}.\n{{Identical|Page ID}}",

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7c3385056751421ba22efb7d8d064981420e8819
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Brian Wolff <bawolff...@gmail.com>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to