Merge "Add mw.ext.TitleBlacklist.test"

This commit is contained in:
jenkins-bot 2014-01-30 17:47:36 +00:00 committed by Gerrit Code Review
commit 75a99bb776
4 changed files with 85 additions and 10 deletions

View file

@ -0,0 +1,33 @@
<?php
class Scribunto_LuaTitleBlacklistLibrary extends Scribunto_LuaLibraryBase {
public function register() {
$lib = array(
'test' => array( $this, 'test' ),
);
$this->getEngine()->registerInterface( __DIR__ . '/mw.ext.TitleBlacklist.lua', $lib, array() );
}
public function test( $action = null, $title = null ) {
$this->checkType( 'mw.ext.TitleBlacklist.test', 1, $action, 'string' );
$this->checkTypeOptional( 'mw.ext.TitleBlacklist.test', 2, $title, 'string', '' );
$this->incrementExpensiveFunctionCount();
if ( $title == '' ) {
$title = $this->getParser()->mTitle->getPrefixedText();
}
$entry = TitleBlacklist::singleton()->isBlacklisted( $title, $action );
if ( $entry ) {
return array( array(
'params' => $entry->getParams(),
'regex' => $entry->getRegex(),
'raw' => $entry->getRaw(),
'version' => $entry->getFormatVersion(),
'message' => $entry->getErrorMessage( $action ),
'custommessage' => $entry->getCustomMessage()
) );
}
return array( null );
}
}

View file

@ -156,7 +156,12 @@ class TitleBlacklist {
if ( $override && self::userCanOverride( $user, $action ) ) {
return false;
} else {
return $this->isBlacklisted( $title, $action );
$entry = $this->isBlacklisted( $title, $action );
if ( !$entry ) {
return false;
}
$params = $entry->getParams();
return isset( $params['autoconfirmed'] ) && $user->isAllowed( 'autoconfirmed' ) ? false : $entry;
}
}
@ -172,17 +177,29 @@ class TitleBlacklist {
public function isBlacklisted( $title, $action = 'edit' ) {
if ( !( $title instanceof Title ) ) {
$title = Title::newFromText( $title );
if ( !( $title instanceof Title ) ) {
// The fact that the page name is invalid will stop whatever
// action is going through. No sense in doing more work here.
return false;
}
}
$blacklist = $this->getBlacklist();
$autoconfirmedItem = false;
foreach ( $blacklist as $item ) {
if ( $item->matches( $title->getFullText(), $action ) ) {
if ( $this->isWhitelisted( $title, $action ) ) {
return false;
}
return $item; // "returning true"
$params = $item->getParams();
if ( !isset( $params['autoconfirmed'] ) ) {
return $item;
}
if ( !$autoconfirmedItem ) {
$autoconfirmedItem = $item;
}
}
}
return false;
return $autoconfirmedItem;
}
/**
@ -370,11 +387,7 @@ class TitleBlacklistEntry {
$match = preg_match( "/^(?:{$this->mRegex})$/us" . ( isset( $this->mParams['casesensitive'] ) ? '' : 'i' ), $title );
wfRestoreWarnings();
global $wgUser;
if ( $match ) {
if ( isset( $this->mParams['autoconfirmed'] ) && $wgUser->isAllowed( 'autoconfirmed' ) ) {
return false;
}
if ( isset( $this->mParams['moveonly'] ) && $action != 'move' ) {
return false;
}
@ -481,10 +494,10 @@ class TitleBlacklistEntry {
}
/**
* @return array This entry's options
* @return array This entry's parameters
*/
public function getOptions() {
return $this->mOptions;
public function getParams() {
return $this->mParams;
}
/**

View file

@ -22,6 +22,7 @@ $dir = __DIR__;
$wgExtensionMessagesFiles['TitleBlacklist'] = $dir . '/TitleBlacklist.i18n.php';
$wgAutoloadClasses['TitleBlacklist'] = $dir . '/TitleBlacklist.list.php';
$wgAutoloadClasses['TitleBlacklistHooks'] = $dir . '/TitleBlacklist.hooks.php';
$wgAutoloadClasses['Scribunto_LuaTitleBlacklistLibrary'] = $dir . '/TitleBlacklist.library.php';
/** @defgroup Title blacklist source types
* @{
@ -80,6 +81,12 @@ $wgHooks['UnitTestsList'][] = function( &$files ) {
$files += glob( __DIR__ . '/tests/*Test.php' );
return true;
};
$wgHooks['ScribuntoExternalLibraries'][] = function( $engine, array &$extraLibraries ) {
if( $engine == 'lua' ) {
$extraLibraries['mw.ext.TitleBlacklist'] = 'Scribunto_LuaTitleBlacklistLibrary';
}
return true;
};
$wgResourceModules['mediawiki.api.titleblacklist'] = array(
'scripts' => 'mediawiki.api.titleblacklist.js',

22
mw.ext.TitleBlacklist.lua Normal file
View file

@ -0,0 +1,22 @@
local TitleBlacklist = {}
local php
function TitleBlacklist.test( action, title )
return php.test( action, title )
end
function TitleBlacklist.setupInterface( options )
-- Boilerplate
TitleBlacklist.setupInterface = nil
php = mw_interface
mw_interface = nil
-- Register this library in the "mw" global
mw = mw or {}
mw.ext = mw.ext or {}
mw.ext.TitleBlacklist = TitleBlacklist
package.loaded['mw.ext.TitleBlacklist'] = TitleBlacklist
end
return TitleBlacklist