<?php
-
/**
- * Created on Sep 7, 2006
- *
* API for MediaWiki 1.8+
*
+ * Created on Sep 7, 2006
+ *
* Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
*
* 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.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
*/
if ( !defined( 'MEDIAWIKI' ) ) {
}
private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false,
- $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_content = false, $fld_tags = false;
+ $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
+ $fld_content = false, $fld_tags = false;
protected function getTokenFunctions() {
// tokenname => function
}
$db = $this->getDB();
- $this->addTables( array( 'page', 'revision' ) );
+ $this->addTables( 'page' );
$this->addFields( Revision::selectFields() );
$this->addWhere( 'page_id = rev_page' );
$this->fld_comment = isset ( $prop['comment'] );
$this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
$this->fld_size = isset ( $prop['size'] );
+ $this->fld_userid = isset( $prop['userid'] );
$this->fld_user = isset ( $prop['user'] );
$this->token = $params['token'];
}
}
+ //Bug 24166 - API error when using rvprop=tags
+ $this->addTables( 'revision' );
+
$userMax = ( $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
$botMax = ( $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
$limit = $params['limit'];
if ( $limit == 'max' ) {
$limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
- $this->getResult()->addValue( 'limits', $this->getModuleName(), $limit );
+ $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
}
if ( $enumRevMode ) {
// This is mostly to prevent parameter errors (and optimize SQL?)
- if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) )
- {
+ if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) ) {
$this->dieUsage( 'start and startid cannot be used together', 'badparams' );
}
$this->dieUsage( 'end and endid cannot be used together', 'badparams' );
}
- if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) )
- {
+ if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
$this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
}
$this->addOption( 'LIMIT', $limit + 1 );
$this->addOption( 'USE INDEX', $index );
- $data = array();
$count = 0;
$res = $this->select( __METHOD__ );
- while ( $row = $db->fetchObject( $res ) ) {
+ foreach ( $res as $row ) {
if ( ++ $count > $limit ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
if ( !$enumRevMode ) {
break;
}
- //
$fit = $this->addPageSubItem( $row->rev_page, $this->extractRowInfo( $row ), 'rev' );
if ( !$fit ) {
if ( $enumRevMode ) {
break;
}
}
- $db->freeResult( $res );
}
private function extractRowInfo( $row ) {
$vals['minor'] = '';
}
- if ( $this->fld_user ) {
+ if ( $this->fld_user || $this->fld_userid ) {
if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
$vals['userhidden'] = '';
} else {
- $vals['user'] = $revision->getUserText();
+ if ( $this->fld_user ) {
+ $vals['user'] = $revision->getUserText();
+ }
+ if ( $this->fld_userid ) {
+ $user = User::newFromText( $revision->getUserText() );
+ $vals['userid'] = $user->getId();
+ }
if ( !$revision->getUser() ) {
$vals['anon'] = '';
}
$vals['commenthidden'] = '';
} else {
$comment = $revision->getComment();
- if ( strval( $comment ) !== '' ) {
- if ( $this->fld_comment ) {
- $vals['comment'] = $comment;
- }
-
- if ( $this->fld_parsedcomment ) {
- global $wgUser;
- $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $comment, $title );
- }
+
+ if ( $this->fld_comment ) {
+ $vals['comment'] = $comment;
+ }
+
+ if ( $this->fld_parsedcomment ) {
+ global $wgUser;
+ $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $comment, $title );
}
}
}
}
$text = null;
+ global $wgParser;
if ( $this->fld_content || !is_null( $this->difftotext ) ) {
- global $wgParser;
$text = $revision->getText();
// Expand templates after getting section content because
// template-added sections don't count and Parser::preprocess()
return $vals;
}
+ public function getCacheMode( $params ) {
+ if ( isset( $params['token'] ) ) {
+ return 'private';
+ }
+ if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
+ // formatComment() calls wfMsg() among other things
+ return 'anon-public-user-private';
+ }
+ return 'public';
+ }
+
public function getAllowedParams() {
return array(
'prop' => array(
'flags',
'timestamp',
'user',
+ 'userid',
'size',
'comment',
'parsedcomment',
}
public function getParamDescription() {
+ $p = $this->getModulePrefix();
return array(
- 'prop' => 'Which properties to get for each revision.',
+ 'prop' => array(
+ 'Which properties to get for each revision:',
+ ' ids - The ID of the revision',
+ ' flags - Revision flags (minor)',
+ ' timestamp - The timestamp of the revision',
+ ' user - User that made the revision',
+ ' userid - User id of revision creator',
+ ' size - Length of the revision',
+ ' comment - Comment by the user for revision',
+ ' parsedcomment - Parsed comment by the user for the revision',
+ ' content - Text of the revision',
+ ' tags - Tags for the revision',
+ ),
'limit' => 'Limit how many revisions will be returned (enum)',
'startid' => 'From which revision id to start enumeration (enum)',
'endid' => 'Stop revision enumeration on this revid (enum)',
'excludeuser' => 'Exclude revisions made by user',
'expandtemplates' => 'Expand templates in revision content',
'generatexml' => 'Generate XML parse tree for revision content',
- 'section' => 'Only retrieve the content of this section',
+ 'section' => 'Only retrieve the content of this section number',
'token' => 'Which tokens to obtain for each revision',
'continue' => 'When more results are available, use this to continue',
'diffto' => array( 'Revision ID to diff each revision to.',
- 'Use "prev", "next" and "cur" for the previous, next and current revision respectively.' ),
+ 'Use "prev", "next" and "cur" for the previous, next and current revision respectively' ),
'difftotext' => array( 'Text to diff each revision to. Only diffs a limited number of revisions.',
- 'Overrides diffto. If rvsection is set, only that section will be diffed against this text.' ),
+ "Overrides {$p}diffto. If {$p}section is set, only that section will be diffed against this text" ),
'tag' => 'Only list revisions tagged with this tag',
);
}
public function getDescription() {
return array(
- 'Get revision information.',
+ 'Get revision information',
'This module may be used in several ways:',
- ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter.',
- ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params.',
- ' 3) Get data about a set of revisions by setting their IDs with revids parameter.',
- 'All parameters marked as (enum) may only be used with a single page (#2).'
+ ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter',
+ ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params',
+ ' 3) Get data about a set of revisions by setting their IDs with revids parameter',
+ 'All parameters marked as (enum) may only be used with a single page (#2)'
);
}