33 $this->props = array_flip(
$params[
'prop'] );
36 $this->
getMain()->setCacheMode(
'public' );
42 if (
$params[
'torelative'] !==
null ) {
44 $this->
dieWithError(
'apierror-compare-relative-to-nothing' );
46 switch (
$params[
'torelative'] ) {
50 $toContent = $fromContent;
51 $fromRev = $relRev->getPrevious();
52 $fromContent = $fromRev
54 : $toContent->getContentHandler()->makeEmptyContent();
55 if ( !$fromContent ) {
57 [
'apierror-missingcontent-revid', $fromRev->getId() ],
'missingcontent'
63 $toRev = $relRev->getNext();
68 $this->
dieWithError( [
'apierror-missingcontent-revid', $toRev->getId() ],
'missingcontent' );
73 $title = $relRev->getTitle();
74 $id = $title->getLatestRevID();
78 [
'apierror-missingrev-title',
wfEscapeWikiText( $title->getPrefixedText() ) ],
'nosuchrevid'
83 $this->
dieWithError( [
'apierror-missingcontent-revid', $toRev->getId() ],
'missingcontent' );
93 if ( !$fromContent || !$toContent ) {
99 if ( $relRev && $relRev->getTitle() ) {
100 $context->setTitle( $relRev->getTitle() );
101 } elseif ( $relRev2 && $relRev2->getTitle() ) {
102 $context->setTitle( $relRev2->getTitle() );
105 if ( $this->guessedTitle ) {
106 $context->setTitle( $this->guessedTitle );
109 $de = $fromContent->getContentHandler()->createDifferenceEngine(
111 $fromRev ? $fromRev->getId() : 0,
112 $toRev ? $toRev->getId() : 0,
117 $de->setContent( $fromContent, $toContent );
118 $difftext = $de->getDiffBody();
119 if ( $difftext ===
false ) {
125 $this->
setVals( $vals,
'from', $fromRev );
126 $this->
setVals( $vals,
'to', $toRev );
128 if ( isset( $this->props[
'rel'] ) ) {
130 $rev = $fromRev->getPrevious();
132 $vals[
'prev'] =
$rev->getId();
136 $rev = $toRev->getNext();
138 $vals[
'next'] =
$rev->getId();
143 if ( isset( $this->props[
'diffsize'] ) ) {
144 $vals[
'diffsize'] = strlen( $difftext );
146 if ( isset( $this->props[
'diff'] ) ) {
165 if ( $this->guessed ) {
169 $this->guessed =
true;
172 foreach ( [
'from',
'to' ] as $prefix ) {
173 if (
$params[
"{$prefix}rev"] !==
null ) {
174 $revId =
$params[
"{$prefix}rev"];
178 $row = $this->
getDB()->selectRow(
182 [
'ar_namespace',
'ar_title' ]
184 [
'ar_rev_id' => $revId ],
192 $this->guessedTitle =
$rev->getTitle();
193 $this->guessedModel =
$rev->getContentModel();
198 if (
$params[
"{$prefix}title"] !==
null ) {
199 $title = Title::newFromText(
$params[
"{$prefix}title"] );
200 if ( $title && !$title->isExternal() ) {
201 $this->guessedTitle =
$title;
206 if (
$params[
"{$prefix}id"] !==
null ) {
207 $title = Title::newFromID(
$params[
"{$prefix}id"] );
209 $this->guessedTitle =
$title;
215 if ( !$this->guessedModel ) {
216 if ( $this->guessedTitle ) {
217 $this->guessedModel = $this->guessedTitle->getContentModel();
218 } elseif (
$params[
'fromcontentmodel'] !==
null ) {
219 $this->guessedModel =
$params[
'fromcontentmodel'];
220 } elseif (
$params[
'tocontentmodel'] !==
null ) {
221 $this->guessedModel =
$params[
'tocontentmodel'];
246 $suppliedContent =
$params[
"{$prefix}text"] !==
null;
250 if (
$params[
"{$prefix}rev"] !==
null ) {
251 $revId =
$params[
"{$prefix}rev"];
252 } elseif (
$params[
"{$prefix}title"] !==
null ||
$params[
"{$prefix}id"] !==
null ) {
253 if (
$params[
"{$prefix}title"] !==
null ) {
254 $title = Title::newFromText(
$params[
"{$prefix}title"] );
255 if ( !$title || $title->isExternal() ) {
261 $title = Title::newFromID(
$params[
"{$prefix}id"] );
263 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
"{$prefix}id"] ] );
266 $revId = $title->getLatestRevID();
270 if ( !$suppliedContent ) {
271 if ( $title->exists() ) {
273 [
'apierror-missingrev-title',
wfEscapeWikiText( $title->getPrefixedText() ) ],
'nosuchrevid'
277 [
'apierror-missingtitle-byname',
wfEscapeWikiText( $title->getPrefixedText() ) ],
284 if ( $revId !==
null ) {
286 if ( !
$rev && $this->
getUser()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
288 $row = $this->
getDB()->selectRow(
292 [
'ar_namespace',
'ar_title' ]
294 [
'ar_rev_id' => $revId ],
299 $rev->isArchive =
true;
303 $this->
dieWithError( [
'apierror-nosuchrevid', $revId ] );
305 $title =
$rev->getTitle();
309 if ( !$suppliedContent ) {
312 $this->
dieWithError( [
'apierror-missingcontent-revid', $revId ],
'missingcontent' );
319 $model =
$params[
"{$prefix}contentmodel"];
320 $format =
$params[
"{$prefix}contentformat"];
322 if ( !$model &&
$rev ) {
323 $model =
$rev->getContentModel();
325 if ( !$model && $title ) {
326 $model = $title->getContentModel();
334 $this->
addWarning( [
'apiwarn-compare-nocontentmodel', $model ] );
346 'wrap' =>
ApiMessage::create(
'apierror-contentserializationexception',
'parseerror' )
350 if (
$params[
"{$prefix}pst"] ) {
354 $popts = ParserOptions::newFromContext( $this->
getContext() );
355 $content = $content->preSaveTransform( $title, $this->
getUser(), $popts );
358 return [
null, $content,
$rev ];
369 $title =
$rev->getTitle();
370 if ( isset( $this->props[
'ids'] ) ) {
371 $vals[
"{$prefix}id"] = $title->getArticleId();
372 $vals[
"{$prefix}revid"] =
$rev->getId();
374 if ( isset( $this->props[
'title'] ) ) {
377 if ( isset( $this->props[
'size'] ) ) {
378 $vals[
"{$prefix}size"] =
$rev->getSize();
383 $vals[
"{$prefix}texthidden"] =
true;
388 $vals[
"{$prefix}userhidden"] =
true;
391 if ( isset( $this->props[
'user'] ) &&
399 $vals[
"{$prefix}commenthidden"] =
true;
403 if ( isset( $this->props[
'comment'] ) ) {
406 if ( isset( $this->props[
'parsedcomment'] ) ) {
415 $this->
getMain()->setCacheMode(
'private' );
417 $vals[
"{$prefix}suppressed"] =
true;
421 if ( !empty(
$rev->isArchive ) ) {
422 $this->
getMain()->setCacheMode(
'private' );
423 $vals[
"{$prefix}archive"] =
true;
451 foreach ( $fromToParams as $k => $v ) {
454 foreach ( $fromToParams as $k => $v ) {
486 'action=compare&fromrev=1&torev=2'
487 =>
'apihelp-compare-example-1',
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
This abstract class implements many basic API functions, and is the base of all API classes.
getDB()
Gets a default replica DB connection object.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
getMain()
Get the main module.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
getResult()
Get the result object.
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
requireAtLeastOneParameter( $params, $required)
Die if none of a certain set of parameters is set and not false.
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
guessTitleAndModel()
Guess an appropriate default Title and content model for this request.
getExamplesMessages()
Returns usage examples for this module.
setVals(&$vals, $prefix, $rev)
Set value fields from a Revision object.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getDiffContent( $prefix, array $params)
Get the Revision and Content for one side of the diff.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
static getAllContentFormats()
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
static getContentModels()
getUser()
Get the User object.
getContext()
Get the base IContextSource object.
An IContextSource implementation which will inherit context from another source but allow individual ...
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Exception representing a failure to serialize or unserialize a content object.
static selectArchiveFields()
Return the list of revision fields that should be selected to create a new revision from an archive r...
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
namespace and then decline to actually register it file or subcat img or subcat $title
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
const CONTENT_MODEL_WIKITEXT