*/
abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
- protected $limit, $diffto, $difftotext, $expandTemplates, $generateXML, $section,
- $parseContent, $fetchContent, $contentFormat, $setParsedLimit = true;
+ protected $limit, $diffto, $difftotext, $difftotextpst, $expandTemplates, $generateXML,
+ $section, $parseContent, $fetchContent, $contentFormat, $setParsedLimit = true;
protected $fld_ids = false, $fld_flags = false, $fld_timestamp = false,
$fld_size = false, $fld_sha1 = false, $fld_comment = false,
protected function parseParameters( $params ) {
if ( !is_null( $params['difftotext'] ) ) {
$this->difftotext = $params['difftotext'];
+ $this->difftotextpst = $params['difftotextpst'];
} elseif ( !is_null( $params['diffto'] ) ) {
if ( $params['diffto'] == 'cur' ) {
$params['diffto'] = 0;
&& $params['diffto'] != 'prev' && $params['diffto'] != 'next'
) {
$p = $this->getModulePrefix();
- $this->dieUsage(
- "{$p}diffto must be set to a non-negative number, \"prev\", \"next\" or \"cur\"",
- 'diffto'
- );
+ $this->dieWithError( [ 'apierror-baddiffto', $p ], 'diffto' );
}
// Check whether the revision exists and is readable,
// DifferenceEngine returns a rather ambiguous empty
if ( $params['diffto'] != 0 ) {
$difftoRev = Revision::newFromId( $params['diffto'] );
if ( !$difftoRev ) {
- $this->dieUsageMsg( array( 'nosuchrevid', $params['diffto'] ) );
+ $this->dieWithError( [ 'apierror-nosuchrevid', $params['diffto'] ] );
}
if ( !$difftoRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
- $this->setWarning( "Couldn't diff to r{$difftoRev->getID()}: content is hidden" );
+ $this->addWarning( [ 'apiwarn-difftohidden', $difftoRev->getId() ] );
$params['diffto'] = null;
}
}
protected function extractRevisionInfo( Revision $revision, $row ) {
$title = $revision->getTitle();
$user = $this->getUser();
- $vals = array();
+ $vals = [];
$anyHidden = false;
if ( $this->fld_ids ) {
}
if ( $revision->userCan( Revision::DELETED_TEXT, $user ) ) {
if ( $revision->getSha1() != '' ) {
- $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
+ $vals['sha1'] = Wikimedia\base_convert( $revision->getSha1(), 36, 16, 40 );
} else {
$vals['sha1'] = '';
}
ApiResult::setIndexedTagName( $tags, 'tag' );
$vals['tags'] = $tags;
} else {
- $vals['tags'] = array();
+ $vals['tags'] = [];
}
}
if ( $content && $this->section !== false ) {
$content = $content->getSection( $this->section, false );
if ( !$content ) {
- $this->dieUsage(
- "There is no section {$this->section} in r" . $revision->getId(),
+ $this->dieWithError(
+ [
+ 'apierror-nosuchsection-what',
+ wfEscapeWikiText( $this->section ),
+ $this->msg( 'revid', $revision->getId() )
+ ],
'nosuchsection'
);
}
}
}
if ( $this->fld_parsetree || ( $this->fld_content && $this->generateXML ) ) {
- if ( !$this->fld_parsetree ) {
- $this->logFeatureUsage( 'action=query&prop=revisions+base&generatexml' );
- }
if ( $content ) {
if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
$t = $content->getNativeData(); # note: don't set $text
Parser::OT_PREPROCESS
);
$dom = $wgParser->preprocessToDom( $t );
- if ( is_callable( array( $dom, 'saveXML' ) ) ) {
+ if ( is_callable( [ $dom, 'saveXML' ] ) ) {
$xml = $dom->saveXML();
} else {
$xml = $dom->__toString();
$vals['parsetree'] = $xml;
} else {
$vals['badcontentformatforparsetree'] = true;
- $this->setWarning( "Conversion to XML is supported for wikitext only, " .
- $title->getPrefixedDBkey() .
- " uses content model " . $content->getModel() );
+ $this->addWarning(
+ [
+ 'apierror-parsetree-notwikitext-title',
+ wfEscapeWikiText( $title->getPrefixedText() ),
+ $content->getModel()
+ ],
+ 'parsetree-notwikitext'
+ );
}
}
}
$text = null;
if ( $this->expandTemplates && !$this->parseContent ) {
- #XXX: implement template expansion for all content types in ContentHandler?
+ # XXX: implement template expansion for all content types in ContentHandler?
if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
$text = $content->getNativeData();
ParserOptions::newFromContext( $this->getContext() )
);
} else {
- $this->setWarning( "Template expansion is supported for wikitext only, " .
- $title->getPrefixedDBkey() .
- " uses content model " . $content->getModel() );
+ $this->addWarning( [
+ 'apierror-templateexpansion-notwikitext',
+ wfEscapeWikiText( $title->getPrefixedText() ),
+ $content->getModel()
+ ] );
$vals['badcontentformat'] = true;
$text = false;
}
}
if ( $text === null ) {
- $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
+ $format = $this->contentFormat ?: $content->getDefaultFormat();
$model = $content->getModel();
if ( !$content->isSupportedFormat( $format ) ) {
- $name = $title->getPrefixedDBkey();
- $this->setWarning( "The requested format {$this->contentFormat} is not " .
- "supported for content model $model used by $name" );
+ $name = wfEscapeWikiText( $title->getPrefixedText() );
+ $this->addWarning( [ 'apierror-badformat', $this->contentFormat, $model, $name ] );
$vals['badcontentformat'] = true;
$text = false;
} else {
static $n = 0; // Number of uncached diffs we've had
if ( $n < $this->getConfig()->get( 'APIMaxUncachedDiffs' ) ) {
- $vals['diff'] = array();
+ $vals['diff'] = [];
$context = new DerivativeContext( $this->getContext() );
$context->setTitle( $title );
$handler = $revision->getContentHandler();
if ( $this->contentFormat
&& !ContentHandler::getForModelID( $model )->isSupportedFormat( $this->contentFormat )
) {
- $name = $title->getPrefixedDBkey();
- $this->setWarning( "The requested format {$this->contentFormat} is not " .
- "supported for content model $model used by $name" );
+ $name = wfEscapeWikiText( $title->getPrefixedText() );
+ $this->addWarning( [ 'apierror-badformat', $this->contentFormat, $model, $name ] );
$vals['diff']['badcontentformat'] = true;
$engine = null;
} else {
$this->contentFormat
);
+ if ( $this->difftotextpst ) {
+ $popts = ParserOptions::newFromContext( $this->getContext() );
+ $difftocontent = $difftocontent->preSaveTransform( $title, $user, $popts );
+ }
+
$engine = $handler->createDifferenceEngine( $context );
$engine->setContent( $content, $difftocontent );
}
} else {
- $engine = $handler->createDifferenceEngine( $context, $revision->getID(), $this->diffto );
+ $engine = $handler->createDifferenceEngine( $context, $revision->getId(), $this->diffto );
$vals['diff']['from'] = $engine->getOldid();
$vals['diff']['to'] = $engine->getNewid();
}
}
public function getAllowedParams() {
- return array(
- 'prop' => array(
+ return [
+ 'prop' => [
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
- ApiBase::PARAM_TYPE => array(
+ ApiBase::PARAM_TYPE => [
'ids',
'flags',
'timestamp',
'content',
'tags',
'parsetree',
- ),
+ ],
ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-prop',
- ApiBase::PARAM_HELP_MSG_PER_VALUE => array(
+ ApiBase::PARAM_HELP_MSG_PER_VALUE => [
'ids' => 'apihelp-query+revisions+base-paramvalue-prop-ids',
'flags' => 'apihelp-query+revisions+base-paramvalue-prop-flags',
'timestamp' => 'apihelp-query+revisions+base-paramvalue-prop-timestamp',
'parsedcomment' => 'apihelp-query+revisions+base-paramvalue-prop-parsedcomment',
'content' => 'apihelp-query+revisions+base-paramvalue-prop-content',
'tags' => 'apihelp-query+revisions+base-paramvalue-prop-tags',
- 'parsetree' => array( 'apihelp-query+revisions+base-paramvalue-prop-parsetree',
- CONTENT_MODEL_WIKITEXT ),
- ),
- ),
- 'limit' => array(
+ 'parsetree' => [ 'apihelp-query+revisions+base-paramvalue-prop-parsetree',
+ CONTENT_MODEL_WIKITEXT ],
+ ],
+ ],
+ 'limit' => [
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2,
ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-limit',
- ),
- 'expandtemplates' => array(
+ ],
+ 'expandtemplates' => [
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-expandtemplates',
- ),
- 'generatexml' => array(
+ ],
+ 'generatexml' => [
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,
ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-generatexml',
- ),
- 'parse' => array(
+ ],
+ 'parse' => [
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-parse',
- ),
- 'section' => array(
- ApiBase::PARAM_DFLT => null,
+ ],
+ 'section' => [
ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-section',
- ),
- 'diffto' => array(
- ApiBase::PARAM_DFLT => null,
+ ],
+ 'diffto' => [
ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-diffto',
- ),
- 'difftotext' => array(
- ApiBase::PARAM_DFLT => null,
+ ],
+ 'difftotext' => [
ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-difftotext',
- ),
- 'contentformat' => array(
+ ],
+ 'difftotextpst' => [
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-difftotextpst',
+ ],
+ 'contentformat' => [
ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
- ApiBase::PARAM_DFLT => null,
ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-contentformat',
- ),
- );
+ ],
+ ];
}
}