Completed
Push — master ( 1c6126...5693c9 )
by Stephan
02:03
created

PurgePage::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace PurgePage;
4
5
use PoolWorkArticleView;
6
7
class PurgePage {
8
9
	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...
10
		$GLOBALS[ 'wgExtensionMessagesFiles' ][ 'PurgePageMagic' ] = __DIR__ . '/PurgePage.magic.php';
11
		$GLOBALS[ 'wgJobClasses' ][ 'parsePage' ] = 'PurgePage\\PageParseJob';
12
	}
13
14
	public static function registerParserFunction( \Parser &$parser ) {
15
16
		$parser->setFunctionHook( 'purge', function () {
17
18
			$params = func_get_args();
19
20
			if ( isset( $params[ 1 ] ) ) {
21
22
				$parser = $params[ 0 ];
23
				$pageName = $params[ 1 ];
24
25
				$title = \Title::newFromText( $pageName );
26
				$job = \Job::factory( 'parsePage', $title, [ 'parseroptions' => $parser->getOptions() ] );
27
28
				\JobQueueGroup::singleton()->lazyPush( [ $job ] );
29
30
			}
31
32
		} );
33
34
		return true;
35
	}
36
}
37