60
61
* Add a set of tables to the internal array
61
* @param mixed $tables Table name or array of table names
62
* @param mixed $alias Table alias, or null for no alias. Cannot be used with multiple tables
62
* @param $tables mixed Table name or array of table names
63
* @param $alias mixed Table alias, or null for no alias. Cannot be
64
* used with multiple tables
64
66
protected function addTables($tables, $alias = null) {
65
67
if (is_array($tables)) {
77
79
* Get the SQL for a table name with alias
78
* @param string $table Table name
79
* @param string $alias Alias
80
* @param $table string Table name
81
* @param $alias string Alias
80
82
* @return string SQL
82
84
protected function getAliasedName($table, $alias) {
87
89
* Add a set of JOIN conditions to the internal array
89
* JOIN conditions are formatted as array( tablename => array(jointype, conditions)
90
* e.g. array('page' => array('LEFT JOIN', 'page_id=rev_page'))
91
* @param array $join_conds JOIN conditions
91
* JOIN conditions are formatted as array( tablename => array(jointype,
92
* conditions) e.g. array('page' => array('LEFT JOIN',
93
* 'page_id=rev_page')) . conditions may be a string or an
94
* addWhere()-style array
95
* @param $join_conds array JOIN conditions
93
97
protected function addJoinConds($join_conds) {
94
98
if(!is_array($join_conds))
111
115
* Same as addFields(), but add the fields only if a condition is met
112
* @param mixed $value See addFields()
113
* @param bool $condition If false, do nothing
116
* @param $value mixed See addFields()
117
* @param $condition bool If false, do nothing
114
118
* @return bool $condition
116
120
protected function addFieldsIf($value, $condition) {
131
135
* For example, array('foo=bar', 'baz' => 3, 'bla' => 'foo') translates
132
136
* to "foo=bar AND baz='3' AND bla='foo'"
133
* @param mixed $value String or array
137
* @param $value mixed String or array
135
139
protected function addWhere($value) {
136
140
if (is_array($value)) {
147
151
* Same as addWhere(), but add the WHERE clauses only if a condition is met
148
* @param mixed $value See addWhere()
149
* @param bool $condition If false, do nothing
152
* @param $value mixed See addWhere()
153
* @param $condition boolIf false, do nothing
150
154
* @return bool $condition
152
156
protected function addWhereIf($value, $condition) {
161
165
* Equivalent to addWhere(array($field => $value))
162
* @param string $field Field name
163
* @param string $value Value; ignored if null or empty array;
166
* @param $field string Field name
167
* @param $value string Value; ignored if null or empty array;
165
169
protected function addWhereFld($field, $value) {
166
170
// Use count() to its full documented capabilities to simultaneously
173
177
* Add a WHERE clause corresponding to a range, and an ORDER BY
174
178
* clause to sort in the right direction
175
* @param string $field Field name
176
* @param string $dir If 'newer', sort in ascending order, otherwise sort in descending order
177
* @param string $start Value to start the list at. If $dir == 'newer' this is the lower boundary, otherwise it's the upper boundary
178
* @param string $end Value to end the list at. If $dir == 'newer' this is the upper boundary, otherwise it's the lower boundary
179
* @param $field string Field name
180
* @param $dir string If 'newer', sort in ascending order, otherwise
181
* sort in descending order
182
* @param $start string Value to start the list at. If $dir == 'newer'
183
* this is the lower boundary, otherwise it's the upper boundary
184
* @param $end string Value to end the list at. If $dir == 'newer' this
185
* is the upper boundary, otherwise it's the lower boundary
186
* @param $sort bool If false, don't add an ORDER BY clause
180
protected function addWhereRange($field, $dir, $start, $end) {
188
protected function addWhereRange($field, $dir, $start, $end, $sort = true) {
181
189
$isDirNewer = ($dir === 'newer');
182
190
$after = ($isDirNewer ? '>=' : '<=');
183
191
$before = ($isDirNewer ? '<=' : '>=');
189
197
if (!is_null($end))
190
198
$this->addWhere($field . $before . $db->addQuotes($end));
192
$order = $field . ($isDirNewer ? '' : ' DESC');
193
if (!isset($this->options['ORDER BY']))
194
$this->addOption('ORDER BY', $order);
196
$this->addOption('ORDER BY', $this->options['ORDER BY'] . ', ' . $order);
201
$order = $field . ($isDirNewer ? '' : ' DESC');
202
if (!isset($this->options['ORDER BY']))
203
$this->addOption('ORDER BY', $order);
205
$this->addOption('ORDER BY', $this->options['ORDER BY'] . ', ' . $order);
200
* Add an option such as LIMIT or USE INDEX
201
* @param string $name Option name
202
* @param string $value Option value
210
* Add an option such as LIMIT or USE INDEX. If an option was set
211
* before, the old value will be overwritten
212
* @param $name string Option name
213
* @param $value string Option value
204
215
protected function addOption($name, $value = null) {
205
216
if (is_null($value))
246
* Add information (title and namespace) about a Title object to a result array
247
* @param array $arr Result array à la ApiResult
248
* @param Title $title Title object
249
* @param string $prefix Module prefix
258
* Add information (title and namespace) about a Title object to a
260
* @param $arr array Result array à la ApiResult
261
* @param $title Title
262
* @param $prefix string Module prefix
251
264
public static function addTitleInfo(&$arr, $title, $prefix='') {
252
265
$arr[$prefix . 'ns'] = intval($title->getNamespace());
273
286
* Add a sub-element under the page element with the given page ID
274
* @param int $pageId Page ID
275
* @param array $data Data array à la ApiResult
287
* @param $pageId int Page ID
288
* @param $data array Data array à la ApiResult
289
* @return bool Whether the element fit in the result
277
291
protected function addPageSubItems($pageId, $data) {
278
292
$result = $this->getResult();
279
293
$result->setIndexedTagName($data, $this->getModulePrefix());
280
$result->addValue(array ('query', 'pages', intval($pageId)),
294
return $result->addValue(array('query', 'pages', intval($pageId)),
281
295
$this->getModuleName(),
300
* Same as addPageSubItems(), but one element of $data at a time
301
* @param $pageId int Page ID
302
* @param $data array Data array à la ApiResult
303
* @param $elemname string XML element name. If null, getModuleName()
305
* @return bool Whether the element fit in the result
307
protected function addPageSubItem($pageId, $item, $elemname = null) {
308
if(is_null($elemname))
309
$elemname = $this->getModulePrefix();
310
$result = $this->getResult();
311
$fit = $result->addValue(array('query', 'pages', $pageId,
312
$this->getModuleName()), null, $item);
315
$result->setIndexedTagName_internal(array('query', 'pages', $pageId,
316
$this->getModuleName()), $elemname);
286
321
* Set a query-continue value
287
* @param $paramName Parameter name
288
* @param $paramValue Parameter value
322
* @param $paramName string Parameter name
323
* @param $paramValue string Parameter value
290
325
protected function setContinueEnumParameter($paramName, $paramValue) {
292
326
$paramName = $this->encodeParamName($paramName);
293
327
$msg = array( $paramName => $paramValue );
328
$this->getResult()->disableSizeCheck();
294
329
$this->getResult()->addValue('query-continue', $this->getModuleName(), $msg);
330
$this->getResult()->enableSizeCheck();
298
* Get the Query database connection (readonly)
334
* Get the Query database connection (read-only)
299
335
* @return Database
301
337
protected function getDB() {
308
344
* Selects the query database connection with the given name.
309
* If no such connection has been requested before, it will be created.
310
* Subsequent calls with the same $name will return the same connection
311
* as the first, regardless of $db or $groups new values.
312
* @param string $name Name to assign to the database connection
313
* @param int $db One of the DB_* constants
314
* @param array $groups Query groups
345
* See ApiQuery::getNamedDB() for more information
346
* @param $name string Name to assign to the database connection
347
* @param $db int One of the DB_* constants
348
* @param $groups array Query groups
315
349
* @return Database
317
351
public function selectNamedDB($name, $db, $groups) {