Gerrit Patch Uploader has uploaded a new change for review.

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

Change subject: [WIP] Add TitleBlacklist hit log
......................................................................

[WIP] Add TitleBlacklist hit log

Will add details when done. Also I know qqq is missing...

Bug: 21206
Change-Id: Ie855701828682345b766b33b16b65c14263b06a0
---
M TitleBlacklist.hooks.php
M TitleBlacklist.php
M api/ApiQueryTitleBlacklist.php
M i18n/en.json
4 files changed, 48 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TitleBlacklist 
refs/changes/50/123150/1

diff --git a/TitleBlacklist.hooks.php b/TitleBlacklist.hooks.php
index f0e8ce1..638baab 100644
--- a/TitleBlacklist.hooks.php
+++ b/TitleBlacklist.hooks.php
@@ -35,6 +35,8 @@
                                $result = array( $blacklisted->getErrorMessage( 
'edit' ),
                                        htmlspecialchars( 
$blacklisted->getRaw() ),
                                        $title->getFullText() );
+                               // TODO should not log whenever checking userCan
+                               self::logFilterHit( $user, $title, 
$blacklisted->getRaw() );
                                return false;
                        }
                }
@@ -61,6 +63,8 @@
                                $blacklisted->getRaw(),
                                $old->getFullText(),
                                $nt->getFullText() )->parse();
+                       self::logFilterHit( $user, $nt, $blacklisted->getRaw() 
);
+
                        return false;
                }
                return true;
@@ -75,12 +79,14 @@
         * @return bool Acceptable
         */
        private static function acceptNewUserName( $userName, $permissionsUser, 
&$err, $override = true ) {
+               global $wgUser;
                $title = Title::makeTitleSafe( NS_USER, $userName );
                $blacklisted = TitleBlacklist::singleton()->userCannot( $title, 
$permissionsUser,
                        'new-account', $override );
                if ( $blacklisted instanceof TitleBlacklistEntry ) {
                        $message = $blacklisted->getErrorMessage( 'new-account' 
);
                        $err = wfMessage( $message, $blacklisted->getRaw(), 
$userName )->parse();
+                       self::logFilterHit( $wgUser, $title, 
$blacklisted->getRaw() );
                        return false;
                }
                return true;
@@ -145,6 +151,7 @@
                                                        $retitle->getFullText() 
)->escaped() .
                                                Html::closeElement( 'div' ) . 
"\n" .
                                                Html::element( 'br', array( 
'clear' => 'all' ) ) . "\n";
+                                       self::logFilterHit( $user, $retitle, 
$blacklisted->getRaw() );
                                }
                        }
 
@@ -179,4 +186,26 @@
                }
                return true;
        }
+
+       /**
+        * Logs the filter hit to Special:Log if
+        * $wgTitleBlacklistLogHits is enabled.
+        *
+        * @param User $user
+        * @param Title $title
+        * @param string $entry
+        */
+       public function logFilterHit( $user, $title, $entry ) {
+               global $wgTitleBlacklistLogHits;
+               if ( $wgTitleBlacklistLogHits ) {
+                       $logEntry = new ManualLogEntry( 'titleblacklist', 'hit' 
);
+                       $logEntry->setPerformer( $user );
+                       $logEntry->setTarget( $title );
+                       $logEntry->setParameters( array(
+                               '4::entry' => $entry
+                       ) );
+                       $logid = $logEntry->insert();
+                       $logEntry->publish( $logid, "rc" );
+               }
+       }
 }
diff --git a/TitleBlacklist.php b/TitleBlacklist.php
index ac94931..459f14e 100644
--- a/TitleBlacklist.php
+++ b/TitleBlacklist.php
@@ -54,6 +54,11 @@
  */
 $wgTitleBlacklistUsernameSources = '*';
 
+/**
+ * Log blacklist hits to Special:Log
+ */
+$wgTitleBlacklistLogHits = false;
+
 $wgTitleBlacklistCaching = array(
        'warningchance' => 100,
        'expiry' => 900,
@@ -89,6 +94,11 @@
        return true;
 };
 
+$wgLogTypes[] = 'titleblacklist';
+$wgLogActionsHandlers['titleblacklist/*'] = 'LogFormatter';
+$wgLogRestrictions['titleblacklist'] = 'titleblacklistlog';
+$wgGroupPermissions['sysop']['titleblacklistlog'] = true;
+
 $wgResourceModules['mediawiki.api.titleblacklist'] = array(
        'scripts' => 'mediawiki.api.titleblacklist.js',
        'localBasePath' => $dir . '/modules',
diff --git a/api/ApiQueryTitleBlacklist.php b/api/ApiQueryTitleBlacklist.php
index 1da70d2..713d3e8 100644
--- a/api/ApiQueryTitleBlacklist.php
+++ b/api/ApiQueryTitleBlacklist.php
@@ -63,6 +63,8 @@
                        $res->addValue( 'titleblacklist', 'result', 
'blacklisted' );
                        // there aren't any messages for create(talk|page), 
using edit for those instead
                        $message = $blacklisted->getErrorMessage( $action !== 
'create' ? $action : 'edit' );
+                       $hooks = TitleBlacklistHooks();
+                       $hooks->logFilterHit( $this->getUser(), $title, 
$blacklisted->getRaw() );
                        $res->addValue( 'titleblacklist', 'reason', wfMessage( 
$message, $result )->text() );
                        $res->addValue( 'titleblacklist', 'message', $message );
                        $res->addValue( 'titleblacklist', 'line', 
htmlspecialchars( $blacklisted->getRaw() ) );
diff --git a/i18n/en.json b/i18n/en.json
index 163f8fa..2ea67fd 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -2,6 +2,10 @@
     "@metadata": {
         "authors": []
     },
+    "action-titleblacklistlog": "view the title blacklist log",
+    "log-name-titleblacklist": "Title blacklist hit log",
+    "log-description-titleblacklist": "These events track title blacklist 
hits.",
+    "logentry-titleblacklist-hit": "$1 caused a title blacklist hit on $3 
matching $4.",
     "titleblacklist-desc": "Allows administrators to forbid creation of pages 
and user accounts per a [[MediaWiki:Titleblacklist|blacklist]] and 
[[MediaWiki:Titlewhitelist|whitelist]]",
     "titleblacklist": "# This is a title blacklist. Titles and users that 
match a regular expression here cannot be created.\n# Use \"#\" for 
comments.\n# This is case insensitive by default",
     "titlewhitelist": "# This is a title whitelist. Use \"#\" for comments.\n# 
This is case insensitive by default",
@@ -12,5 +16,6 @@
     "titleblacklist-invalid": "The following {{PLURAL:$1|line|lines}} in the 
title blacklist {{PLURAL:$1|is|are}} invalid;\nplease correct 
{{PLURAL:$1|it|them}} before saving:",
     "titleblacklist-override": "Ignore the blacklist",
     "right-tboverride": "Override the title or username blacklist",
-    "right-tboverride-account": "Override the username blacklist"
-}
\ No newline at end of file
+    "right-tboverride-account": "Override the username blacklist",
+    "right-titleblacklistlog": "View title blacklist log"
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie855701828682345b766b33b16b65c14263b06a0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TitleBlacklist
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploa...@gmail.com>
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