Cenarium has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/206476

Change subject: Implement ChangeTagsRegister
......................................................................

Implement ChangeTagsRegister

This implements the ChangeTagsRegister hook introduced by
Change-Id: I4f4b097d660ada77f5cf7b4231925009b27127ea. Special:Tags
now indicates when a filter is defined by AbuseFilter, and which
filter uses it. The default messages are kept pretty basic.
The cache of registered tags is purged whenever filters are edited.
Newly defined non-existing tags are checked with the canCreate
function of the ChangeTag class.

Change-Id: Ibfadd04acfebbedaad1b67c5818dfa5c1b7037b3
---
M AbuseFilter.hooks.php
M AbuseFilter.php
M Views/AbuseFilterViewEdit.php
M i18n/en.json
M i18n/qqq.json
5 files changed, 38 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter 
refs/changes/76/206476/1

diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php
index 892d901..fc935fb 100644
--- a/AbuseFilter.hooks.php
+++ b/AbuseFilter.hooks.php
@@ -443,32 +443,41 @@
 
        /**
         * @param array $tags
-        * @param bool $enabled
         * @return bool
         */
-       private static function fetchAllTags( array &$tags, $enabled ) {
+       private static function fetchAllTags( array &$tags ) {
                # This is a pretty awful hack.
                $dbr = wfGetDB( DB_SLAVE );
 
-               $where = array( 'afa_consequence' => 'tag', 'af_deleted' => 
false );
-               if ( $enabled ) {
-                       $where['af_enabled'] = true;
-               }
+               $where = array( 'afa_consequence' => 'tag', 'af_deleted' => 0 );
+
                $res = $dbr->select(
                        array( 'abuse_filter_action', 'abuse_filter' ),
-                       'afa_parameters',
+                       array( 'afa_parameters', 'af_enabled', 'af_id' ),
                        $where,
                        __METHOD__,
                        array(),
                        array( 'abuse_filter' => array( 'INNER JOIN', 
'afa_filter=af_id' ) )
                );
 
+               $fetchedTags = array();
                foreach ( $res as $row ) {
-                       $tags = array_filter(
-                               array_merge( explode( "\n", 
$row->afa_parameters ), $tags )
-                       );
+                       $afTags = explode( "\n", $row->afa_parameters );
+                       foreach ( $afTags as $tag ) {
+                               if ( !isset( $fetchedTags[$tag] ) ) {
+                                       $fetchedTags[$tag] = array(
+                                               'extName' => 'AbuseFilter',
+                                               'descParams' => array()
+                                       );
+                               }
+                               $fetchedTags[$tag]['descParams'][] = 
$row->af_id;
+                               if ( $row->af_enabled ) {
+                                       $fetchedTags[$tag]['active'] = true;
+                               }
+                       }
                }
 
+               $tags = array_filter( array_merge( $fetchedTags, $tags ) );
                return true;
        }
 
@@ -476,16 +485,8 @@
         * @param array $tags
         * @return bool
         */
-       public static function onListDefinedTags( array &$tags ) {
-               return self::fetchAllTags( $tags, false );
-       }
-
-       /**
-        * @param array $tags
-        * @return bool
-        */
-       public static function onChangeTagsListActive( array &$tags ) {
-               return self::fetchAllTags( $tags, true );
+       public static function onChangeTagsRegister( array &$tags ) {
+               return self::fetchAllTags( $tags );
        }
 
        /**
diff --git a/AbuseFilter.php b/AbuseFilter.php
index fb3542a..60e5e07 100644
--- a/AbuseFilter.php
+++ b/AbuseFilter.php
@@ -95,8 +95,7 @@
 $wgHooks['AbortAutoAccount'][] = 'AbuseFilterHooks::onAbortAutoAccount';
 $wgHooks['ArticleDelete'][] = 'AbuseFilterHooks::onArticleDelete';
 $wgHooks['RecentChange_save'][] = 'AbuseFilterHooks::onRecentChangeSave';
-$wgHooks['ListDefinedTags'][] = 'AbuseFilterHooks::onListDefinedTags';
-$wgHooks['ChangeTagsListActive'][] = 
'AbuseFilterHooks::onChangeTagsListActive';
+$wgHooks['ChangeTagsRegister'][] = 'AbuseFilterHooks::onChangeTagsRegister';
 $wgHooks['LoadExtensionSchemaUpdates'][] = 
'AbuseFilterHooks::onLoadExtensionSchemaUpdates';
 $wgHooks['ContributionsToolLinks'][] = 
'AbuseFilterHooks::onContributionsToolLinks';
 $wgHooks['UploadVerifyFile'][] = 'AbuseFilterHooks::onUploadVerifyFile';
diff --git a/Views/AbuseFilterViewEdit.php b/Views/AbuseFilterViewEdit.php
index 7f7c634..3c5ecc9 100644
--- a/Views/AbuseFilterViewEdit.php
+++ b/Views/AbuseFilterViewEdit.php
@@ -108,13 +108,13 @@
                        // If we've activated the 'tag' option, check the 
arguments for validity.
                        if ( !empty( $actions['tag'] ) ) {
                                $bad = false;
-                               foreach ( $actions['tag']['parameters'] as $tag 
) {
-                                       $t = Title::makeTitleSafe( 
NS_MEDIAWIKI, 'tag-' . $tag );
-                                       if ( !$t ) {
-                                               $bad = true;
-                                       }
+                               $context = new ChangeTagsContext();
+                               $context->getDefined();
+                               $context->getStats();
 
-                                       if ( $bad ) {
+                               foreach ( $actions['tag']['parameters'] as $tag 
) {
+                                       $changeTag = new ChangeTag( $tag, 
$context );
+                                       if ( !$changeTag->exists() && 
!$changeTag->canCreate()->isOK() ) {
                                                $out->addHTML(
                                                        
$this->buildFilterEditor(
                                                                $this->msg( 
'abusefilter-edit-bad-tags' )->parseAsBlock(),
@@ -126,6 +126,10 @@
                                        }
                                }
                        }
+
+                       // Purging cache of registered tags for immediate 
update at Special:Tags
+                       // (we don't check $actions['tag'] since tags might 
have been removed)
+                       ChangeTagsContext::purgeRegisteredTagsCache();
 
                        $newRow = get_object_vars( $newRow ); // Convert from 
object to array
 
@@ -259,12 +263,6 @@
                        $lp = new LogPage( 'abusefilter' );
 
                        $lp->addEntry( 'modify', $this->getTitle( $new_id ), 
'', array( $history_id, $new_id ) );
-
-                       // Special-case stuff for tags -- purge the tag list 
cache.
-                       if ( isset( $actions['tag'] ) ) {
-                               global $wgMemc;
-                               $wgMemc->delete( wfMemcKey( 'valid-tags' ) );
-                       }
 
                        AbuseFilter::resetFilterProfile( $new_id );
 
diff --git a/i18n/en.json b/i18n/en.json
index 033b7ac..bda6233 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -430,5 +430,7 @@
        "apihelp-query+abuselog-param-limit": "The maximum amount of entries to 
list.",
        "apihelp-query+abuselog-param-prop": "Which properties to get.",
        "apihelp-query+abuselog-example-1": "Show recent log entries",
-       "apihelp-query+abuselog-example-2": "Show recent log entries for 
[[API]]"
+       "apihelp-query+abuselog-example-2": "Show recent log entries for 
[[API]]",
+       "tags-description-extension-AbuseFilter": "Defined in 
[[Special:AbuseFilter/$1|filter $1]]",
+       "tags-source-extension-AbuseFilter": "Applied by the Abuse Filter"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 51b9a7a..e4c70cb 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -404,5 +404,7 @@
        "apihelp-query+abuselog-param-limit": 
"{{doc-apihelp-param|query+abuselog|limit}}",
        "apihelp-query+abuselog-param-prop": 
"{{doc-apihelp-param|query+abuselog|prop}}",
        "apihelp-query+abuselog-example-1": 
"{{doc-apihelp-example|query+abuselog}}",
-       "apihelp-query+abuselog-example-2": 
"{{doc-apihelp-example|query+abuselog}}"
+       "apihelp-query+abuselog-example-2": 
"{{doc-apihelp-example|query+abuselog}}",
+       "tags-description-extension-AbuseFilter": "Message at Special:Tags 
indicating the abuse filters applying the tag (params are abuse filter ids)",
+       "tags-source-extension-AbuseFilter": "Message at Special:Tags 
indicating AbuseFilter as the source of tags applied by AbuseFilter"
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibfadd04acfebbedaad1b67c5818dfa5c1b7037b3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Cenarium <cenarium.sy...@gmail.com>

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

Reply via email to