MediaWiki master
DumpNamespaceFilter.php
Go to the documentation of this file.
1<?php
12namespace MediaWiki\Export;
13
14use InvalidArgumentException;
15
21 public $invert = false;
22
24 public $namespaces = [];
25
30 public function __construct( &$sink, $param ) {
31 parent::__construct( $sink );
32
33 $constants = [
34 "NS_MAIN" => NS_MAIN,
35 "NS_TALK" => NS_TALK,
36 "NS_USER" => NS_USER,
37 "NS_USER_TALK" => NS_USER_TALK,
38 "NS_PROJECT" => NS_PROJECT,
39 "NS_PROJECT_TALK" => NS_PROJECT_TALK,
40 "NS_FILE" => NS_FILE,
41 "NS_FILE_TALK" => NS_FILE_TALK,
42 "NS_MEDIAWIKI" => NS_MEDIAWIKI,
43 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK,
44 "NS_TEMPLATE" => NS_TEMPLATE,
45 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK,
46 "NS_HELP" => NS_HELP,
47 "NS_HELP_TALK" => NS_HELP_TALK,
48 "NS_CATEGORY" => NS_CATEGORY,
49 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK ];
50
51 if ( $param[0] == '!' ) {
52 $this->invert = true;
53 $param = substr( $param, 1 );
54 }
55
56 foreach ( explode( ',', $param ) as $key ) {
57 $key = trim( $key );
58 if ( isset( $constants[$key] ) ) {
59 $ns = $constants[$key];
60 $this->namespaces[$ns] = true;
61 } elseif ( is_numeric( $key ) ) {
62 $ns = intval( $key );
63 $this->namespaces[$ns] = true;
64 } else {
65 throw new InvalidArgumentException( "Unrecognized namespace key '$key'\n" );
66 }
67 }
68 }
69
74 protected function pass( $page ) {
75 $match = isset( $this->namespaces[$page->page_namespace] );
76 return $this->invert xor $match;
77 }
78}
79
81class_alias( DumpNamespaceFilter::class, 'DumpNamespaceFilter' );
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.