Debian Codegraph @

extensions/TitleBlacklist/includes/LuaTitleBlacklistLibrary.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\TitleBlacklist;
4
5 use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LibraryBase;
6 use MediaWiki\MediaWikiServices;
7
8 class LuaTitleBlacklistLibrary extends LibraryBase {
9 public function register() {
10 $lib = [
11 'test' => [ $this, 'test' ],
12 ];
13
14 return $this->getEngine()->registerInterface(
15 __DIR__ . '/mw.ext.TitleBlacklist.lua', $lib, []
16 );
17 }
18
19 public function test( $action = null, $title = null ) {
20 $this->checkType( 'mw.ext.TitleBlacklist.test', 1, $action, 'string' );
21 $this->checkTypeOptional( 'mw.ext.TitleBlacklist.test', 2, $title, 'string', '' );
22 $this->incrementExpensiveFunctionCount();
23 if ( $title == '' ) {
24 $page = $this->getParser()->getPage();
25 if ( !$page ) {
26 // Nothing to check
27 return [ null ];
28 }
29 $title = MediaWikiServices::getInstance()->getTitleFormatter()->getPrefixedText( $page );
30 }
31 $entry = TitleBlacklist::singleton()->isBlacklisted( $title, $action );
32
33 // check if not whitelisted
34 $whitelist = TitleBlacklist::singleton()->isWhitelisted( $title, $action );
35 if ( $whitelist ) {
36 // page is whitelisted, don't continue and return a null object
37 return [ null ];
38 }
39
40 if ( $entry ) {
41 return [ [
42 'params' => $entry->getParams(),
43 'regex' => $entry->getRegex(),
44 'raw' => $entry->getRaw(),
45 'version' => $entry->getFormatVersion(),
46 'message' => $entry->getErrorMessage( $action ),
47 'custommessage' => $entry->getCustomMessage()
48 ] ];
49 }
50 return [ null ];
51 }
52
53 }