Completed
Push — master ( 2df768...364599 )
by Stephan
02:08
created

PurgePage::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace PurgePage;
4
5
class PurgePage {
6
7
	public static function init() {
0 ignored issues
show
Coding Style introduced by
init uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
8
		$GLOBALS[ 'wgExtensionMessagesFiles' ][ 'PurgePageMagic' ] = __DIR__ . '/PurgePage.magic.php';
9
	}
10
11
	public static function registerParserFunction( \Parser &$parser ) {
12
13
		$parser->setFunctionHook( 'purge', function ( $parser ) {
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
15
			$params = func_get_args();
16
17
			if ( isset( $params[ 0 ] ) && isset( $params[ 1 ] ) ) {
18
19
				$pageName = $params[ 1 ];
20
21
				$title = \Title::newFromText( $pageName );
22
23
				if ( $title->isContentPage() && $title->exists() ) {
24
					\WikiPage::factory( $title )->doPurge();
25
				}
26
27
			}
28
29
		} );
30
31
		return true;
32
	}
33
}
34