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
53 ? $fromRev->getContent( Revision::FOR_THIS_USER, $this->
getUser() )
54 : $toContent->getContentHandler()->makeEmptyContent();
55 if ( !$fromContent ) {
57 [
'apierror-missingcontent-revid', $fromRev->getId() ],
'missingcontent'
63 $toRev = $relRev->getNext();
65 ? $toRev->getContent( Revision::FOR_THIS_USER, $this->
getUser() )
68 $this->
dieWithError( [
'apierror-missingcontent-revid', $toRev->getId() ],
'missingcontent' );
73 $title = $relRev->getTitle();
74 $id = $title->getLatestRevID();
75 $toRev = $id ? Revision::newFromId( $id ) :
null;
78 [
'apierror-missingrev-title',
wfEscapeWikiText( $title->getPrefixedText() ) ],
82 $toContent = $toRev->getContent( Revision::FOR_THIS_USER, $this->
getUser() );
84 $this->
dieWithError( [
'apierror-missingcontent-revid', $toRev->getId() ],
'missingcontent' );
94 if ( !$fromContent || !$toContent ) {
99 if ( isset(
$params[
'fromsection'] ) ) {
100 $fromContent = $fromContent->getSection(
$params[
'fromsection'] );
101 if ( !$fromContent ) {
108 if ( isset(
$params[
'tosection'] ) ) {
109 $toContent = $toContent->getSection(
$params[
'tosection'] );
120 if ( $relRev && $relRev->getTitle() ) {
121 $context->setTitle( $relRev->getTitle() );
122 } elseif ( $relRev2 && $relRev2->getTitle() ) {
123 $context->setTitle( $relRev2->getTitle() );
126 if ( $this->guessedTitle ) {
127 $context->setTitle( $this->guessedTitle );
130 $de = $fromContent->getContentHandler()->createDifferenceEngine(
132 $fromRev ? $fromRev->getId() : 0,
133 $toRev ? $toRev->getId() : 0,
138 $de->setContent( $fromContent, $toContent );
139 $difftext = $de->getDiffBody();
140 if ( $difftext ===
false ) {
146 $this->
setVals( $vals,
'from', $fromRev );
147 $this->
setVals( $vals,
'to', $toRev );
149 if ( isset( $this->props[
'rel'] ) ) {
151 $rev = $fromRev->getPrevious();
153 $vals[
'prev'] =
$rev->getId();
157 $rev = $toRev->getNext();
159 $vals[
'next'] =
$rev->getId();
164 if ( isset( $this->props[
'diffsize'] ) ) {
165 $vals[
'diffsize'] = strlen( $difftext );
167 if ( isset( $this->props[
'diff'] ) ) {
189 if ( $this->guessed ) {
193 $this->guessed =
true;
196 foreach ( [
'from',
'to' ] as $prefix ) {
197 if (
$params[
"{$prefix}rev"] !==
null ) {
198 $revId =
$params[
"{$prefix}rev"];
199 $rev = Revision::newFromId( $revId );
202 $arQuery = Revision::getArchiveQueryInfo();
203 $row = $this->
getDB()->selectRow(
207 [
'ar_namespace',
'ar_title' ]
209 [
'ar_rev_id' => $revId ],
215 $rev = Revision::newFromArchiveRow( $row );
219 $this->guessedTitle =
$rev->getTitle();
220 $this->guessedModel =
$rev->getContentModel();
225 if (
$params[
"{$prefix}title"] !==
null ) {
226 $title = Title::newFromText(
$params[
"{$prefix}title"] );
227 if ( $title && !$title->isExternal() ) {
228 $this->guessedTitle =
$title;
233 if (
$params[
"{$prefix}id"] !==
null ) {
234 $title = Title::newFromID(
$params[
"{$prefix}id"] );
236 $this->guessedTitle =
$title;
242 if ( !$this->guessedModel ) {
243 if ( $this->guessedTitle ) {
244 $this->guessedModel = $this->guessedTitle->getContentModel();
245 } elseif (
$params[
'fromcontentmodel'] !==
null ) {
246 $this->guessedModel =
$params[
'fromcontentmodel'];
247 } elseif (
$params[
'tocontentmodel'] !==
null ) {
248 $this->guessedModel =
$params[
'tocontentmodel'];
273 $suppliedContent =
$params[
"{$prefix}text"] !==
null;
277 if (
$params[
"{$prefix}rev"] !==
null ) {
278 $revId =
$params[
"{$prefix}rev"];
279 } elseif (
$params[
"{$prefix}title"] !==
null ||
$params[
"{$prefix}id"] !==
null ) {
280 if (
$params[
"{$prefix}title"] !==
null ) {
281 $title = Title::newFromText(
$params[
"{$prefix}title"] );
282 if ( !$title || $title->isExternal() ) {
288 $title = Title::newFromID(
$params[
"{$prefix}id"] );
290 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
"{$prefix}id"] ] );
293 $revId = $title->getLatestRevID();
297 if ( !$suppliedContent ) {
298 if ( $title->exists() ) {
300 [
'apierror-missingrev-title',
wfEscapeWikiText( $title->getPrefixedText() ) ],
305 [
'apierror-missingtitle-byname',
wfEscapeWikiText( $title->getPrefixedText() ) ],
312 if ( $revId !==
null ) {
313 $rev = Revision::newFromId( $revId );
314 if ( !
$rev && $this->
getUser()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
316 $arQuery = Revision::getArchiveQueryInfo();
317 $row = $this->
getDB()->selectRow(
321 [
'ar_namespace',
'ar_title' ]
323 [
'ar_rev_id' => $revId ],
329 $rev = Revision::newFromArchiveRow( $row );
330 $rev->isArchive =
true;
334 $this->
dieWithError( [
'apierror-nosuchrevid', $revId ] );
336 $title =
$rev->getTitle();
340 if ( !$suppliedContent ) {
341 $content =
$rev->getContent( Revision::FOR_THIS_USER, $this->
getUser() );
343 $this->
dieWithError( [
'apierror-missingcontent-revid', $revId ],
'missingcontent' );
350 $model =
$params[
"{$prefix}contentmodel"];
351 $format =
$params[
"{$prefix}contentformat"];
353 if ( !$model &&
$rev ) {
354 $model =
$rev->getContentModel();
356 if ( !$model && $title ) {
357 $model = $title->getContentModel();
365 $this->
addWarning( [
'apiwarn-compare-nocontentmodel', $model ] );
374 $content = ContentHandler::makeContent(
$params[
"{$prefix}text"], $title, $model, $format );
377 'wrap' =>
ApiMessage::create(
'apierror-contentserializationexception',
'parseerror' )
381 if (
$params[
"{$prefix}pst"] ) {
385 $popts = ParserOptions::newFromContext( $this->
getContext() );
386 $content = $content->preSaveTransform( $title, $this->
getUser(), $popts );
389 return [
null, $content,
$rev ];
400 $title =
$rev->getTitle();
401 if ( isset( $this->props[
'ids'] ) ) {
402 $vals[
"{$prefix}id"] = $title->getArticleID();
403 $vals[
"{$prefix}revid"] =
$rev->getId();
405 if ( isset( $this->props[
'title'] ) ) {
408 if ( isset( $this->props[
'size'] ) ) {
409 $vals[
"{$prefix}size"] =
$rev->getSize();
413 if (
$rev->isDeleted( Revision::DELETED_TEXT ) ) {
414 $vals[
"{$prefix}texthidden"] =
true;
418 if (
$rev->isDeleted( Revision::DELETED_USER ) ) {
419 $vals[
"{$prefix}userhidden"] =
true;
422 if ( isset( $this->props[
'user'] ) &&
423 $rev->userCan( Revision::DELETED_USER, $this->getUser() )
425 $vals[
"{$prefix}user"] =
$rev->getUserText( Revision::RAW );
426 $vals[
"{$prefix}userid"] =
$rev->getUser( Revision::RAW );
429 if (
$rev->isDeleted( Revision::DELETED_COMMENT ) ) {
430 $vals[
"{$prefix}commenthidden"] =
true;
433 if (
$rev->userCan( Revision::DELETED_COMMENT, $this->getUser() ) ) {
434 if ( isset( $this->props[
'comment'] ) ) {
435 $vals[
"{$prefix}comment"] =
$rev->getComment( Revision::RAW );
437 if ( isset( $this->props[
'parsedcomment'] ) ) {
439 $rev->getComment( Revision::RAW ),
446 $this->
getMain()->setCacheMode(
'private' );
447 if (
$rev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
448 $vals[
"{$prefix}suppressed"] =
true;
452 if ( !empty(
$rev->isArchive ) ) {
453 $this->
getMain()->setCacheMode(
'private' );
454 $vals[
"{$prefix}archive"] =
true;
483 foreach ( $fromToParams as $k => $v ) {
486 foreach ( $fromToParams as $k => $v ) {
518 'action=compare&fromrev=1&torev=2'
519 =>
'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.
const NO_SIZE_CHECK
For addValue() and similar functions, do not check size while adding a value Don't use this unless yo...
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
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.
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