summaryrefslogtreecommitdiff
path: root/extensions/TitleBlacklist/TitleBlacklist.library.php
blob: fd767d1e51a086abd99635908a521fb926c4c75d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

class Scribunto_LuaTitleBlacklistLibrary extends Scribunto_LuaLibraryBase {
	public function register() {
		$lib = array(
			'test' => array( $this, 'test' ),
		);

		return $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 );
	}

}