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