2006-11-01 12:07:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Created on Oct 16, 2006
|
|
|
|
|
*
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
2007-05-20 23:41:25 +00:00
|
|
|
* Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
|
2006-11-01 12:07:20 +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.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2006-11-01 12:07:20 +00:00
|
|
|
// Eclipse helper - will be ignored in production
|
2010-01-11 15:55:52 +00:00
|
|
|
require_once ( 'ApiQueryBase.php' );
|
2006-11-01 12:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
2007-05-20 23:41:25 +00:00
|
|
|
* This query action adds a list of a specified user's contributions to the output.
|
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-11-01 12:07:20 +00:00
|
|
|
class ApiQueryContributions extends ApiQueryBase {
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $query, $moduleName ) {
|
|
|
|
|
parent :: __construct( $query, $moduleName, 'uc' );
|
2006-11-01 12:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-13 18:18:18 +00:00
|
|
|
private $params, $username;
|
2007-05-21 04:34:48 +00:00
|
|
|
private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
|
2010-01-31 23:06:35 +00:00
|
|
|
$fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
|
2009-11-01 10:42:41 +00:00
|
|
|
$fld_patrolled = false, $fld_tags = false;
|
2007-05-15 03:35:32 +00:00
|
|
|
|
2007-05-20 23:41:25 +00:00
|
|
|
public function execute() {
|
|
|
|
|
// Parse some parameters
|
|
|
|
|
$this->params = $this->extractRequestParams();
|
2007-06-16 00:39:01 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$prop = array_flip( $this->params['prop'] );
|
|
|
|
|
$this->fld_ids = isset( $prop['ids'] );
|
|
|
|
|
$this->fld_title = isset( $prop['title'] );
|
|
|
|
|
$this->fld_comment = isset( $prop['comment'] );
|
2010-01-31 23:06:35 +00:00
|
|
|
$this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->fld_size = isset( $prop['size'] );
|
|
|
|
|
$this->fld_flags = isset( $prop['flags'] );
|
|
|
|
|
$this->fld_timestamp = isset( $prop['timestamp'] );
|
|
|
|
|
$this->fld_patrolled = isset( $prop['patrolled'] );
|
|
|
|
|
$this->fld_tags = isset( $prop['tags'] );
|
2006-11-01 12:07:20 +00:00
|
|
|
|
2007-05-20 23:41:25 +00:00
|
|
|
// TODO: if the query is going only against the revision table, should this be done?
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->selectNamedDB( 'contributions', DB_SLAVE, 'contributions' );
|
2007-01-22 23:50:42 +00:00
|
|
|
$db = $this->getDB();
|
2006-11-01 12:07:20 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( isset( $this->params['userprefix'] ) )
|
2008-02-26 16:56:08 +00:00
|
|
|
{
|
|
|
|
|
$this->prefixMode = true;
|
2008-10-18 10:14:02 +00:00
|
|
|
$this->multiUserMode = true;
|
2008-02-26 16:56:08 +00:00
|
|
|
$this->userprefix = $this->params['userprefix'];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$this->usernames = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_array( $this->params['user'] ) )
|
|
|
|
|
$this->params['user'] = array( $this->params['user'] );
|
|
|
|
|
if ( !count( $this->params['user'] ) )
|
|
|
|
|
$this->dieUsage( 'User parameter may not be empty.', 'param_user' );
|
|
|
|
|
foreach ( $this->params['user'] as $u )
|
|
|
|
|
$this->prepareUsername( $u );
|
2008-02-26 16:56:08 +00:00
|
|
|
$this->prefixMode = false;
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->multiUserMode = ( count( $this->params['user'] ) > 1 );
|
2008-02-26 16:56:08 +00:00
|
|
|
}
|
2007-05-20 23:41:25 +00:00
|
|
|
$this->prepareQuery();
|
2006-11-01 12:07:20 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
// Do the actual query.
|
2007-05-20 23:41:25 +00:00
|
|
|
$res = $this->select( __METHOD__ );
|
2006-11-01 12:07:20 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
// Initialise some variables
|
2006-11-01 12:07:20 +00:00
|
|
|
$count = 0;
|
2007-05-20 23:41:25 +00:00
|
|
|
$limit = $this->params['limit'];
|
2006-11-01 12:07:20 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
// Fetch each row
|
2006-11-01 12:07:20 +00:00
|
|
|
while ( $row = $db->fetchObject( $res ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( ++ $count > $limit ) {
|
2006-11-01 12:07:20 +00:00
|
|
|
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->multiUserMode )
|
|
|
|
|
$this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
|
2008-10-18 10:14:02 +00:00
|
|
|
else
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rev_timestamp ) );
|
2006-11-01 12:07:20 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$vals = $this->extractRowInfo( $row );
|
|
|
|
|
$fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
|
|
|
|
|
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
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->multiUserMode )
|
|
|
|
|
$this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
|
* 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
|
|
|
else
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rev_timestamp ) );
|
* 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
|
|
|
break;
|
|
|
|
|
}
|
2006-11-01 12:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
// Free the database record so the connection can get on with other stuff
|
|
|
|
|
$db->freeResult( $res );
|
2006-11-01 12:07:20 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'item' );
|
2006-11-01 12:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-20 23:41:25 +00:00
|
|
|
/**
|
2007-08-13 18:15:35 +00:00
|
|
|
* Validate the 'user' parameter and set the value to compare
|
|
|
|
|
* against `revision`.`rev_user_text`
|
2007-05-20 23:41:25 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function prepareUsername( $user ) {
|
|
|
|
|
if ( !is_null( $user ) && $user !== '' ) {
|
2007-08-13 18:15:35 +00:00
|
|
|
$name = User::isIP( $user )
|
|
|
|
|
? $user
|
|
|
|
|
: User::getCanonicalName( $user, 'valid' );
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $name === false ) {
|
2007-08-13 18:15:35 +00:00
|
|
|
$this->dieUsage( "User name {$user} is not valid", 'param_user' );
|
|
|
|
|
} else {
|
2008-02-05 15:40:58 +00:00
|
|
|
$this->usernames[] = $name;
|
2007-08-13 18:15:35 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->dieUsage( 'User parameter may not be empty', 'param_user' );
|
|
|
|
|
}
|
2007-05-20 23:41:25 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-20 23:41:25 +00:00
|
|
|
/**
|
|
|
|
|
* Prepares the query and returns the limit of rows requested
|
|
|
|
|
*/
|
|
|
|
|
private function prepareQuery() {
|
2009-01-19 16:04:33 +00:00
|
|
|
// We're after the revision table, and the corresponding page
|
|
|
|
|
// row for anything we retrieve. We may also need the
|
2009-11-01 10:42:41 +00:00
|
|
|
// recentchanges row and/or tag summary row.
|
2009-04-22 09:21:33 +00:00
|
|
|
global $wgUser;
|
2010-01-11 15:55:52 +00:00
|
|
|
$tables = array( 'page', 'revision' ); // Order may change
|
|
|
|
|
$this->addWhere( 'page_id=rev_page' );
|
2009-01-19 16:04:33 +00:00
|
|
|
|
2008-10-18 10:14:02 +00:00
|
|
|
// Handle continue parameter
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->multiUserMode && !is_null( $this->params['continue'] ) )
|
2008-10-18 10:14:02 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$continue = explode( '|', $this->params['continue'] );
|
|
|
|
|
if ( count( $continue ) != 2 )
|
|
|
|
|
$this->dieUsage( "Invalid continue param. You should pass the original " .
|
|
|
|
|
"value returned by the previous query", "_badcontinue" );
|
|
|
|
|
$encUser = $this->getDB()->strencode( $continue[0] );
|
|
|
|
|
$encTS = wfTimestamp( TS_MW, $continue[1] );
|
|
|
|
|
$op = ( $this->params['dir'] == 'older' ? '<' : '>' );
|
|
|
|
|
$this->addWhere( "rev_user_text $op '$encUser' OR " .
|
2008-10-18 10:14:02 +00:00
|
|
|
"(rev_user_text = '$encUser' AND " .
|
2010-01-11 15:55:52 +00:00
|
|
|
"rev_timestamp $op= '$encTS')" );
|
2008-10-18 10:14:02 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !$wgUser->isAllowed( 'hideuser' ) )
|
|
|
|
|
$this->addWhere( $this->getDB()->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
|
2008-02-05 15:40:58 +00:00
|
|
|
// We only want pages by the specified users.
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->prefixMode )
|
|
|
|
|
$this->addWhere( 'rev_user_text' . $this->getDB()->buildLike( $this->userprefix, $this->getDB()->anyString() ) );
|
2008-04-14 07:45:50 +00:00
|
|
|
else
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addWhereFld( 'rev_user_text', $this->usernames );
|
2007-05-20 23:41:25 +00:00
|
|
|
// ... and in the specified timeframe.
|
2008-04-10 17:18:27 +00:00
|
|
|
// Ensure the same sort order for rev_user_text and rev_timestamp
|
|
|
|
|
// so our query is indexed
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->multiUserMode )
|
|
|
|
|
$this->addWhereRange( 'rev_user_text', $this->params['dir'], null, null );
|
|
|
|
|
$this->addWhereRange( 'rev_timestamp',
|
2007-05-20 23:41:25 +00:00
|
|
|
$this->params['dir'], $this->params['start'], $this->params['end'] );
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addWhereFld( 'page_namespace', $this->params['namespace'] );
|
2007-07-05 15:09:06 +00:00
|
|
|
|
2007-05-20 23:41:25 +00:00
|
|
|
$show = $this->params['show'];
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_null( $show ) ) {
|
|
|
|
|
$show = array_flip( $show );
|
|
|
|
|
if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
|
|
|
|
|
|| ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) ) )
|
2010-02-14 15:19:45 +00:00
|
|
|
$this->dieUsageMsg( array( 'show' ) );
|
2010-01-11 15:55:52 +00:00
|
|
|
|
|
|
|
|
$this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
|
|
|
|
|
$this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
|
|
|
|
|
$this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
|
|
|
|
|
$this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
|
2007-05-20 23:41:25 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addOption( 'LIMIT', $this->params['limit'] + 1 );
|
2010-02-05 04:40:57 +00:00
|
|
|
$index = array( 'revision' => 'usertext_timestamp' );
|
2007-05-20 23:41:25 +00:00
|
|
|
|
2007-05-21 04:34:48 +00:00
|
|
|
// Mandatory fields: timestamp allows request continuation
|
2008-02-05 15:40:58 +00:00
|
|
|
// ns+title checks if the user has access rights for this page
|
2008-04-14 07:45:50 +00:00
|
|
|
// user_text is necessary if multiple users were specified
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addFields( array(
|
2007-05-21 04:34:48 +00:00
|
|
|
'rev_timestamp',
|
|
|
|
|
'page_namespace',
|
|
|
|
|
'page_title',
|
2008-02-05 15:40:58 +00:00
|
|
|
'rev_user_text',
|
2009-04-22 09:21:33 +00:00
|
|
|
'rev_deleted'
|
2010-01-11 15:55:52 +00:00
|
|
|
) );
|
2009-01-19 16:04:33 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
|
|
|
|
|
$this->fld_patrolled )
|
2009-01-19 16:04:33 +00:00
|
|
|
{
|
|
|
|
|
global $wgUser;
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() )
|
|
|
|
|
$this->dieUsage( "You need the patrol right to request the patrolled flag", 'permissiondenied' );
|
2009-02-04 23:19:18 +00:00
|
|
|
// Use a redundant join condition on both
|
|
|
|
|
// timestamp and ID so we can use the timestamp
|
|
|
|
|
// index
|
2009-02-09 14:07:18 +00:00
|
|
|
$index['recentchanges'] = 'rc_user_text';
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) )
|
2009-02-04 23:19:18 +00:00
|
|
|
{
|
2009-02-09 14:07:18 +00:00
|
|
|
// Put the tables in the right order for
|
|
|
|
|
// STRAIGHT_JOIN
|
2010-01-11 15:55:52 +00:00
|
|
|
$tables = array( 'revision', 'recentchanges', 'page' );
|
|
|
|
|
$this->addOption( 'STRAIGHT_JOIN' );
|
|
|
|
|
$this->addWhere( 'rc_user_text=rev_user_text' );
|
|
|
|
|
$this->addWhere( 'rc_timestamp=rev_timestamp' );
|
|
|
|
|
$this->addWhere( 'rc_this_oldid=rev_id' );
|
2009-02-04 23:19:18 +00:00
|
|
|
}
|
2009-01-19 16:04:33 +00:00
|
|
|
else
|
2009-02-09 14:07:18 +00:00
|
|
|
{
|
|
|
|
|
$tables[] = 'recentchanges';
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addJoinConds( array( 'recentchanges' => array(
|
2009-02-04 23:19:18 +00:00
|
|
|
'LEFT JOIN', array(
|
2009-02-09 14:07:18 +00:00
|
|
|
'rc_user_text=rev_user_text',
|
2009-02-04 23:19:18 +00:00
|
|
|
'rc_timestamp=rev_timestamp',
|
2010-01-11 15:55:52 +00:00
|
|
|
'rc_this_oldid=rev_id' ) ) ) );
|
2009-02-09 14:07:18 +00:00
|
|
|
}
|
2009-01-19 16:04:33 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addTables( $tables );
|
|
|
|
|
$this->addFieldsIf( 'rev_page', $this->fld_ids );
|
|
|
|
|
$this->addFieldsIf( 'rev_id', $this->fld_ids || $this->fld_flags );
|
|
|
|
|
$this->addFieldsIf( 'page_latest', $this->fld_flags );
|
2007-05-21 04:34:48 +00:00
|
|
|
// $this->addFieldsIf('rev_text_id', $this->fld_ids); // Should this field be exposed?
|
2010-01-31 23:06:35 +00:00
|
|
|
$this->addFieldsIf( 'rev_comment', $this->fld_comment || $this->fld_parsedcomment );
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addFieldsIf( 'rev_len', $this->fld_size );
|
|
|
|
|
$this->addFieldsIf( 'rev_minor_edit', $this->fld_flags );
|
|
|
|
|
$this->addFieldsIf( 'rev_parent_id', $this->fld_flags );
|
|
|
|
|
$this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
|
2009-11-01 10:42:41 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->fld_tags )
|
2009-11-01 10:42:41 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addTables( 'tag_summary' );
|
|
|
|
|
$this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
|
|
|
|
|
$this->addFields( 'ts_tags' );
|
2009-11-01 10:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-30 12:09:28 +00:00
|
|
|
if ( isset( $this->params['tag'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addTables( 'change_tag' );
|
|
|
|
|
$this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
|
|
|
|
|
$this->addWhereFld( 'ct_tag', $this->params['tag'] );
|
2010-02-03 23:30:19 +00:00
|
|
|
global $wgOldChangeTagsIndex;
|
|
|
|
|
$index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
|
2009-11-01 10:42:41 +00:00
|
|
|
}
|
2010-02-03 23:30:19 +00:00
|
|
|
|
|
|
|
|
$this->addOption( 'USE INDEX', $index );
|
2007-05-20 23:41:25 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-20 23:41:25 +00:00
|
|
|
/**
|
|
|
|
|
* Extract fields from the database row and append them to a result array
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function extractRowInfo( $row ) {
|
2007-05-20 23:41:25 +00:00
|
|
|
|
|
|
|
|
$vals = array();
|
|
|
|
|
|
2008-02-05 15:40:58 +00:00
|
|
|
$vals['user'] = $row->rev_user_text;
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $row->rev_deleted & Revision::DELETED_USER )
|
2009-04-22 09:21:33 +00:00
|
|
|
$vals['userhidden'] = '';
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->fld_ids ) {
|
|
|
|
|
$vals['pageid'] = intval( $row->rev_page );
|
|
|
|
|
$vals['revid'] = intval( $row->rev_id );
|
2007-05-21 04:34:48 +00:00
|
|
|
// $vals['textid'] = intval($row->rev_text_id); // todo: Should this field be exposed?
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-02-01 15:36:14 +00:00
|
|
|
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
|
2010-01-31 23:06:35 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->fld_title )
|
2010-02-01 15:36:14 +00:00
|
|
|
ApiQueryBase::addTitleInfo( $vals, $title );
|
2007-05-20 23:41:25 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->fld_timestamp )
|
|
|
|
|
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
|
2007-05-20 23:41:25 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->fld_flags ) {
|
|
|
|
|
if ( $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id ) )
|
2007-05-20 23:41:25 +00:00
|
|
|
$vals['new'] = '';
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $row->rev_minor_edit )
|
2007-05-20 23:41:25 +00:00
|
|
|
$vals['minor'] = '';
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $row->page_latest == $row->rev_id )
|
2008-07-09 11:44:49 +00:00
|
|
|
$vals['top'] = '';
|
2007-05-20 23:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-01 15:36:14 +00:00
|
|
|
if ( ( $this->fld_comment || $this->fld_parsedcomment ) && isset( $row->rev_comment ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $row->rev_deleted & Revision::DELETED_COMMENT )
|
2009-04-22 09:21:33 +00:00
|
|
|
$vals['commenthidden'] = '';
|
2010-01-31 23:12:17 +00:00
|
|
|
else {
|
2010-01-31 23:06:35 +00:00
|
|
|
if ( $this->fld_comment )
|
|
|
|
|
$vals['comment'] = $row->rev_comment;
|
|
|
|
|
|
|
|
|
|
if ( $this->fld_parsedcomment ) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rev_comment, $title );
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-04-22 09:21:33 +00:00
|
|
|
}
|
2007-05-20 23:41:25 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->fld_patrolled && $row->rc_patrolled )
|
2009-01-19 16:04:33 +00:00
|
|
|
$vals['patrolled'] = '';
|
2009-05-10 09:25:46 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->fld_size && !is_null( $row->rev_len ) )
|
|
|
|
|
$vals['size'] = intval( $row->rev_len );
|
2009-01-19 16:04:33 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->fld_tags ) {
|
|
|
|
|
if ( $row->ts_tags ) {
|
|
|
|
|
$tags = explode( ',', $row->ts_tags );
|
|
|
|
|
$this->getResult()->setIndexedTagName( $tags, 'tag' );
|
2009-11-01 10:42:41 +00:00
|
|
|
$vals['tags'] = $tags;
|
|
|
|
|
} else {
|
|
|
|
|
$vals['tags'] = array();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-20 23:41:25 +00:00
|
|
|
return $vals;
|
|
|
|
|
}
|
2008-10-18 10:14:02 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
private function continueStr( $row )
|
2008-10-18 10:14:02 +00:00
|
|
|
{
|
|
|
|
|
return $row->rev_user_text . '|' .
|
2010-01-11 15:55:52 +00:00
|
|
|
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
|
2008-10-18 10:14:02 +00:00
|
|
|
}
|
2007-05-20 23:41:25 +00:00
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2006-11-01 12:07:20 +00:00
|
|
|
return array (
|
|
|
|
|
'limit' => array (
|
2006-11-01 15:49:34 +00:00
|
|
|
ApiBase :: PARAM_DFLT => 10,
|
2006-11-01 12:07:20 +00:00
|
|
|
ApiBase :: PARAM_TYPE => 'limit',
|
|
|
|
|
ApiBase :: PARAM_MIN => 1,
|
2007-05-19 18:08:36 +00:00
|
|
|
ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
|
2006-11-01 12:07:20 +00:00
|
|
|
ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
|
|
|
|
|
),
|
|
|
|
|
'start' => array (
|
|
|
|
|
ApiBase :: PARAM_TYPE => 'timestamp'
|
|
|
|
|
),
|
|
|
|
|
'end' => array (
|
|
|
|
|
ApiBase :: PARAM_TYPE => 'timestamp'
|
|
|
|
|
),
|
2008-10-18 10:14:02 +00:00
|
|
|
'continue' => null,
|
2007-05-19 04:26:08 +00:00
|
|
|
'user' => array (
|
2008-02-05 15:40:58 +00:00
|
|
|
ApiBase :: PARAM_ISMULTI => true
|
2007-05-19 04:26:08 +00:00
|
|
|
),
|
2008-02-26 16:56:08 +00:00
|
|
|
'userprefix' => null,
|
2006-11-01 12:07:20 +00:00
|
|
|
'dir' => array (
|
|
|
|
|
ApiBase :: PARAM_DFLT => 'older',
|
|
|
|
|
ApiBase :: PARAM_TYPE => array (
|
|
|
|
|
'newer',
|
|
|
|
|
'older'
|
|
|
|
|
)
|
2007-05-20 23:41:25 +00:00
|
|
|
),
|
2007-07-05 15:09:06 +00:00
|
|
|
'namespace' => array (
|
|
|
|
|
ApiBase :: PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase :: PARAM_TYPE => 'namespace'
|
|
|
|
|
),
|
2007-05-20 23:41:25 +00:00
|
|
|
'prop' => array (
|
|
|
|
|
ApiBase :: PARAM_ISMULTI => true,
|
2009-05-10 09:25:46 +00:00
|
|
|
ApiBase :: PARAM_DFLT => 'ids|title|timestamp|comment|size|flags',
|
2007-05-20 23:41:25 +00:00
|
|
|
ApiBase :: PARAM_TYPE => array (
|
2007-05-21 04:34:48 +00:00
|
|
|
'ids',
|
2007-05-20 23:41:25 +00:00
|
|
|
'title',
|
|
|
|
|
'timestamp',
|
|
|
|
|
'comment',
|
2010-01-31 23:06:35 +00:00
|
|
|
'parsedcomment',
|
2009-05-10 09:25:46 +00:00
|
|
|
'size',
|
2009-01-19 16:04:33 +00:00
|
|
|
'flags',
|
2009-02-04 23:19:18 +00:00
|
|
|
'patrolled',
|
2009-11-01 10:42:41 +00:00
|
|
|
'tags'
|
2007-05-20 23:41:25 +00:00
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
'show' => array (
|
|
|
|
|
ApiBase :: PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase :: PARAM_TYPE => array (
|
|
|
|
|
'minor',
|
|
|
|
|
'!minor',
|
2009-02-04 23:19:18 +00:00
|
|
|
'patrolled',
|
|
|
|
|
'!patrolled',
|
2007-05-20 23:41:25 +00:00
|
|
|
)
|
|
|
|
|
),
|
2010-02-03 23:30:19 +00:00
|
|
|
'tag' => null,
|
2006-11-01 12:07:20 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2006-11-01 12:07:20 +00:00
|
|
|
return array (
|
|
|
|
|
'limit' => 'The maximum number of contributions to return.',
|
|
|
|
|
'start' => 'The start timestamp to return from.',
|
|
|
|
|
'end' => 'The end timestamp to return to.',
|
2008-10-18 10:14:02 +00:00
|
|
|
'continue' => 'When more results are available, use this to continue.',
|
2006-11-01 12:07:20 +00:00
|
|
|
'user' => 'The user to retrieve contributions for.',
|
2008-04-10 17:18:27 +00:00
|
|
|
'userprefix' => 'Retrieve contibutions for all users whose names begin with this value. Overrides ucuser.',
|
2007-05-20 23:41:25 +00:00
|
|
|
'dir' => 'The direction to search (older or newer).',
|
2007-07-05 15:09:06 +00:00
|
|
|
'namespace' => 'Only list contributions in these namespaces',
|
2007-05-20 23:41:25 +00:00
|
|
|
'prop' => 'Include additional pieces of information',
|
2010-01-11 15:55:52 +00:00
|
|
|
'show' => array( 'Show only items that meet this criteria, e.g. non minor edits only: show=!minor',
|
|
|
|
|
'NOTE: if show=patrolled or show=!patrolled is set, revisions older than $wgRCMaxAge won\'t be shown', ),
|
2010-02-03 23:30:19 +00:00
|
|
|
'tag' => 'Only list revisions tagged with this tag',
|
2006-11-01 12:07:20 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2007-07-05 15:09:06 +00:00
|
|
|
return 'Get all edits by a user';
|
2006-11-01 12:07:20 +00:00
|
|
|
}
|
2010-02-13 01:21:52 +00:00
|
|
|
|
|
|
|
|
public function getPossibleErrors() {
|
|
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
|
|
|
|
array( 'code' => 'param_user', 'info' => 'User parameter may not be empty.' ),
|
|
|
|
|
array( 'code' => 'param_user', 'info' => 'User name user is not valid' ),
|
2010-02-14 15:16:09 +00:00
|
|
|
array( 'show' ),
|
2010-02-13 01:21:52 +00:00
|
|
|
array( 'code' => 'permissiondenied', 'info' => 'You need the patrol right to request the patrolled flag' ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
2006-11-01 12:07:20 +00:00
|
|
|
|
|
|
|
|
protected function getExamples() {
|
|
|
|
|
return array (
|
2008-02-26 16:56:08 +00:00
|
|
|
'api.php?action=query&list=usercontribs&ucuser=YurikBot',
|
|
|
|
|
'api.php?action=query&list=usercontribs&ucuserprefix=217.121.114.',
|
2006-11-01 12:07:20 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
2007-12-06 18:33:18 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2006-11-01 12:07:20 +00:00
|
|
|
}
|
2009-05-15 10:42:25 +00:00
|
|
|
}
|