mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TitleBlacklist
synced 2024-11-28 07:50:32 +00:00
TitleBlacklist:
* Extend and prettify messages * Refactor code * Handle page moves correctly
This commit is contained in:
parent
665cc70c51
commit
3299f7bc9a
|
@ -9,7 +9,15 @@ function efGetTitleBlacklistMessages()
|
||||||
# Every title that matches regex here are forbidden to create and edit
|
# Every title that matches regex here are forbidden to create and edit
|
||||||
# Use \"#\" for comments
|
# 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(
|
'ar' => array(
|
||||||
|
|
|
@ -11,6 +11,7 @@ $wgExtensionCredits['other'][] = array(
|
||||||
|
|
||||||
$wgExtensionFunctions[] = 'efSetupTitleBlacklistMessages';
|
$wgExtensionFunctions[] = 'efSetupTitleBlacklistMessages';
|
||||||
$wgHooks['userCan'][] = 'efUserCanCreateTitle';
|
$wgHooks['userCan'][] = 'efUserCanCreateTitle';
|
||||||
|
$wgHooks['AbortMove'][] = 'efTitleBlacklistCanMove';
|
||||||
|
|
||||||
$wgAvailableRights[] = 'tboverride';
|
$wgAvailableRights[] = 'tboverride';
|
||||||
$wgGroupPermissions['sysop']['tboverride'] = true;
|
$wgGroupPermissions['sysop']['tboverride'] = true;
|
||||||
|
@ -24,8 +25,7 @@ function efSetupTitleBlacklistMessages() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function efGetTitleBlacklist() {
|
function efGetTitleBlacklist() {
|
||||||
global $wgMessageCache;
|
return wfMsgForContent( 'titleblacklist' );
|
||||||
return $wgMessageCache->get("titleblacklist");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function efParseTitleBlacklist( $list ) {
|
function efParseTitleBlacklist( $list ) {
|
||||||
|
@ -41,22 +41,39 @@ function efParseTitleBlacklist( $list ) {
|
||||||
return $result;
|
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 )
|
function efUserCanCreateTitle( $title, $user, $action, &$result )
|
||||||
{
|
{
|
||||||
if ( $action != 'create' && $action != 'move' )
|
if ( $action != 'create' || $user->isAllowed('tboverride') ) {
|
||||||
{
|
|
||||||
$result = true;
|
$result = true;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
$blacklist = efParseTitleBlacklist( efGetTitleBlacklist() );
|
$blacklisted = efIsBlacklistedTitle( $title );
|
||||||
foreach ( $blacklist as $item )
|
if( is_string( $blacklisted ) ) {
|
||||||
{
|
return wfMsgWikiHtml( "titleblacklist-forbidden", $blacklisted, $title->getFullText() );
|
||||||
if( preg_match( "/^$item$/is", $title->getText() ) && !$user->isAllowed('tboverride')) {
|
|
||||||
$result = false;
|
|
||||||
return wfMsgWikiHtml( "titleblacklist-forbidden", $item );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = true;
|
$result = true;
|
||||||
return $result;
|
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;
|
||||||
|
}
|
Loading…
Reference in a new issue