MediaWiki master
DumpNamespaceFilter.php
Go to the documentation of this file.
1<?php
17 public $invert = false;
18
20 public $namespaces = [];
21
26 public function __construct( &$sink, $param ) {
27 parent::__construct( $sink );
28
29 $constants = [
30 "NS_MAIN" => NS_MAIN,
31 "NS_TALK" => NS_TALK,
32 "NS_USER" => NS_USER,
33 "NS_USER_TALK" => NS_USER_TALK,
34 "NS_PROJECT" => NS_PROJECT,
35 "NS_PROJECT_TALK" => NS_PROJECT_TALK,
36 "NS_FILE" => NS_FILE,
37 "NS_FILE_TALK" => NS_FILE_TALK,
38 "NS_MEDIAWIKI" => NS_MEDIAWIKI,
39 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK,
40 "NS_TEMPLATE" => NS_TEMPLATE,
41 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK,
42 "NS_HELP" => NS_HELP,
43 "NS_HELP_TALK" => NS_HELP_TALK,
44 "NS_CATEGORY" => NS_CATEGORY,
45 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK ];
46
47 if ( $param[0] == '!' ) {
48 $this->invert = true;
49 $param = substr( $param, 1 );
50 }
51
52 foreach ( explode( ',', $param ) as $key ) {
53 $key = trim( $key );
54 if ( isset( $constants[$key] ) ) {
55 $ns = $constants[$key];
56 $this->namespaces[$ns] = true;
57 } elseif ( is_numeric( $key ) ) {
58 $ns = intval( $key );
59 $this->namespaces[$ns] = true;
60 } else {
61 throw new InvalidArgumentException( "Unrecognized namespace key '$key'\n" );
62 }
63 }
64 }
65
70 protected function pass( $page ) {
71 $match = isset( $this->namespaces[$page->page_namespace] );
72 return $this->invert xor $match;
73 }
74}
const NS_HELP
Definition Defines.php:63
const NS_USER
Definition Defines.php:53
const NS_FILE
Definition Defines.php:57
const NS_MEDIAWIKI_TALK
Definition Defines.php:60
const NS_MAIN
Definition Defines.php:51
const NS_PROJECT_TALK
Definition Defines.php:56
const NS_MEDIAWIKI
Definition Defines.php:59
const NS_TEMPLATE
Definition Defines.php:61
const NS_FILE_TALK
Definition Defines.php:58
const NS_HELP_TALK
Definition Defines.php:64
const NS_CATEGORY_TALK
Definition Defines.php:66
const NS_TALK
Definition Defines.php:52
const NS_USER_TALK
Definition Defines.php:54
const NS_PROJECT
Definition Defines.php:55
const NS_CATEGORY
Definition Defines.php:65
const NS_TEMPLATE_TALK
Definition Defines.php:62
DumpOutput $sink
FIXME will need to be made protected whenever legacy code is updated.
__construct(&$sink, $param)