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