http://www.mediawiki.org/wiki/Special:Code/MediaWiki/76344
Revision: 76344
Author: vasilievvv
Date: 2010-11-08 21:55:05 +0000 (Mon, 08 Nov 2010)
Log Message:
-----------
Title blacklist:
* (bug 22141) Introduce a separate user right for overriding title blacklist on
account creations only
* Some minor refactorings
Modified Paths:
--------------
trunk/extensions/TitleBlacklist/TitleBlacklist.hooks.php
trunk/extensions/TitleBlacklist/TitleBlacklist.i18n.php
trunk/extensions/TitleBlacklist/TitleBlacklist.list.php
trunk/extensions/TitleBlacklist/TitleBlacklist.php
Modified: trunk/extensions/TitleBlacklist/TitleBlacklist.hooks.php
===================================================================
--- trunk/extensions/TitleBlacklist/TitleBlacklist.hooks.php 2010-11-08
21:26:55 UTC (rev 76343)
+++ trunk/extensions/TitleBlacklist/TitleBlacklist.hooks.php 2010-11-08
21:55:05 UTC (rev 76344)
@@ -1,8 +1,8 @@
<?php
/**
* Hooks for Title Blacklist
- * @author VasilievVV
- * @copyright © 2007 VasilievVV
+ * @author Victor Vasiliev
+ * @copyright © 2007-2010 Victor Vasiliev et al
* @license GNU General Public License 2.0 or later
*/
@@ -17,12 +17,9 @@
global $wgTitleBlacklist;
if( $action == 'create' || $action == 'edit' || $action ==
'upload' ) {
efInitTitleBlacklist();
- $blacklisted = $wgTitleBlacklist->isBlacklisted(
$title, $action );
+ $blacklisted = $wgTitleBlacklist->userCannot( $title,
$user, $action );
if( $blacklisted instanceof TitleBlacklistEntry ) {
- $message = $blacklisted->getCustomMessage();
- if( is_null( $message ) )
- $message =
'titleblacklist-forbidden-edit';
- $result = array( $message,
+ $result = array( $blacklisted->getErrorMessage(
'edit' ),
htmlspecialchars(
$blacklisted->getRaw() ),
$title->getFullText() );
return false;
@@ -35,14 +32,11 @@
public static function abortMove( $old, $nt, $user, &$err ) {
global $wgTitleBlacklist;
efInitTitleBlacklist();
- $blacklisted = $wgTitleBlacklist->isBlacklisted( $nt, 'move' );
+ $blacklisted = $wgTitleBlacklist->userCannot( $nt, $user,
'move' );
if( !$blacklisted )
- $blacklisted = $wgTitleBlacklist->isBlacklisted( $old,
'edit' );
+ $blacklisted = $wgTitleBlacklist->userCannot( $old,
$user, 'edit' );
if( $blacklisted instanceof TitleBlacklistEntry ) {
- $message = $blacklisted->getCustomMessage();
- if( is_null( $message ) )
- $message = 'titleblacklist-forbidden-move';
- $err = wfMsgWikiHtml( $message,
+ $err = wfMsgWikiHtml( $blacklisted->getErrorMessage(
'move' ),
htmlspecialchars( $blacklisted->getRaw() ),
htmlspecialchars( $old->getFullText() ),
htmlspecialchars( $nt->getFullText() ) );
@@ -59,17 +53,13 @@
*
* @return bool Acceptable
*/
- private static function acceptNewUserName( $userName, &$err ) {
- global $wgTitleBlacklist;
+ private static function acceptNewUserName( $userName, &$err, $override
= true ) {
+ global $wgTitleBlacklist, $wgUser;
efInitTitleBlacklist();
$title = Title::makeTitleSafe( NS_USER, $userName );
- $blacklisted = $wgTitleBlacklist->isBlacklisted( $title,
'new-account' );
- if( !( $blacklisted instanceof TitleBlacklistEntry ) )
- $blacklisted = $wgTitleBlacklist->isBlacklisted(
$title, 'create' );
+ $blacklisted = $wgTitleBlacklist->userCannot( $title, $wgUser,
'new-account', $override );
if( $blacklisted instanceof TitleBlacklistEntry ) {
- $message = $blacklisted->getCustomMessage();
- if ( is_null( $message ) )
- $message =
'titleblacklist-forbidden-new-account';
+ $message = $blacklisted->getErrorMessage( 'new-account'
);
$err = wfMsgWikiHtml( $message, $blacklisted->getRaw(),
$userName );
return false;
}
@@ -78,10 +68,9 @@
/** AbortNewAccount hook */
public static function abortNewAccount( $user, &$message ) {
- global $wgUser;
- if( $wgUser->isAllowed( 'tboverride' ) )
- return true;
- return self::acceptNewUserName( $user->getName(), $message );
+ global $wgUser, $wgRequest;
+ $override = $wgRequest->getCheck( 'wpIgnoreTitleBlacklist' );
+ return self::acceptNewUserName( $user->getName(), $message,
$override );
}
/** CentralAuthAutoCreate hook */
@@ -92,7 +81,7 @@
/** EditFilter hook */
public static function validateBlacklist( $editor, $text, $section,
$error ) {
- global $wgTitleBlacklist;
+ global $wgTitleBlacklist, $wgUser;
efInitTitleBlacklist();
$title = $editor->mTitle;
if( $title->getNamespace() == NS_MEDIAWIKI &&
$title->getDBkey() == 'Titleblacklist' ) {
@@ -118,7 +107,7 @@
# Block redirects to nonexistent blacklisted titles
$retitle = Title::newFromRedirect( $text );
if( $retitle !== null && !$retitle->exists() ) {
- $blacklisted =
$wgTitleBlacklist->isBlacklisted( $retitle, 'create' );
+ $blacklisted = $wgTitleBlacklist->userCannot(
$retitle, $wgUser, 'create' );
if( $blacklisted instanceof TitleBlacklistEntry
) {
$error = Html::openElement( 'div',
array( 'class' => 'errorbox' ) ) .
wfMsg(
'titleblacklist-forbidden-edit',
@@ -146,4 +135,15 @@
}
return true;
}
+
+ /** UserCreateForm hook based on the one from AntiSpoof extension */
+ public static function addOverrideCheckbox( &$template ) {
+ global $wgRequest, $wgUser;
+
+ if ( TitleBlacklist::userCanOverride( 'new-account' ) )
+ $template->addInputItem( 'wpIgnoreTitleBlacklist',
+ $wgRequest->getCheck( 'wpIgnoreTitleBlacklist'
),
+ 'checkbox', 'titleblacklist-override' );
+ return true;
+ }
}
Modified: trunk/extensions/TitleBlacklist/TitleBlacklist.i18n.php
===================================================================
--- trunk/extensions/TitleBlacklist/TitleBlacklist.i18n.php 2010-11-08
21:26:55 UTC (rev 76343)
+++ trunk/extensions/TitleBlacklist/TitleBlacklist.i18n.php 2010-11-08
21:55:05 UTC (rev 76344)
@@ -25,7 +25,9 @@
It matches the following blacklist entry: <code>$1</code>',
'titleblacklist-invalid' => 'The following
{{PLURAL:$1|line|lines}} in the title blacklist {{PLURAL:$1|is|are}} invalid;
please correct {{PLURAL:$1|it|them}} before saving:',
+ 'titleblacklist-override' => 'Ignore the blacklist',
'right-tboverride' => 'Override the title blacklist',
+ 'right-tboverride-account' => 'Override the username blacklist',
);
/** Message documentation (Message documentation)
Modified: trunk/extensions/TitleBlacklist/TitleBlacklist.list.php
===================================================================
--- trunk/extensions/TitleBlacklist/TitleBlacklist.list.php 2010-11-08
21:26:55 UTC (rev 76343)
+++ trunk/extensions/TitleBlacklist/TitleBlacklist.list.php 2010-11-08
21:55:05 UTC (rev 76344)
@@ -1,8 +1,8 @@
<?php
/**
* Title Blacklist class
- * @author VasilievVV
- * @copyright © 2007 VasilievVV
+ * @author Victor Vasiliev
+ * @copyright © 2007-2010 Victor Vasiliev et al
* @license GNU General Public License 2.0 or later
* @file
*/
@@ -129,22 +129,39 @@
}
/**
- * Check whether the blacklist restricts the current User from
+ * Check whether the blacklist restricts giver nuser
* performing a specific action on the given Title
*
* @param $title Title to check
+ * @param $user User to check
* @param $action Action to check; 'edit' if unspecified
+ * @param $override If set to true, overrides work
* @return The corresponding TitleBlacklistEntry if blacklisted;
* otherwise FALSE
*/
+ public function userCannot( $title, $user, $action = 'edit', $override
= true ) {
+ if( $override && self::userCanOverride( $action ) )
+ return false;
+ else
+ return $this->isBlacklisted( $title, $action );
+ }
+
+ /**
+ * Check whether the blacklist restricts
+ * performing a specific action on the given Title
+ *
+ * @param $title Title to check
+ * @param $action Action to check; 'edit' if unspecified
+ * @return The corresponding TitleBlacklistEntry if blacklisted;
+ * otherwise FALSE
+ */
public function isBlacklisted( $title, $action = 'edit' ) {
- global $wgUser;
if( !($title instanceof Title) ) {
$title = Title::newFromText( $title );
}
$blacklist = $this->getBlacklist();
foreach ( $blacklist as $item ) {
- if( !$item->userCan( $title, $wgUser, $action ) ) {
+ if( !$item->matches( $title, $action ) ) {
if( $this->isWhitelisted( $title, $action ) ) {
return false;
}
@@ -169,7 +186,7 @@
}
$whitelist = $this->getWhitelist();
foreach( $whitelist as $item ) {
- if( !$item->userCan( $title, $wgUser, $action ) ) {
+ if( !$item->matches( $title, $action ) ) {
return true;
}
}
@@ -245,6 +262,17 @@
}
return $badEntries;
}
+
+ /**
+ * Inidcates whether user can override blacklist on certain action.
+ *
+ * @param $action Action
+ */
+ public static function userCanOverride( $action ) {
+ global $wgUser;
+ return $wgUser->isAllowed( 'tboverride' ) ||
+ ( $action == 'new-account' && $wgUser->isAllowed(
'tboverride-account' ) );
+ }
}
@@ -273,18 +301,14 @@
}
/**
- * Check whether the specified User can perform the specified action
+ * Check whether a user can perform the specified action
* on the specified Title
*
* @param $title Title to check
- * @param $user User to check
* @param $action %Action to check
* @return TRUE if the user can; otherwise FALSE
*/
- public function userCan( $title, $user, $action ) {
- if( $user->isAllowed( 'tboverride' ) ) {
- return true;
- }
+ public function matches( $title, $action ) {
wfSuppressWarnings();
$match = preg_match( "/^(?:{$this->mRegex})$/us" . ( isset(
$this->mParams['casesensitive'] ) ? '' : 'i' ), $title->getFullText() );
wfRestoreWarnings();
@@ -419,6 +443,18 @@
* @param $v New version to set
*/
public function setFormatVersion( $v ) { $this->mFormatVersion = $v; }
+
+ /**
+ * Return the error message name for the blacklist entry.
+ *
+ * @param $operation Operation name (as in titleblacklist-forbidden
message name)
+ *
+ * @returns The error message name
+ */
+ public function getErrorMessage( $operation ) {
+ $message = $this->getCustomMessage();
+ return $message ? $message :
"titleblacklist-forbidden-{$operation}";
+ }
}
-//@}
\ No newline at end of file
+//@}
Modified: trunk/extensions/TitleBlacklist/TitleBlacklist.php
===================================================================
--- trunk/extensions/TitleBlacklist/TitleBlacklist.php 2010-11-08 21:26:55 UTC
(rev 76343)
+++ trunk/extensions/TitleBlacklist/TitleBlacklist.php 2010-11-08 21:55:05 UTC
(rev 76344)
@@ -12,7 +12,7 @@
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'Title Blacklist',
- 'author' => array( 'VasilievVV', 'Fran Rogers' ),
+ 'author' => array( 'Victor Vasiliev', 'Fran Rogers' ),
'version' => '1.4.2',
'url' =>
'http://www.mediawiki.org/wiki/Extension:Title_Blacklist',
'descriptionmsg' => 'titleblacklist-desc',
@@ -40,7 +40,8 @@
'warningexpiry' => 600,
);
-$wgAvailableRights[] = 'tboverride';
+$wgAvailableRights[] = 'tboverride'; // Implies tboverride-account
+$wgAvailableRights[] = 'tboverride-account'; // For account creation
$wgGroupPermissions['sysop']['tboverride'] = true;
$wgHooks['getUserPermissionsErrorsExpensive'][] =
'TitleBlacklistHooks::userCan';
@@ -49,6 +50,7 @@
$wgHooks['CentralAuthAutoCreate'][] =
'TitleBlacklistHooks::centralAuthAutoCreate';
$wgHooks['EditFilter'][] = 'TitleBlacklistHooks::validateBlacklist';
$wgHooks['ArticleSaveComplete'][] = 'TitleBlacklistHooks::clearBlacklist';
+$wgHooks['UserCreateForm'][] = 'TitleBlacklistHooks::addOverrideCheckbox';
/**
* Initialize the title blacklist
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs