summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryDeletedrevs.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
committerPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
commit222b01f5169f1c7e69762e0e8904c24f78f71882 (patch)
tree8e932e12546bb991357ec48eb1638d1770be7a35 /includes/api/ApiQueryDeletedrevs.php
parent00ab76a6b686e98a914afc1975812d2b1aaa7016 (diff)
update to MediaWiki 1.16.0
Diffstat (limited to 'includes/api/ApiQueryDeletedrevs.php')
-rw-r--r--includes/api/ApiQueryDeletedrevs.php257
1 files changed, 130 insertions, 127 deletions
diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php
index bd767b1b..b26c7051 100644
--- a/includes/api/ApiQueryDeletedrevs.php
+++ b/includes/api/ApiQueryDeletedrevs.php
@@ -23,9 +23,9 @@
* http://www.gnu.org/copyleft/gpl.html
*/
-if (!defined('MEDIAWIKI')) {
+if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ('ApiQueryBase.php');
+ require_once ( 'ApiQueryBase.php' );
}
/**
@@ -35,27 +35,28 @@ if (!defined('MEDIAWIKI')) {
*/
class ApiQueryDeletedrevs extends ApiQueryBase {
- public function __construct($query, $moduleName) {
- parent :: __construct($query, $moduleName, 'dr');
+ public function __construct( $query, $moduleName ) {
+ parent :: __construct( $query, $moduleName, 'dr' );
}
public function execute() {
global $wgUser;
// Before doing anything at all, let's check permissions
- if(!$wgUser->isAllowed('deletedhistory'))
- $this->dieUsage('You don\'t have permission to view deleted revision information', 'permissiondenied');
+ if ( !$wgUser->isAllowed( 'deletedhistory' ) )
+ $this->dieUsage( 'You don\'t have permission to view deleted revision information', 'permissiondenied' );
$db = $this->getDB();
- $params = $this->extractRequestParams(false);
- $prop = array_flip($params['prop']);
- $fld_revid = isset($prop['revid']);
- $fld_user = isset($prop['user']);
- $fld_comment = isset($prop['comment']);
- $fld_minor = isset($prop['minor']);
- $fld_len = isset($prop['len']);
- $fld_content = isset($prop['content']);
- $fld_token = isset($prop['token']);
+ $params = $this->extractRequestParams( false );
+ $prop = array_flip( $params['prop'] );
+ $fld_revid = isset( $prop['revid'] );
+ $fld_user = isset( $prop['user'] );
+ $fld_comment = isset( $prop['comment'] );
+ $fld_parsedcomment = isset ( $prop['parsedcomment'] );
+ $fld_minor = isset( $prop['minor'] );
+ $fld_len = isset( $prop['len'] );
+ $fld_content = isset( $prop['content'] );
+ $fld_token = isset( $prop['token'] );
$result = $this->getResult();
$pageSet = $this->getPageSet();
@@ -67,36 +68,35 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
// 'user': List deleted revs by a certain user
// 'all': List all deleted revs
$mode = 'all';
- if(count($titles) > 0)
+ if ( count( $titles ) > 0 )
$mode = 'revs';
- else if(!is_null($params['user']))
+ else if ( !is_null( $params['user'] ) )
$mode = 'user';
- if(!is_null($params['user']) && !is_null($params['excludeuser']))
- $this->dieUsage('user and excludeuser cannot be used together', 'badparams');
+ if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) )
+ $this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
- $this->addTables('archive');
- $this->addWhere('ar_deleted = 0');
- $this->addFields(array('ar_title', 'ar_namespace', 'ar_timestamp'));
- if($fld_revid)
- $this->addFields('ar_rev_id');
- if($fld_user)
- $this->addFields('ar_user_text');
- if($fld_comment)
- $this->addFields('ar_comment');
- if($fld_minor)
- $this->addFields('ar_minor_edit');
- if($fld_len)
- $this->addFields('ar_len');
- if($fld_content)
- {
- $this->addTables('text');
- $this->addFields(array('ar_text', 'ar_text_id', 'old_text', 'old_flags'));
- $this->addWhere('ar_text_id = old_id');
+ $this->addTables( 'archive' );
+ $this->addWhere( 'ar_deleted = 0' );
+ $this->addFields( array( 'ar_title', 'ar_namespace', 'ar_timestamp' ) );
+ if ( $fld_revid )
+ $this->addFields( 'ar_rev_id' );
+ if ( $fld_user )
+ $this->addFields( 'ar_user_text' );
+ if ( $fld_comment || $fld_parsedcomment )
+ $this->addFields( 'ar_comment' );
+ if ( $fld_minor )
+ $this->addFields( 'ar_minor_edit' );
+ if ( $fld_len )
+ $this->addFields( 'ar_len' );
+ if ( $fld_content ) {
+ $this->addTables( 'text' );
+ $this->addFields( array( 'ar_text', 'ar_text_id', 'old_text', 'old_flags' ) );
+ $this->addWhere( 'ar_text_id = old_id' );
// This also means stricter restrictions
- if(!$wgUser->isAllowed('undelete'))
- $this->dieUsage('You don\'t have permission to view deleted revision content', 'permissiondenied');
+ if ( !$wgUser->isAllowed( 'undelete' ) )
+ $this->dieUsage( 'You don\'t have permission to view deleted revision content', 'permissiondenied' );
}
// Check limits
$userMax = $fld_content ? ApiBase :: LIMIT_SML1 : ApiBase :: LIMIT_BIG1;
@@ -104,143 +104,136 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
$limit = $params['limit'];
- if( $limit == 'max' ) {
+ if ( $limit == 'max' ) {
$limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
$this->getResult()->addValue( 'limits', $this->getModuleName(), $limit );
}
- $this->validateLimit('limit', $limit, 1, $userMax, $botMax);
+ $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
- if($fld_token)
+ if ( $fld_token )
// Undelete tokens are identical for all pages, so we cache one here
$token = $wgUser->editToken();
// We need a custom WHERE clause that matches all titles.
- if($mode == 'revs')
- {
- $lb = new LinkBatch($titles);
- $where = $lb->constructSet('ar', $db);
- $this->addWhere($where);
- }
- elseif($mode == 'all')
- {
- $this->addWhereFld('ar_namespace', $params['namespace']);
- if(!is_null($params['from']))
+ if ( $mode == 'revs' ) {
+ $lb = new LinkBatch( $titles );
+ $where = $lb->constructSet( 'ar', $db );
+ $this->addWhere( $where );
+ } elseif ( $mode == 'all' ) {
+ $this->addWhereFld( 'ar_namespace', $params['namespace'] );
+ if ( !is_null( $params['from'] ) )
{
- $from = $this->getDB()->strencode($this->titleToKey($params['from']));
- $this->addWhere("ar_title >= '$from'");
+ $from = $this->getDB()->strencode( $this->titleToKey( $params['from'] ) );
+ $this->addWhere( "ar_title >= '$from'" );
}
}
- if(!is_null($params['user'])) {
- $this->addWhereFld('ar_user_text', $params['user']);
- } elseif(!is_null($params['excludeuser'])) {
- $this->addWhere('ar_user_text != ' .
- $this->getDB()->addQuotes($params['excludeuser']));
+ if ( !is_null( $params['user'] ) ) {
+ $this->addWhereFld( 'ar_user_text', $params['user'] );
+ } elseif ( !is_null( $params['excludeuser'] ) ) {
+ $this->addWhere( 'ar_user_text != ' .
+ $this->getDB()->addQuotes( $params['excludeuser'] ) );
}
- if(!is_null($params['continue']) && ($mode == 'all' || $mode == 'revs'))
+ if ( !is_null( $params['continue'] ) && ( $mode == 'all' || $mode == 'revs' ) )
{
- $cont = explode('|', $params['continue']);
- if(count($cont) != 3)
- $this->dieUsage("Invalid continue param. You should pass the original value returned by the previous query", "badcontinue");
- $ns = intval($cont[0]);
- $title = $this->getDB()->strencode($this->titleToKey($cont[1]));
- $ts = $this->getDB()->strencode($cont[2]);
- $op = ($params['dir'] == 'newer' ? '>' : '<');
- $this->addWhere("ar_namespace $op $ns OR " .
+ $cont = explode( '|', $params['continue'] );
+ if ( count( $cont ) != 3 )
+ $this->dieUsage( "Invalid continue param. You should pass the original value returned by the previous query", "badcontinue" );
+ $ns = intval( $cont[0] );
+ $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
+ $ts = $this->getDB()->strencode( $cont[2] );
+ $op = ( $params['dir'] == 'newer' ? '>' : '<' );
+ $this->addWhere( "ar_namespace $op $ns OR " .
"(ar_namespace = $ns AND " .
"(ar_title $op '$title' OR " .
"(ar_title = '$title' AND " .
- "ar_timestamp = '$ts')))");
+ "ar_timestamp $op= '$ts')))" );
}
- $this->addOption('LIMIT', $limit + 1);
- $this->addOption('USE INDEX', array('archive' => ($mode == 'user' ? 'usertext_timestamp' : 'name_title_timestamp')));
- if($mode == 'all')
- {
- if($params['unique'])
+ $this->addOption( 'LIMIT', $limit + 1 );
+ $this->addOption( 'USE INDEX', array( 'archive' => ( $mode == 'user' ? 'usertext_timestamp' : 'name_title_timestamp' ) ) );
+ if ( $mode == 'all' ) {
+ if ( $params['unique'] )
{
- $this->addOption('GROUP BY', 'ar_title');
- $this->addOption('ORDER BY', 'ar_title');
- }
- else
- $this->addOption('ORDER BY', 'ar_title, ar_timestamp');
- }
- else
- {
- if($mode == 'revs')
+ $this->addOption( 'GROUP BY', 'ar_title' );
+ $this->addOption( 'ORDER BY', 'ar_title' );
+ } else
+ $this->addOption( 'ORDER BY', 'ar_title, ar_timestamp' );
+ } else {
+ if ( $mode == 'revs' )
{
// Sort by ns and title in the same order as timestamp for efficiency
- $this->addWhereRange('ar_namespace', $params['dir'], null, null);
- $this->addWhereRange('ar_title', $params['dir'], null, null);
+ $this->addWhereRange( 'ar_namespace', $params['dir'], null, null );
+ $this->addWhereRange( 'ar_title', $params['dir'], null, null );
}
- $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']);
+ $this->addWhereRange( 'ar_timestamp', $params['dir'], $params['start'], $params['end'] );
}
- $res = $this->select(__METHOD__);
+ $res = $this->select( __METHOD__ );
$pageMap = array(); // Maps ns&title to (fake) pageid
$count = 0;
$newPageID = 0;
- while($row = $db->fetchObject($res))
+ while ( $row = $db->fetchObject( $res ) )
{
- if(++$count > $limit)
- {
+ if ( ++$count > $limit ) {
// We've had enough
- if($mode == 'all' || $mode == 'revs')
- $this->setContinueEnumParameter('continue', intval($row->ar_namespace) . '|' .
- $this->keyToTitle($row->ar_title) . '|' . $row->ar_timestamp);
+ if ( $mode == 'all' || $mode == 'revs' )
+ $this->setContinueEnumParameter( 'continue', intval( $row->ar_namespace ) . '|' .
+ $this->keyToTitle( $row->ar_title ) . '|' . $row->ar_timestamp );
else
- $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ar_timestamp));
+ $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->ar_timestamp ) );
break;
}
$rev = array();
- $rev['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ar_timestamp);
- if($fld_revid)
- $rev['revid'] = intval($row->ar_rev_id);
- if($fld_user)
+ $rev['timestamp'] = wfTimestamp( TS_ISO_8601, $row->ar_timestamp );
+ if ( $fld_revid )
+ $rev['revid'] = intval( $row->ar_rev_id );
+ if ( $fld_user )
$rev['user'] = $row->ar_user_text;
- if($fld_comment)
+ if ( $fld_comment )
$rev['comment'] = $row->ar_comment;
- if($fld_minor)
- if($row->ar_minor_edit == 1)
- $rev['minor'] = '';
- if($fld_len)
+
+ $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+
+ if ( $fld_parsedcomment ) {
+ global $wgUser;
+ $rev['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->ar_comment, $title );
+ }
+ if ( $fld_minor && $row->ar_minor_edit == 1 )
+ $rev['minor'] = '';
+ if ( $fld_len )
$rev['len'] = $row->ar_len;
- if($fld_content)
- ApiResult::setContent($rev, Revision::getRevisionText($row));
+ if ( $fld_content )
+ ApiResult::setContent( $rev, Revision::getRevisionText( $row ) );
- if(!isset($pageMap[$row->ar_namespace][$row->ar_title]))
- {
+ if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
$pageID = $newPageID++;
$pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
- $t = Title::makeTitle($row->ar_namespace, $row->ar_title);
- $a['revisions'] = array($rev);
- $result->setIndexedTagName($a['revisions'], 'rev');
- ApiQueryBase::addTitleInfo($a, $t);
- if($fld_token)
+ $a['revisions'] = array( $rev );
+ $result->setIndexedTagName( $a['revisions'], 'rev' );
+ ApiQueryBase::addTitleInfo( $a, $title );
+ if ( $fld_token )
$a['token'] = $token;
- $fit = $result->addValue(array('query', $this->getModuleName()), $pageID, $a);
- }
- else
- {
+ $fit = $result->addValue( array( 'query', $this->getModuleName() ), $pageID, $a );
+ } else {
$pageID = $pageMap[$row->ar_namespace][$row->ar_title];
$fit = $result->addValue(
- array('query', $this->getModuleName(), $pageID, 'revisions'),
- null, $rev);
+ array( 'query', $this->getModuleName(), $pageID, 'revisions' ),
+ null, $rev );
}
- if(!$fit)
- {
- if($mode == 'all' || $mode == 'revs')
- $this->setContinueEnumParameter('continue', intval($row->ar_namespace) . '|' .
- $this->keyToTitle($row->ar_title) . '|' . $row->ar_timestamp);
+ if ( !$fit ) {
+ if ( $mode == 'all' || $mode == 'revs' )
+ $this->setContinueEnumParameter( 'continue', intval( $row->ar_namespace ) . '|' .
+ $this->keyToTitle( $row->ar_title ) . '|' . $row->ar_timestamp );
else
- $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ar_timestamp));
+ $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->ar_timestamp ) );
break;
}
}
- $db->freeResult($res);
- $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'page');
+ $db->freeResult( $res );
+ $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'page' );
}
public function getAllowedParams() {
@@ -284,6 +277,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
'revid',
'user',
'comment',
+ 'parsedcomment',
'minor',
'len',
'content',
@@ -320,6 +314,15 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
'For instance, a parameter marked (1) only applies to mode 1 and is ignored in modes 2 and 3.',
);
}
+
+ public function getPossibleErrors() {
+ return array_merge( parent::getPossibleErrors(), array(
+ array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view deleted revision information' ),
+ array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together' ),
+ array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view deleted revision content' ),
+ array( 'code' => 'badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
+ ) );
+ }
protected function getExamples() {
return array (
@@ -335,6 +338,6 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
}
public function getVersion() {
- return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 69579 2010-07-20 02:49:55Z tstarling $';
+ return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 69578 2010-07-20 02:46:20Z tstarling $';
}
} \ No newline at end of file