mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TitleBlacklist
synced 2024-11-24 06:04:05 +00:00
Add phpcs and make pass
Change-Id: If5a2ec9700148eb842d6580945e51e1942a2e0ed
This commit is contained in:
parent
968c6e8cd2
commit
55d068708a
|
@ -54,10 +54,10 @@ class TitleBlacklistHooks {
|
|||
$blacklisted = TitleBlacklist::singleton()->userCannot( $title, $user, $action );
|
||||
if ( $blacklisted instanceof TitleBlacklistEntry ) {
|
||||
$errmsg = $blacklisted->getErrorMessage( 'edit' );
|
||||
$params = array(
|
||||
$params = [
|
||||
$blacklisted->getRaw(),
|
||||
$title->getFullText()
|
||||
);
|
||||
];
|
||||
ApiResult::setIndexedTagName( $params, 'param' );
|
||||
$result = ApiMessage::create(
|
||||
wfMessage(
|
||||
|
@ -66,18 +66,18 @@ class TitleBlacklistHooks {
|
|||
$title->getFullText()
|
||||
),
|
||||
'titleblacklist-forbidden',
|
||||
array(
|
||||
'message' => array(
|
||||
[
|
||||
'message' => [
|
||||
'key' => $errmsg,
|
||||
'params' => $params,
|
||||
),
|
||||
],
|
||||
'line' => $blacklisted->getRaw(),
|
||||
// As $errmsg usually represents a non-default message here, and ApiBase
|
||||
// uses ->inLanguage( 'en' )->useDatabase( false ) for all messages, it will
|
||||
// never result in useful 'info' text in the API. Try this, extra data seems
|
||||
// to override the default.
|
||||
'info' => 'TitleBlacklist prevents this title from being created',
|
||||
)
|
||||
]
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
@ -265,12 +265,12 @@ class TitleBlacklistHooks {
|
|||
$errlines = '* <code>' .
|
||||
implode( "</code>\n* <code>", array_map( 'wfEscapeWikiText', $ok ) ) .
|
||||
'</code>';
|
||||
$error = Html::openElement( 'div', array( 'class' => 'errorbox' ) ) .
|
||||
$error = Html::openElement( 'div', [ 'class' => 'errorbox' ] ) .
|
||||
$errmsg .
|
||||
"\n" .
|
||||
$errlines .
|
||||
Html::closeElement( 'div' ) . "\n" .
|
||||
Html::element( 'br', array( 'clear' => 'all' ) ) . "\n";
|
||||
Html::element( 'br', [ 'clear' => 'all' ] ) . "\n";
|
||||
|
||||
// $error will be displayed by the edit class
|
||||
}
|
||||
|
@ -283,8 +283,8 @@ class TitleBlacklistHooks {
|
|||
* @param Article $article
|
||||
*/
|
||||
public static function clearBlacklist( &$article, &$user,
|
||||
$content, $summary, $isminor, $iswatch, $section )
|
||||
{
|
||||
$content, $summary, $isminor, $iswatch, $section
|
||||
) {
|
||||
$title = $article->getTitle();
|
||||
if ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDBkey() == 'Titleblacklist' ) {
|
||||
TitleBlacklist::singleton()->invalidate();
|
||||
|
@ -311,10 +311,10 @@ class TitleBlacklistHooks {
|
|||
*/
|
||||
public static function onAPIGetAllowedParams( ApiBase &$module, array &$params ) {
|
||||
if ( $module instanceof ApiCreateAccount ) {
|
||||
$params['ignoretitleblacklist'] = array(
|
||||
$params['ignoretitleblacklist'] = [
|
||||
ApiBase::PARAM_TYPE => 'boolean',
|
||||
ApiBase::PARAM_DFLT => false
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -356,9 +356,9 @@ class TitleBlacklistHooks {
|
|||
$logEntry = new ManualLogEntry( 'titleblacklist', 'hit-username' );
|
||||
$logEntry->setPerformer( $user );
|
||||
$logEntry->setTarget( $title );
|
||||
$logEntry->setParameters( array(
|
||||
$logEntry->setParameters( [
|
||||
'4::entry' => $entry,
|
||||
) );
|
||||
] );
|
||||
$logid = $logEntry->insert();
|
||||
$logEntry->publish( $logid );
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ class TitleBlacklistHooks {
|
|||
* @return bool
|
||||
*/
|
||||
public static function scribuntoExternalLibraries( $engine, array &$extraLibraries ) {
|
||||
if( $engine == 'lua' ) {
|
||||
if ( $engine == 'lua' ) {
|
||||
$extraLibraries['mw.ext.TitleBlacklist'] = 'Scribunto_LuaTitleBlacklistLibrary';
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
class Scribunto_LuaTitleBlacklistLibrary extends Scribunto_LuaLibraryBase {
|
||||
public function register() {
|
||||
$lib = array(
|
||||
'test' => array( $this, 'test' ),
|
||||
);
|
||||
$lib = [
|
||||
'test' => [ $this, 'test' ],
|
||||
];
|
||||
|
||||
return $this->getEngine()->registerInterface(
|
||||
__DIR__ . '/mw.ext.TitleBlacklist.lua', $lib, array()
|
||||
__DIR__ . '/mw.ext.TitleBlacklist.lua', $lib, []
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -20,16 +20,16 @@ class Scribunto_LuaTitleBlacklistLibrary extends Scribunto_LuaLibraryBase {
|
|||
}
|
||||
$entry = TitleBlacklist::singleton()->isBlacklisted( $title, $action );
|
||||
if ( $entry ) {
|
||||
return array( array(
|
||||
return [ [
|
||||
'params' => $entry->getParams(),
|
||||
'regex' => $entry->getRegex(),
|
||||
'raw' => $entry->getRaw(),
|
||||
'version' => $entry->getFormatVersion(),
|
||||
'message' => $entry->getErrorMessage( $action ),
|
||||
'custommessage' => $entry->getCustomMessage()
|
||||
) );
|
||||
] ];
|
||||
}
|
||||
return array( null );
|
||||
return [ null ];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
//@{
|
||||
/**
|
||||
* @ingroup Extensions
|
||||
*/
|
||||
|
@ -70,9 +69,9 @@ class TitleBlacklist {
|
|||
}
|
||||
|
||||
$sources = $wgTitleBlacklistSources;
|
||||
$sources['local'] = array( 'type' => 'message' );
|
||||
$this->mBlacklist = array();
|
||||
foreach( $sources as $sourceName => $source ) {
|
||||
$sources['local'] = [ 'type' => 'message' ];
|
||||
$this->mBlacklist = [];
|
||||
foreach ( $sources as $sourceName => $source ) {
|
||||
$this->mBlacklist = array_merge(
|
||||
$this->mBlacklist,
|
||||
$this->parseBlacklist( $this->getBlacklistText( $source ), $sourceName )
|
||||
|
@ -156,7 +155,7 @@ class TitleBlacklist {
|
|||
*/
|
||||
public static function parseBlacklist( $list, $sourceName ) {
|
||||
$lines = preg_split( "/\r?\n/", $list );
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ( $lines as $line ) {
|
||||
$line = TitleBlacklistEntry :: newFromString( $line, $sourceName );
|
||||
if ( $line ) {
|
||||
|
@ -312,7 +311,7 @@ class TitleBlacklist {
|
|||
* @return Array of bad entries; empty array means blacklist is valid
|
||||
*/
|
||||
public function validate( $blacklist ) {
|
||||
$badEntries = array();
|
||||
$badEntries = [];
|
||||
foreach ( $blacklist as $e ) {
|
||||
wfSuppressWarnings();
|
||||
$regex = $e->getRegex();
|
||||
|
@ -337,7 +336,6 @@ class TitleBlacklist {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents a title blacklist entry
|
||||
*/
|
||||
|
@ -370,15 +368,15 @@ class TitleBlacklistEntry {
|
|||
private function filtersNewAccounts() {
|
||||
global $wgTitleBlacklistUsernameSources;
|
||||
|
||||
if( $wgTitleBlacklistUsernameSources === '*' ) {
|
||||
if ( $wgTitleBlacklistUsernameSources === '*' ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !$wgTitleBlacklistUsernameSources ) {
|
||||
if ( !$wgTitleBlacklistUsernameSources ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !is_array( $wgTitleBlacklistUsernameSources ) ) {
|
||||
if ( !is_array( $wgTitleBlacklistUsernameSources ) ) {
|
||||
throw new Exception(
|
||||
'$wgTitleBlacklistUsernameSources must be "*", false or an array' );
|
||||
}
|
||||
|
@ -462,7 +460,7 @@ class TitleBlacklistEntry {
|
|||
*/
|
||||
public static function newFromString( $line, $source ) {
|
||||
$raw = $line; // Keep line for raw data
|
||||
$options = array();
|
||||
$options = [];
|
||||
// Strip comments
|
||||
$line = preg_replace( "/^\\s*([^#]*)\\s*((.*)?)$/", "\\1", $line );
|
||||
$line = trim( $line );
|
||||
|
@ -507,7 +505,7 @@ class TitleBlacklistEntry {
|
|||
preg_match_all( '/{{\s*([a-z]+)\s*:\s*(.+?)\s*}}/', $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] ) ) {
|
||||
switch ( strtolower( $mword[1] ) ) {
|
||||
case 'ns':
|
||||
$cpf_result = CoreParserFunctions::ns( $wgParser, $mword[2] );
|
||||
if ( is_string( $cpf_result ) ) {
|
||||
|
@ -523,7 +521,7 @@ class TitleBlacklistEntry {
|
|||
}
|
||||
}
|
||||
// Return result
|
||||
if( $regex ) {
|
||||
if ( $regex ) {
|
||||
return new TitleBlacklistEntry( $regex, $options, $raw, $source );
|
||||
} else {
|
||||
return null;
|
||||
|
@ -561,14 +559,18 @@ class TitleBlacklistEntry {
|
|||
/**
|
||||
* @return string The format version
|
||||
*/
|
||||
public function getFormatVersion() { return $this->mFormatVersion; }
|
||||
public function getFormatVersion() {
|
||||
return $this->mFormatVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the format version
|
||||
*
|
||||
* @param $v string New version to set
|
||||
*/
|
||||
public function setFormatVersion( $v ) { $this->mFormatVersion = $v; }
|
||||
public function setFormatVersion( $v ) {
|
||||
$this->mFormatVersion = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the error message name for the blacklist entry.
|
||||
|
@ -585,5 +587,3 @@ class TitleBlacklistEntry {
|
|||
return $message ? $message : "titleblacklist-forbidden-{$operation}";
|
||||
}
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -47,10 +47,10 @@ class ApiQueryTitleBlacklist extends ApiBase {
|
|||
if ( !$title ) {
|
||||
if ( is_callable( [ $this, 'dieWithError' ] ) ) {
|
||||
$this->dieWithError(
|
||||
array( 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) )
|
||||
[ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ]
|
||||
);
|
||||
} else {
|
||||
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
|
||||
$this->dieUsageMsg( [ 'invalidtitle', $params['title'] ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,10 +59,10 @@ class ApiQueryTitleBlacklist extends ApiBase {
|
|||
);
|
||||
if ( $blacklisted instanceof TitleBlacklistEntry ) {
|
||||
// this title is blacklisted.
|
||||
$result = array(
|
||||
$result = [
|
||||
htmlspecialchars( $blacklisted->getRaw() ),
|
||||
htmlspecialchars( $params['title'] ),
|
||||
);
|
||||
];
|
||||
|
||||
$res = $this->getResult();
|
||||
$res->addValue( 'titleblacklist', 'result', 'blacklisted' );
|
||||
|
@ -78,33 +78,33 @@ class ApiQueryTitleBlacklist extends ApiBase {
|
|||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'title' => array(
|
||||
return [
|
||||
'title' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
),
|
||||
'action' => array(
|
||||
],
|
||||
'action' => [
|
||||
ApiBase::PARAM_DFLT => 'edit',
|
||||
ApiBase::PARAM_ISMULTI => false,
|
||||
ApiBase::PARAM_TYPE => array(
|
||||
ApiBase::PARAM_TYPE => [
|
||||
// createtalk and createpage are useless as they're treated exactly like create
|
||||
'create', 'edit', 'upload', 'createtalk', 'createpage', 'move', 'new-account'
|
||||
),
|
||||
),
|
||||
'nooverride' => array(
|
||||
],
|
||||
],
|
||||
'nooverride' => [
|
||||
ApiBase::PARAM_DFLT => false,
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ApiBase::getExamplesMessages()
|
||||
*/
|
||||
protected function getExamplesMessages() {
|
||||
return array(
|
||||
return [
|
||||
'action=titleblacklist&tbtitle=Foo'
|
||||
=> 'apihelp-titleblacklist-example-1',
|
||||
'action=titleblacklist&tbtitle=Bar&tbaction=edit'
|
||||
=> 'apihelp-titleblacklist-example-2',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
{
|
||||
"require-dev": {
|
||||
"jakub-onderka/php-parallel-lint": "0.9.2",
|
||||
"jakub-onderka/php-console-highlighter": "0.3.2"
|
||||
"jakub-onderka/php-console-highlighter": "0.3.2",
|
||||
"mediawiki/mediawiki-codesniffer": "0.7.2"
|
||||
},
|
||||
"scripts": {
|
||||
"fix": "phpcbf",
|
||||
"test": [
|
||||
"parallel-lint . --exclude node_modules --exclude vendor"
|
||||
"parallel-lint . --exclude node_modules --exclude vendor",
|
||||
"phpcs -p -s"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
18
phpcs.xml
Normal file
18
phpcs.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset>
|
||||
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
|
||||
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>
|
||||
<exclude name="PSR2.Classes.PropertyDeclaration.ScopeMissing"/><!-- T166381 -->
|
||||
<exclude name="Squiz.WhiteSpace.ScopeKeywordSpacing.Incorrect"/><!-- T166381 -->
|
||||
</rule>
|
||||
<rule ref="MediaWiki.NamingConventions.ValidGlobalName">
|
||||
<properties>
|
||||
<property name="ignoreList" type="array" value="$messageMemc" />
|
||||
</properties>
|
||||
</rule>
|
||||
<file>.</file>
|
||||
<arg name="extensions" value="php,php5,inc"/>
|
||||
<arg name="encoding" value="UTF-8"/>
|
||||
<exclude-pattern>vendor</exclude-pattern>
|
||||
<exclude-pattern>node_modules</exclude-pattern>
|
||||
</ruleset>
|
|
@ -24,12 +24,12 @@ class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|||
$this->doLogin();
|
||||
|
||||
TitleBlacklist::destroySingleton();
|
||||
$this->setMwGlobals( 'wgTitleBlacklistSources', array(
|
||||
array(
|
||||
$this->setMwGlobals( 'wgTitleBlacklistSources', [
|
||||
[
|
||||
'type' => 'file',
|
||||
'src' => __DIR__ . '/testSource',
|
||||
),
|
||||
) );
|
||||
],
|
||||
] );
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
|
@ -41,13 +41,13 @@ class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|||
* Verify we allow a title which is not blacklisted
|
||||
*/
|
||||
function testCheckingUnlistedTitle() {
|
||||
$unlisted = $this->doApiRequest( array(
|
||||
$unlisted = $this->doApiRequest( [
|
||||
'action' => 'titleblacklist',
|
||||
// evil_acc is blacklisted as <newaccountonly>
|
||||
'tbtitle' => 'evil_acc',
|
||||
'tbaction' => 'create',
|
||||
'tbnooverride' => true,
|
||||
) );
|
||||
] );
|
||||
|
||||
$this->assertEquals(
|
||||
'ok',
|
||||
|
@ -66,11 +66,11 @@ class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|||
$this->stashMwGlobals( 'wgGroupPermissions' );
|
||||
$wgGroupPermissions['*']['tboverride'] = true;
|
||||
|
||||
$unlisted = $this->doApiRequest( array(
|
||||
$unlisted = $this->doApiRequest( [
|
||||
'action' => 'titleblacklist',
|
||||
'tbtitle' => 'bar',
|
||||
'tbaction' => 'create',
|
||||
) );
|
||||
] );
|
||||
|
||||
$this->assertEquals(
|
||||
'ok',
|
||||
|
@ -83,12 +83,12 @@ class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|||
* Verify a blacklisted title gives out an error.
|
||||
*/
|
||||
function testCheckingBlackListedTitle() {
|
||||
$listed = $this->doApiRequest( array(
|
||||
$listed = $this->doApiRequest( [
|
||||
'action' => 'titleblacklist',
|
||||
'tbtitle' => 'bar',
|
||||
'tbaction' => 'create',
|
||||
'tbnooverride' => true,
|
||||
) );
|
||||
] );
|
||||
|
||||
$this->assertEquals(
|
||||
'blacklisted',
|
||||
|
@ -119,16 +119,16 @@ class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|||
* Tests integration with the AntiSpoof extension
|
||||
*/
|
||||
function testAntiSpoofIntegration() {
|
||||
if ( !class_exists( 'AntiSpoof') ) {
|
||||
if ( !class_exists( 'AntiSpoof' ) ) {
|
||||
$this->markTestSkipped( "This test requires the AntiSpoof extension" );
|
||||
}
|
||||
|
||||
$listed = $this->doApiRequest( array(
|
||||
$listed = $this->doApiRequest( [
|
||||
'action' => 'titleblacklist',
|
||||
'tbtitle' => 'AVVVV',
|
||||
'tbaction' => 'create',
|
||||
'tbnooverride' => true,
|
||||
) );
|
||||
] );
|
||||
|
||||
$this->assertEquals(
|
||||
'blacklisted',
|
||||
|
|
|
@ -12,7 +12,7 @@ class TitleBlacklistAuthenticationRequestTest extends AuthenticationRequestTestC
|
|||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function getInstance( array $args = [ ] ) {
|
||||
protected function getInstance( array $args = [] ) {
|
||||
return new TitleBlacklistAuthenticationRequest();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue