MediaWiki  1.28.0
ApiEditPage.php
Go to the documentation of this file.
1 <?php
36 class ApiEditPage extends ApiBase {
37  public function execute() {
39 
40  $user = $this->getUser();
41  $params = $this->extractRequestParams();
42 
43  if ( is_null( $params['text'] ) && is_null( $params['appendtext'] ) &&
44  is_null( $params['prependtext'] ) &&
45  $params['undo'] == 0
46  ) {
47  $this->dieUsageMsg( 'missingtext' );
48  }
49 
50  $pageObj = $this->getTitleOrPageId( $params );
51  $titleObj = $pageObj->getTitle();
52  $apiResult = $this->getResult();
53 
54  if ( $params['redirect'] ) {
55  if ( $params['prependtext'] === null && $params['appendtext'] === null
56  && $params['section'] !== 'new'
57  ) {
58  $this->dieUsage( 'You have attempted to edit using the "redirect"-following'
59  . ' mode, which must be used in conjuction with section=new, prependtext'
60  . ', or appendtext.', 'redirect-appendonly' );
61  }
62  if ( $titleObj->isRedirect() ) {
63  $oldTitle = $titleObj;
64 
65  $titles = Revision::newFromTitle( $oldTitle, false, Revision::READ_LATEST )
66  ->getContent( Revision::FOR_THIS_USER, $user )
67  ->getRedirectChain();
68  // array_shift( $titles );
69 
70  $redirValues = [];
71 
73  foreach ( $titles as $id => $newTitle ) {
74 
75  if ( !isset( $titles[$id - 1] ) ) {
76  $titles[$id - 1] = $oldTitle;
77  }
78 
79  $redirValues[] = [
80  'from' => $titles[$id - 1]->getPrefixedText(),
81  'to' => $newTitle->getPrefixedText()
82  ];
83 
84  $titleObj = $newTitle;
85  }
86 
87  ApiResult::setIndexedTagName( $redirValues, 'r' );
88  $apiResult->addValue( null, 'redirects', $redirValues );
89 
90  // Since the page changed, update $pageObj
91  $pageObj = WikiPage::factory( $titleObj );
92  }
93  }
94 
95  if ( !isset( $params['contentmodel'] ) || $params['contentmodel'] == '' ) {
96  $contentHandler = $pageObj->getContentHandler();
97  } else {
98  $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] );
99  }
100  $contentModel = $contentHandler->getModelID();
101 
102  $name = $titleObj->getPrefixedDBkey();
103  $model = $contentHandler->getModelID();
104 
105  if ( $params['undo'] > 0 ) {
106  // allow undo via api
107  } elseif ( $contentHandler->supportsDirectApiEditing() === false ) {
108  $this->dieUsage(
109  "Direct editing via API is not supported for content model $model used by $name",
110  'no-direct-editing'
111  );
112  }
113 
114  if ( !isset( $params['contentformat'] ) || $params['contentformat'] == '' ) {
115  $contentFormat = $contentHandler->getDefaultFormat();
116  } else {
117  $contentFormat = $params['contentformat'];
118  }
119 
120  if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) {
121 
122  $this->dieUsage( "The requested format $contentFormat is not supported for content model " .
123  " $model used by $name", 'badformat' );
124  }
125 
126  if ( $params['createonly'] && $titleObj->exists() ) {
127  $this->dieUsageMsg( 'createonly-exists' );
128  }
129  if ( $params['nocreate'] && !$titleObj->exists() ) {
130  $this->dieUsageMsg( 'nocreate-missing' );
131  }
132 
133  // Now let's check whether we're even allowed to do this
134  $errors = $titleObj->getUserPermissionsErrors( 'edit', $user );
135  if ( !$titleObj->exists() ) {
136  $errors = array_merge( $errors, $titleObj->getUserPermissionsErrors( 'create', $user ) );
137  }
138  if ( count( $errors ) ) {
139  if ( is_array( $errors[0] ) ) {
140  switch ( $errors[0][0] ) {
141  case 'blockedtext':
142  $this->dieUsage(
143  'You have been blocked from editing',
144  'blocked',
145  0,
146  [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
147  );
148  break;
149  case 'autoblockedtext':
150  $this->dieUsage(
151  'Your IP address has been blocked automatically, because it was used by a blocked user',
152  'autoblocked',
153  0,
154  [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
155  );
156  break;
157  default:
158  $this->dieUsageMsg( $errors[0] );
159  }
160  } else {
161  $this->dieUsageMsg( $errors[0] );
162  }
163  }
164 
165  $toMD5 = $params['text'];
166  if ( !is_null( $params['appendtext'] ) || !is_null( $params['prependtext'] ) ) {
167  $content = $pageObj->getContent();
168 
169  if ( !$content ) {
170  if ( $titleObj->getNamespace() == NS_MEDIAWIKI ) {
171  # If this is a MediaWiki:x message, then load the messages
172  # and return the message value for x.
173  $text = $titleObj->getDefaultMessageText();
174  if ( $text === false ) {
175  $text = '';
176  }
177 
178  try {
179  $content = ContentHandler::makeContent( $text, $this->getTitle() );
180  } catch ( MWContentSerializationException $ex ) {
181  $this->dieUsage( $ex->getMessage(), 'parseerror' );
182 
183  return;
184  }
185  } else {
186  # Otherwise, make a new empty content.
187  $content = $contentHandler->makeEmptyContent();
188  }
189  }
190 
191  // @todo Add support for appending/prepending to the Content interface
192 
193  if ( !( $content instanceof TextContent ) ) {
194  $mode = $contentHandler->getModelID();
195  $this->dieUsage( "Can't append to pages using content model $mode", 'appendnotsupported' );
196  }
197 
198  if ( !is_null( $params['section'] ) ) {
199  if ( !$contentHandler->supportsSections() ) {
200  $modelName = $contentHandler->getModelID();
201  $this->dieUsage(
202  "Sections are not supported for this content model: $modelName.",
203  'sectionsnotsupported'
204  );
205  }
206 
207  if ( $params['section'] == 'new' ) {
208  // DWIM if they're trying to prepend/append to a new section.
209  $content = null;
210  } else {
211  // Process the content for section edits
212  $section = $params['section'];
213  $content = $content->getSection( $section );
214 
215  if ( !$content ) {
216  $this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
217  }
218  }
219  }
220 
221  if ( !$content ) {
222  $text = '';
223  } else {
224  $text = $content->serialize( $contentFormat );
225  }
226 
227  $params['text'] = $params['prependtext'] . $text . $params['appendtext'];
228  $toMD5 = $params['prependtext'] . $params['appendtext'];
229  }
230 
231  if ( $params['undo'] > 0 ) {
232  if ( $params['undoafter'] > 0 ) {
233  if ( $params['undo'] < $params['undoafter'] ) {
234  list( $params['undo'], $params['undoafter'] ) =
235  [ $params['undoafter'], $params['undo'] ];
236  }
237  $undoafterRev = Revision::newFromId( $params['undoafter'] );
238  }
239  $undoRev = Revision::newFromId( $params['undo'] );
240  if ( is_null( $undoRev ) || $undoRev->isDeleted( Revision::DELETED_TEXT ) ) {
241  $this->dieUsageMsg( [ 'nosuchrevid', $params['undo'] ] );
242  }
243 
244  if ( $params['undoafter'] == 0 ) {
245  $undoafterRev = $undoRev->getPrevious();
246  }
247  if ( is_null( $undoafterRev ) || $undoafterRev->isDeleted( Revision::DELETED_TEXT ) ) {
248  $this->dieUsageMsg( [ 'nosuchrevid', $params['undoafter'] ] );
249  }
250 
251  if ( $undoRev->getPage() != $pageObj->getId() ) {
252  $this->dieUsageMsg( [ 'revwrongpage', $undoRev->getId(),
253  $titleObj->getPrefixedText() ] );
254  }
255  if ( $undoafterRev->getPage() != $pageObj->getId() ) {
256  $this->dieUsageMsg( [ 'revwrongpage', $undoafterRev->getId(),
257  $titleObj->getPrefixedText() ] );
258  }
259 
260  $newContent = $contentHandler->getUndoContent(
261  $pageObj->getRevision(),
262  $undoRev,
263  $undoafterRev
264  );
265 
266  if ( !$newContent ) {
267  $this->dieUsageMsg( 'undo-failure' );
268  }
269  if ( empty( $params['contentmodel'] )
270  && empty( $params['contentformat'] )
271  ) {
272  // If we are reverting content model, the new content model
273  // might not support the current serialization format, in
274  // which case go back to the old serialization format,
275  // but only if the user hasn't specified a format/model
276  // parameter.
277  if ( !$newContent->isSupportedFormat( $contentFormat ) ) {
278  $contentFormat = $undoafterRev->getContentFormat();
279  }
280  // Override content model with model of undid revision.
281  $contentModel = $newContent->getModel();
282  }
283  $params['text'] = $newContent->serialize( $contentFormat );
284  // If no summary was given and we only undid one rev,
285  // use an autosummary
286  if ( is_null( $params['summary'] ) &&
287  $titleObj->getNextRevisionID( $undoafterRev->getId() ) == $params['undo']
288  ) {
289  $params['summary'] = wfMessage( 'undo-summary' )
290  ->params( $params['undo'], $undoRev->getUserText() )->inContentLanguage()->text();
291  }
292  }
293 
294  // See if the MD5 hash checks out
295  if ( !is_null( $params['md5'] ) && md5( $toMD5 ) !== $params['md5'] ) {
296  $this->dieUsageMsg( 'hashcheckfailed' );
297  }
298 
299  // EditPage wants to parse its stuff from a WebRequest
300  // That interface kind of sucks, but it's workable
301  $requestArray = [
302  'wpTextbox1' => $params['text'],
303  'format' => $contentFormat,
304  'model' => $contentModel,
305  'wpEditToken' => $params['token'],
306  'wpIgnoreBlankSummary' => true,
307  'wpIgnoreBlankArticle' => true,
308  'wpIgnoreSelfRedirect' => true,
309  'bot' => $params['bot'],
310  ];
311 
312  if ( !is_null( $params['summary'] ) ) {
313  $requestArray['wpSummary'] = $params['summary'];
314  }
315 
316  if ( !is_null( $params['sectiontitle'] ) ) {
317  $requestArray['wpSectionTitle'] = $params['sectiontitle'];
318  }
319 
320  // TODO: Pass along information from 'undoafter' as well
321  if ( $params['undo'] > 0 ) {
322  $requestArray['wpUndidRevision'] = $params['undo'];
323  }
324 
325  // Watch out for basetimestamp == '' or '0'
326  // It gets treated as NOW, almost certainly causing an edit conflict
327  if ( $params['basetimestamp'] !== null && (bool)$this->getMain()->getVal( 'basetimestamp' ) ) {
328  $requestArray['wpEdittime'] = $params['basetimestamp'];
329  } else {
330  $requestArray['wpEdittime'] = $pageObj->getTimestamp();
331  }
332 
333  if ( $params['starttimestamp'] !== null ) {
334  $requestArray['wpStarttime'] = $params['starttimestamp'];
335  } else {
336  $requestArray['wpStarttime'] = wfTimestampNow(); // Fake wpStartime
337  }
338 
339  if ( $params['minor'] || ( !$params['notminor'] && $user->getOption( 'minordefault' ) ) ) {
340  $requestArray['wpMinoredit'] = '';
341  }
342 
343  if ( $params['recreate'] ) {
344  $requestArray['wpRecreate'] = '';
345  }
346 
347  if ( !is_null( $params['section'] ) ) {
348  $section = $params['section'];
349  if ( !preg_match( '/^((T-)?\d+|new)$/', $section ) ) {
350  $this->dieUsage( "The section parameter must be a valid section id or 'new'",
351  'invalidsection' );
352  }
353  $content = $pageObj->getContent();
354  if ( $section !== '0' && $section != 'new'
355  && ( !$content || !$content->getSection( $section ) )
356  ) {
357  $this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
358  }
359  $requestArray['wpSection'] = $params['section'];
360  } else {
361  $requestArray['wpSection'] = '';
362  }
363 
364  $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
365 
366  // Deprecated parameters
367  if ( $params['watch'] ) {
368  $watch = true;
369  } elseif ( $params['unwatch'] ) {
370  $watch = false;
371  }
372 
373  if ( $watch ) {
374  $requestArray['wpWatchthis'] = '';
375  }
376 
377  // Apply change tags
378  if ( count( $params['tags'] ) ) {
379  $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
380  if ( $tagStatus->isOK() ) {
381  $requestArray['wpChangeTags'] = implode( ',', $params['tags'] );
382  } else {
383  $this->dieStatus( $tagStatus );
384  }
385  }
386 
387  // Pass through anything else we might have been given, to support extensions
388  // This is kind of a hack but it's the best we can do to make extensions work
389  $requestArray += $this->getRequest()->getValues();
390 
392 
393  $req = new DerivativeRequest( $this->getRequest(), $requestArray, true );
394 
395  // Some functions depend on $wgTitle == $ep->mTitle
396  // TODO: Make them not or check if they still do
397  $wgTitle = $titleObj;
398 
399  $articleContext = new RequestContext;
400  $articleContext->setRequest( $req );
401  $articleContext->setWikiPage( $pageObj );
402  $articleContext->setUser( $this->getUser() );
403 
405  $articleObject = Article::newFromWikiPage( $pageObj, $articleContext );
406 
407  $ep = new EditPage( $articleObject );
408 
409  $ep->setApiEditOverride( true );
410  $ep->setContextTitle( $titleObj );
411  $ep->importFormData( $req );
412  $content = $ep->textbox1;
413 
414  // Run hooks
415  // Handle APIEditBeforeSave parameters
416  $r = [];
417  // Deprecated in favour of EditFilterMergedContent
418  if ( !Hooks::run( 'APIEditBeforeSave', [ $ep, $content, &$r ], '1.28' ) ) {
419  if ( count( $r ) ) {
420  $r['result'] = 'Failure';
421  $apiResult->addValue( null, $this->getModuleName(), $r );
422 
423  return;
424  }
425 
426  $this->dieUsageMsg( 'hookaborted' );
427  }
428 
429  // Do the actual save
430  $oldRevId = $articleObject->getRevIdFetched();
431  $result = null;
432  // Fake $wgRequest for some hooks inside EditPage
433  // @todo FIXME: This interface SUCKS
434  $oldRequest = $wgRequest;
435  $wgRequest = $req;
436 
437  $status = $ep->attemptSave( $result );
438  $wgRequest = $oldRequest;
439 
440  switch ( $status->value ) {
443  if ( isset( $status->apiHookResult ) ) {
444  $r = $status->apiHookResult;
445  $r['result'] = 'Failure';
446  $apiResult->addValue( null, $this->getModuleName(), $r );
447  return;
448  } else {
449  $this->dieUsageMsg( 'hookaborted' );
450  }
451 
453  $this->dieUsage( $status->getMessage(), 'parseerror' );
454 
456  $this->dieUsageMsg( 'noimageredirect-anon' );
457 
459  $this->dieUsageMsg( 'noimageredirect-logged' );
460 
462  $this->dieUsageMsg( [ 'spamdetected', $result['spam'] ] );
463 
465  $this->dieUsage(
466  'You have been blocked from editing',
467  'blocked',
468  0,
469  [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
470  );
471 
474  $this->dieUsageMsg( [ 'contenttoobig', $this->getConfig()->get( 'MaxArticleSize' ) ] );
475 
477  $this->dieUsageMsg( 'noedit-anon' );
478 
480  $this->dieUsageMsg( 'noedit' );
481 
483  $this->dieReadOnly();
484 
486  $this->dieUsageMsg( 'actionthrottledtext' );
487 
489  $this->dieUsageMsg( 'wasdeleted' );
490 
492  $this->dieUsageMsg( 'nocreate-loggedin' );
493 
495  $this->dieUsageMsg( 'cantchangecontentmodel' );
496 
498  $this->dieUsageMsg( 'blankpage' );
499 
501  $this->dieUsageMsg( 'editconflict' );
502 
504  $this->dieUsageMsg( 'emptynewsection' );
505 
507  $this->dieStatus( $status );
508 
510  $r['new'] = true;
511  // fall-through
512 
514  $r['result'] = 'Success';
515  $r['pageid'] = intval( $titleObj->getArticleID() );
516  $r['title'] = $titleObj->getPrefixedText();
517  $r['contentmodel'] = $articleObject->getContentModel();
518  $newRevId = $articleObject->getLatest();
519  if ( $newRevId == $oldRevId ) {
520  $r['nochange'] = true;
521  } else {
522  $r['oldrevid'] = intval( $oldRevId );
523  $r['newrevid'] = intval( $newRevId );
524  $r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
525  $pageObj->getTimestamp() );
526  }
527  break;
528 
530  // Shouldn't happen since we set wpIgnoreBlankSummary, but just in case
531  $this->dieUsageMsg( 'summaryrequired' );
532 
533  case EditPage::AS_END:
534  default:
535  // $status came from WikiPage::doEditContent()
536  $errors = $status->getErrorsArray();
537  $this->dieUsageMsg( $errors[0] ); // TODO: Add new errors to message map
538  break;
539  }
540  $apiResult->addValue( null, $this->getModuleName(), $r );
541  }
542 
543  public function mustBePosted() {
544  return true;
545  }
546 
547  public function isWriteMode() {
548  return true;
549  }
550 
551  public function getAllowedParams() {
552  return [
553  'title' => [
554  ApiBase::PARAM_TYPE => 'string',
555  ],
556  'pageid' => [
557  ApiBase::PARAM_TYPE => 'integer',
558  ],
559  'section' => null,
560  'sectiontitle' => [
561  ApiBase::PARAM_TYPE => 'string',
562  ],
563  'text' => [
564  ApiBase::PARAM_TYPE => 'text',
565  ],
566  'summary' => null,
567  'tags' => [
568  ApiBase::PARAM_TYPE => 'tags',
569  ApiBase::PARAM_ISMULTI => true,
570  ],
571  'minor' => false,
572  'notminor' => false,
573  'bot' => false,
574  'basetimestamp' => [
575  ApiBase::PARAM_TYPE => 'timestamp',
576  ],
577  'starttimestamp' => [
578  ApiBase::PARAM_TYPE => 'timestamp',
579  ],
580  'recreate' => false,
581  'createonly' => false,
582  'nocreate' => false,
583  'watch' => [
584  ApiBase::PARAM_DFLT => false,
586  ],
587  'unwatch' => [
588  ApiBase::PARAM_DFLT => false,
590  ],
591  'watchlist' => [
592  ApiBase::PARAM_DFLT => 'preferences',
594  'watch',
595  'unwatch',
596  'preferences',
597  'nochange'
598  ],
599  ],
600  'md5' => null,
601  'prependtext' => [
602  ApiBase::PARAM_TYPE => 'text',
603  ],
604  'appendtext' => [
605  ApiBase::PARAM_TYPE => 'text',
606  ],
607  'undo' => [
608  ApiBase::PARAM_TYPE => 'integer'
609  ],
610  'undoafter' => [
611  ApiBase::PARAM_TYPE => 'integer'
612  ],
613  'redirect' => [
614  ApiBase::PARAM_TYPE => 'boolean',
615  ApiBase::PARAM_DFLT => false,
616  ],
617  'contentformat' => [
619  ],
620  'contentmodel' => [
622  ],
623  'token' => [
624  // Standard definition automatically inserted
625  ApiBase::PARAM_HELP_MSG_APPEND => [ 'apihelp-edit-param-token' ],
626  ],
627  ];
628  }
629 
630  public function needsToken() {
631  return 'csrf';
632  }
633 
634  protected function getExamplesMessages() {
635  return [
636  'action=edit&title=Test&summary=test%20summary&' .
637  'text=article%20content&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
638  => 'apihelp-edit-example-edit',
639  'action=edit&title=Test&summary=NOTOC&minor=&' .
640  'prependtext=__NOTOC__%0A&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
641  => 'apihelp-edit-example-prepend',
642  'action=edit&title=Test&undo=13585&undoafter=13579&' .
643  'basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
644  => 'apihelp-edit-example-undo',
645  ];
646  }
647 
648  public function getHelpUrls() {
649  return 'https://www.mediawiki.org/wiki/API:Edit';
650  }
651 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:115
const FOR_THIS_USER
Definition: Revision.php:93
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:88
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
Definition: deferred.txt:11
const AS_READ_ONLY_PAGE_ANON
Status: this anonymous user is not allowed to edit this page.
Definition: EditPage.php:76
getResult()
Get the result object.
Definition: ApiBase.php:577
setRequest(WebRequest $r)
Set the WebRequest object.
Group all the pieces relevant to the context of a request into one instance.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
static getAllContentFormats()
const AS_ARTICLE_WAS_DELETED
Status: article was deleted while editing and param wpRecreate == false or form was not posted...
Definition: EditPage.php:97
if(!$wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:664
const AS_HOOK_ERROR
Status: Article update aborted by a hook function.
Definition: EditPage.php:56
static getForModelID($modelId)
Returns the ContentHandler singleton for the given model ID.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
Definition: ApiBase.php:2752
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:50
getMain()
Get the main module.
Definition: ApiBase.php:473
static getContentModels()
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition: EditPage.php:42
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
const AS_SUMMARY_NEEDED
Status: no edit summary given and the user has forceeditsummary set and the user is not editing in hi...
Definition: EditPage.php:119
const AS_HOOK_ERROR_EXPECTED
Status: A hook function returned an error.
Definition: EditPage.php:61
getWatchlistValue($watchlist, $titleObj, $userOption=null)
Return true if we're to watch the page, false if not, null if no change.
Definition: ApiBase.php:870
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
Definition: ApiBase.php:678
const AS_BLOCKED_PAGE_FOR_USER
Status: User is blocked from editing this page.
Definition: EditPage.php:66
const AS_NO_CREATE_PERMISSION
Status: user tried to create this page, but is not allowed to do that ( Title->userCan('create') == f...
Definition: EditPage.php:103
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target...
Definition: Revision.php:128
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
Definition: defines.php:28
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:618
getTitle()
Get the Title object.
static getBlockInfo(Block $block)
Get basic info about a given block.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1934
const AS_CONTENT_TOO_BIG
Status: Content too big (> $wgMaxArticleSize)
Definition: EditPage.php:71
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getRequest()
Get the WebRequest object.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
Definition: ApiBase.php:132
getTitleOrPageId($params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
Definition: ApiBase.php:833
Content object implementation for representing flat text.
Definition: TextContent.php:35
const AS_SPAM_ERROR
Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex.
Definition: EditPage.php:139
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"&lt
const AS_SUCCESS_UPDATE
Status: Article successfully updated.
Definition: EditPage.php:46
const AS_READ_ONLY_PAGE
Status: wiki is in readonly mode (wfReadOnly() == true)
Definition: EditPage.php:86
getConfig()
Get the Config object.
A module that allows for editing and creating pages.
Definition: ApiEditPage.php:36
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
const AS_NO_CHANGE_CONTENT_MODEL
Status: user tried to modify the content model, but is not allowed to do that ( User::isAllowed('edit...
Definition: EditPage.php:155
$params
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:457
static dieReadOnly()
Helper function for readonly errors.
Definition: ApiBase.php:2181
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
static makeContent($text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
const AS_SUCCESS_NEW_ARTICLE
Status: Article successfully created.
Definition: EditPage.php:51
const AS_IMAGE_REDIRECT_LOGGED
Status: logged in user is not allowed to upload (User::isAllowed('upload') == false) ...
Definition: EditPage.php:149
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
Definition: distributors.txt:9
const NS_MEDIAWIKI
Definition: Defines.php:64
const AS_END
Status: WikiPage::doEdit() was unsuccessful.
Definition: EditPage.php:134
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition: hooks.txt:2889
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
Definition: hooks.txt:242
const DELETED_TEXT
Definition: Revision.php:85
static newFromId($id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:110
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
Definition: injection.txt:35
this hook is for auditing only $req
Definition: hooks.txt:1007
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
const AS_RATE_LIMITED
Status: rate limiter for action 'edit' was tripped.
Definition: EditPage.php:91
versus $oldTitle
Definition: globals.txt:16
const AS_MAX_ARTICLE_SIZE_EXCEEDED
Status: article is too big (> $wgMaxArticleSize), after merging in the new section.
Definition: EditPage.php:129
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition: hooks.txt:1046
const AS_IMAGE_REDIRECT_ANON
Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false) ...
Definition: EditPage.php:144
const AS_TEXTBOX_EMPTY
Status: user tried to create a new section without content.
Definition: EditPage.php:124
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:53
dieUsage($description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
Definition: ApiBase.php:1574
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1046
This abstract class implements many basic API functions, and is the base of all API classes...
Definition: ApiBase.php:39
const AS_BLANK_ARTICLE
Status: user tried to create a blank page and wpIgnoreBlankArticle == false.
Definition: EditPage.php:108
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:106
static canAddTagsAccompanyingChange(array $tags, User $user=null)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
Definition: ChangeTags.php:392
if(!$wgRequest->checkUrlExtension()) if(!$wgEnableAPI) $wgTitle
Definition: api.php:57
const AS_CONFLICT_DETECTED
Status: (non-resolvable) edit conflict.
Definition: EditPage.php:113
static newFromWikiPage(WikiPage $page, IContextSource $context)
Create an Article object of the appropriate class for the given page.
Definition: Article.php:144
dieStatus($status)
Throw a UsageException based on the errors in the Status object.
Definition: ApiBase.php:1663
const AS_READ_ONLY_PAGE_LOGGED
Status: this logged in user is not allowed to edit this page.
Definition: EditPage.php:81
const AS_PARSE_ERROR
Status: can't parse content.
Definition: EditPage.php:172
getUser()
Get the User object.
dieUsageMsg($error)
Output the error message related to a certain array.
Definition: ApiBase.php:2192
Exception representing a failure to serialize or unserialize a content object.
const AS_CHANGE_TAG_ERROR
Status: an error relating to change tagging.
Definition: EditPage.php:167
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300