Merge ".mailmap: Correct two contributor names"
[mediawiki.git] / includes / export / DumpNamespaceFilter.php
blob57f1bd79b356fa93e4b3eef8a25ef26c29a1b84e
1 <?php
2 /**
3 * Dump output filter to include or exclude pages in a given set of namespaces.
5 * Copyright © 2003, 2005, 2006 Brooke Vibber <bvibber@wikimedia.org>
6 * https://www.mediawiki.org/
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
23 * @file
26 /**
27 * @ingroup Dump
29 class DumpNamespaceFilter extends DumpFilter {
30 /** @var bool */
31 public $invert = false;
33 /** @var array */
34 public $namespaces = [];
36 /**
37 * @param DumpOutput &$sink
38 * @param string $param
40 public function __construct( &$sink, $param ) {
41 parent::__construct( $sink );
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 ];
61 if ( $param[0] == '!' ) {
62 $this->invert = true;
63 $param = substr( $param, 1 );
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" );
80 /**
81 * @param stdClass $page
82 * @return bool
84 protected function pass( $page ) {
85 $match = isset( $this->namespaces[$page->page_namespace] );
86 return $this->invert xor $match;