TitleBlacklist:

* Add {{ns}} and {{int}} support to blacklist (for interlingual blacklists)
* Add "caseinsenitive" attribute
This commit is contained in:
Victor Vasiliev 2007-12-14 17:54:06 +00:00
parent 63e9cf39df
commit 9ecaa4f5b2
2 changed files with 28 additions and 6 deletions

View file

@ -12,15 +12,15 @@ function efGetTitleBlacklistMessages()
'titleblacklist-forbidden-edit' => " 'titleblacklist-forbidden-edit' => "
<div align=\"center\" style=\"border: 1px solid #f88; padding: 0.5em; margin-bottom: 3px; font-size: 95%; width: auto;\"> <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 /> '''A page titled \"\$2\" cannot be created''' <br />
It matches the following blacklist regex: '''''\$1''''' It matches the following blacklist entry: '''''\$1'''''
</div>", </div>",
'titleblacklist-forbidden-move' => "<span class=\"error\"> 'titleblacklist-forbidden-move' => "<span class=\"error\">
'''A page titled \"\$2\" cannot be moved to \"\$3\"''' <br /> '''A page titled \"\$2\" cannot be moved to \"\$3\"''' <br />
It matches the following blacklist regex: '''''\$1''''' It matches the following blacklist entry: '''''\$1'''''
</span>", </span>",
'titleblacklist-forbidden-upload' => " 'titleblacklist-forbidden-upload' => "
'''A file named \"\$2\" cannot be uploaded''' <br /> '''A file named \"\$2\" cannot be uploaded''' <br />
It matches the following blacklist regex: '''''\$1'''''", It matches the following blacklist entry: '''''\$1'''''",
), ),
'ar' => array( 'ar' => array(

View file

@ -113,7 +113,7 @@ class TitleBlacklistEntry {
if( $user->isAllowed( 'tboverride' ) ) { if( $user->isAllowed( 'tboverride' ) ) {
return true; return true;
} }
if( preg_match( "/^{$this->mRegex}$/is", $title->getFullText() ) ) { if( preg_match( "/^{$this->mRegex}$/s" . ( isset( $this->mParams['casesensitive'] ) ? '' : 'i' ), $title->getFullText() ) ) {
if( isset( $this->mParams['autoconfirmed'] ) && $user->isAllowed( 'autoconfirmed' ) ) { if( isset( $this->mParams['autoconfirmed'] ) && $user->isAllowed( 'autoconfirmed' ) ) {
return false; return false;
} }
@ -140,12 +140,34 @@ class TitleBlacklistEntry {
//Parse opts //Parse opts
$opts = preg_split( '/\s*\|\s*/', $opts_str ); $opts = preg_split( '/\s*\|\s*/', $opts_str );
foreach( $opts as $opt ) { foreach( $opts as $opt ) {
if( $opt == 'autoconfirmed' ) { $opt2 = strtolower( $opt );
if( $opt2 == 'autoconfirmed' ) {
$options['autoconfirmed'] = true; $options['autoconfirmed'] = true;
} }
if( $opt == 'noedit' ) { if( $opt2 == 'noedit' ) {
$options['noedit'] = true; $options['noedit'] = true;
} }
if( $opt2 == 'casesensitive' ) {
$options['casesensitive'] = true;
}
}
//Process magic words
preg_match_all( '/{{([a-z]+):(.+?)}}/', $regex, $magicwords, PREG_SET_ORDER );
foreach( $magicwords as $mword ) {
global $wgParser; //Functions we're calling don't need, nevertheless let's use it
switch( strtolower( $mword[1] ) ) {
case 'ns':
$cpf_result = CoreParserFunctions::ns( $wgParser, $mword[2] );
if( is_string( $cpf_result ) ) {
$regex = str_replace( $mword[0], $cpf_result, $regex ); //All result will have the same value, so we can just use str_seplace()
}
break;
case 'int':
$cpf_result = CoreParserFunctions::intFunction( $wgParser, $mword[2] );
if( is_string( $cpf_result ) ) {
$regex = str_replace( $mword[0], $cpf_result, $regex );
}
}
} }
//Return result //Return result
if( $regex ) { if( $regex ) {