MediaWiki  master
ApiEditPage.php
Go to the documentation of this file.
1 <?php
27 
37 class ApiEditPage extends ApiBase {
38 
40 
41  public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) {
42  parent::__construct( $mainModule, $moduleName, $modulePrefix );
43 
44  $this->watchlistExpiryEnabled = $this->getConfig()->get( 'WatchlistExpiry' );
45  $this->watchlistMaxDuration = $this->getConfig()->get( 'WatchlistExpiryMaxDuration' );
46  }
47 
48  public function execute() {
50 
51  $user = $this->getUser();
52  $params = $this->extractRequestParams();
53 
54  $this->requireAtLeastOneParameter( $params, 'text', 'appendtext', 'prependtext', 'undo' );
55 
56  $pageObj = $this->getTitleOrPageId( $params );
57  $titleObj = $pageObj->getTitle();
58  $apiResult = $this->getResult();
59  $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup();
60 
61  if ( $params['redirect'] ) {
62  if ( $params['prependtext'] === null && $params['appendtext'] === null
63  && $params['section'] !== 'new'
64  ) {
65  $this->dieWithError( 'apierror-redirect-appendonly' );
66  }
67  if ( $titleObj->isRedirect() ) {
68  $oldTitle = $titleObj;
69 
70  $titles = $revisionLookup
71  ->getRevisionByTitle( $oldTitle, 0, IDBAccessObject::READ_LATEST )
72  ->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $user )
73  ->getRedirectChain();
74  // array_shift( $titles );
75  '@phan-var Title[] $titles';
76 
77  $redirValues = [];
78 
80  foreach ( $titles as $id => $newTitle ) {
81  $titles[$id - 1] = $titles[$id - 1] ?? $oldTitle;
82 
83  $redirValues[] = [
84  'from' => $titles[$id - 1]->getPrefixedText(),
85  'to' => $newTitle->getPrefixedText()
86  ];
87 
88  $titleObj = $newTitle;
89 
90  // T239428: Check whether the new title is valid
91  if ( $titleObj->isExternal() || !$titleObj->canExist() ) {
92  $redirValues[count( $redirValues ) - 1]['to'] = $titleObj->getFullText();
93  $this->dieWithError(
94  [
95  'apierror-edit-invalidredirect',
96  Message::plaintextParam( $oldTitle->getPrefixedText() ),
97  Message::plaintextParam( $titleObj->getFullText() ),
98  ],
99  'edit-invalidredirect',
100  [ 'redirects' => $redirValues ]
101  );
102  }
103  }
104 
105  ApiResult::setIndexedTagName( $redirValues, 'r' );
106  $apiResult->addValue( null, 'redirects', $redirValues );
107 
108  // Since the page changed, update $pageObj
109  $pageObj = WikiPage::factory( $titleObj );
110  }
111  }
112 
113  if ( $params['contentmodel'] ) {
114  $contentHandler = $this->getContentHandlerFactory()
115  ->getContentHandler( $params['contentmodel'] );
116  } else {
117  $contentHandler = $pageObj->getContentHandler();
118  }
119  $contentModel = $contentHandler->getModelID();
120 
121  $name = $titleObj->getPrefixedDBkey();
122  $model = $contentHandler->getModelID();
123 
124  if ( $params['undo'] > 0 ) {
125  // allow undo via api
126  } elseif ( $contentHandler->supportsDirectApiEditing() === false ) {
127  $this->dieWithError( [ 'apierror-no-direct-editing', $model, $name ] );
128  }
129 
130  $contentFormat = $params['contentformat'] ?: $contentHandler->getDefaultFormat();
131 
132  if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) {
133  $this->dieWithError( [ 'apierror-badformat', $contentFormat, $model, $name ] );
134  }
135 
136  if ( $params['createonly'] && $titleObj->exists() ) {
137  $this->dieWithError( 'apierror-articleexists' );
138  }
139  if ( $params['nocreate'] && !$titleObj->exists() ) {
140  $this->dieWithError( 'apierror-missingtitle' );
141  }
142 
143  // Now let's check whether we're even allowed to do this
145  $titleObj,
146  $titleObj->exists() ? 'edit' : [ 'edit', 'create' ],
147  [ 'autoblock' => true ]
148  );
149 
150  $toMD5 = $params['text'];
151  if ( $params['appendtext'] !== null || $params['prependtext'] !== null ) {
152  $content = $pageObj->getContent();
153 
154  if ( !$content ) {
155  if ( $titleObj->getNamespace() === NS_MEDIAWIKI ) {
156  # If this is a MediaWiki:x message, then load the messages
157  # and return the message value for x.
158  $text = $titleObj->getDefaultMessageText();
159  if ( $text === false ) {
160  $text = '';
161  }
162 
163  try {
164  $content = ContentHandler::makeContent( $text, $titleObj );
165  } catch ( MWContentSerializationException $ex ) {
166  $this->dieWithException( $ex, [
167  'wrap' => ApiMessage::create( 'apierror-contentserializationexception', 'parseerror' )
168  ] );
169  return;
170  }
171  } else {
172  # Otherwise, make a new empty content.
173  $content = $contentHandler->makeEmptyContent();
174  }
175  }
176 
177  // @todo Add support for appending/prepending to the Content interface
178 
179  if ( !( $content instanceof TextContent ) ) {
180  $modelName = $contentHandler->getModelID();
181  $this->dieWithError( [ 'apierror-appendnotsupported', $modelName ] );
182  }
183 
184  if ( $params['section'] !== null ) {
185  if ( !$contentHandler->supportsSections() ) {
186  $modelName = $contentHandler->getModelID();
187  $this->dieWithError( [ 'apierror-sectionsnotsupported', $modelName ] );
188  }
189 
190  if ( $params['section'] == 'new' ) {
191  // DWIM if they're trying to prepend/append to a new section.
192  $content = null;
193  } else {
194  // Process the content for section edits
195  $section = $params['section'];
196  $content = $content->getSection( $section );
197 
198  if ( !$content ) {
199  $this->dieWithError( [ 'apierror-nosuchsection', wfEscapeWikiText( $section ) ] );
200  }
201  }
202  }
203 
204  if ( !$content ) {
205  $text = '';
206  } else {
207  $text = $content->serialize( $contentFormat );
208  }
209 
210  $params['text'] = $params['prependtext'] . $text . $params['appendtext'];
211  $toMD5 = $params['prependtext'] . $params['appendtext'];
212  }
213 
214  if ( $params['undo'] > 0 ) {
215  if ( $params['undoafter'] > 0 ) {
216  if ( $params['undo'] < $params['undoafter'] ) {
217  list( $params['undo'], $params['undoafter'] ) =
218  [ $params['undoafter'], $params['undo'] ];
219  }
220  $undoafterRev = $revisionLookup->getRevisionById( $params['undoafter'] );
221  }
222  $undoRev = $revisionLookup->getRevisionById( $params['undo'] );
223  if ( $undoRev === null || $undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
224  $this->dieWithError( [ 'apierror-nosuchrevid', $params['undo'] ] );
225  }
226 
227  if ( $params['undoafter'] == 0 ) {
228  $undoafterRev = $revisionLookup->getPreviousRevision( $undoRev );
229  }
230  if ( $undoafterRev === null || $undoafterRev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
231  $this->dieWithError( [ 'apierror-nosuchrevid', $params['undoafter'] ] );
232  }
233 
234  if ( $undoRev->getPageId() != $pageObj->getId() ) {
235  $this->dieWithError( [ 'apierror-revwrongpage', $undoRev->getId(),
236  $titleObj->getPrefixedText() ] );
237  }
238  if ( $undoafterRev->getPageId() != $pageObj->getId() ) {
239  $this->dieWithError( [ 'apierror-revwrongpage', $undoafterRev->getId(),
240  $titleObj->getPrefixedText() ] );
241  }
242 
243  $newContent = $contentHandler->getUndoContent(
244  $pageObj->getRevisionRecord()->getContent( SlotRecord::MAIN ),
245  $undoRev->getContent( SlotRecord::MAIN ),
246  $undoafterRev->getContent( SlotRecord::MAIN ),
247  $pageObj->getRevisionRecord()->getId() === $undoRev->getId()
248  );
249 
250  if ( !$newContent ) {
251  $this->dieWithError( 'undo-failure', 'undofailure' );
252  }
253  if ( !$params['contentmodel'] && !$params['contentformat'] ) {
254  // If we are reverting content model, the new content model
255  // might not support the current serialization format, in
256  // which case go back to the old serialization format,
257  // but only if the user hasn't specified a format/model
258  // parameter.
259  if ( !$newContent->isSupportedFormat( $contentFormat ) ) {
260  $undoafterRevMainSlot = $undoafterRev->getSlot(
261  SlotRecord::MAIN,
262  RevisionRecord::RAW
263  );
264  $contentFormat = $undoafterRevMainSlot->getFormat();
265  if ( !$contentFormat ) {
266  // fall back to default content format for the model
267  // of $undoafterRev
268  $contentFormat = MediaWikiServices::getInstance()
269  ->getContentHandlerFactory()
270  ->getContentHandler( $undoafterRevMainSlot->getModel() )
271  ->getDefaultFormat();
272  }
273  }
274  // Override content model with model of undid revision.
275  $contentModel = $newContent->getModel();
276  }
277  $params['text'] = $newContent->serialize( $contentFormat );
278  // If no summary was given and we only undid one rev,
279  // use an autosummary
280 
281  if ( $params['summary'] === null ) {
282  $nextRev = $revisionLookup->getNextRevision( $undoafterRev );
283  if ( $nextRev && $nextRev->getId() == $params['undo'] ) {
284  $undoRevUser = $undoRev->getUser();
285  $params['summary'] = wfMessage( 'undo-summary' )
286  ->params( $params['undo'], $undoRevUser ? $undoRevUser->getName() : '' )
287  ->inContentLanguage()->text();
288  }
289  }
290  }
291 
292  // See if the MD5 hash checks out
293  if ( $params['md5'] !== null && md5( $toMD5 ) !== $params['md5'] ) {
294  $this->dieWithError( 'apierror-badmd5' );
295  }
296 
297  // EditPage wants to parse its stuff from a WebRequest
298  // That interface kind of sucks, but it's workable
299  $requestArray = [
300  'wpTextbox1' => $params['text'],
301  'format' => $contentFormat,
302  'model' => $contentModel,
303  'wpEditToken' => $params['token'],
304  'wpIgnoreBlankSummary' => true,
305  'wpIgnoreBlankArticle' => true,
306  'wpIgnoreSelfRedirect' => true,
307  'bot' => $params['bot'],
308  'wpUnicodeCheck' => EditPage::UNICODE_CHECK,
309  ];
310 
311  if ( $params['summary'] !== null ) {
312  $requestArray['wpSummary'] = $params['summary'];
313  }
314 
315  if ( $params['sectiontitle'] !== null ) {
316  $requestArray['wpSectionTitle'] = $params['sectiontitle'];
317  }
318 
319  if ( $params['undo'] > 0 ) {
320  $requestArray['wpUndidRevision'] = $params['undo'];
321  }
322  if ( $params['undoafter'] > 0 ) {
323  $requestArray['wpUndoAfter'] = $params['undoafter'];
324  }
325 
326  // Skip for baserevid == null or '' or '0' or 0
327  if ( !empty( $params['baserevid'] ) ) {
328  $requestArray['editRevId'] = $params['baserevid'];
329  }
330 
331  // Watch out for basetimestamp == '' or '0'
332  // It gets treated as NOW, almost certainly causing an edit conflict
333  if ( $params['basetimestamp'] !== null && (bool)$this->getMain()->getVal( 'basetimestamp' ) ) {
334  $requestArray['wpEdittime'] = $params['basetimestamp'];
335  } elseif ( empty( $params['baserevid'] ) ) {
336  // Only set if baserevid is not set. Otherwise, conflicts would be ignored,
337  // due to the way userWasLastToEdit() works.
338  $requestArray['wpEdittime'] = $pageObj->getTimestamp();
339  }
340 
341  if ( $params['starttimestamp'] !== null ) {
342  $requestArray['wpStarttime'] = $params['starttimestamp'];
343  } else {
344  $requestArray['wpStarttime'] = wfTimestampNow(); // Fake wpStartime
345  }
346 
347  if ( $params['minor'] || ( !$params['notminor'] && $user->getOption( 'minordefault' ) ) ) {
348  $requestArray['wpMinoredit'] = '';
349  }
350 
351  if ( $params['recreate'] ) {
352  $requestArray['wpRecreate'] = '';
353  }
354 
355  if ( $params['section'] !== null ) {
356  $section = $params['section'];
357  if ( !preg_match( '/^((T-)?\d+|new)$/', $section ) ) {
358  $this->dieWithError( 'apierror-invalidsection' );
359  }
360  $content = $pageObj->getContent();
361  if ( $section !== '0' && $section != 'new'
362  && ( !$content || !$content->getSection( $section ) )
363  ) {
364  $this->dieWithError( [ 'apierror-nosuchsection', $section ] );
365  }
366  $requestArray['wpSection'] = $params['section'];
367  } else {
368  $requestArray['wpSection'] = '';
369  }
370 
371  $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
372  $watchlistExpiry = $params['watchlistexpiry'] ?? null;
373 
374  // Deprecated parameters
375  if ( $params['watch'] ) {
376  $watch = true;
377  } elseif ( $params['unwatch'] ) {
378  $watch = false;
379  }
380 
381  if ( $watch ) {
382  $requestArray['wpWatchthis'] = '';
383 
384  if ( $this->watchlistExpiryEnabled && $watchlistExpiry ) {
385  $requestArray['wpWatchlistExpiry'] = $watchlistExpiry;
386  }
387  }
388 
389  // Apply change tags
390  if ( $params['tags'] ) {
391  $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
392  if ( $tagStatus->isOK() ) {
393  $requestArray['wpChangeTags'] = implode( ',', $params['tags'] );
394  } else {
395  $this->dieStatus( $tagStatus );
396  }
397  }
398 
399  // Pass through anything else we might have been given, to support extensions
400  // This is kind of a hack but it's the best we can do to make extensions work
401  $requestArray += $this->getRequest()->getValues();
402 
403  global $wgTitle, $wgRequest;
404 
405  $req = new DerivativeRequest( $this->getRequest(), $requestArray, true );
406 
407  // Some functions depend on $wgTitle == $ep->mTitle
408  // TODO: Make them not or check if they still do
409  $wgTitle = $titleObj;
410 
411  $articleContext = new RequestContext;
412  $articleContext->setRequest( $req );
413  $articleContext->setWikiPage( $pageObj );
414  $articleContext->setUser( $this->getUser() );
415 
417  $articleObject = Article::newFromWikiPage( $pageObj, $articleContext );
418 
419  $ep = new EditPage( $articleObject );
420 
421  $ep->setApiEditOverride( true );
422  $ep->setContextTitle( $titleObj );
423  $ep->importFormData( $req );
424 
425  // Do the actual save
426  $oldRevId = $articleObject->getRevIdFetched();
427  $result = null;
428  // Fake $wgRequest for some hooks inside EditPage
429  // @todo FIXME: This interface SUCKS
430  $oldRequest = $wgRequest;
431  $wgRequest = $req;
432 
433  $status = $ep->attemptSave( $result );
434  $wgRequest = $oldRequest;
435 
436  $r = [];
437  switch ( $status->value ) {
440  if ( isset( $status->apiHookResult ) ) {
441  $r = $status->apiHookResult;
442  $r['result'] = 'Failure';
443  $apiResult->addValue( null, $this->getModuleName(), $r );
444  return;
445  }
446  if ( !$status->getErrors() ) {
447  // This appears to be unreachable right now, because all
448  // code paths will set an error. Could change, though.
449  $status->fatal( 'hookaborted' ); // @codeCoverageIgnore
450  }
451  $this->dieStatus( $status );
452 
453  // These two cases will normally have been caught earlier, and will
454  // only occur if something blocks the user between the earlier
455  // check and the check in EditPage (presumably a hook). It's not
456  // obvious that this is even possible.
457  // @codeCoverageIgnoreStart
459  $this->dieBlocked( $user->getBlock() );
460 
462  $this->dieReadOnly();
463  // @codeCoverageIgnoreEnd
464 
466  $r['new'] = true;
467  // fall-through
468 
470  $r['result'] = 'Success';
471  $r['pageid'] = (int)$titleObj->getArticleID();
472  $r['title'] = $titleObj->getPrefixedText();
473  $r['contentmodel'] = $articleObject->getPage()->getContentModel();
474  $newRevId = $articleObject->getPage()->getLatest();
475  if ( $newRevId == $oldRevId ) {
476  $r['nochange'] = true;
477  } else {
478  $r['oldrevid'] = (int)$oldRevId;
479  $r['newrevid'] = (int)$newRevId;
480  $r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
481  $pageObj->getTimestamp() );
482  }
483 
484  if ( $watch ) {
485  $r['watched'] = $status->isOK();
486 
487  if ( $this->watchlistExpiryEnabled ) {
488  $r['watchlistexpiry'] = ApiResult::formatExpiry( $watchlistExpiry );
489  }
490  }
491  break;
492 
493  default:
494  if ( !$status->getErrors() ) {
495  // EditPage sometimes only sets the status code without setting
496  // any actual error messages. Supply defaults for those cases.
497  switch ( $status->value ) {
498  // Currently needed
500  $status->fatal( 'apierror-noimageredirect-anon' );
501  break;
503  $status->fatal( 'apierror-noimageredirect' );
504  break;
507  $status->fatal( 'apierror-contenttoobig', $this->getConfig()->get( 'MaxArticleSize' ) );
508  break;
510  $status->fatal( 'apierror-noedit-anon' );
511  break;
513  $status->fatal( 'apierror-cantchangecontentmodel' );
514  break;
516  $status->fatal( 'apierror-pagedeleted' );
517  break;
519  $status->fatal( 'edit-conflict' );
520  break;
521 
522  // Currently shouldn't be needed, but here in case
523  // hooks use them without setting appropriate
524  // errors on the status.
525  // @codeCoverageIgnoreStart
527  $status->fatal( 'apierror-spamdetected', $result['spam'] );
528  break;
530  $status->fatal( 'apierror-noedit' );
531  break;
533  $status->fatal( 'apierror-ratelimited' );
534  break;
536  $status->fatal( 'nocreate-loggedin' );
537  break;
539  $status->fatal( 'apierror-emptypage' );
540  break;
542  $status->fatal( 'apierror-emptynewsection' );
543  break;
545  $status->fatal( 'apierror-summaryrequired' );
546  break;
547  default:
548  wfWarn( __METHOD__ . ": Unknown EditPage code {$status->value} with no message" );
549  $status->fatal( 'apierror-unknownerror-editpage', $status->value );
550  break;
551  // @codeCoverageIgnoreEnd
552  }
553  }
554  $this->dieStatus( $status );
555  }
556  $apiResult->addValue( null, $this->getModuleName(), $r );
557  }
558 
559  public function mustBePosted() {
560  return true;
561  }
562 
563  public function isWriteMode() {
564  return true;
565  }
566 
567  public function getAllowedParams() {
568  $params = [
569  'title' => [
570  ApiBase::PARAM_TYPE => 'string',
571  ],
572  'pageid' => [
573  ApiBase::PARAM_TYPE => 'integer',
574  ],
575  'section' => null,
576  'sectiontitle' => [
577  ApiBase::PARAM_TYPE => 'string',
578  ],
579  'text' => [
580  ApiBase::PARAM_TYPE => 'text',
581  ],
582  'summary' => null,
583  'tags' => [
584  ApiBase::PARAM_TYPE => 'tags',
585  ApiBase::PARAM_ISMULTI => true,
586  ],
587  'minor' => false,
588  'notminor' => false,
589  'bot' => false,
590  'baserevid' => [
591  ApiBase::PARAM_TYPE => 'integer',
592  ],
593  'basetimestamp' => [
594  ApiBase::PARAM_TYPE => 'timestamp',
595  ],
596  'starttimestamp' => [
597  ApiBase::PARAM_TYPE => 'timestamp',
598  ],
599  'recreate' => false,
600  'createonly' => false,
601  'nocreate' => false,
602  'watch' => [
603  ApiBase::PARAM_DFLT => false,
605  ],
606  'unwatch' => [
607  ApiBase::PARAM_DFLT => false,
609  ],
610  ];
611 
612  // Params appear in the docs in the order they are defined,
613  // which is why this is here and not at the bottom.
614  $params += $this->getWatchlistParams();
615 
616  return $params + [
617  'md5' => null,
618  'prependtext' => [
619  ApiBase::PARAM_TYPE => 'text',
620  ],
621  'appendtext' => [
622  ApiBase::PARAM_TYPE => 'text',
623  ],
624  'undo' => [
625  ApiBase::PARAM_TYPE => 'integer',
626  ApiBase::PARAM_MIN => 0,
628  ],
629  'undoafter' => [
630  ApiBase::PARAM_TYPE => 'integer',
631  ApiBase::PARAM_MIN => 0,
633  ],
634  'redirect' => [
635  ApiBase::PARAM_TYPE => 'boolean',
636  ApiBase::PARAM_DFLT => false,
637  ],
638  'contentformat' => [
639  ApiBase::PARAM_TYPE => $this->getContentHandlerFactory()->getAllContentFormats(),
640  ],
641  'contentmodel' => [
642  ApiBase::PARAM_TYPE => $this->getContentHandlerFactory()->getContentModels(),
643  ],
644  'token' => [
645  // Standard definition automatically inserted
646  ApiBase::PARAM_HELP_MSG_APPEND => [ 'apihelp-edit-param-token' ],
647  ],
648  ];
649  }
650 
651  public function needsToken() {
652  return 'csrf';
653  }
654 
655  protected function getExamplesMessages() {
656  return [
657  'action=edit&title=Test&summary=test%20summary&' .
658  'text=article%20content&baserevid=1234567&token=123ABC'
659  => 'apihelp-edit-example-edit',
660  'action=edit&title=Test&summary=NOTOC&minor=&' .
661  'prependtext=__NOTOC__%0A&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
662  => 'apihelp-edit-example-prepend',
663  'action=edit&title=Test&undo=13585&undoafter=13579&' .
664  'basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
665  => 'apihelp-edit-example-undo',
666  ];
667  }
668 
669  public function getHelpUrls() {
670  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Edit';
671  }
672 
674  return MediaWikiServices::getInstance()->getContentHandlerFactory();
675  }
676 }
ApiEditPage
A module that allows for editing and creating pages.
Definition: ApiEditPage.php:37
MediaWiki\EditPage\IEditObject\AS_READ_ONLY_PAGE_ANON
const AS_READ_ONLY_PAGE_ANON
Status: this anonymous user is not allowed to edit this page.
Definition: IEditObject.php:32
DerivativeRequest
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Definition: DerivativeRequest.php:36
ApiMain
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:47
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:67
MediaWiki\EditPage\IEditObject\AS_ARTICLE_WAS_DELETED
const AS_ARTICLE_WAS_DELETED
Status: article was deleted while editing and wpRecreate == false or form was not posted.
Definition: IEditObject.php:44
MediaWiki\EditPage\IEditObject\AS_SUCCESS_NEW_ARTICLE
const AS_SUCCESS_NEW_ARTICLE
Status: Article successfully created.
Definition: IEditObject.php:17
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
MediaWiki\EditPage\IEditObject\AS_BLOCKED_PAGE_FOR_USER
const AS_BLOCKED_PAGE_FOR_USER
Status: User is blocked from editing this page.
Definition: IEditObject.php:26
ApiEditPage\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiEditPage.php:655
MediaWiki\EditPage\IEditObject\AS_TEXTBOX_EMPTY
const AS_TEXTBOX_EMPTY
Status: user tried to create a new section without content.
Definition: IEditObject.php:62
RequestContext\setRequest
setRequest(WebRequest $request)
Definition: RequestContext.php:118
MediaWiki\EditPage\IEditObject\AS_SUMMARY_NEEDED
const AS_SUMMARY_NEEDED
Status: no edit summary given and the user has forceeditsummary set and the user is not editing in hi...
Definition: IEditObject.php:59
MediaWiki\EditPage\IEditObject\AS_CONFLICT_DETECTED
const AS_CONFLICT_DETECTED
Status: (non-resolvable) edit conflict.
Definition: IEditObject.php:53
ApiEditPage\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiEditPage.php:669
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1382
ApiEditPage\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiEditPage.php:567
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1808
ApiBase\getTitleOrPageId
getTitleOrPageId( $params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
Definition: ApiBase.php:986
ApiBase\PARAM_TYPE
const PARAM_TYPE
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:71
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:565
MediaWiki\EditPage\IEditObject\AS_SPAM_ERROR
const AS_SPAM_ERROR
Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex.
Definition: IEditObject.php:71
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1219
ApiBase\dieBlocked
dieBlocked(AbstractBlock $block)
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die wit...
Definition: ApiBase.php:1409
MediaWiki\EditPage\IEditObject\AS_CONTENT_TOO_BIG
const AS_CONTENT_TOO_BIG
Status: Content too big (> $wgMaxArticleSize)
Definition: IEditObject.php:29
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:76
MediaWiki\EditPage\IEditObject\AS_NO_CREATE_PERMISSION
const AS_NO_CREATE_PERMISSION
Status: user tried to create this page, but is not allowed to do that.
Definition: IEditObject.php:47
MediaWiki\EditPage\IEditObject\AS_SUCCESS_UPDATE
const AS_SUCCESS_UPDATE
Status: Article successfully updated.
Definition: IEditObject.php:14
ApiEditPage\mustBePosted
mustBePosted()
Indicates whether this module must be called with a POST request Stable to override.
Definition: ApiEditPage.php:559
ContextSource\getUser
getUser()
Stable to override.
Definition: ContextSource.php:131
ApiEditPage\getContentHandlerFactory
getContentHandlerFactory()
Definition: ApiEditPage.php:673
ApiBase\PARAM_HELP_MSG_APPEND
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
Definition: ApiBase.php:114
$wgTitle
$wgTitle
Definition: Setup.php:794
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:52
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:76
ApiBase\PARAM_MIN
const PARAM_MIN
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:74
Article\newFromWikiPage
static newFromWikiPage(WikiPage $page, IContextSource $context)
Create an Article object of the appropriate class for the given page.
Definition: Article.php:226
MediaWiki\EditPage\IEditObject\AS_RATE_LIMITED
const AS_RATE_LIMITED
Status: rate limiter for action 'edit' was tripped.
Definition: IEditObject.php:41
EditPage\UNICODE_CHECK
const UNICODE_CHECK
Used for Unicode support checks.
Definition: EditPage.php:69
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:156
ApiEditPage\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiEditPage.php:48
ApiEditPage\__construct
__construct(ApiMain $mainModule, $moduleName, $modulePrefix='')
Stable to call.
Definition: ApiEditPage.php:41
MWContentSerializationException
Exception representing a failure to serialize or unserialize a content object.
Definition: MWContentSerializationException.php:8
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:717
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1837
RequestContext
Group all the pieces relevant to the context of a request into one instance @newable.
Definition: RequestContext.php:38
ApiBase\requireAtLeastOneParameter
requireAtLeastOneParameter( $params,... $required)
Die if none of a certain set of parameters is set and not false.
Definition: ApiBase.php:914
ApiMessage\create
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
Definition: ApiMessage.php:42
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:142
MediaWiki\EditPage\IEditObject\AS_NO_CHANGE_CONTENT_MODEL
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: IEditObject.php:83
MediaWiki\EditPage\IEditObject\AS_READ_ONLY_PAGE_LOGGED
const AS_READ_ONLY_PAGE_LOGGED
Status: this logged in user is not allowed to edit this page.
Definition: IEditObject.php:35
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:604
$content
$content
Definition: router.php:76
MediaWiki\Content\IContentHandlerFactory
Definition: IContentHandlerFactory.php:10
MediaWiki\EditPage\IEditObject\AS_IMAGE_REDIRECT_ANON
const AS_IMAGE_REDIRECT_ANON
Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false)
Definition: IEditObject.php:74
Message\plaintextParam
static plaintextParam( $plaintext)
Definition: Message.php:1114
ApiBase\dieReadOnly
dieReadOnly()
Helper function for readonly errors.
Definition: ApiBase.php:1468
ApiBase\useTransactionalTimeLimit
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
Definition: ApiBase.php:1239
getWatchlistValue
getWatchlistValue(string $watchlist, Title $titleObj, ?string $userOption=null)
Return true if we're to watch the page, false if not.
Definition: ApiWatchlistTrait.php:89
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1487
ApiEditPage\isWriteMode
isWriteMode()
Indicates whether this module requires write mode.
Definition: ApiEditPage.php:563
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:39
EditPage
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition: EditPage.php:62
ApiWatchlistTrait
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Definition: ApiWatchlistTrait.php:17
ApiBase\PARAM_RANGE_ENFORCE
const PARAM_RANGE_ENFORCE
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:93
ChangeTags\canAddTagsAccompanyingChange
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:544
MediaWiki\EditPage\IEditObject\AS_BLANK_ARTICLE
const AS_BLANK_ARTICLE
Status: user tried to create a blank page and wpIgnoreBlankArticle == false.
Definition: IEditObject.php:50
Title
Represents a title within MediaWiki.
Definition: Title.php:42
getWatchlistParams
getWatchlistParams(array $watchOptions=[])
Get additional allow params specific to watchlisting.
Definition: ApiWatchlistTrait.php:35
MediaWiki\EditPage\IEditObject\AS_IMAGE_REDIRECT_LOGGED
const AS_IMAGE_REDIRECT_LOGGED
Status: logged in user is not allowed to upload (User::isAllowed('upload') == false)
Definition: IEditObject.php:77
MediaWiki\EditPage\IEditObject\AS_MAX_ARTICLE_SIZE_EXCEEDED
const AS_MAX_ARTICLE_SIZE_EXCEEDED
Status: article is too big (> $wgMaxArticleSize), after merging in the new section.
Definition: IEditObject.php:65
ApiBase\PARAM_DFLT
const PARAM_DFLT
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:69
MediaWiki\EditPage\IEditObject\AS_READ_ONLY_PAGE
const AS_READ_ONLY_PAGE
Status: wiki is in readonly mode (wfReadOnly() == true)
Definition: IEditObject.php:38
ApiBase\dieWithException
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
Definition: ApiBase.php:1394
ApiBase\dieStatus
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition: ApiBase.php:1440
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:444
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:70
ApiResult\formatExpiry
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.
Definition: ApiResult.php:1193
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:460
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1073
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:77
ApiBase\checkTitleUserPermissions
checkTitleUserPermissions(LinkTarget $linkTarget, $actions, array $options=[])
Helper function for permission-denied errors.
Definition: ApiBase.php:1509
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:644
MediaWiki\EditPage\IEditObject\AS_HOOK_ERROR_EXPECTED
const AS_HOOK_ERROR_EXPECTED
Status: A hook function returned an error.
Definition: IEditObject.php:23
ApiEditPage\needsToken
needsToken()
Returns the token type this module requires in order to execute.
Definition: ApiEditPage.php:651
MediaWiki\EditPage\IEditObject\AS_HOOK_ERROR
const AS_HOOK_ERROR
Status: Article update aborted by a hook function.
Definition: IEditObject.php:20
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39