2006-10-01 20:17:16 +00:00
|
|
|
<?php
|
2010-02-24 13:34:11 +00:00
|
|
|
/**
|
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
|
|
|
*/
|
|
|
|
|
|
2019-09-10 17:42:58 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-02-07 04:49:57 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2019-06-19 19:43:51 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
2017-02-19 05:03:13 +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 {
|
2019-09-05 18:24:28 +00:00
|
|
|
use ApiQueryBlockInfoTrait;
|
2006-10-01 20:17:16 +00:00
|
|
|
|
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
|
|
|
|
2014-08-27 19:41:05 +00:00
|
|
|
/************************************************************************//**
|
|
|
|
|
* @name Methods to implement
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
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';
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 19:41:05 +00:00
|
|
|
/**
|
|
|
|
|
* Override this method to request extra fields from the pageSet
|
|
|
|
|
* using $pageSet->requestField('fieldName')
|
2014-10-30 17:30:45 +00:00
|
|
|
*
|
|
|
|
|
* Note this only makes sense for 'prop' modules, as 'list' and 'meta'
|
|
|
|
|
* modules should not be using the pageset.
|
|
|
|
|
*
|
2014-08-27 19:41:05 +00:00
|
|
|
* @param ApiPageSet $pageSet
|
|
|
|
|
*/
|
|
|
|
|
public function requestExtraData( $pageSet ) {
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 17:00:00 +00:00
|
|
|
/** @} */
|
2014-08-27 19:41:05 +00:00
|
|
|
|
|
|
|
|
/************************************************************************//**
|
|
|
|
|
* @name Data access
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the main Query module
|
|
|
|
|
* @return ApiQuery
|
|
|
|
|
*/
|
|
|
|
|
public function getQuery() {
|
|
|
|
|
return $this->mQueryModule;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-09 20:47:04 +00:00
|
|
|
/** @inheritDoc */
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
public function getParent() {
|
|
|
|
|
return $this->getQuery();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 19:41:05 +00:00
|
|
|
/**
|
|
|
|
|
* Get the Query database connection (read-only)
|
2017-02-07 04:49:57 +00:00
|
|
|
* @return IDatabase
|
2014-08-27 19:41:05 +00:00
|
|
|
*/
|
|
|
|
|
protected function getDB() {
|
|
|
|
|
if ( is_null( $this->mDb ) ) {
|
|
|
|
|
$this->mDb = $this->getQuery()->getDB();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->mDb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selects the query database connection with the given name.
|
|
|
|
|
* See ApiQuery::getNamedDB() for more information
|
|
|
|
|
* @param string $name Name to assign to the database connection
|
|
|
|
|
* @param int $db One of the DB_* constants
|
2017-09-10 22:14:33 +00:00
|
|
|
* @param string|string[] $groups Query groups
|
2017-02-07 04:49:57 +00:00
|
|
|
* @return IDatabase
|
2014-08-27 19:41:05 +00:00
|
|
|
*/
|
|
|
|
|
public function selectNamedDB( $name, $db, $groups ) {
|
|
|
|
|
$this->mDb = $this->getQuery()->getNamedDB( $name, $db, $groups );
|
2015-04-09 05:20:56 +00:00
|
|
|
return $this->mDb;
|
2014-08-27 19:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the PageSet object to work on
|
|
|
|
|
* @return ApiPageSet
|
|
|
|
|
*/
|
|
|
|
|
protected function getPageSet() {
|
|
|
|
|
return $this->getQuery()->getPageSet();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 17:00:00 +00:00
|
|
|
/** @} */
|
2014-08-27 19:41:05 +00:00
|
|
|
|
|
|
|
|
/************************************************************************//**
|
|
|
|
|
* @name Querying
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
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() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->tables = [];
|
|
|
|
|
$this->where = [];
|
|
|
|
|
$this->fields = [];
|
|
|
|
|
$this->options = [];
|
|
|
|
|
$this->join_conds = [];
|
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
|
2019-06-07 15:19:48 +00:00
|
|
|
* @param string|array $tables Table name or array of table names
|
|
|
|
|
* or nested arrays for joins using parentheses for grouping
|
2014-07-03 19:29:02 +00:00
|
|
|
* @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 ) ) {
|
2019-03-29 20:12:24 +00:00
|
|
|
if ( $alias !== null ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
ApiBase::dieDebug( __METHOD__, 'Multiple table aliases not supported' );
|
|
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->tables = array_merge( $this->tables, $tables );
|
2019-03-29 20:12:24 +00:00
|
|
|
} elseif ( $alias !== null ) {
|
|
|
|
|
$this->tables[$alias] = $tables;
|
2007-07-30 08:09:15 +00:00
|
|
|
} else {
|
2019-03-29 20:12:24 +00:00
|
|
|
$this->tables[] = $tables;
|
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
|
|
|
|
|
*
|
2016-07-25 01:25:09 +00:00
|
|
|
* JOIN conditions are formatted as [ tablename => [ jointype, conditions ] ]
|
|
|
|
|
* e.g. [ 'page' => [ '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.
|
2016-07-25 01:25:09 +00:00
|
|
|
* Clauses can be formatted as 'foo=bar' or [ 'foo' => 'bar' ],
|
2008-05-10 09:29:34 +00:00
|
|
|
* 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.
|
|
|
|
|
*
|
2016-07-25 01:25:09 +00:00
|
|
|
* For example, [ 'foo=bar', 'baz' => 3, 'bla' => 'foo' ] translates
|
2008-05-10 09:29:34 +00:00
|
|
|
* 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
|
|
|
/**
|
2017-01-16 15:42:53 +00:00
|
|
|
* Equivalent to addWhere( [ $field => $value ] )
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $field Field name
|
2019-12-08 12:37:24 +00:00
|
|
|
* @param int|string|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 ) {
|
2017-12-08 16:46:58 +00:00
|
|
|
if ( $value !== null && !( is_array( $value ) && !$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
|
|
|
}
|
|
|
|
|
|
2016-07-14 18:55:22 +00:00
|
|
|
/**
|
|
|
|
|
* Like addWhereFld for an integer list of IDs
|
|
|
|
|
* @since 1.33
|
|
|
|
|
* @param string $table Table name
|
|
|
|
|
* @param string $field Field name
|
|
|
|
|
* @param int[] $ids IDs
|
|
|
|
|
* @return int Count of IDs actually included
|
|
|
|
|
*/
|
|
|
|
|
protected function addWhereIDsFld( $table, $field, $ids ) {
|
|
|
|
|
// Use count() to its full documented capabilities to simultaneously
|
|
|
|
|
// test for null, empty array or empty countable object
|
|
|
|
|
if ( count( $ids ) ) {
|
|
|
|
|
$ids = $this->filterIDs( [ [ $table, $field ] ], $ids );
|
|
|
|
|
|
2019-01-09 16:24:36 +00:00
|
|
|
if ( $ids === [] ) {
|
2016-07-14 18:55:22 +00:00
|
|
|
// Return nothing, no IDs are valid
|
|
|
|
|
$this->where[] = '0 = 1';
|
|
|
|
|
} else {
|
|
|
|
|
$this->where[$field] = $ids;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count( $ids );
|
|
|
|
|
}
|
|
|
|
|
|
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']
|
2016-02-17 09:09:32 +00:00
|
|
|
: [];
|
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 ) {
|
2015-11-07 21:10:23 +00:00
|
|
|
$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
|
2019-12-08 12:37:24 +00:00
|
|
|
* @param int|string|string[]|null $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
|
2016-07-25 01:25:09 +00:00
|
|
|
* Format is [
|
2013-11-14 17:38:36 +00:00
|
|
|
* 'tables' => ...,
|
|
|
|
|
* 'fields' => ...,
|
|
|
|
|
* 'where' => ...,
|
|
|
|
|
* 'options' => ...,
|
|
|
|
|
* 'join_conds' => ...
|
2016-07-25 01:25:09 +00:00
|
|
|
* ]
|
2016-09-14 18:22:35 +00:00
|
|
|
* @param array|null &$hookData If set, the ApiQueryBaseBeforeQuery and
|
|
|
|
|
* ApiQueryBaseAfterQuery hooks will be called, and the
|
|
|
|
|
* ApiQueryBaseProcessRow hook will be expected.
|
2019-06-19 19:43:51 +00:00
|
|
|
* @return IResultWrapper
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2016-09-14 18:22:35 +00:00
|
|
|
protected function select( $method, $extraQuery = [], array &$hookData = null ) {
|
2013-11-14 17:38:36 +00:00
|
|
|
$tables = array_merge(
|
|
|
|
|
$this->tables,
|
2016-02-17 09:09:32 +00:00
|
|
|
isset( $extraQuery['tables'] ) ? (array)$extraQuery['tables'] : []
|
2013-11-14 17:38:36 +00:00
|
|
|
);
|
|
|
|
|
$fields = array_merge(
|
|
|
|
|
$this->fields,
|
2016-02-17 09:09:32 +00:00
|
|
|
isset( $extraQuery['fields'] ) ? (array)$extraQuery['fields'] : []
|
2013-11-14 17:38:36 +00:00
|
|
|
);
|
|
|
|
|
$where = array_merge(
|
|
|
|
|
$this->where,
|
2016-02-17 09:09:32 +00:00
|
|
|
isset( $extraQuery['where'] ) ? (array)$extraQuery['where'] : []
|
2013-11-14 17:38:36 +00:00
|
|
|
);
|
|
|
|
|
$options = array_merge(
|
|
|
|
|
$this->options,
|
2016-02-17 09:09:32 +00:00
|
|
|
isset( $extraQuery['options'] ) ? (array)$extraQuery['options'] : []
|
2013-11-14 17:38:36 +00:00
|
|
|
);
|
|
|
|
|
$join_conds = array_merge(
|
|
|
|
|
$this->join_conds,
|
2016-02-17 09:09:32 +00:00
|
|
|
isset( $extraQuery['join_conds'] ) ? (array)$extraQuery['join_conds'] : []
|
2013-11-14 17:38:36 +00:00
|
|
|
);
|
2011-03-20 22:35:41 +00:00
|
|
|
|
2016-09-14 18:22:35 +00:00
|
|
|
if ( $hookData !== null ) {
|
|
|
|
|
Hooks::run( 'ApiQueryBaseBeforeQuery',
|
|
|
|
|
[ $this, &$tables, &$fields, &$where, &$options, &$join_conds, &$hookData ]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 22:26:31 +00:00
|
|
|
$res = $this->getDB()->select( $tables, $fields, $where, $method, $options, $join_conds );
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2016-09-14 18:22:35 +00:00
|
|
|
if ( $hookData !== null ) {
|
|
|
|
|
Hooks::run( 'ApiQueryBaseAfterQuery', [ $this, $res, &$hookData ] );
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-20 07:10:18 +00:00
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 18:22:35 +00:00
|
|
|
/**
|
|
|
|
|
* Call the ApiQueryBaseProcessRow hook
|
|
|
|
|
*
|
|
|
|
|
* Generally, a module that passed $hookData to self::select() will call
|
|
|
|
|
* this just before calling ApiResult::addValue(), and treat a false return
|
|
|
|
|
* here in the same way it treats a false return from addValue().
|
|
|
|
|
*
|
|
|
|
|
* @since 1.28
|
|
|
|
|
* @param object $row Database row
|
|
|
|
|
* @param array &$data Data to be added to the result
|
|
|
|
|
* @param array &$hookData Hook data from ApiQueryBase::select()
|
|
|
|
|
* @return bool Return false if row processing should end with continuation
|
|
|
|
|
*/
|
|
|
|
|
protected function processRow( $row, array &$data, array &$hookData ) {
|
|
|
|
|
return Hooks::run( 'ApiQueryBaseProcessRow', [ $this, $row, &$data, &$hookData ] );
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 17:00:00 +00:00
|
|
|
/** @} */
|
2014-08-27 19:41:05 +00:00
|
|
|
|
|
|
|
|
/************************************************************************//**
|
|
|
|
|
* @name Utility methods
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
2017-08-11 00:23:16 +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 = '' ) {
|
2019-02-25 00:38:33 +00:00
|
|
|
$arr[$prefix . 'ns'] = (int)$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
|
|
|
|
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();
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $data, $this->getModulePrefix() );
|
2013-11-14 12:51:06 +00:00
|
|
|
|
2019-02-25 00:38:33 +00:00
|
|
|
return $result->addValue( [ 'query', 'pages', (int)$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
|
2019-05-17 14:15:31 +00:00
|
|
|
* @param mixed $item Data à la ApiResult
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $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();
|
2016-02-17 09:09:32 +00:00
|
|
|
$fit = $result->addValue( [ 'query', 'pages', $pageId,
|
|
|
|
|
$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
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$result->addIndexedTagName( [ 'query', 'pages', $pageId,
|
|
|
|
|
$this->getModuleName() ], $elemname );
|
2013-11-14 12:51:06 +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
|
|
|
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
|
2019-12-08 12:37:24 +00:00
|
|
|
* @param int|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 ) {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$this->getContinuationManager()->addContinueParam( $this, $paramName, $paramValue );
|
2006-10-16 00:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-01 20:17:16 +00:00
|
|
|
/**
|
2014-08-27 19:41:05 +00:00
|
|
|
* Convert an input title or title prefix into a dbkey.
|
|
|
|
|
*
|
|
|
|
|
* $namespace should always be specified in order to handle per-namespace
|
|
|
|
|
* capitalization settings.
|
|
|
|
|
*
|
|
|
|
|
* @param string $titlePart Title part
|
2015-05-13 18:42:39 +00:00
|
|
|
* @param int $namespace Namespace of the title
|
2014-08-27 19:41:05 +00:00
|
|
|
* @return string DBkey (no namespace prefix)
|
2008-08-27 16:48:30 +00:00
|
|
|
*/
|
2014-08-27 19:41:05 +00:00
|
|
|
public function titlePartToKey( $titlePart, $namespace = NS_MAIN ) {
|
|
|
|
|
$t = Title::makeTitleSafe( $namespace, $titlePart . 'x' );
|
2015-02-20 15:18:00 +00:00
|
|
|
if ( !$t || $t->hasFragment() ) {
|
|
|
|
|
// Invalid title (e.g. bad chars) or contained a '#'.
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $titlePart ) ] );
|
2013-11-17 17:52:54 +00:00
|
|
|
}
|
2014-08-27 19:41:05 +00:00
|
|
|
if ( $namespace != $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.
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $titlePart ) ] );
|
2013-11-17 17:52:54 +00:00
|
|
|
}
|
2014-02-05 11:02:29 +00:00
|
|
|
|
2015-11-07 21:10:23 +00:00
|
|
|
return substr( $t->getDBkey(), 0, -1 );
|
2008-08-27 16:48:30 +00:00
|
|
|
}
|
2010-02-24 13:34:11 +00:00
|
|
|
|
2015-05-13 18:42:39 +00:00
|
|
|
/**
|
2019-10-02 12:33:48 +00:00
|
|
|
* Convert an input title or title prefix into a TitleValue.
|
2015-05-13 18:42:39 +00:00
|
|
|
*
|
2019-10-02 12:33:48 +00:00
|
|
|
* @since 1.35
|
2015-05-13 18:42:39 +00:00
|
|
|
* @param string $titlePart Title part
|
|
|
|
|
* @param int $defaultNamespace Default namespace if none is given
|
2019-10-02 12:33:48 +00:00
|
|
|
* @return TitleValue
|
|
|
|
|
*/
|
|
|
|
|
protected function parsePrefixedTitlePart( $titlePart, $defaultNamespace = NS_MAIN ) {
|
|
|
|
|
try {
|
|
|
|
|
$titleParser = MediaWikiServices::getInstance()->getTitleParser();
|
|
|
|
|
$t = $titleParser->parseTitle( $titlePart . 'X', $defaultNamespace );
|
|
|
|
|
} catch ( MalformedTitleException $e ) {
|
|
|
|
|
$t = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$t || $t->hasFragment() || $t->isExternal() || $t->getDBkey() === 'X' ) {
|
2015-05-13 18:42:39 +00:00
|
|
|
// Invalid title (e.g. bad chars) or contained a '#'.
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $titlePart ) ] );
|
2015-05-13 18:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-02 12:33:48 +00:00
|
|
|
return new TitleValue( $t->getNamespace(), substr( $t->getDBkey(), 0, -1 ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert an input title or title prefix into a namespace constant and dbkey.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.26
|
|
|
|
|
* @deprecated sine 1.35, use parsePrefixedTitlePart() instead.
|
|
|
|
|
* @param string $titlePart Title part parsePrefixedTitlePart instead
|
|
|
|
|
* @param int $defaultNamespace Default namespace if none is given
|
|
|
|
|
* @return array (int, string) Namespace number and DBkey
|
|
|
|
|
*/
|
|
|
|
|
public function prefixedTitlePartToKey( $titlePart, $defaultNamespace = NS_MAIN ) {
|
|
|
|
|
wfDeprecated( __METHOD__, '1.35' );
|
|
|
|
|
$t = $this->parsePrefixedTitlePart( $titlePart, $defaultNamespace );
|
|
|
|
|
return [ $t->getNamespace(), $t->getDBkey() ];
|
2015-05-13 18:42:39 +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 ) {
|
2016-12-08 05:04:53 +00:00
|
|
|
return (bool)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 ) {
|
2016-12-08 05:04:53 +00:00
|
|
|
return (bool)preg_match( '/^[a-z0-9]{31}$/', $hash );
|
2011-06-25 03:50:41 +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() {
|
2019-08-21 22:42:08 +00:00
|
|
|
return $this->getPermissionManager()->userHasAnyRight(
|
|
|
|
|
$this->getUser(),
|
2014-06-12 22:18:51 +00:00
|
|
|
'deletedhistory',
|
|
|
|
|
'deletedtext',
|
|
|
|
|
'suppressrevision',
|
|
|
|
|
'viewsuppressed'
|
|
|
|
|
);
|
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
|
|
|
}
|
2014-08-27 19:41:05 +00:00
|
|
|
|
2019-09-10 17:42:58 +00:00
|
|
|
/**
|
|
|
|
|
* Preprocess the result set to fill the GenderCache with the necessary information
|
|
|
|
|
* before using self::addTitleInfo
|
|
|
|
|
*
|
|
|
|
|
* @param IResultWrapper $res Result set to work on.
|
|
|
|
|
* The result set must have _namespace and _title fields with the provided field prefix
|
|
|
|
|
* @param string $fname The caller function name, always use __METHOD__
|
|
|
|
|
* @param string $fieldPrefix Prefix for fields to check gender for
|
|
|
|
|
*/
|
|
|
|
|
protected function executeGenderCacheFromResultWrapper(
|
|
|
|
|
IResultWrapper $res, $fname = __METHOD__, $fieldPrefix = 'page'
|
|
|
|
|
) {
|
|
|
|
|
if ( !$res->numRows() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
2019-10-10 17:44:04 +00:00
|
|
|
if ( !$services->getContentLanguage()->needsGenderDistinction() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 17:42:58 +00:00
|
|
|
$nsInfo = $services->getNamespaceInfo();
|
|
|
|
|
$namespaceField = $fieldPrefix . '_namespace';
|
|
|
|
|
$titleField = $fieldPrefix . '_title';
|
|
|
|
|
|
|
|
|
|
$usernames = [];
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) {
|
|
|
|
|
$usernames[] = $row->$titleField;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $usernames === [] ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$genderCache = $services->getGenderCache();
|
|
|
|
|
$genderCache->doQuery( $usernames, $fname );
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 17:00:00 +00:00
|
|
|
/** @} */
|
2019-09-05 18:24:28 +00:00
|
|
|
|
|
|
|
|
/************************************************************************//**
|
|
|
|
|
* @name Deprecated methods
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Filters hidden users (where the user doesn't have the right to view them)
|
|
|
|
|
* Also adds relevant block information
|
|
|
|
|
*
|
|
|
|
|
* @deprecated since 1.34, use ApiQueryBlockInfoTrait instead
|
|
|
|
|
* @param bool $showBlockInfo
|
|
|
|
|
*/
|
|
|
|
|
public function showHiddenUsersAddBlockInfo( $showBlockInfo ) {
|
|
|
|
|
wfDeprecated( __METHOD__, '1.34' );
|
2019-11-04 01:10:23 +00:00
|
|
|
$this->addBlockInfoToQuery( $showBlockInfo );
|
2019-09-05 18:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @} */
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|