TitleBlacklist:

* Extend and prettify messages
* Refactor code
* Handle page moves correctly
This commit is contained in:
Victor Vasiliev 2007-12-08 18:38:05 +00:00
parent 665cc70c51
commit 3299f7bc9a
2 changed files with 37 additions and 12 deletions

View file

@ -9,7 +9,15 @@ function efGetTitleBlacklistMessages()
# Every title that matches regex here are forbidden to create and edit
# Use \"#\" for comments
",
'titleblacklist-forbidden' => "'''This page title is blacklisted.''' It matches following blacklist regex: '''''\$1'''''",
'titleblacklist-forbidden' => "
<div align=\"center\" style=\"border: 1px solid #f88; padding: 0.5em; margin-bottom: 3px; font-size: 95%; width: auto;\">
'''A page titled \"\$2\" cannot be created''' <br/>
It matches the following blacklist regex: '''''\$1'''''
</div>",
'titleblacklist-forbidden-move' => "<span class=\"error\">
'''A page titled \"\$2\" cannot be moved to \"\$3\"''' <br/>
It matches the following blacklist regex: '''''\$1'''''
</span>",
),
'ar' => array(

View file

@ -11,6 +11,7 @@ $wgExtensionCredits['other'][] = array(
$wgExtensionFunctions[] = 'efSetupTitleBlacklistMessages';
$wgHooks['userCan'][] = 'efUserCanCreateTitle';
$wgHooks['AbortMove'][] = 'efTitleBlacklistCanMove';
$wgAvailableRights[] = 'tboverride';
$wgGroupPermissions['sysop']['tboverride'] = true;
@ -24,8 +25,7 @@ function efSetupTitleBlacklistMessages() {
}
function efGetTitleBlacklist() {
global $wgMessageCache;
return $wgMessageCache->get("titleblacklist");
return wfMsgForContent( 'titleblacklist' );
}
function efParseTitleBlacklist( $list ) {
@ -41,22 +41,39 @@ function efParseTitleBlacklist( $list ) {
return $result;
}
function efIsBlacklistedTitle( $title ) {
if( $title instanceof Title ) {
$title = $title->getFullText();
}
$blacklist = efParseTitleBlacklist( efGetTitleBlacklist() );
foreach ( $blacklist as $item ) {
if( preg_match( "/^$item$/is", $title ) ) {
return $item;
}
}
return false;
}
function efUserCanCreateTitle( $title, $user, $action, &$result )
{
if ( $action != 'create' && $action != 'move' )
{
if ( $action != 'create' || $user->isAllowed('tboverride') ) {
$result = true;
return $result;
}
$blacklist = efParseTitleBlacklist( efGetTitleBlacklist() );
foreach ( $blacklist as $item )
{
if( preg_match( "/^$item$/is", $title->getText() ) && !$user->isAllowed('tboverride')) {
$result = false;
return wfMsgWikiHtml( "titleblacklist-forbidden", $item );
}
$blacklisted = efIsBlacklistedTitle( $title );
if( is_string( $blacklisted ) ) {
return wfMsgWikiHtml( "titleblacklist-forbidden", $blacklisted, $title->getFullText() );
}
$result = true;
return $result;
}
function efTitleBlacklistCanMove( $old, $nt, $user, &$err ) {
$blacklisted = efIsBlacklistedTitle( $nt );
if( !$user->isAllowed( 'tboverride' ) && is_string( $blacklisted ) ) {
$err = wfMsgWikiHtml( "titleblacklist-forbidden-move", $blacklisted, $nt->getFullText(), $old->getFullText() );
return false;
}
return true;
}