-
Notifications
You must be signed in to change notification settings - Fork 0
/
DpleFeatureNamespace.php
119 lines (99 loc) · 2.96 KB
/
DpleFeatureNamespace.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}
/**
* @brief Class DpleFeatureNamespace.
*
* @file
*
* @ingroup Extensions
* @ingroup Extensions-DynamicPageListEngine
*
* @author [RV1971](http://www.mediawiki.org/wiki/User:RV1971)
*
*/
/**
* @brief Selection by namespace.
*
* Recognizes the parameters `namespace` and `notnamespace` which may
* be a namespace name or index or an array thereof. Any invalid
* value, including the empty string, is interpreted as the main
* namespace, for compatibility with
* [Extension:DynamicPageList](https://www.mediawiki.org/wiki/Extension:DynamicPageList_(Wikimedia%29).
*
* If `namespace` is an array, the result is (obviously) the union of
* the record sets satisfying its elements, unlike other parameters
* (including `notnamespace`) where the result is the intersection.
*
* @ingroup Extensions
* @ingroup Extensions-DynamicPageListEngine
*/
class DpleFeatureNamespace extends DpleFeatureBase
implements DpleFeatureInterface {
/* == private variables == */
/** @brief Array of [Namespace]
* (http://www.mediawiki.org/wiki/Help:Namespace) indexes to
* choose from.*/
private $namespaces_;
/** @brief Array of [Namespace]
* (http://www.mediawiki.org/wiki/Help:Namespace) indexes to
* exclude.*/
private $notNamespaces_;
/* == magic methods == */
/// Constructor. Evaluate parameters.
public function __construct( array $params, array &$features ) {
parent::__construct( $features );
if ( isset( $params['namespace'] ) ) {
$this->namespaces_ =
array_map( array( $this, 'parseNamespace' ),
(array)$params['namespace'] );
}
if ( isset( $params['notnamespace'] ) ) {
$this->notNamespaces_ =
array_map( array( $this, 'parseNamespace' ),
(array)$params['notnamespace'] );
}
}
/* == accessors == */
/// Get @ref $namespaces_.
public function getNamespaces() {
return $this->namespaces_;
}
/// Get @ref $notNamespaces_.
public function getNotNamespaces() {
return $this->notNamespaces_;
}
/// Get the database cost generated by this feature instance.
public function getCost() {
return isset( $this->namespaces_ )
|| isset( $this->notNamespaces_ )
? parent::getCost() : 0;
}
/* == operations == */
/// Modify a given query. @copydetails DpleFeatureBase::modifyQuery()
public function modifyQuery( DpleQuery &$query ) {
switch ( count( $this->namespaces_ ) ) {
case 0:
break;
case 1:
$query->addConds( "page_namespace = {$this->namespaces_[0]}" );
break;
default:
$query->addConds( 'page_namespace IN ('
. implode( ',', $this->namespaces_ ) . ')' );
}
switch ( count( $this->notNamespaces_ ) ) {
case 0:
break;
case 1:
$query->addConds(
"page_namespace != {$this->notNamespaces_[0]}" );
break;
default:
$query->addConds( 'page_namespace NOT IN ('
. implode( ',', $this->notNamespaces_ ) . ')' );
}
}
}