jenkins-bot has submitted this change and it was merged.
Change subject: Optionally integrate with AntiSpoof
......................................................................
Optionally integrate with AntiSpoof
Introduces a new "antispoof" parameter. If set, try to normalize
the title using the AntiSpoof extension.
Bug: 53901
Change-Id: I9b3c5f5f5d9eeda65562fd83e21c9c2ba97e5569
---
M TitleBlacklist.list.php
M tests/ApiQueryTitleBlacklistTest.php
M tests/testSource
3 files changed, 39 insertions(+), 4 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
jenkins-bot: Verified
diff --git a/TitleBlacklist.list.php b/TitleBlacklist.list.php
index d197a9c..cec4dd8 100644
--- a/TitleBlacklist.list.php
+++ b/TitleBlacklist.list.php
@@ -175,7 +175,7 @@
}
$blacklist = $this->getBlacklist();
foreach ( $blacklist as $item ) {
- if ( $item->matches( $title, $action ) ) {
+ if ( $item->matches( $title->getFullText(), $action ) )
{
if ( $this->isWhitelisted( $title, $action ) ) {
return false;
}
@@ -199,7 +199,7 @@
}
$whitelist = $this->getWhitelist();
foreach ( $whitelist as $item ) {
- if ( $item->matches( $title, $action ) ) {
+ if ( $item->matches( $title->getFullText(), $action ) )
{
return true;
}
}
@@ -343,7 +343,7 @@
* Check whether a user can perform the specified action
* on the specified Title
*
- * @param $title Title to check
+ * @param $title string to check
* @param $action %Action to check
* @return bool TRUE if the the regex matches the title, and is not
overridden
* else false if it doesn't match (or was overridden)
@@ -357,8 +357,17 @@
return false;
}
+ if ( isset( $this->mParams['antispoof'] ) && is_callable(
'AntiSpoof::checkUnicodeString' ) ) {
+ list( $ok, $norm ) = AntiSpoof::checkUnicodeString(
$title );
+ if ( $ok == "OK" ) {
+ list( $ver, $title ) = explode( ':', $norm, 2 );
+ } else {
+ wfDebugLog( 'TitleBlacklist', 'AntiSpoof could
not normalize "' . $title . '".' );
+ }
+ }
+
wfSuppressWarnings();
- $match = preg_match( "/^(?:{$this->mRegex})$/us" . ( isset(
$this->mParams['casesensitive'] ) ? '' : 'i' ), $title->getFullText() );
+ $match = preg_match( "/^(?:{$this->mRegex})$/us" . ( isset(
$this->mParams['casesensitive'] ) ? '' : 'i' ), $title );
wfRestoreWarnings();
global $wgUser;
@@ -427,6 +436,9 @@
if ( preg_match( '/errmsg\s*=\s*(.+)/i', $opt, $matches
) ) {
$options['errmsg'] = $matches[1];
}
+ if ( $opt2 == 'antispoof' ) {
+ $options['antispoof'] = true;
+ }
}
// Process magic words
preg_match_all( '/{{\s*([a-z]+)\s*:\s*(.+?)\s*}}/', $regex,
$magicwords, PREG_SET_ORDER );
diff --git a/tests/ApiQueryTitleBlacklistTest.php
b/tests/ApiQueryTitleBlacklistTest.php
index 1f8164e..344e999 100644
--- a/tests/ApiQueryTitleBlacklistTest.php
+++ b/tests/ApiQueryTitleBlacklistTest.php
@@ -105,6 +105,28 @@
$listed[0]['titleblacklist']['line'],
'Correct blacklist line is returned'
);
+ }
+
+ /**
+ * Tests integration with the AntiSpoof extension
+ */
+ function testAntiSpoofIntegration() {
+ if ( !class_exists( 'AntiSpoof') ) {
+ $this->markTestSkipped( "This test requires the
AntiSpoof extension" );
+ }
+
+ $listed = $this->doApiRequest( array(
+ 'action' => 'titleblacklist',
+ 'tbtitle' => 'AVVVV',
+ 'tbaction' => 'create',
+ 'tbnooverride' => true,
+ ) );
+
+ $this->assertEquals(
+ 'blacklisted',
+ $listed[0]['titleblacklist']['result'],
+ 'Spoofed title is blacklisted'
+ );
}
}
diff --git a/tests/testSource b/tests/testSource
index f73d9dd..235cc67 100644
--- a/tests/testSource
+++ b/tests/testSource
@@ -2,3 +2,4 @@
.*[Ff]ail.*
.*[Nn]yancat.* <errmsg=blacklisted-nyancat>
.*evil_acc.* <newaccountonly>
+AW{1,10} <antispoof>
--
To view, visit https://gerrit.wikimedia.org/r/83354
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9b3c5f5f5d9eeda65562fd83e21c9c2ba97e5569
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/TitleBlacklist
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Victor Vasiliev <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits