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