40 parent::__construct( $mainModule, $moduleName, $modulePrefix );
41 $this->revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
42 $this->slotRoleRegistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
50 $params,
'fromtitle',
'fromid',
'fromrev',
'fromtext',
'fromslots'
53 $params,
'totitle',
'toid',
'torev',
'totext',
'torelative',
'toslots'
56 $this->props = array_flip(
$params[
'prop'] );
59 $this->
getMain()->setCacheMode(
'public' );
65 if (
$params[
'torelative'] !==
null ) {
67 $this->
dieWithError(
'apierror-compare-relative-to-nothing' );
74 switch (
$params[
'torelative'] ) {
77 list( $toRev, $toRelRev, $toValsRev ) = [ $fromRev, $fromRelRev, $fromValsRev ];
78 $fromRev = $this->revisionStore->getPreviousRevision( $toRelRev );
79 $fromRelRev = $fromRev;
80 $fromValsRev = $fromRev;
82 $title = Title::newFromLinkTarget( $toRelRev->getPageAsLinkTarget() );
84 'apiwarn-compare-no-prev',
91 $fromRev = $this->revisionStore->newMutableRevisionFromArray( [
92 'title' =>
$title ?: Title::makeTitle(
NS_SPECIAL,
'Badtitle/' . __METHOD__ )
96 $toRelRev->getContent( SlotRecord::MAIN, RevisionRecord::RAW )
104 $toRev = $this->revisionStore->getNextRevision( $fromRelRev );
108 $title = Title::newFromLinkTarget( $fromRelRev->getPageAsLinkTarget() );
110 'apiwarn-compare-no-next',
117 $toRev = MutableRevisionRecord::newFromParentRevision( $fromRelRev );
122 $title = $fromRelRev->getPageAsLinkTarget();
123 $toRev = $this->revisionStore->getRevisionByTitle(
$title );
140 if ( !$fromRev || !$toRev ) {
146 if ( !$fromRev->audienceCan(
147 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_THIS_USER, $this->getUser()
149 $this->
dieWithError( [
'apierror-missingcontent-revid', $fromRev->getId() ],
'missingcontent' );
151 if ( !$toRev->audienceCan(
152 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_THIS_USER, $this->getUser()
154 $this->
dieWithError( [
'apierror-missingcontent-revid', $toRev->getId() ],
'missingcontent' );
159 if ( $fromRelRev && $fromRelRev->getPageAsLinkTarget() ) {
160 $context->setTitle( Title::newFromLinkTarget( $fromRelRev->getPageAsLinkTarget() ) );
161 } elseif ( $toRelRev && $toRelRev->getPageAsLinkTarget() ) {
162 $context->setTitle( Title::newFromLinkTarget( $toRelRev->getPageAsLinkTarget() ) );
170 $de->setRevisions( $fromRev, $toRev );
171 if (
$params[
'slots'] ===
null ) {
172 $difftext = $de->getDiffBody();
173 if ( $difftext ===
false ) {
179 $difftext[$role] = $de->getDiffBodyForRole( $role );
185 $this->
setVals( $vals,
'from', $fromValsRev );
186 $this->
setVals( $vals,
'to', $toValsRev );
188 if ( isset( $this->props[
'rel'] ) ) {
190 $rev = $this->revisionStore->getPreviousRevision( $fromRev );
192 $vals[
'prev'] =
$rev->getId();
196 $rev = $this->revisionStore->getNextRevision( $toRev );
198 $vals[
'next'] =
$rev->getId();
203 if ( isset( $this->props[
'diffsize'] ) ) {
204 $vals[
'diffsize'] = 0;
205 foreach ( (
array)$difftext
as $text ) {
206 $vals[
'diffsize'] += strlen( $text );
209 if ( isset( $this->props[
'diff'] ) ) {
210 if ( is_array( $difftext ) ) {
212 $vals[
'bodies'] = $difftext;
233 $rev = $this->revisionStore->getRevisionById( $id );
234 if ( !
$rev && $this->
getUser()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
236 $arQuery = $this->revisionStore->getArchiveQueryInfo();
237 $row = $this->
getDB()->selectRow(
241 [
'ar_namespace',
'ar_title' ]
243 [
'ar_rev_id' => $id ],
249 $rev = $this->revisionStore->newRevisionFromArchiveRow( $row );
250 $rev->isArchive =
true;
262 if ( $this->guessedTitle !==
false ) {
266 $this->guessedTitle =
null;
269 foreach ( [
'from',
'to' ]
as $prefix ) {
270 if (
$params[
"{$prefix}rev"] !==
null ) {
273 $this->guessedTitle = Title::newFromLinkTarget(
$rev->getPageAsLinkTarget() );
278 if (
$params[
"{$prefix}title"] !==
null ) {
281 $this->guessedTitle =
$title;
286 if (
$params[
"{$prefix}id"] !==
null ) {
289 $this->guessedTitle =
$title;
307 foreach ( [
'from',
'to' ]
as $prefix ) {
308 if (
$params[
"{$prefix}rev"] !==
null ) {
310 if (
$rev &&
$rev->hasSlot( $role ) ) {
311 return $rev->getSlot( $role, RevisionRecord::RAW )->getModel();
318 return $this->slotRoleRegistry->getRoleHandler( $role )->getDefaultModel(
$guessedTitle );
321 if ( isset(
$params[
"fromcontentmodel-$role"] ) ) {
322 return $params[
"fromcontentmodel-$role"];
324 if ( isset(
$params[
"tocontentmodel-$role"] ) ) {
325 return $params[
"tocontentmodel-$role"];
328 if ( $role === SlotRecord::MAIN ) {
329 if ( isset(
$params[
'fromcontentmodel'] ) ) {
330 return $params[
'fromcontentmodel'];
332 if ( isset(
$params[
'tocontentmodel'] ) ) {
333 return $params[
'tocontentmodel'];
359 if (
$params[
"{$prefix}text"] !==
null ) {
360 $params[
"{$prefix}slots"] = [ SlotRecord::MAIN ];
362 $params[
"{$prefix}section-main"] =
null;
363 $params[
"{$prefix}contentmodel-main"] =
$params[
"{$prefix}contentmodel"];
364 $params[
"{$prefix}contentformat-main"] =
$params[
"{$prefix}contentformat"];
369 $suppliedContent =
$params[
"{$prefix}slots"] !==
null;
373 if (
$params[
"{$prefix}rev"] !==
null ) {
374 $revId =
$params[
"{$prefix}rev"];
375 } elseif (
$params[
"{$prefix}title"] !==
null ||
$params[
"{$prefix}id"] !==
null ) {
376 if (
$params[
"{$prefix}title"] !==
null ) {
386 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
"{$prefix}id"] ] );
389 $revId =
$title->getLatestRevID();
393 if ( !$suppliedContent ) {
407 if ( $revId !==
null ) {
410 $this->
dieWithError( [
'apierror-nosuchrevid', $revId ] );
412 $title = Title::newFromLinkTarget(
$rev->getPageAsLinkTarget() );
416 if ( !$suppliedContent ) {
420 if ( isset(
$params[
"{$prefix}section"] ) ) {
422 $newRev = MutableRevisionRecord::newFromParentRevision(
$rev );
423 $content =
$rev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER,
427 [
'apierror-missingcontent-revid-role',
$rev->getId(), SlotRecord::MAIN ],
'missingcontent'
434 "nosuch{$prefix}section"
449 $newRev = MutableRevisionRecord::newFromParentRevision(
$rev );
451 $newRev = $this->revisionStore->newMutableRevisionFromArray( [
452 'title' =>
$title ?: Title::makeTitle(
NS_SPECIAL,
'Badtitle/' . __METHOD__ )
455 foreach (
$params[
"{$prefix}slots"]
as $role ) {
456 $text =
$params[
"{$prefix}text-{$role}"];
457 if ( $text ===
null ) {
459 if ( $role === SlotRecord::MAIN ) {
460 $this->
dieWithError( [
'apierror-compare-maintextrequired', $prefix ] );
465 foreach ( [
'section',
'contentmodel',
'contentformat' ]
as $param ) {
466 if ( isset(
$params[
"{$prefix}{$param}-{$role}"] ) ) {
468 'apierror-compare-notext',
479 $model =
$params[
"{$prefix}contentmodel-{$role}"];
480 $format =
$params[
"{$prefix}contentformat-{$role}"];
482 if ( !$model &&
$rev &&
$rev->hasSlot( $role ) ) {
483 $model =
$rev->getSlot( $role, RevisionRecord::RAW )->getModel();
485 if ( !$model &&
$title && $role === SlotRecord::MAIN ) {
487 $model =
$title->getContentModel();
494 $this->
addWarning( [
'apiwarn-compare-nocontentmodel', $model ] );
498 $content = ContentHandler::makeContent( $text,
$title, $model, $format );
501 'wrap' =>
ApiMessage::create(
'apierror-contentserializationexception',
'parseerror' )
505 if (
$params[
"{$prefix}pst"] ) {
509 $popts = ParserOptions::newFromContext( $this->
getContext() );
516 $this->
dieWithError(
"apierror-compare-no{$prefix}revision" );
518 $oldContent =
$rev->getContent( $role, RevisionRecord::FOR_THIS_USER, $this->
getUser() );
519 if ( !$oldContent ) {
525 if ( !$oldContent->getContentHandler()->supportsSections() ) {
530 }
catch ( Exception $ex ) {
535 $this->
dieWithError( [
'apierror-sectionreplacefailed' ] );
540 if ( $role === SlotRecord::MAIN && isset(
$params[
"{$prefix}section"] ) ) {
546 "nosuch{$prefix}section"
566 if ( isset( $this->props[
'ids'] ) ) {
567 $vals[
"{$prefix}id"] =
$title->getArticleID();
568 $vals[
"{$prefix}revid"] =
$rev->getId();
570 if ( isset( $this->props[
'title'] ) ) {
573 if ( isset( $this->props[
'size'] ) ) {
574 $vals[
"{$prefix}size"] =
$rev->getSize();
578 if (
$rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
579 $vals[
"{$prefix}texthidden"] =
true;
583 if (
$rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
584 $vals[
"{$prefix}userhidden"] =
true;
587 if ( isset( $this->props[
'user'] ) ) {
590 $vals[
"{$prefix}user"] =
$user->getName();
591 $vals[
"{$prefix}userid"] =
$user->getId();
595 if (
$rev->isDeleted( RevisionRecord::DELETED_COMMENT ) ) {
596 $vals[
"{$prefix}commenthidden"] =
true;
599 if ( isset( $this->props[
'comment'] ) || isset( $this->props[
'parsedcomment'] ) ) {
600 $comment =
$rev->getComment( RevisionRecord::FOR_THIS_USER, $this->
getUser() );
601 if ( $comment !==
null ) {
602 if ( isset( $this->props[
'comment'] ) ) {
603 $vals[
"{$prefix}comment"] = $comment->text;
606 $comment->text, Title::newFromLinkTarget(
$title )
612 $this->
getMain()->setCacheMode(
'private' );
613 if (
$rev->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
614 $vals[
"{$prefix}suppressed"] =
true;
618 if ( !empty(
$rev->isArchive ) ) {
619 $this->
getMain()->setCacheMode(
'private' );
620 $vals[
"{$prefix}archive"] =
true;
626 $slotRoles = $this->slotRoleRegistry->getKnownRoles();
627 sort( $slotRoles, SORT_STRING );
647 'section-{slot}' => [
651 'contentformat-{slot}' => [
655 'contentmodel-{slot}' => [
680 foreach ( $fromToParams
as $k => $v ) {
686 foreach ( $fromToParams
as $k => $v ) {
727 'action=compare&fromrev=1&torev=2'
728 =>
'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.
MediaWiki Revision SlotRoleRegistry $slotRoleRegistry
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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
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
return true to allow those checks to and false if checking is done & $user
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
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))