2006-10-01 20:17:16 +00:00
|
|
|
<?php
|
2010-02-24 13:34:11 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2006-10-01 20:17:16 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Sep 7, 2006
|
|
|
|
|
*
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
|
2006-10-01 20:17:16 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-10-01 20:17:16 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2006-10-01 20:17:16 +00:00
|
|
|
*/
|
|
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
2007-05-20 23:31:44 +00:00
|
|
|
* This is a base class for all Query modules.
|
2009-02-13 14:13:03 +00:00
|
|
|
* It provides some common functionality such as constructing various SQL
|
|
|
|
|
* queries.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
2006-10-01 20:17:16 +00:00
|
|
|
abstract class ApiQueryBase extends ApiBase {
|
|
|
|
|
|
2008-05-10 10:49:26 +00:00
|
|
|
private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds;
|
2006-10-16 00:08:03 +00:00
|
|
|
|
2011-12-11 20:43:42 +00:00
|
|
|
/**
|
2014-03-25 17:22:11 +00:00
|
|
|
* @param ApiQuery $queryModule
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $moduleName
|
|
|
|
|
* @param string $paramPrefix
|
2011-12-11 20:43:42 +00:00
|
|
|
*/
|
2014-03-25 17:22:11 +00:00
|
|
|
public function __construct( ApiQuery $queryModule, $moduleName, $paramPrefix = '' ) {
|
|
|
|
|
parent::__construct( $queryModule->getMain(), $moduleName, $paramPrefix );
|
|
|
|
|
$this->mQueryModule = $queryModule;
|
2007-05-15 02:16:48 +00:00
|
|
|
$this->mDb = null;
|
2006-10-30 00:18:05 +00:00
|
|
|
$this->resetQueryParams();
|
|
|
|
|
}
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
/**
|
2010-07-23 10:15:29 +00:00
|
|
|
* Get the cache mode for the data generated by this module. Override
|
|
|
|
|
* this in the module subclass. For possible return values and other
|
|
|
|
|
* details about cache modes, see ApiMain::setCacheMode()
|
2010-07-23 07:17:56 +00:00
|
|
|
*
|
2010-07-23 07:33:40 +00:00
|
|
|
* Public caching will only be allowed if *all* the modules that supply
|
2010-07-23 07:17:56 +00:00
|
|
|
* data for a given request return a cache mode of public.
|
2011-05-08 21:47:01 +00:00
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $params
|
2011-05-08 21:47:01 +00:00
|
|
|
* @return string
|
2010-07-23 07:17:56 +00:00
|
|
|
*/
|
|
|
|
|
public function getCacheMode( $params ) {
|
|
|
|
|
return 'private';
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Blank the internal arrays with query parameters
|
|
|
|
|
*/
|
2006-10-30 00:18:05 +00:00
|
|
|
protected function resetQueryParams() {
|
2010-02-24 13:34:11 +00:00
|
|
|
$this->tables = array();
|
|
|
|
|
$this->where = array();
|
|
|
|
|
$this->fields = array();
|
|
|
|
|
$this->options = array();
|
|
|
|
|
$this->join_conds = array();
|
2006-10-20 07:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Add a set of tables to the internal array
|
2014-07-03 19:29:02 +00:00
|
|
|
* @param string|string[] $tables Table name or array of table names
|
|
|
|
|
* @param string|null $alias Table alias, or null for no alias. Cannot be
|
2009-02-13 14:13:03 +00:00
|
|
|
* used with multiple tables
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addTables( $tables, $alias = null ) {
|
|
|
|
|
if ( is_array( $tables ) ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !is_null( $alias ) ) {
|
|
|
|
|
ApiBase::dieDebug( __METHOD__, 'Multiple table aliases not supported' );
|
|
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->tables = array_merge( $this->tables, $tables );
|
2007-07-30 08:09:15 +00:00
|
|
|
} else {
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !is_null( $alias ) ) {
|
2011-04-30 23:18:34 +00:00
|
|
|
$this->tables[$alias] = $tables;
|
|
|
|
|
} else {
|
|
|
|
|
$this->tables[] = $tables;
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2007-07-30 08:09:15 +00:00
|
|
|
}
|
2006-10-20 07:10:18 +00:00
|
|
|
}
|
2010-02-24 13:34:11 +00:00
|
|
|
|
2008-05-10 10:49:26 +00:00
|
|
|
/**
|
|
|
|
|
* Add a set of JOIN conditions to the internal array
|
|
|
|
|
*
|
2009-02-13 14:13:03 +00:00
|
|
|
* JOIN conditions are formatted as array( tablename => array(jointype,
|
|
|
|
|
* conditions) e.g. array('page' => array('LEFT JOIN',
|
|
|
|
|
* 'page_id=rev_page')) . conditions may be a string or an
|
|
|
|
|
* addWhere()-style array
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $join_conds JOIN conditions
|
2008-05-10 10:49:26 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addJoinConds( $join_conds ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !is_array( $join_conds ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
ApiBase::dieDebug( __METHOD__, 'Join conditions have to be arrays' );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->join_conds = array_merge( $this->join_conds, $join_conds );
|
2008-05-10 10:49:26 +00:00
|
|
|
}
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Add a set of fields to select to the internal array
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array|string $value Field name or array of field names
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addFields( $value ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( is_array( $value ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->fields = array_merge( $this->fields, $value );
|
2010-02-24 13:34:11 +00:00
|
|
|
} else {
|
2006-10-20 07:10:18 +00:00
|
|
|
$this->fields[] = $value;
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2006-10-20 07:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Same as addFields(), but add the fields only if a condition is met
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array|string $value See addFields()
|
|
|
|
|
* @param bool $condition If false, do nothing
|
2008-05-10 09:29:34 +00:00
|
|
|
* @return bool $condition
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addFieldsIf( $value, $condition ) {
|
|
|
|
|
if ( $condition ) {
|
|
|
|
|
$this->addFields( $value );
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2006-10-21 08:26:32 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2006-10-21 08:26:32 +00:00
|
|
|
return false;
|
2006-10-20 07:10:18 +00:00
|
|
|
}
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Add a set of WHERE clauses to the internal array.
|
|
|
|
|
* Clauses can be formatted as 'foo=bar' or array('foo' => 'bar'),
|
|
|
|
|
* the latter only works if the value is a constant (i.e. not another field)
|
|
|
|
|
*
|
2008-10-07 18:23:39 +00:00
|
|
|
* If $value is an empty array, this function does nothing.
|
|
|
|
|
*
|
2008-05-10 09:29:34 +00:00
|
|
|
* For example, array('foo=bar', 'baz' => 3, 'bla' => 'foo') translates
|
|
|
|
|
* to "foo=bar AND baz='3' AND bla='foo'"
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string|array $value
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addWhere( $value ) {
|
|
|
|
|
if ( is_array( $value ) ) {
|
2008-10-07 18:23:39 +00:00
|
|
|
// Sanity check: don't insert empty arrays,
|
|
|
|
|
// Database::makeList() chokes on them
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( count( $value ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->where = array_merge( $this->where, $value );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2006-10-20 07:10:18 +00:00
|
|
|
$this->where[] = $value;
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Same as addWhere(), but add the WHERE clauses only if a condition is met
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string|array $value
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param bool $condition If false, do nothing
|
2008-05-10 09:29:34 +00:00
|
|
|
* @return bool $condition
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addWhereIf( $value, $condition ) {
|
|
|
|
|
if ( $condition ) {
|
|
|
|
|
$this->addWhere( $value );
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2006-10-21 08:26:32 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2006-10-21 08:26:32 +00:00
|
|
|
return false;
|
2006-10-20 07:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Equivalent to addWhere(array($field => $value))
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $field Field name
|
|
|
|
|
* @param string $value Value; ignored if null or empty array;
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addWhereFld( $field, $value ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
// Use count() to its full documented capabilities to simultaneously
|
2008-10-25 08:13:40 +00:00
|
|
|
// test for null, empty array or empty countable object
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( count( $value ) ) {
|
2006-10-20 07:10:18 +00:00
|
|
|
$this->where[$field] = $value;
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2006-10-20 07:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Add a WHERE clause corresponding to a range, and an ORDER BY
|
|
|
|
|
* clause to sort in the right direction
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $field Field name
|
|
|
|
|
* @param string $dir If 'newer', sort in ascending order, otherwise
|
2009-02-13 14:13:03 +00:00
|
|
|
* sort in descending order
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $start Value to start the list at. If $dir == 'newer'
|
2009-02-13 14:13:03 +00:00
|
|
|
* this is the lower boundary, otherwise it's the upper boundary
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $end Value to end the list at. If $dir == 'newer' this
|
2009-02-13 14:13:03 +00:00
|
|
|
* is the upper boundary, otherwise it's the lower boundary
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param bool $sort If false, don't add an ORDER BY clause
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addWhereRange( $field, $dir, $start, $end, $sort = true ) {
|
|
|
|
|
$isDirNewer = ( $dir === 'newer' );
|
|
|
|
|
$after = ( $isDirNewer ? '>=' : '<=' );
|
|
|
|
|
$before = ( $isDirNewer ? '<=' : '>=' );
|
2006-11-29 05:45:03 +00:00
|
|
|
$db = $this->getDB();
|
2006-10-20 07:10:18 +00:00
|
|
|
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !is_null( $start ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addWhere( $field . $after . $db->addQuotes( $start ) );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2006-10-01 20:17:16 +00:00
|
|
|
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !is_null( $end ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addWhere( $field . $before . $db->addQuotes( $end ) );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $sort ) {
|
|
|
|
|
$order = $field . ( $isDirNewer ? '' : ' DESC' );
|
2011-11-14 08:19:55 +00:00
|
|
|
// Append ORDER BY
|
2013-11-14 17:38:36 +00:00
|
|
|
$optionOrderBy = isset( $this->options['ORDER BY'] )
|
|
|
|
|
? (array)$this->options['ORDER BY']
|
|
|
|
|
: array();
|
2011-11-14 08:19:55 +00:00
|
|
|
$optionOrderBy[] = $order;
|
|
|
|
|
$this->addOption( 'ORDER BY', $optionOrderBy );
|
2009-02-18 15:26:09 +00:00
|
|
|
}
|
2006-10-20 07:10:18 +00:00
|
|
|
}
|
2011-10-28 18:10:41 +00:00
|
|
|
|
2011-10-06 20:46:24 +00:00
|
|
|
/**
|
|
|
|
|
* Add a WHERE clause corresponding to a range, similar to addWhereRange,
|
|
|
|
|
* but converts $start and $end to database timestamps.
|
|
|
|
|
* @see addWhereRange
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $field
|
|
|
|
|
* @param string $dir
|
|
|
|
|
* @param string $start
|
|
|
|
|
* @param string $end
|
|
|
|
|
* @param bool $sort
|
2011-10-06 20:46:24 +00:00
|
|
|
*/
|
|
|
|
|
protected function addTimestampWhereRange( $field, $dir, $start, $end, $sort = true ) {
|
|
|
|
|
$db = $this->getDb();
|
2012-04-19 13:07:40 +00:00
|
|
|
$this->addWhereRange( $field, $dir,
|
2011-10-07 19:11:08 +00:00
|
|
|
$db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort );
|
2011-10-06 20:46:24 +00:00
|
|
|
}
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
2009-02-13 14:13:03 +00:00
|
|
|
* Add an option such as LIMIT or USE INDEX. If an option was set
|
|
|
|
|
* before, the old value will be overwritten
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $name Option name
|
|
|
|
|
* @param string $value Option value
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addOption( $name, $value = null ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( is_null( $value ) ) {
|
2006-10-31 21:00:00 +00:00
|
|
|
$this->options[] = $name;
|
2010-02-24 13:34:11 +00:00
|
|
|
} else {
|
2006-10-31 21:00:00 +00:00
|
|
|
$this->options[$name] = $value;
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2006-10-21 08:26:32 +00:00
|
|
|
}
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Execute a SELECT query based on the values in the internal arrays
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $method Function the query should be attributed to.
|
2009-02-13 14:13:03 +00:00
|
|
|
* You should usually use __METHOD__ here
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $extraQuery Query data to add but not store in the object
|
2013-11-14 17:38:36 +00:00
|
|
|
* Format is array(
|
|
|
|
|
* 'tables' => ...,
|
|
|
|
|
* 'fields' => ...,
|
|
|
|
|
* 'where' => ...,
|
|
|
|
|
* 'options' => ...,
|
|
|
|
|
* 'join_conds' => ...
|
|
|
|
|
* )
|
2008-05-10 09:29:34 +00:00
|
|
|
* @return ResultWrapper
|
|
|
|
|
*/
|
2011-03-20 16:25:01 +00:00
|
|
|
protected function select( $method, $extraQuery = array() ) {
|
2011-03-20 22:35:41 +00:00
|
|
|
|
2013-11-14 17:38:36 +00:00
|
|
|
$tables = array_merge(
|
|
|
|
|
$this->tables,
|
|
|
|
|
isset( $extraQuery['tables'] ) ? (array)$extraQuery['tables'] : array()
|
|
|
|
|
);
|
|
|
|
|
$fields = array_merge(
|
|
|
|
|
$this->fields,
|
|
|
|
|
isset( $extraQuery['fields'] ) ? (array)$extraQuery['fields'] : array()
|
|
|
|
|
);
|
|
|
|
|
$where = array_merge(
|
|
|
|
|
$this->where,
|
|
|
|
|
isset( $extraQuery['where'] ) ? (array)$extraQuery['where'] : array()
|
|
|
|
|
);
|
|
|
|
|
$options = array_merge(
|
|
|
|
|
$this->options,
|
|
|
|
|
isset( $extraQuery['options'] ) ? (array)$extraQuery['options'] : array()
|
|
|
|
|
);
|
|
|
|
|
$join_conds = array_merge(
|
|
|
|
|
$this->join_conds,
|
|
|
|
|
isset( $extraQuery['join_conds'] ) ? (array)$extraQuery['join_conds'] : array()
|
|
|
|
|
);
|
2011-03-20 22:35:41 +00:00
|
|
|
|
2006-10-25 03:54:56 +00:00
|
|
|
// getDB has its own profileDBIn/Out calls
|
2006-11-29 05:45:03 +00:00
|
|
|
$db = $this->getDB();
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2006-10-20 07:10:18 +00:00
|
|
|
$this->profileDBIn();
|
2011-03-20 16:25:01 +00:00
|
|
|
$res = $db->select( $tables, $fields, $where, $method, $options, $join_conds );
|
2006-10-20 07:10:18 +00:00
|
|
|
$this->profileDBOut();
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2006-10-20 07:10:18 +00:00
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Estimate the row count for the SELECT query that would be run if we
|
|
|
|
|
* called select() right now, and check if it's acceptable.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return bool True if acceptable, false otherwise
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2008-03-26 13:43:11 +00:00
|
|
|
protected function checkRowCount() {
|
|
|
|
|
$db = $this->getDB();
|
|
|
|
|
$this->profileDBIn();
|
2013-11-14 17:38:36 +00:00
|
|
|
$rowcount = $db->estimateRowCount(
|
|
|
|
|
$this->tables,
|
|
|
|
|
$this->fields,
|
|
|
|
|
$this->where,
|
|
|
|
|
__METHOD__,
|
|
|
|
|
$this->options
|
|
|
|
|
);
|
2008-03-26 13:43:11 +00:00
|
|
|
$this->profileDBOut();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $rowcount > $this->getConfig()->get( 'APIMaxDBRows' ) ) {
|
2008-03-26 13:43:11 +00:00
|
|
|
return false;
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2008-03-26 13:43:11 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
2011-12-20 21:37:04 +00:00
|
|
|
* Add information (title and namespace) about a Title object to a
|
2009-02-13 14:13:03 +00:00
|
|
|
* result array
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $arr Result array à la ApiResult
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param Title $title
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $prefix Module prefix
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public static function addTitleInfo( &$arr, $title, $prefix = '' ) {
|
|
|
|
|
$arr[$prefix . 'ns'] = intval( $title->getNamespace() );
|
2007-07-14 19:04:31 +00:00
|
|
|
$arr[$prefix . 'title'] = $title->getPrefixedText();
|
2007-05-14 05:28:06 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-10-01 20:17:16 +00:00
|
|
|
/**
|
|
|
|
|
* Override this method to request extra fields from the pageSet
|
2007-06-03 17:22:09 +00:00
|
|
|
* using $pageSet->requestField('fieldName')
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiPageSet $pageSet
|
2006-10-01 20:17:16 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function requestExtraData( $pageSet ) {
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2006-10-17 09:27:39 +00:00
|
|
|
* Get the main Query module
|
2008-05-10 09:29:34 +00:00
|
|
|
* @return ApiQuery
|
2006-10-01 20:17:16 +00:00
|
|
|
*/
|
|
|
|
|
public function getQuery() {
|
|
|
|
|
return $this->mQueryModule;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-07 03:05:09 +00:00
|
|
|
/**
|
2008-05-10 09:29:34 +00:00
|
|
|
* Add a sub-element under the page element with the given page ID
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $pageId Page ID
|
|
|
|
|
* @param array $data Data array à la ApiResult
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
* @return bool Whether the element fit in the result
|
2007-07-07 03:05:09 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addPageSubItems( $pageId, $data ) {
|
2007-07-07 03:05:09 +00:00
|
|
|
$result = $this->getResult();
|
2010-01-11 15:55:52 +00:00
|
|
|
$result->setIndexedTagName( $data, $this->getModulePrefix() );
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
return $result->addValue( array( 'query', 'pages', intval( $pageId ) ),
|
2007-07-07 03:05:09 +00:00
|
|
|
$this->getModuleName(),
|
2010-01-11 15:55:52 +00:00
|
|
|
$data );
|
2007-07-07 03:05:09 +00:00
|
|
|
}
|
2010-02-24 13:34:11 +00:00
|
|
|
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
/**
|
2009-02-13 14:13:03 +00:00
|
|
|
* Same as addPageSubItems(), but one element of $data at a time
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $pageId Page ID
|
|
|
|
|
* @param array $item Data array à la ApiResult
|
|
|
|
|
* @param string $elemname XML element name. If null, getModuleName()
|
2009-02-13 14:13:03 +00:00
|
|
|
* is used
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
* @return bool Whether the element fit in the result
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function addPageSubItem( $pageId, $item, $elemname = null ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( is_null( $elemname ) ) {
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
$elemname = $this->getModulePrefix();
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
$result = $this->getResult();
|
2010-01-11 15:55:52 +00:00
|
|
|
$fit = $result->addValue( array( 'query', 'pages', $pageId,
|
2013-02-03 18:47:42 +00:00
|
|
|
$this->getModuleName() ), null, $item );
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !$fit ) {
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
return false;
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$result->setIndexedTagName_internal( array( 'query', 'pages', $pageId,
|
2013-11-14 12:51:06 +00:00
|
|
|
$this->getModuleName() ), $elemname );
|
|
|
|
|
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2007-07-07 03:05:09 +00:00
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Set a query-continue value
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $paramName Parameter name
|
2014-02-07 01:52:58 +00:00
|
|
|
* @param string|array $paramValue Parameter value
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function setContinueEnumParameter( $paramName, $paramValue ) {
|
2014-02-07 01:52:58 +00:00
|
|
|
$this->getResult()->setContinueParam( $this, $paramName, $paramValue );
|
2006-10-16 00:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-01 20:17:16 +00:00
|
|
|
/**
|
2009-02-13 14:13:03 +00:00
|
|
|
* Get the Query database connection (read-only)
|
2011-06-05 21:04:48 +00:00
|
|
|
* @return DatabaseBase
|
2006-10-01 20:17:16 +00:00
|
|
|
*/
|
|
|
|
|
protected function getDB() {
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( is_null( $this->mDb ) ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
$this->mDb = $this->getQuery()->getDB();
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2007-05-15 02:16:48 +00:00
|
|
|
return $this->mDb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selects the query database connection with the given name.
|
2009-02-13 14:13:03 +00:00
|
|
|
* See ApiQuery::getNamedDB() for more information
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $name Name to assign to the database connection
|
|
|
|
|
* @param int $db One of the DB_* constants
|
|
|
|
|
* @param array $groups Query groups
|
2012-02-09 18:01:54 +00:00
|
|
|
* @return DatabaseBase
|
2007-05-15 02:16:48 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function selectNamedDB( $name, $db, $groups ) {
|
|
|
|
|
$this->mDb = $this->getQuery()->getNamedDB( $name, $db, $groups );
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the PageSet object to work on
|
2008-05-10 09:29:34 +00:00
|
|
|
* @return ApiPageSet
|
2006-10-01 20:17:16 +00:00
|
|
|
*/
|
|
|
|
|
protected function getPageSet() {
|
2007-05-15 02:16:48 +00:00
|
|
|
return $this->getQuery()->getPageSet();
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-16 02:14:10 +00:00
|
|
|
/**
|
2008-06-26 15:48:44 +00:00
|
|
|
* Convert a title to a DB key
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $title Page title with spaces
|
2008-05-10 09:29:34 +00:00
|
|
|
* @return string Page title with underscores
|
2006-10-16 02:14:10 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function titleToKey( $title ) {
|
2010-01-23 22:52:40 +00:00
|
|
|
// Don't throw an error if we got an empty string
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( trim( $title ) == '' ) {
|
2008-08-27 16:48:30 +00:00
|
|
|
return '';
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !$t ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $title ) );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2013-03-09 20:14:22 +00:00
|
|
|
return $t->getPrefixedDBkey();
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
2006-10-03 05:41:55 +00:00
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* The inverse of titleToKey()
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $key Page title with underscores
|
2008-05-10 09:29:34 +00:00
|
|
|
* @return string Page title with spaces
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function keyToTitle( $key ) {
|
2010-01-23 22:52:40 +00:00
|
|
|
// Don't throw an error if we got an empty string
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( trim( $key ) == '' ) {
|
2008-08-27 16:48:30 +00:00
|
|
|
return '';
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2013-03-22 07:39:02 +00:00
|
|
|
$t = Title::newFromDBkey( $key );
|
2010-01-23 22:52:40 +00:00
|
|
|
// This really shouldn't happen but we gotta check anyway
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !$t ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $key ) );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2008-08-25 06:50:31 +00:00
|
|
|
return $t->getPrefixedText();
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
2010-02-24 13:34:11 +00:00
|
|
|
|
2008-08-27 16:48:30 +00:00
|
|
|
/**
|
2013-11-17 17:52:54 +00:00
|
|
|
* An alternative to titleToKey() that doesn't trim trailing spaces, and
|
|
|
|
|
* does not mangle the input if starts with something that looks like a
|
|
|
|
|
* namespace. It is advisable to pass the namespace parameter in order to
|
|
|
|
|
* handle per-namespace capitalization settings.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $titlePart Title part with spaces
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param int $defaultNamespace Namespace to assume
|
2008-08-27 16:48:30 +00:00
|
|
|
* @return string Title part with underscores
|
|
|
|
|
*/
|
2013-11-17 17:52:54 +00:00
|
|
|
public function titlePartToKey( $titlePart, $defaultNamespace = NS_MAIN ) {
|
|
|
|
|
$t = Title::makeTitleSafe( $defaultNamespace, $titlePart . 'x' );
|
|
|
|
|
if ( !$t ) {
|
|
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $titlePart ) );
|
|
|
|
|
}
|
2014-01-02 10:59:10 +00:00
|
|
|
if ( $defaultNamespace != $t->getNamespace() || $t->isExternal() ) {
|
2013-11-17 17:52:54 +00:00
|
|
|
// This can happen in two cases. First, if you call titlePartToKey with a title part
|
|
|
|
|
// that looks like a namespace, but with $defaultNamespace = NS_MAIN. It would be very
|
|
|
|
|
// difficult to handle such a case. Such cases cannot exist and are therefore treated
|
|
|
|
|
// as invalid user input. The second case is when somebody specifies a title interwiki
|
|
|
|
|
// prefix.
|
|
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $titlePart ) );
|
|
|
|
|
}
|
2014-02-05 11:02:29 +00:00
|
|
|
|
2013-11-17 17:52:54 +00:00
|
|
|
return substr( $t->getDbKey(), 0, -1 );
|
2008-08-27 16:48:30 +00:00
|
|
|
}
|
2010-02-24 13:34:11 +00:00
|
|
|
|
2008-08-27 16:48:30 +00:00
|
|
|
/**
|
|
|
|
|
* An alternative to keyToTitle() that doesn't trim trailing spaces
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $keyPart Key part with spaces
|
2008-08-27 16:48:30 +00:00
|
|
|
* @return string Key part with underscores
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function keyPartToTitle( $keyPart ) {
|
2013-11-14 12:51:06 +00:00
|
|
|
return substr( $this->keyToTitle( $keyPart . 'x' ), 0, -1 );
|
2008-08-27 16:48:30 +00:00
|
|
|
}
|
2010-02-24 13:34:11 +00:00
|
|
|
|
2011-03-13 00:07:22 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the personalised direction parameter description
|
|
|
|
|
*
|
|
|
|
|
* @param string $p ModulePrefix
|
|
|
|
|
* @param string $extraDirText Any extra text to be appended on the description
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2011-03-12 23:39:15 +00:00
|
|
|
public function getDirectionDescription( $p = '', $extraDirText = '' ) {
|
|
|
|
|
return array(
|
2013-11-14 12:51:06 +00:00
|
|
|
"In which direction to enumerate{$extraDirText}",
|
|
|
|
|
" newer - List oldest first. Note: {$p}start has to be before {$p}end.",
|
|
|
|
|
" older - List newest first (default). Note: {$p}start has to be later than {$p}end.",
|
|
|
|
|
);
|
2011-03-12 23:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-27 21:31:47 +00:00
|
|
|
/**
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $query
|
|
|
|
|
* @param string $protocol
|
2011-02-27 21:31:47 +00:00
|
|
|
* @return null|string
|
|
|
|
|
*/
|
2013-04-27 12:02:08 +00:00
|
|
|
public function prepareUrlQuerySearchString( $query = null, $protocol = null ) {
|
2011-02-27 21:31:47 +00:00
|
|
|
$db = $this->getDb();
|
|
|
|
|
if ( !is_null( $query ) || $query != '' ) {
|
|
|
|
|
if ( is_null( $protocol ) ) {
|
|
|
|
|
$protocol = 'http://';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$likeQuery = LinkFilter::makeLikeArray( $query, $protocol );
|
|
|
|
|
if ( !$likeQuery ) {
|
|
|
|
|
$this->dieUsage( 'Invalid query', 'bad_query' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2011-02-27 21:31:47 +00:00
|
|
|
return 'el_index ' . $db->buildLike( $likeQuery );
|
|
|
|
|
} elseif ( !is_null( $protocol ) ) {
|
|
|
|
|
return 'el_index ' . $db->buildLike( "$protocol", $db->anyString() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-06 17:59:08 +00:00
|
|
|
/**
|
|
|
|
|
* Filters hidden users (where the user doesn't have the right to view them)
|
|
|
|
|
* Also adds relevant block information
|
|
|
|
|
*
|
|
|
|
|
* @param bool $showBlockInfo
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2011-03-06 17:59:08 +00:00
|
|
|
*/
|
|
|
|
|
public function showHiddenUsersAddBlockInfo( $showBlockInfo ) {
|
2013-11-22 19:30:58 +00:00
|
|
|
$this->addTables( 'ipblocks' );
|
|
|
|
|
$this->addJoinConds( array(
|
|
|
|
|
'ipblocks' => array( 'LEFT JOIN', 'ipb_user=user_id' ),
|
|
|
|
|
) );
|
2011-03-06 17:59:08 +00:00
|
|
|
|
2013-11-22 19:30:58 +00:00
|
|
|
$this->addFields( 'ipb_deleted' );
|
2011-03-06 20:51:31 +00:00
|
|
|
|
2013-11-22 19:30:58 +00:00
|
|
|
if ( $showBlockInfo ) {
|
|
|
|
|
$this->addFields( array( 'ipb_id', 'ipb_by', 'ipb_by_text', 'ipb_reason', 'ipb_expiry' ) );
|
|
|
|
|
}
|
2011-03-06 17:59:08 +00:00
|
|
|
|
2013-11-22 19:30:58 +00:00
|
|
|
// Don't show hidden names
|
|
|
|
|
if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
|
|
|
|
|
$this->addWhere( 'ipb_deleted = 0 OR ipb_deleted IS NULL' );
|
2011-03-06 17:59:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-25 03:50:41 +00:00
|
|
|
/**
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $hash
|
2011-06-25 03:50:41 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function validateSha1Hash( $hash ) {
|
2012-11-17 21:43:12 +00:00
|
|
|
return preg_match( '/^[a-f0-9]{40}$/', $hash );
|
2011-06-25 03:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $hash
|
2011-06-25 03:50:41 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function validateSha1Base36Hash( $hash ) {
|
2012-11-17 21:43:12 +00:00
|
|
|
return preg_match( '/^[a-z0-9]{31}$/', $hash );
|
2011-06-25 03:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-08 21:47:01 +00:00
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2010-02-14 14:29:24 +00:00
|
|
|
public function getPossibleErrors() {
|
2013-01-15 02:19:16 +00:00
|
|
|
$errors = parent::getPossibleErrors();
|
|
|
|
|
$errors = array_merge( $errors, array(
|
2010-02-13 00:28:27 +00:00
|
|
|
array( 'invalidtitle', 'title' ),
|
|
|
|
|
array( 'invalidtitle', 'key' ),
|
2010-02-14 14:29:24 +00:00
|
|
|
) );
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2013-01-15 02:19:16 +00:00
|
|
|
return $errors;
|
2010-02-13 00:28:27 +00:00
|
|
|
}
|
Improve API query RevDel handling
* ApiQueryDeletedrevs, ApiQueryFilearchive, ApiQueryRecentChanges, and
ApiQueryWatchlist will now return entires where fields have been
revision-deleted. "Hidden" indicators will be provided as appropriate.
* ApiQueryImageInfo, ApiQueryLogEvents, ApiQueryRevisions,
ApiQueryContributions will now return field values in addition to the
"hidden" indicators when the requesting user has the necessary rights.
* Modules that return "hidden" indicators will now also return a
"suppressed" indicator.
* ApiQueryImageInfo will now return info for DELETED_FILE file revisions
if the requesting user has the 'deletedtext' right.
* ApiQueryLogEvents, when searching by user or title, will now return
entries where the user or action are revision-deleted if the
requesting user has the 'deletedhistory' right.
* ApiQueryContributions now uses the correct user rights rather than
'hideuser' to determine when to show contributions where the username
was revision-deleted.
* ApiQueryContributions will now indicate when the revision text is
hidden.
* Fix a bug in ApiQueryDeletedrevs found during testing where specifying
the "content" prop along with the "tags" prop or "drtag" parameter
would cause an SQL error.
* Fix various PHP warnings in ApiQueryFilearchive caused by the lack of
ArchivedFile::selectFields() fields.
* ApiQueryImageInfo::getInfo's $metadataOpts parameter has been renamed
$opts, and now may have an option to indicate the user to use for
RevDel visibility checks.
* ApiQueryWatchlist now properly uses the actual user's rights for
checking whether wlprop=patrol is allowed, rather than using the
wlowner's rights.
Bug: 27747
Bug: 27748
Bug: 28261
Bug: 34926
Bug: 48966
Change-Id: Idec2199976f460e1c73a26d0717e9fc4ab8042bb
2013-12-18 21:58:39 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check whether the current user has permission to view revision-deleted
|
|
|
|
|
* fields.
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function userCanSeeRevDel() {
|
|
|
|
|
return $this->getUser()->isAllowedAny( 'deletedhistory', 'deletedtext', 'suppressrevision' );
|
|
|
|
|
}
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
2006-10-03 05:41:55 +00:00
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
2006-10-03 05:41:55 +00:00
|
|
|
abstract class ApiQueryGeneratorBase extends ApiQueryBase {
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
private $mGeneratorPageSet = null;
|
2006-10-03 05:41:55 +00:00
|
|
|
|
2012-07-12 15:53:00 +00:00
|
|
|
/**
|
2013-02-08 20:39:40 +00:00
|
|
|
* Switch this module to generator mode. By default, generator mode is
|
|
|
|
|
* switched off and the module acts like a normal query module.
|
|
|
|
|
* @since 1.21 requires pageset parameter
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiPageSet $generatorPageSet ApiPageSet object that the module will get
|
2013-02-08 20:39:40 +00:00
|
|
|
* by calling getPageSet() when in generator mode.
|
2012-07-12 15:53:00 +00:00
|
|
|
*/
|
2013-02-08 20:39:40 +00:00
|
|
|
public function setGeneratorMode( ApiPageSet $generatorPageSet ) {
|
|
|
|
|
if ( $generatorPageSet === null ) {
|
|
|
|
|
ApiBase::dieDebug( __METHOD__, 'Required parameter missing - $generatorPageSet' );
|
|
|
|
|
}
|
|
|
|
|
$this->mGeneratorPageSet = $generatorPageSet;
|
2006-10-03 05:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
2013-02-08 20:39:40 +00:00
|
|
|
* Get the PageSet object to work on.
|
|
|
|
|
* If this module is generator, the pageSet object is different from other module's
|
|
|
|
|
* @return ApiPageSet
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2013-02-08 20:39:40 +00:00
|
|
|
protected function getPageSet() {
|
|
|
|
|
if ( $this->mGeneratorPageSet !== null ) {
|
|
|
|
|
return $this->mGeneratorPageSet;
|
|
|
|
|
}
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
return parent::getPageSet();
|
2006-10-03 05:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Overrides base class to prepend 'g' to every generator parameter
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $paramName Parameter name
|
2009-02-13 14:13:03 +00:00
|
|
|
* @return string Prefixed parameter name
|
2006-10-03 05:41:55 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function encodeParamName( $paramName ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( $this->mGeneratorPageSet !== null ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
return 'g' . parent::encodeParamName( $paramName );
|
|
|
|
|
} else {
|
|
|
|
|
return parent::encodeParamName( $paramName );
|
|
|
|
|
}
|
2006-10-03 05:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-02 00:06:46 +00:00
|
|
|
/**
|
2014-02-07 01:52:58 +00:00
|
|
|
* Overridden to set the generator param if in generator mode
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $paramName Parameter name
|
2014-02-07 01:52:58 +00:00
|
|
|
* @param string|array $paramValue Parameter value
|
2013-03-02 00:06:46 +00:00
|
|
|
*/
|
|
|
|
|
protected function setContinueEnumParameter( $paramName, $paramValue ) {
|
2014-02-07 01:52:58 +00:00
|
|
|
if ( $this->mGeneratorPageSet !== null ) {
|
|
|
|
|
$this->getResult()->setGeneratorContinueParam( $this, $paramName, $paramValue );
|
|
|
|
|
} else {
|
2013-03-02 00:06:46 +00:00
|
|
|
parent::setContinueEnumParameter( $paramName, $paramValue );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-03 05:41:55 +00:00
|
|
|
/**
|
|
|
|
|
* Execute this module as a generator
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiPageSet $resultPageSet All output should be appended to this object
|
2006-10-03 05:41:55 +00:00
|
|
|
*/
|
2013-01-26 19:00:09 +00:00
|
|
|
abstract public function executeGenerator( $resultPageSet );
|
2006-10-03 05:41:55 +00:00
|
|
|
}
|