-
Notifications
You must be signed in to change notification settings - Fork 0
/
DpleFeatureCheck.php
124 lines (100 loc) · 2.97 KB
/
DpleFeatureCheck.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
120
121
122
123
124
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}
/**
* @brief Class DpleFeatureCheck.
*
* @file
*
* @ingroup Extensions
* @ingroup Extensions-DynamicPageListEngine
*
* @author [RV1971](http://www.mediawiki.org/wiki/User:RV1971)
*
*/
/**
* @brief Check whether the whole specification is acceptable.
*
* @ingroup Extensions
* @ingroup Extensions-DynamicPageListEngine
*/
class DpleFeatureCheck extends DpleFeatureBase
implements DpleFeatureInterface {
/* == private static variables == */
/// Whether the global configuration has been initialized.
private static $intitialized_ = false;
/* == public static methods == */
/// Initialize the global configuration.
public static function initConf() {
if ( self::$intitialized_ ) {
return;
}
self::$intitialized_ = true;
global $wgDpleMaxCost;
global $wgDLPmaxCategories, $wgDLPAllowUnlimitedCategories;
/**
* If the global configuration variable @ref $wgDpleMaxCost is
* unset, initialize it with the corresponding configuration
* from
* [Extension:DynamicPageList](https://www.mediawiki.org/wiki/Extension:DynamicPageList_(Wikimedia%29);
* if the latter is unset as well, initialize with the
* defaults from Extension:DynamicPageList.
*
* For simplicity of implementation, 'unlimited' is
* implemented just with unrealistically large numbers.
*/
if( !isset( $wgDpleMaxCost ) ) {
if( isset( $wgDLPAllowUnlimitedCategories )
&& $wgDLPAllowUnlimitedCategories ) {
$wgDpleMaxCost = 1000;
} elseif( isset( $wgDLPmaxCategories ) ) {
$wgDpleMaxCost = $wgDLPmaxCategories;
} else {
$wgDpleMaxCost = 6;
}
}
}
/* == private data members == */
private $totalCost_; ///< Total cost of the query.
/* == magic methods == */
/// Constructor. Evaluate parameters.
public function __construct( array $params, array &$features ) {
/** Call initConf(). */
self::initConf();
parent::__construct( $features );
}
/* == accessors == */
/**
* @brief Get @ref $totalCost_.
*
* Supplies a value only after invocation of modifyQuery().
*/
public function getTotalCost() {
return $this->totalCost_;
}
/* == operations == */
/// Modify a given query. @copydetails DpleFeatureBase::modifyQuery()
public function modifyQuery( DpleQuery &$query ) {
global $wgDpleMaxCost;
/** Throw an exception if there is no WHERE clause. */
if ( !$query->getConds() ) {
throw new Scribunto_LuaError(
wfMessage( 'dple-error-no-criteria' )->text() );
}
/** Sum up the total cost. */
$this->totalCost_ = 0;
foreach ( $this->getFeatures() as $feature ) {
$this->totalCost_ += $feature->getCost();
}
/** Throw an exception if @ref $totalCost_ exceeds @ref
* $wgDpleMaxCost#. */
if( $this->totalCost_ > $wgDpleMaxCost ) {
throw new Scribunto_LuaError(
wfMessage( 'dple-error-too-expensive',
$this->totalCost_,
$wgDpleMaxCost )->text() );
}
}
}