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