36 parent::__construct( $mainModule, $moduleName, $modulePrefix );
37 $this->revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
45 $params,
'fromtitle',
'fromid',
'fromrev',
'fromtext',
'fromslots'
48 $params,
'totitle',
'toid',
'torev',
'totext',
'torelative',
'toslots'
51 $this->props = array_flip(
$params[
'prop'] );
54 $this->
getMain()->setCacheMode(
'public' );
60 if (
$params[
'torelative'] !==
null ) {
62 $this->
dieWithError(
'apierror-compare-relative-to-nothing' );
64 switch (
$params[
'torelative'] ) {
67 list( $toRev, $toRelRev, $toValsRev ) = [ $fromRev, $fromRelRev, $fromValsRev ];
68 $fromRev = $this->revisionStore->getPreviousRevision( $toRelRev );
69 $fromRelRev = $fromRev;
70 $fromValsRev = $fromRev;
72 $title = Title::newFromLinkTarget( $toRelRev->getPageAsLinkTarget() );
74 'apiwarn-compare-no-prev',
81 $fromRev = $this->revisionStore->newMutableRevisionFromArray( [
82 'title' =>
$title ?: Title::makeTitle(
NS_SPECIAL,
'Badtitle/' . __METHOD__ )
86 $toRelRev->getContent( SlotRecord::MAIN, RevisionRecord::RAW )
94 $toRev = $this->revisionStore->getNextRevision( $fromRelRev );
98 $title = Title::newFromLinkTarget( $fromRelRev->getPageAsLinkTarget() );
100 'apiwarn-compare-no-next',
107 $toRev = MutableRevisionRecord::newFromParentRevision( $fromRelRev );
112 $title = $fromRelRev->getPageAsLinkTarget();
113 $toRev = $this->revisionStore->getRevisionByTitle(
$title );
130 if ( !$fromRev || !$toRev ) {
136 if ( !$fromRev->audienceCan(
137 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_THIS_USER, $this->getUser()
139 $this->
dieWithError( [
'apierror-missingcontent-revid', $fromRev->getId() ],
'missingcontent' );
141 if ( !$toRev->audienceCan(
142 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_THIS_USER, $this->getUser()
144 $this->
dieWithError( [
'apierror-missingcontent-revid', $toRev->getId() ],
'missingcontent' );
149 if ( $fromRelRev && $fromRelRev->getPageAsLinkTarget() ) {
150 $context->setTitle( Title::newFromLinkTarget( $fromRelRev->getPageAsLinkTarget() ) );
151 } elseif ( $toRelRev && $toRelRev->getPageAsLinkTarget() ) {
152 $context->setTitle( Title::newFromLinkTarget( $toRelRev->getPageAsLinkTarget() ) );
160 $de->setRevisions( $fromRev, $toRev );
161 if (
$params[
'slots'] ===
null ) {
162 $difftext = $de->getDiffBody();
163 if ( $difftext ===
false ) {
169 $difftext[$role] = $de->getDiffBodyForRole( $role );
175 $this->
setVals( $vals,
'from', $fromValsRev );
176 $this->
setVals( $vals,
'to', $toValsRev );
178 if ( isset( $this->props[
'rel'] ) ) {
180 $rev = $this->revisionStore->getPreviousRevision( $fromRev );
182 $vals[
'prev'] =
$rev->getId();
186 $rev = $this->revisionStore->getNextRevision( $toRev );
188 $vals[
'next'] =
$rev->getId();
193 if ( isset( $this->props[
'diffsize'] ) ) {
194 $vals[
'diffsize'] = 0;
195 foreach ( (
array)$difftext
as $text ) {
196 $vals[
'diffsize'] += strlen( $text );
199 if ( isset( $this->props[
'diff'] ) ) {
200 if ( is_array( $difftext ) ) {
202 $vals[
'bodies'] = $difftext;
223 $rev = $this->revisionStore->getRevisionById( $id );
224 if ( !
$rev && $this->
getUser()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
226 $arQuery = $this->revisionStore->getArchiveQueryInfo();
227 $row = $this->
getDB()->selectRow(
231 [
'ar_namespace',
'ar_title' ]
233 [
'ar_rev_id' => $id ],
239 $rev = $this->revisionStore->newRevisionFromArchiveRow( $row );
240 $rev->isArchive =
true;
252 if ( $this->guessedTitle !==
false ) {
256 $this->guessedTitle =
null;
259 foreach ( [
'from',
'to' ]
as $prefix ) {
260 if (
$params[
"{$prefix}rev"] !==
null ) {
263 $this->guessedTitle = Title::newFromLinkTarget(
$rev->getPageAsLinkTarget() );
268 if (
$params[
"{$prefix}title"] !==
null ) {
271 $this->guessedTitle =
$title;
276 if (
$params[
"{$prefix}id"] !==
null ) {
279 $this->guessedTitle =
$title;
297 foreach ( [
'from',
'to' ]
as $prefix ) {
298 if (
$params[
"{$prefix}rev"] !==
null ) {
301 if (
$rev->hasSlot( $role ) ) {
302 return $rev->getSlot( $role, RevisionRecord::RAW )->getModel();
314 if ( isset(
$params[
"fromcontentmodel-$role"] ) ) {
315 return $params[
"fromcontentmodel-$role"];
317 if ( isset(
$params[
"tocontentmodel-$role"] ) ) {
318 return $params[
"tocontentmodel-$role"];
321 if ( $role === SlotRecord::MAIN ) {
322 if ( isset(
$params[
'fromcontentmodel'] ) ) {
323 return $params[
'fromcontentmodel'];
325 if ( isset(
$params[
'tocontentmodel'] ) ) {
326 return $params[
'tocontentmodel'];
352 if (
$params[
"{$prefix}text"] !==
null ) {
353 $params[
"{$prefix}slots"] = [ SlotRecord::MAIN ];
355 $params[
"{$prefix}section-main"] =
null;
356 $params[
"{$prefix}contentmodel-main"] =
$params[
"{$prefix}contentmodel"];
357 $params[
"{$prefix}contentformat-main"] =
$params[
"{$prefix}contentformat"];
362 $suppliedContent =
$params[
"{$prefix}slots"] !==
null;
366 if (
$params[
"{$prefix}rev"] !==
null ) {
367 $revId =
$params[
"{$prefix}rev"];
368 } elseif (
$params[
"{$prefix}title"] !==
null ||
$params[
"{$prefix}id"] !==
null ) {
369 if (
$params[
"{$prefix}title"] !==
null ) {
379 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
"{$prefix}id"] ] );
382 $revId =
$title->getLatestRevID();
386 if ( !$suppliedContent ) {
400 if ( $revId !==
null ) {
403 $this->
dieWithError( [
'apierror-nosuchrevid', $revId ] );
405 $title = Title::newFromLinkTarget(
$rev->getPageAsLinkTarget() );
409 if ( !$suppliedContent ) {
413 if ( isset(
$params[
"{$prefix}section"] ) ) {
415 $newRev = MutableRevisionRecord::newFromParentRevision(
$rev );
416 $content =
$rev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER,
420 [
'apierror-missingcontent-revid-role',
$rev->getId(), SlotRecord::MAIN ],
'missingcontent'
427 "nosuch{$prefix}section"
442 $newRev = MutableRevisionRecord::newFromParentRevision(
$rev );
444 $newRev = $this->revisionStore->newMutableRevisionFromArray( [
445 'title' =>
$title ?: Title::makeTitle(
NS_SPECIAL,
'Badtitle/' . __METHOD__ )
448 foreach (
$params[
"{$prefix}slots"]
as $role ) {
449 $text =
$params[
"{$prefix}text-{$role}"];
450 if ( $text ===
null ) {
452 if ( $role === SlotRecord::MAIN ) {
453 $this->
dieWithError( [
'apierror-compare-maintextrequired', $prefix ] );
458 foreach ( [
'section',
'contentmodel',
'contentformat' ]
as $param ) {
459 if ( isset(
$params[
"{$prefix}{$param}-{$role}"] ) ) {
461 'apierror-compare-notext',
472 $model =
$params[
"{$prefix}contentmodel-{$role}"];
473 $format =
$params[
"{$prefix}contentformat-{$role}"];
475 if ( !$model &&
$rev &&
$rev->hasSlot( $role ) ) {
476 $model =
$rev->getSlot( $role, RevisionRecord::RAW )->getModel();
478 if ( !$model &&
$title && $role === SlotRecord::MAIN ) {
480 $model =
$title->getContentModel();
487 $this->
addWarning( [
'apiwarn-compare-nocontentmodel', $model ] );
491 $content = ContentHandler::makeContent( $text,
$title, $model, $format );
494 'wrap' =>
ApiMessage::create(
'apierror-contentserializationexception',
'parseerror' )
498 if (
$params[
"{$prefix}pst"] ) {
502 $popts = ParserOptions::newFromContext( $this->
getContext() );
509 $this->
dieWithError(
"apierror-compare-no{$prefix}revision" );
511 $oldContent =
$rev->getContent( $role, RevisionRecord::FOR_THIS_USER, $this->
getUser() );
512 if ( !$oldContent ) {
518 if ( !$oldContent->getContentHandler()->supportsSections() ) {
523 }
catch ( Exception $ex ) {
528 $this->
dieWithError( [
'apierror-sectionreplacefailed' ] );
533 if ( $role === SlotRecord::MAIN && isset(
$params[
"{$prefix}section"] ) ) {
539 "nosuch{$prefix}section"
559 if ( isset( $this->props[
'ids'] ) ) {
560 $vals[
"{$prefix}id"] =
$title->getArticleID();
561 $vals[
"{$prefix}revid"] =
$rev->getId();
563 if ( isset( $this->props[
'title'] ) ) {
566 if ( isset( $this->props[
'size'] ) ) {
567 $vals[
"{$prefix}size"] =
$rev->getSize();
571 if (
$rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
572 $vals[
"{$prefix}texthidden"] =
true;
576 if (
$rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
577 $vals[
"{$prefix}userhidden"] =
true;
580 if ( isset( $this->props[
'user'] ) ) {
583 $vals[
"{$prefix}user"] =
$user->getName();
584 $vals[
"{$prefix}userid"] =
$user->getId();
588 if (
$rev->isDeleted( RevisionRecord::DELETED_COMMENT ) ) {
589 $vals[
"{$prefix}commenthidden"] =
true;
592 if ( isset( $this->props[
'comment'] ) || isset( $this->props[
'parsedcomment'] ) ) {
593 $comment =
$rev->getComment( RevisionRecord::FOR_THIS_USER, $this->
getUser() );
594 if ( $comment !==
null ) {
595 if ( isset( $this->props[
'comment'] ) ) {
596 $vals[
"{$prefix}comment"] = $comment->text;
599 $comment->text, Title::newFromLinkTarget(
$title )
605 $this->
getMain()->setCacheMode(
'private' );
606 if (
$rev->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
607 $vals[
"{$prefix}suppressed"] =
true;
611 if ( !empty(
$rev->isArchive ) ) {
612 $this->
getMain()->setCacheMode(
'private' );
613 $vals[
"{$prefix}archive"] =
true;
619 $slotRoles = MediaWikiServices::getInstance()->getSlotRoleStore()->getMap();
620 if ( !in_array( SlotRecord::MAIN, $slotRoles,
true ) ) {
621 $slotRoles[] = SlotRecord::MAIN;
623 sort( $slotRoles, SORT_STRING );
643 'section-{slot}' => [
647 'contentformat-{slot}' => [
651 'contentmodel-{slot}' => [
676 foreach ( $fromToParams
as $k => $v ) {
682 foreach ( $fromToParams
as $k => $v ) {
723 'action=compare&fromrev=1&torev=2'
724 =>
'apihelp-compare-example-1',
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
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.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const PARAM_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
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.
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
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.
getDiffRevision( $prefix, array $params)
Get the RevisionRecord for one side of the diff.
getExamplesMessages()
Returns usage examples for this module.
setVals(&$vals, $prefix, $rev)
Set value fields from a RevisionRecord object.
getRevisionById( $id)
Load a revision by ID.
__construct(ApiMain $mainModule, $moduleName, $modulePrefix='')
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
RevisionStore $revisionStore
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
guessTitle()
Guess an appropriate default Title for this request.
guessModel( $role)
Guess an appropriate default content model for this request.
This is the main API class, used for both external and internal processing.
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 setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
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 ...
DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const CONTENT_MODEL_WIKITEXT
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 & $ret
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
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
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))