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 | use Job; |
||
6 | use JobQueueGroup; |
||
7 | use Title; |
||
8 | |||
9 | class PurgePage { |
||
10 | |||
11 | public static function init() { |
||
0 ignored issues
–
show
|
|||
12 | $GLOBALS[ 'wgExtensionMessagesFiles' ][ 'PurgePageMagic' ] = __DIR__ . '/PurgePage.magic.php'; |
||
13 | $GLOBALS[ 'wgJobClasses' ][ 'parsePage' ] = 'PurgePage\\PageParseJob'; |
||
14 | } |
||
15 | |||
16 | public static function registerParserFunction( \Parser &$parser ) { |
||
17 | |||
18 | $parser->setFunctionHook( 'purge', function () { |
||
19 | |||
20 | $params = func_get_args(); |
||
21 | |||
22 | if ( isset( $params[ 1 ] ) ) { |
||
23 | |||
24 | $parser = $params[ 0 ]; |
||
25 | $pageName = $params[ 1 ]; |
||
26 | |||
27 | $title = Title::newFromText( $pageName ); |
||
28 | |||
29 | if ( $title !== null && $title->isContentPage() && $title->exists() ) { |
||
30 | /** @var \ParserOptions $parserOptions */ |
||
31 | $parserOptions = $parser->getOptions(); |
||
32 | $job = Job::factory( 'parsePage', $title, [ 'user' => $parserOptions->getUser(), 'lang' => $parserOptions->getUserLang() ] ); |
||
33 | JobQueueGroup::singleton()->lazyPush( $job ); |
||
34 | } |
||
35 | |||
36 | |||
37 | } |
||
38 | |||
39 | } ); |
||
40 | |||
41 | return true; |
||
42 | } |
||
43 | } |
||
44 |
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: