s7eph4n /
PurgePage
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 PoolWorkArticleView; |
||
| 6 | |||
| 7 | class PurgePage { |
||
| 8 | |||
| 9 | public static function init() { |
||
|
0 ignored issues
–
show
|
|||
| 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 |
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: