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