mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TitleBlacklist
synced 2024-11-27 15:30:48 +00:00
4382b2f8e1
* Class names should not have underscores * No class alias is created, as there is no usage expected outside of the extension. Change-Id: I50f1271a773d1045262135c707496a289f6ddf28
54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\TitleBlacklist;
|
|
|
|
use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LibraryBase;
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
class LuaTitleBlacklistLibrary extends LibraryBase {
|
|
public function register() {
|
|
$lib = [
|
|
'test' => [ $this, 'test' ],
|
|
];
|
|
|
|
return $this->getEngine()->registerInterface(
|
|
__DIR__ . '/mw.ext.TitleBlacklist.lua', $lib, []
|
|
);
|
|
}
|
|
|
|
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 == '' ) {
|
|
$page = $this->getParser()->getPage();
|
|
if ( !$page ) {
|
|
// Nothing to check
|
|
return [ null ];
|
|
}
|
|
$title = MediaWikiServices::getInstance()->getTitleFormatter()->getPrefixedText( $page );
|
|
}
|
|
$entry = TitleBlacklist::singleton()->isBlacklisted( $title, $action );
|
|
|
|
// check if not whitelisted
|
|
$whitelist = TitleBlacklist::singleton()->isWhitelisted( $title, $action );
|
|
if ( $whitelist ) {
|
|
// page is whitelisted, don't continue and return a null object
|
|
return [ null ];
|
|
}
|
|
|
|
if ( $entry ) {
|
|
return [ [
|
|
'params' => $entry->getParams(),
|
|
'regex' => $entry->getRegex(),
|
|
'raw' => $entry->getRaw(),
|
|
'version' => $entry->getFormatVersion(),
|
|
'message' => $entry->getErrorMessage( $action ),
|
|
'custommessage' => $entry->getCustomMessage()
|
|
] ];
|
|
}
|
|
return [ null ];
|
|
}
|
|
|
|
}
|