Merge "Replace Pakaran with Punjabi"
[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 $content = $pageObj->getContent();
284 if ( $section !== 0 && ( !$content || !$content->getSection( $section ) ) ) {
285 $this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
286 }
287 $requestArray['wpSection'] = $params['section'];
288 } else {
289 $requestArray['wpSection'] = '';
290 }
291
292 $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
293
294 // Deprecated parameters
295 if ( $params['watch'] ) {
296 $watch = true;
297 } elseif ( $params['unwatch'] ) {
298 $watch = false;
299 }
300
301 if ( $watch ) {
302 $requestArray['wpWatchthis'] = '';
303 }
304
305 // Pass through anything else we might have been given, to support extensions
306 // This is kind of a hack but it's the best we can do to make extensions work
307 $requestArray += $this->getRequest()->getValues();
308
309 global $wgTitle, $wgRequest;
310
311 $req = new DerivativeRequest( $this->getRequest(), $requestArray, true );
312
313 // Some functions depend on $wgTitle == $ep->mTitle
314 // TODO: Make them not or check if they still do
315 $wgTitle = $titleObj;
316
317 $articleContext = new RequestContext;
318 $articleContext->setRequest( $req );
319 $articleContext->setWikiPage( $pageObj );
320 $articleContext->setUser( $this->getUser() );
321
322 /** @var $articleObject Article */
323 $articleObject = Article::newFromWikiPage( $pageObj, $articleContext );
324
325 $ep = new EditPage( $articleObject );
326
327 // allow editing of non-textual content.
328 $ep->allowNonTextContent = true;
329
330 $ep->setContextTitle( $titleObj );
331 $ep->importFormData( $req );
332 $content = $ep->textbox1;
333
334 // The following is needed to give the hook the full content of the
335 // new revision rather than just the current section. (Bug 52077)
336 if ( !is_null( $params['section'] ) && $contentHandler->supportsSections() && $titleObj->exists() ) {
337
338 $sectionTitle = '';
339 // If sectiontitle is set, use it, otherwise use the summary as the section title (for
340 // backwards compatibility with old forms/bots).
341 if ( $ep->sectiontitle !== '' ) {
342 $sectionTitle = $ep->sectiontitle;
343 } else {
344 $sectionTitle = $ep->summary;
345 }
346
347 $contentObj = $contentHandler->unserializeContent( $content, $contentFormat );
348
349 $fullContentObj = $articleObject->replaceSectionContent( $params['section'], $contentObj, $sectionTitle );
350 if ( $fullContentObj ) {
351 $content = $fullContentObj->serialize( $contentFormat );
352 } else {
353 // This most likely means we have an edit conflict which means that the edit
354 // wont succeed anyway.
355 $this->dieUsageMsg( 'editconflict' );
356 }
357 }
358
359 // Run hooks
360 // Handle APIEditBeforeSave parameters
361 $r = array();
362 if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $content, &$r ) ) ) {
363 if ( count( $r ) ) {
364 $r['result'] = 'Failure';
365 $apiResult->addValue( null, $this->getModuleName(), $r );
366 return;
367 } else {
368 $this->dieUsageMsg( 'hookaborted' );
369 }
370 }
371
372 // Do the actual save
373 $oldRevId = $articleObject->getRevIdFetched();
374 $result = null;
375 // Fake $wgRequest for some hooks inside EditPage
376 // @todo FIXME: This interface SUCKS
377 $oldRequest = $wgRequest;
378 $wgRequest = $req;
379
380 $status = $ep->internalAttemptSave( $result, $user->isAllowed( 'bot' ) && $params['bot'] );
381 $wgRequest = $oldRequest;
382 global $wgMaxArticleSize;
383
384 switch ( $status->value ) {
385 case EditPage::AS_HOOK_ERROR:
386 case EditPage::AS_HOOK_ERROR_EXPECTED:
387 $this->dieUsageMsg( 'hookaborted' );
388
389 case EditPage::AS_PARSE_ERROR:
390 $this->dieUsage( $status->getMessage(), 'parseerror' );
391
392 case EditPage::AS_IMAGE_REDIRECT_ANON:
393 $this->dieUsageMsg( 'noimageredirect-anon' );
394
395 case EditPage::AS_IMAGE_REDIRECT_LOGGED:
396 $this->dieUsageMsg( 'noimageredirect-logged' );
397
398 case EditPage::AS_SPAM_ERROR:
399 $this->dieUsageMsg( array( 'spamdetected', $result['spam'] ) );
400
401 case EditPage::AS_BLOCKED_PAGE_FOR_USER:
402 $this->dieUsageMsg( 'blockedtext' );
403
404 case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
405 case EditPage::AS_CONTENT_TOO_BIG:
406 $this->dieUsageMsg( array( 'contenttoobig', $wgMaxArticleSize ) );
407
408 case EditPage::AS_READ_ONLY_PAGE_ANON:
409 $this->dieUsageMsg( 'noedit-anon' );
410
411 case EditPage::AS_READ_ONLY_PAGE_LOGGED:
412 $this->dieUsageMsg( 'noedit' );
413
414 case EditPage::AS_READ_ONLY_PAGE:
415 $this->dieReadOnly();
416
417 case EditPage::AS_RATE_LIMITED:
418 $this->dieUsageMsg( 'actionthrottledtext' );
419
420 case EditPage::AS_ARTICLE_WAS_DELETED:
421 $this->dieUsageMsg( 'wasdeleted' );
422
423 case EditPage::AS_NO_CREATE_PERMISSION:
424 $this->dieUsageMsg( 'nocreate-loggedin' );
425
426 case EditPage::AS_BLANK_ARTICLE:
427 $this->dieUsageMsg( 'blankpage' );
428
429 case EditPage::AS_CONFLICT_DETECTED:
430 $this->dieUsageMsg( 'editconflict' );
431
432 // case EditPage::AS_SUMMARY_NEEDED: Can't happen since we set wpIgnoreBlankSummary
433 case EditPage::AS_TEXTBOX_EMPTY:
434 $this->dieUsageMsg( 'emptynewsection' );
435
436 case EditPage::AS_SUCCESS_NEW_ARTICLE:
437 $r['new'] = '';
438 // fall-through
439
440 case EditPage::AS_SUCCESS_UPDATE:
441 $r['result'] = 'Success';
442 $r['pageid'] = intval( $titleObj->getArticleID() );
443 $r['title'] = $titleObj->getPrefixedText();
444 $r['contentmodel'] = $titleObj->getContentModel();
445 $newRevId = $articleObject->getLatest();
446 if ( $newRevId == $oldRevId ) {
447 $r['nochange'] = '';
448 } else {
449 $r['oldrevid'] = intval( $oldRevId );
450 $r['newrevid'] = intval( $newRevId );
451 $r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
452 $pageObj->getTimestamp() );
453 }
454 break;
455
456 case EditPage::AS_SUMMARY_NEEDED:
457 $this->dieUsageMsg( 'summaryrequired' );
458
459 case EditPage::AS_END:
460 default:
461 // $status came from WikiPage::doEdit()
462 $errors = $status->getErrorsArray();
463 $this->dieUsageMsg( $errors[0] ); // TODO: Add new errors to message map
464 break;
465 }
466 $apiResult->addValue( null, $this->getModuleName(), $r );
467 }
468
469 public function mustBePosted() {
470 return true;
471 }
472
473 public function isWriteMode() {
474 return true;
475 }
476
477 public function getDescription() {
478 return 'Create and edit pages.';
479 }
480
481 public function getPossibleErrors() {
482 global $wgMaxArticleSize;
483
484 return array_merge( parent::getPossibleErrors(),
485 $this->getTitleOrPageIdErrorMessage(),
486 array(
487 array( 'missingtext' ),
488 array( 'createonly-exists' ),
489 array( 'nocreate-missing' ),
490 array( 'nosuchrevid', 'undo' ),
491 array( 'nosuchrevid', 'undoafter' ),
492 array( 'revwrongpage', 'id', 'text' ),
493 array( 'undo-failure' ),
494 array( 'hashcheckfailed' ),
495 array( 'hookaborted' ),
496 array( 'code' => 'parseerror', 'info' => 'Failed to parse the given text.' ),
497 array( 'noimageredirect-anon' ),
498 array( 'noimageredirect-logged' ),
499 array( 'spamdetected', 'spam' ),
500 array( 'summaryrequired' ),
501 array( 'blockedtext' ),
502 array( 'contenttoobig', $wgMaxArticleSize ),
503 array( 'noedit-anon' ),
504 array( 'noedit' ),
505 array( 'actionthrottledtext' ),
506 array( 'wasdeleted' ),
507 array( 'nocreate-loggedin' ),
508 array( 'blankpage' ),
509 array( 'editconflict' ),
510 array( 'emptynewsection' ),
511 array( 'unknownerror', 'retval' ),
512 array( 'code' => 'nosuchsection', 'info' => 'There is no section section.' ),
513 array( 'code' => 'invalidsection', 'info' => 'The section parameter must be set to an integer or \'new\'' ),
514 array( 'code' => 'sectionsnotsupported', 'info' => 'Sections are not supported for this type of page.' ),
515 array( 'code' => 'editnotsupported', 'info' => 'Editing of this type of page is not supported using '
516 . 'the text based edit API.' ),
517 array( 'code' => 'appendnotsupported', 'info' => 'This type of page can not be edited by appending '
518 . 'or prepending text.' ),
519 array( 'code' => 'badformat', 'info' => 'The requested serialization format can not be applied to '
520 . 'the page\'s content model' ),
521 array( 'customcssprotected' ),
522 array( 'customjsprotected' ),
523 )
524 );
525 }
526
527 public function getAllowedParams() {
528 return array(
529 'title' => array(
530 ApiBase::PARAM_TYPE => 'string',
531 ),
532 'pageid' => array(
533 ApiBase::PARAM_TYPE => 'integer',
534 ),
535 'section' => null,
536 'sectiontitle' => array(
537 ApiBase::PARAM_TYPE => 'string',
538 ),
539 'text' => null,
540 'token' => array(
541 ApiBase::PARAM_TYPE => 'string',
542 ApiBase::PARAM_REQUIRED => true
543 ),
544 'summary' => null,
545 'minor' => false,
546 'notminor' => false,
547 'bot' => false,
548 'basetimestamp' => null,
549 'starttimestamp' => null,
550 'recreate' => false,
551 'createonly' => false,
552 'nocreate' => false,
553 'watch' => array(
554 ApiBase::PARAM_DFLT => false,
555 ApiBase::PARAM_DEPRECATED => true,
556 ),
557 'unwatch' => array(
558 ApiBase::PARAM_DFLT => false,
559 ApiBase::PARAM_DEPRECATED => true,
560 ),
561 'watchlist' => array(
562 ApiBase::PARAM_DFLT => 'preferences',
563 ApiBase::PARAM_TYPE => array(
564 'watch',
565 'unwatch',
566 'preferences',
567 'nochange'
568 ),
569 ),
570 'md5' => null,
571 'prependtext' => null,
572 'appendtext' => null,
573 'undo' => array(
574 ApiBase::PARAM_TYPE => 'integer'
575 ),
576 'undoafter' => array(
577 ApiBase::PARAM_TYPE => 'integer'
578 ),
579 'redirect' => array(
580 ApiBase::PARAM_TYPE => 'boolean',
581 ApiBase::PARAM_DFLT => false,
582 ),
583 'contentformat' => array(
584 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
585 ),
586 'contentmodel' => array(
587 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
588 )
589 );
590 }
591
592 public function getParamDescription() {
593 $p = $this->getModulePrefix();
594 return array(
595 'title' => "Title of the page you want to edit. Cannot be used together with {$p}pageid",
596 'pageid' => "Page ID of the page you want to edit. Cannot be used together with {$p}title",
597 'section' => 'Section number. 0 for the top section, \'new\' for a new section',
598 'sectiontitle' => 'The title for a new section',
599 'text' => 'Page content',
600 'token' => array( 'Edit token. You can get one of these through prop=info.',
601 "The token should always be sent as the last parameter, or at least, after the {$p}text parameter"
602 ),
603 'summary' => "Edit summary. Also section title when {$p}section=new and {$p}sectiontitle is not set",
604 'minor' => 'Minor edit',
605 'notminor' => 'Non-minor edit',
606 'bot' => 'Mark this edit as bot',
607 'basetimestamp' => array( 'Timestamp of the base revision (obtained through prop=revisions&rvprop=timestamp).',
608 'Used to detect edit conflicts; leave unset to ignore conflicts'
609 ),
610 'starttimestamp' => array( 'Timestamp when you obtained the edit token.',
611 'Used to detect edit conflicts; leave unset to ignore conflicts'
612 ),
613 'recreate' => 'Override any errors about the article having been deleted in the meantime',
614 'createonly' => 'Don\'t edit the page if it exists already',
615 'nocreate' => 'Throw an error if the page doesn\'t exist',
616 'watch' => 'Add the page to your watchlist',
617 'unwatch' => 'Remove the page from your watchlist',
618 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
619 'md5' => array( "The MD5 hash of the {$p}text parameter, or the {$p}prependtext and {$p}appendtext parameters concatenated.",
620 'If set, the edit won\'t be done unless the hash is correct' ),
621 'prependtext' => "Add this text to the beginning of the page. Overrides {$p}text",
622 'appendtext' => array( "Add this text to the end of the page. Overrides {$p}text.",
623 "Use {$p}section=new to append a new section" ),
624 'undo' => "Undo this revision. Overrides {$p}text, {$p}prependtext and {$p}appendtext",
625 'undoafter' => 'Undo all revisions from undo to this one. If not set, just undo one revision',
626 'redirect' => 'Automatically resolve redirects',
627 'contentformat' => 'Content serialization format used for the input text',
628 'contentmodel' => 'Content model of the new content',
629 );
630 }
631
632 public function getResultProperties() {
633 return array(
634 '' => array(
635 'new' => 'boolean',
636 'result' => array(
637 ApiBase::PROP_TYPE => array(
638 'Success',
639 'Failure'
640 ),
641 ),
642 'pageid' => array(
643 ApiBase::PROP_TYPE => 'integer',
644 ApiBase::PROP_NULLABLE => true
645 ),
646 'title' => array(
647 ApiBase::PROP_TYPE => 'string',
648 ApiBase::PROP_NULLABLE => true
649 ),
650 'nochange' => 'boolean',
651 'oldrevid' => array(
652 ApiBase::PROP_TYPE => 'integer',
653 ApiBase::PROP_NULLABLE => true
654 ),
655 'newrevid' => array(
656 ApiBase::PROP_TYPE => 'integer',
657 ApiBase::PROP_NULLABLE => true
658 ),
659 'newtimestamp' => array(
660 ApiBase::PROP_TYPE => 'string',
661 ApiBase::PROP_NULLABLE => true
662 )
663 )
664 );
665 }
666
667 public function needsToken() {
668 return true;
669 }
670
671 public function getTokenSalt() {
672 return '';
673 }
674
675 public function getExamples() {
676 return array(
677 'api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\'
678 => 'Edit a page (anonymous user)',
679 'api.php?action=edit&title=Test&summary=NOTOC&minor=&prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\'
680 => 'Prepend __NOTOC__ to a page (anonymous user)',
681 'api.php?action=edit&title=Test&undo=13585&undoafter=13579&basetimestamp=20070824123454&token=%2B\\'
682 => 'Undo r13579 through r13585 with autosummary (anonymous user)',
683 );
684 }
685
686 public function getHelpUrls() {
687 return 'https://www.mediawiki.org/wiki/API:Edit';
688 }
689 }