Completed
Push — master ( 364599...be4002 )
by Stephan
02:10
created

PurgePage.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PurgePage;
4
5
class PurgePage {
6
7
	public static function init() {
0 ignored issues
show
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 () {
14
15
			$params = func_get_args();
16
17
			if ( 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