Merge "Make image pagination not require a page load."
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
1 <?php
2 /**
3 *
4 *
5 * Created on August 16, 2007
6 *
7 * Copyright © 2007 Iker Labarga "<Firstname><Lastname>@gmail.com"
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 */
26
27 /**
28 * A module that allows for editing and creating pages.
29 *
30 * Currently, this wraps around the EditPage class in an ugly way,
31 * EditPage.php should be rewritten to provide a cleaner interface
32 * @ingroup API
33 */
34 class ApiEditPage extends ApiBase {
35
36 public function execute() {
37 $user = $this->getUser();
38 $params = $this->extractRequestParams();
39
40 if ( is_null( $params['text'] ) && is_null( $params['appendtext'] ) &&
41 is_null( $params['prependtext'] ) &&
42 $params['undo'] == 0 )
43 {
44 $this->dieUsageMsg( 'missingtext' );
45 }
46
47 $pageObj = $this->getTitleOrPageId( $params );
48 $titleObj = $pageObj->getTitle();
49 $apiResult = $this->getResult();
50
51 if ( $params['redirect'] ) {
52 if ( $titleObj->isRedirect() ) {
53 $oldTitle = $titleObj;
54
55 $titles = Revision::newFromTitle( $oldTitle, false, Revision::READ_LATEST )
56 ->getContent( Revision::FOR_THIS_USER, $user )
57 ->getRedirectChain();
58 // array_shift( $titles );
59
60 $redirValues = array();
61
62 /** @var $newTitle Title */
63 foreach ( $titles as $id => $newTitle ) {
64
65 if ( !isset( $titles[$id - 1] ) ) {
66 $titles[$id - 1] = $oldTitle;
67 }
68
69 $redirValues[] = array(
70 'from' => $titles[$id - 1]->getPrefixedText(),
71 'to' => $newTitle->getPrefixedText()
72 );
73
74 $titleObj = $newTitle;
75 }
76
77 $apiResult->setIndexedTagName( $redirValues, 'r' );
78 $apiResult->addValue( null, 'redirects', $redirValues );
79
80 // Since the page changed, update $pageObj
81 $pageObj = WikiPage::factory( $titleObj );
82 }
83 }
84
85 if ( !isset( $params['contentmodel'] ) || $params['contentmodel'] == '' ) {
86 $contentHandler = $pageObj->getContentHandler();
87 } else {
88 $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] );
89 }
90
91 // @todo ask handler whether direct editing is supported at all! make allowFlatEdit() method or some such
92
93 if ( !isset( $params['contentformat'] ) || $params['contentformat'] == '' ) {
94 $params['contentformat'] = $contentHandler->getDefaultFormat();
95 }
96
97 $contentFormat = $params['contentformat'];
98
99 if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) {
100 $name = $titleObj->getPrefixedDBkey();
101 $model = $contentHandler->getModelID();
102
103 $this->dieUsage( "The requested format $contentFormat is not supported for content model " .
104 " $model used by $name", 'badformat' );
105 }
106
107 if ( $params['createonly'] && $titleObj->exists() ) {
108 $this->dieUsageMsg( 'createonly-exists' );
109 }
110 if ( $params['nocreate'] && !$titleObj->exists() ) {
111 $this->dieUsageMsg( 'nocreate-missing' );
112 }
113
114 // Now let's check whether we're even allowed to do this
115 $errors = $titleObj->getUserPermissionsErrors( 'edit', $user );
116 if ( !$titleObj->exists() ) {
117 $errors = array_merge( $errors, $titleObj->getUserPermissionsErrors( 'create', $user ) );
118 }
119 if ( count( $errors ) ) {
120 $this->dieUsageMsg( $errors[0] );
121 }
122
123 $toMD5 = $params['text'];
124 if ( !is_null( $params['appendtext'] ) || !is_null( $params['prependtext'] ) )
125 {
126 $content = $pageObj->getContent();
127
128 if ( !$content ) {
129 if ( $titleObj->getNamespace() == NS_MEDIAWIKI ) {
130 # If this is a MediaWiki:x message, then load the messages
131 # and return the message value for x.
132 $text = $titleObj->getDefaultMessageText();
133 if ( $text === false ) {
134 $text = '';
135 }
136
137 try {
138 $content = ContentHandler::makeContent( $text, $this->getTitle() );
139 } catch ( MWContentSerializationException $ex ) {
140 $this->dieUsage( $ex->getMessage(), 'parseerror' );
141 return;
142 }
143 } else {
144 # Otherwise, make a new empty content.
145 $content = $contentHandler->makeEmptyContent();
146 }
147 }
148
149 // @todo Add support for appending/prepending to the Content interface
150
151 if ( !( $content instanceof TextContent ) ) {
152 $mode = $contentHandler->getModelID();
153 $this->dieUsage( "Can't append to pages using content model $mode", 'appendnotsupported' );
154 }
155
156 if ( !is_null( $params['section'] ) ) {
157 if ( !$contentHandler->supportsSections() ) {
158 $modelName = $contentHandler->getModelID();
159 $this->dieUsage( "Sections are not supported for this content model: $modelName.", 'sectionsnotsupported' );
160 }
161
162 if ( $params['section'] == 'new' ) {
163 // DWIM if they're trying to prepend/append to a new section.
164 $content = null;
165 } else {
166 // Process the content for section edits
167 $section = intval( $params['section'] );
168 $content = $content->getSection( $section );
169
170 if ( !$content ) {
171 $this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
172 }
173 }
174 }
175
176 if ( !$content ) {
177 $text = '';
178 } else {
179 $text = $content->serialize( $contentFormat );
180 }
181
182 $params['text'] = $params['prependtext'] . $text . $params['appendtext'];
183 $toMD5 = $params['prependtext'] . $params['appendtext'];
184 }
185
186 if ( $params['undo'] > 0 ) {
187 if ( $params['undoafter'] > 0 ) {
188 if ( $params['undo'] < $params['undoafter'] ) {
189 list( $params['undo'], $params['undoafter'] ) =
190 array( $params['undoafter'], $params['undo'] );
191 }
192 $undoafterRev = Revision::newFromID( $params['undoafter'] );
193 }
194 $undoRev = Revision::newFromID( $params['undo'] );
195 if ( is_null( $undoRev ) || $undoRev->isDeleted( Revision::DELETED_TEXT ) ) {
196 $this->dieUsageMsg( array( 'nosuchrevid', $params['undo'] ) );
197 }
198
199 if ( $params['undoafter'] == 0 ) {
200 $undoafterRev = $undoRev->getPrevious();
201 }
202 if ( is_null( $undoafterRev ) || $undoafterRev->isDeleted( Revision::DELETED_TEXT ) ) {
203 $this->dieUsageMsg( array( 'nosuchrevid', $params['undoafter'] ) );
204 }
205
206 if ( $undoRev->getPage() != $pageObj->getID() ) {
207 $this->dieUsageMsg( array( 'revwrongpage', $undoRev->getID(), $titleObj->getPrefixedText() ) );
208 }
209 if ( $undoafterRev->getPage() != $pageObj->getID() ) {
210 $this->dieUsageMsg( array( 'revwrongpage', $undoafterRev->getID(), $titleObj->getPrefixedText() ) );
211 }
212
213 $newContent = $contentHandler->getUndoContent( $pageObj->getRevision(), $undoRev, $undoafterRev );
214
215 if ( !$newContent ) {
216 $this->dieUsageMsg( 'undo-failure' );
217 }
218
219 $params['text'] = $newContent->serialize( $params['contentformat'] );
220
221 // If no summary was given and we only undid one rev,
222 // use an autosummary
223 if ( is_null( $params['summary'] ) && $titleObj->getNextRevisionID( $undoafterRev->getID() ) == $params['undo'] ) {
224 $params['summary'] = wfMessage( 'undo-summary', $params['undo'], $undoRev->getUserText() )->inContentLanguage()->text();
225 }
226 }
227
228 // See if the MD5 hash checks out
229 if ( !is_null( $params['md5'] ) && md5( $toMD5 ) !== $params['md5'] ) {
230 $this->dieUsageMsg( 'hashcheckfailed' );
231 }
232
233 // EditPage wants to parse its stuff from a WebRequest
234 // That interface kind of sucks, but it's workable
235 $requestArray = array(
236 'wpTextbox1' => $params['text'],
237 'format' => $contentFormat,
238 'model' => $contentHandler->getModelID(),
239 'wpEditToken' => $params['token'],
240 'wpIgnoreBlankSummary' => ''
241 );
242
243 if ( !is_null( $params['summary'] ) ) {
244 $requestArray['wpSummary'] = $params['summary'];
245 }
246
247 if ( !is_null( $params['sectiontitle'] ) ) {
248 $requestArray['wpSectionTitle'] = $params['sectiontitle'];
249 }
250
251 // TODO: Pass along information from 'undoafter' as well
252 if ( $params['undo'] > 0 ) {
253 $requestArray['wpUndidRevision'] = $params['undo'];
254 }
255
256 // Watch out for basetimestamp == ''
257 // wfTimestamp() treats it as NOW, almost certainly causing an edit conflict
258 if ( !is_null( $params['basetimestamp'] ) && $params['basetimestamp'] != '' ) {
259 $requestArray['wpEdittime'] = wfTimestamp( TS_MW, $params['basetimestamp'] );
260 } else {
261 $requestArray['wpEdittime'] = $pageObj->getTimestamp();
262 }
263
264 if ( !is_null( $params['starttimestamp'] ) && $params['starttimestamp'] != '' ) {
265 $requestArray['wpStarttime'] = wfTimestamp( TS_MW, $params['starttimestamp'] );
266 } else {
267 $requestArray['wpStarttime'] = wfTimestampNow(); // Fake wpStartime
268 }
269
270 if ( $params['minor'] || ( !$params['notminor'] && $user->getOption( 'minordefault' ) ) ) {
271 $requestArray['wpMinoredit'] = '';
272 }
273
274 if ( $params['recreate'] ) {
275 $requestArray['wpRecreate'] = '';
276 }
277
278 if ( !is_null( $params['section'] ) ) {
279 $section = intval( $params['section'] );
280 if ( $section == 0 && $params['section'] != '0' && $params['section'] != 'new' ) {
281 $this->dieUsage( "The section parameter must be set to an integer or 'new'", "invalidsection" );
282 }
283 $requestArray['wpSection'] = $params['section'];
284 } else {
285 $requestArray['wpSection'] = '';
286 }
287
288 $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
289
290 // Deprecated parameters
291 if ( $params['watch'] ) {
292 $watch = true;
293 } elseif ( $params['unwatch'] ) {
294 $watch = false;
295 }
296
297 if ( $watch ) {
298 $requestArray['wpWatchthis'] = '';
299 }
300
301 // Pass through anything else we might have been given, to support extensions
302 // This is kind of a hack but it's the best we can do to make extensions work
303 $requestArray += $this->getRequest()->getValues();
304
305 global $wgTitle, $wgRequest;
306
307 $req = new DerivativeRequest( $this->getRequest(), $requestArray, true );
308
309 // Some functions depend on $wgTitle == $ep->mTitle
310 // TODO: Make them not or check if they still do
311 $wgTitle = $titleObj;
312
313 $articleContext = new RequestContext;
314 $articleContext->setRequest( $req );
315 $articleContext->setWikiPage( $pageObj );
316 $articleContext->setUser( $this->getUser() );
317
318 /** @var $articleObject Article */
319 $articleObject = Article::newFromWikiPage( $pageObj, $articleContext );
320
321 $ep = new EditPage( $articleObject );
322
323 // allow editing of non-textual content.
324 $ep->allowNonTextContent = true;
325
326 $ep->setContextTitle( $titleObj );
327 $ep->importFormData( $req );
328 $content = $ep->textbox1;
329
330 // The following is needed to give the hook the full content of the
331 // new revision rather than just the current section. (Bug 52077)
332 if ( !is_null( $params['section'] ) && $contentHandler->supportsSections() ) {
333
334 $sectionTitle = '';
335 // If sectiontitle is set, use it, otherwise use the summary as the section title (for
336 // backwards compatibility with old forms/bots).
337 if ( $ep->sectiontitle !== '' ) {
338 $sectionTitle = $ep->sectiontitle;
339 } else {
340 $sectionTitle = $ep->summary;
341 }
342
343 $contentObj = $contentHandler->unserializeContent( $content, $contentFormat );
344
345 $fullContentObj = $articleObject->replaceSectionContent( $params['section'], $contentObj, $sectionTitle );
346 if ( $fullContentObj ) {
347 $content = $fullContentObj->serialize( $contentFormat );
348 } else {
349 // This most likely means we have an edit conflict which means that the edit
350 // wont succeed anyway.
351 $this->dieUsageMsg( 'editconflict' );
352 }
353 }
354
355 // Run hooks
356 // Handle APIEditBeforeSave parameters
357 $r = array();
358 if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $content, &$r ) ) ) {
359 if ( count( $r ) ) {
360 $r['result'] = 'Failure';
361 $apiResult->addValue( null, $this->getModuleName(), $r );
362 return;
363 } else {
364 $this->dieUsageMsg( 'hookaborted' );
365 }
366 }
367
368 // Do the actual save
369 $oldRevId = $articleObject->getRevIdFetched();
370 $result = null;
371 // Fake $wgRequest for some hooks inside EditPage
372 // @todo FIXME: This interface SUCKS
373 $oldRequest = $wgRequest;
374 $wgRequest = $req;
375
376 $status = $ep->internalAttemptSave( $result, $user->isAllowed( 'bot' ) && $params['bot'] );
377 $wgRequest = $oldRequest;
378 global $wgMaxArticleSize;
379
380 switch ( $status->value ) {
381 case EditPage::AS_HOOK_ERROR:
382 case EditPage::AS_HOOK_ERROR_EXPECTED:
383 $this->dieUsageMsg( 'hookaborted' );
384
385 case EditPage::AS_PARSE_ERROR:
386 $this->dieUsage( $status->getMessage(), 'parseerror' );
387
388 case EditPage::AS_IMAGE_REDIRECT_ANON:
389 $this->dieUsageMsg( 'noimageredirect-anon' );
390
391 case EditPage::AS_IMAGE_REDIRECT_LOGGED:
392 $this->dieUsageMsg( 'noimageredirect-logged' );
393
394 case EditPage::AS_SPAM_ERROR:
395 $this->dieUsageMsg( array( 'spamdetected', $result['spam'] ) );
396
397 case EditPage::AS_BLOCKED_PAGE_FOR_USER:
398 $this->dieUsageMsg( 'blockedtext' );
399
400 case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
401 case EditPage::AS_CONTENT_TOO_BIG:
402 $this->dieUsageMsg( array( 'contenttoobig', $wgMaxArticleSize ) );
403
404 case EditPage::AS_READ_ONLY_PAGE_ANON:
405 $this->dieUsageMsg( 'noedit-anon' );
406
407 case EditPage::AS_READ_ONLY_PAGE_LOGGED:
408 $this->dieUsageMsg( 'noedit' );
409
410 case EditPage::AS_READ_ONLY_PAGE:
411 $this->dieReadOnly();
412
413 case EditPage::AS_RATE_LIMITED:
414 $this->dieUsageMsg( 'actionthrottledtext' );
415
416 case EditPage::AS_ARTICLE_WAS_DELETED:
417 $this->dieUsageMsg( 'wasdeleted' );
418
419 case EditPage::AS_NO_CREATE_PERMISSION:
420 $this->dieUsageMsg( 'nocreate-loggedin' );
421
422 case EditPage::AS_BLANK_ARTICLE:
423 $this->dieUsageMsg( 'blankpage' );
424
425 case EditPage::AS_CONFLICT_DETECTED:
426 $this->dieUsageMsg( 'editconflict' );
427
428 // case EditPage::AS_SUMMARY_NEEDED: Can't happen since we set wpIgnoreBlankSummary
429 case EditPage::AS_TEXTBOX_EMPTY:
430 $this->dieUsageMsg( 'emptynewsection' );
431
432 case EditPage::AS_SUCCESS_NEW_ARTICLE:
433 $r['new'] = '';
434 // fall-through
435
436 case EditPage::AS_SUCCESS_UPDATE:
437 $r['result'] = 'Success';
438 $r['pageid'] = intval( $titleObj->getArticleID() );
439 $r['title'] = $titleObj->getPrefixedText();
440 $r['contentmodel'] = $titleObj->getContentModel();
441 $newRevId = $articleObject->getLatest();
442 if ( $newRevId == $oldRevId ) {
443 $r['nochange'] = '';
444 } else {
445 $r['oldrevid'] = intval( $oldRevId );
446 $r['newrevid'] = intval( $newRevId );
447 $r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
448 $pageObj->getTimestamp() );
449 }
450 break;
451
452 case EditPage::AS_SUMMARY_NEEDED:
453 $this->dieUsageMsg( 'summaryrequired' );
454
455 case EditPage::AS_END:
456 default:
457 // $status came from WikiPage::doEdit()
458 $errors = $status->getErrorsArray();
459 $this->dieUsageMsg( $errors[0] ); // TODO: Add new errors to message map
460 break;
461 }
462 $apiResult->addValue( null, $this->getModuleName(), $r );
463 }
464
465 public function mustBePosted() {
466 return true;
467 }
468
469 public function isWriteMode() {
470 return true;
471 }
472
473 public function getDescription() {
474 return 'Create and edit pages.';
475 }
476
477 public function getPossibleErrors() {
478 global $wgMaxArticleSize;
479
480 return array_merge( parent::getPossibleErrors(),
481 $this->getTitleOrPageIdErrorMessage(),
482 array(
483 array( 'missingtext' ),
484 array( 'createonly-exists' ),
485 array( 'nocreate-missing' ),
486 array( 'nosuchrevid', 'undo' ),
487 array( 'nosuchrevid', 'undoafter' ),
488 array( 'revwrongpage', 'id', 'text' ),
489 array( 'undo-failure' ),
490 array( 'hashcheckfailed' ),
491 array( 'hookaborted' ),
492 array( 'code' => 'parseerror', 'info' => 'Failed to parse the given text.' ),
493 array( 'noimageredirect-anon' ),
494 array( 'noimageredirect-logged' ),
495 array( 'spamdetected', 'spam' ),
496 array( 'summaryrequired' ),
497 array( 'blockedtext' ),
498 array( 'contenttoobig', $wgMaxArticleSize ),
499 array( 'noedit-anon' ),
500 array( 'noedit' ),
501 array( 'actionthrottledtext' ),
502 array( 'wasdeleted' ),
503 array( 'nocreate-loggedin' ),
504 array( 'blankpage' ),
505 array( 'editconflict' ),
506 array( 'emptynewsection' ),
507 array( 'unknownerror', 'retval' ),
508 array( 'code' => 'nosuchsection', 'info' => 'There is no section section.' ),
509 array( 'code' => 'invalidsection', 'info' => 'The section parameter must be set to an integer or \'new\'' ),
510 array( 'code' => 'sectionsnotsupported', 'info' => 'Sections are not supported for this type of page.' ),
511 array( 'code' => 'editnotsupported', 'info' => 'Editing of this type of page is not supported using '
512 . 'the text based edit API.' ),
513 array( 'code' => 'appendnotsupported', 'info' => 'This type of page can not be edited by appending '
514 . 'or prepending text.' ),
515 array( 'code' => 'badformat', 'info' => 'The requested serialization format can not be applied to '
516 . 'the page\'s content model' ),
517 array( 'customcssprotected' ),
518 array( 'customjsprotected' ),
519 )
520 );
521 }
522
523 public function getAllowedParams() {
524 return array(
525 'title' => array(
526 ApiBase::PARAM_TYPE => 'string',
527 ),
528 'pageid' => array(
529 ApiBase::PARAM_TYPE => 'integer',
530 ),
531 'section' => null,
532 'sectiontitle' => array(
533 ApiBase::PARAM_TYPE => 'string',
534 ),
535 'text' => null,
536 'token' => array(
537 ApiBase::PARAM_TYPE => 'string',
538 ApiBase::PARAM_REQUIRED => true
539 ),
540 'summary' => null,
541 'minor' => false,
542 'notminor' => false,
543 'bot' => false,
544 'basetimestamp' => null,
545 'starttimestamp' => null,
546 'recreate' => false,
547 'createonly' => false,
548 'nocreate' => false,
549 'watch' => array(
550 ApiBase::PARAM_DFLT => false,
551 ApiBase::PARAM_DEPRECATED => true,
552 ),
553 'unwatch' => array(
554 ApiBase::PARAM_DFLT => false,
555 ApiBase::PARAM_DEPRECATED => true,
556 ),
557 'watchlist' => array(
558 ApiBase::PARAM_DFLT => 'preferences',
559 ApiBase::PARAM_TYPE => array(
560 'watch',
561 'unwatch',
562 'preferences',
563 'nochange'
564 ),
565 ),
566 'md5' => null,
567 'prependtext' => null,
568 'appendtext' => null,
569 'undo' => array(
570 ApiBase::PARAM_TYPE => 'integer'
571 ),
572 'undoafter' => array(
573 ApiBase::PARAM_TYPE => 'integer'
574 ),
575 'redirect' => array(
576 ApiBase::PARAM_TYPE => 'boolean',
577 ApiBase::PARAM_DFLT => false,
578 ),
579 'contentformat' => array(
580 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
581 ),
582 'contentmodel' => array(
583 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
584 )
585 );
586 }
587
588 public function getParamDescription() {
589 $p = $this->getModulePrefix();
590 return array(
591 'title' => "Title of the page you want to edit. Cannot be used together with {$p}pageid",
592 'pageid' => "Page ID of the page you want to edit. Cannot be used together with {$p}title",
593 'section' => 'Section number. 0 for the top section, \'new\' for a new section',
594 'sectiontitle' => 'The title for a new section',
595 'text' => 'Page content',
596 'token' => array( 'Edit token. You can get one of these through prop=info.',
597 "The token should always be sent as the last parameter, or at least, after the {$p}text parameter"
598 ),
599 'summary' => "Edit summary. Also section title when {$p}section=new and {$p}sectiontitle is not set",
600 'minor' => 'Minor edit',
601 'notminor' => 'Non-minor edit',
602 'bot' => 'Mark this edit as bot',
603 'basetimestamp' => array( 'Timestamp of the base revision (obtained through prop=revisions&rvprop=timestamp).',
604 'Used to detect edit conflicts; leave unset to ignore conflicts'
605 ),
606 'starttimestamp' => array( 'Timestamp when you obtained the edit token.',
607 'Used to detect edit conflicts; leave unset to ignore conflicts'
608 ),
609 'recreate' => 'Override any errors about the article having been deleted in the meantime',
610 'createonly' => 'Don\'t edit the page if it exists already',
611 'nocreate' => 'Throw an error if the page doesn\'t exist',
612 'watch' => 'Add the page to your watchlist',
613 'unwatch' => 'Remove the page from your watchlist',
614 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
615 'md5' => array( "The MD5 hash of the {$p}text parameter, or the {$p}prependtext and {$p}appendtext parameters concatenated.",
616 'If set, the edit won\'t be done unless the hash is correct' ),
617 'prependtext' => "Add this text to the beginning of the page. Overrides {$p}text",
618 'appendtext' => array( "Add this text to the end of the page. Overrides {$p}text.",
619 "Use {$p}section=new to append a new section" ),
620 'undo' => "Undo this revision. Overrides {$p}text, {$p}prependtext and {$p}appendtext",
621 'undoafter' => 'Undo all revisions from undo to this one. If not set, just undo one revision',
622 'redirect' => 'Automatically resolve redirects',
623 'contentformat' => 'Content serialization format used for the input text',
624 'contentmodel' => 'Content model of the new content',
625 );
626 }
627
628 public function getResultProperties() {
629 return array(
630 '' => array(
631 'new' => 'boolean',
632 'result' => array(
633 ApiBase::PROP_TYPE => array(
634 'Success',
635 'Failure'
636 ),
637 ),
638 'pageid' => array(
639 ApiBase::PROP_TYPE => 'integer',
640 ApiBase::PROP_NULLABLE => true
641 ),
642 'title' => array(
643 ApiBase::PROP_TYPE => 'string',
644 ApiBase::PROP_NULLABLE => true
645 ),
646 'nochange' => 'boolean',
647 'oldrevid' => array(
648 ApiBase::PROP_TYPE => 'integer',
649 ApiBase::PROP_NULLABLE => true
650 ),
651 'newrevid' => array(
652 ApiBase::PROP_TYPE => 'integer',
653 ApiBase::PROP_NULLABLE => true
654 ),
655 'newtimestamp' => array(
656 ApiBase::PROP_TYPE => 'string',
657 ApiBase::PROP_NULLABLE => true
658 )
659 )
660 );
661 }
662
663 public function needsToken() {
664 return true;
665 }
666
667 public function getTokenSalt() {
668 return '';
669 }
670
671 public function getExamples() {
672 return array(
673 'api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\'
674 => 'Edit a page (anonymous user)',
675 'api.php?action=edit&title=Test&summary=NOTOC&minor=&prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\'
676 => 'Prepend __NOTOC__ to a page (anonymous user)',
677 'api.php?action=edit&title=Test&undo=13585&undoafter=13579&basetimestamp=20070824123454&token=%2B\\'
678 => 'Undo r13579 through r13585 with autosummary (anonymous user)',
679 );
680 }
681
682 public function getHelpUrls() {
683 return 'https://www.mediawiki.org/wiki/API:Edit';
684 }
685 }