Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 365
0.00% covered (danger)
0.00%
0 / 15
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiVisualEditorEdit
0.00% covered (danger)
0.00%
0 / 365
0.00% covered (danger)
0.00%
0 / 15
3080
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 getParsoidClient
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 saveWikitext
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 1
12
 parseWikitext
0.00% covered (danger)
0.00%
0 / 47
0.00% covered (danger)
0.00%
0 / 1
30
 getWikitext
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 getWikitextNoCache
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
12
 storeInSerializationCache
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
30
 pruneExcessStashedEntries
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 trySerializationCache
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 diffWikitext
0.00% covered (danger)
0.00%
0 / 39
0.00% covered (danger)
0.00%
0 / 1
12
 execute
0.00% covered (danger)
0.00%
0 / 105
0.00% covered (danger)
0.00%
0 / 1
506
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 72
0.00% covered (danger)
0.00%
0 / 1
2
 needsToken
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isInternal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isWriteMode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Parsoid/RESTBase+MediaWiki API wrapper.
4 *
5 * @file
6 * @ingroup Extensions
7 * @copyright 2011-2021 VisualEditor Team and others; see AUTHORS.txt
8 * @license MIT
9 */
10
11namespace MediaWiki\Extension\VisualEditor;
12
13use ApiBase;
14use ApiMain;
15use BagOStuff;
16use ContentHandler;
17use Deflate;
18use DerivativeContext;
19use DifferenceEngine;
20use ExtensionRegistry;
21use FlaggablePageView;
22use IBufferingStatsdDataFactory;
23use IDBAccessObject;
24use MediaWiki\HookContainer\HookContainer;
25use MediaWiki\Logger\LoggerFactory;
26use MediaWiki\Page\WikiPageFactory;
27use MediaWiki\Request\DerivativeRequest;
28use MediaWiki\Revision\SlotRecord;
29use MediaWiki\SpecialPage\SpecialPageFactory;
30use MediaWiki\Storage\PageEditStash;
31use MediaWiki\Title\Title;
32use MediaWiki\User\UserIdentity;
33use ObjectCache;
34use RequestContext;
35use Sanitizer;
36use SkinFactory;
37use Wikimedia\ParamValidator\ParamValidator;
38
39class ApiVisualEditorEdit extends ApiBase {
40    use ApiParsoidTrait;
41
42    private const MAX_CACHE_RECENT = 2;
43    private const MAX_CACHE_TTL = 900;
44
45    private VisualEditorHookRunner $hookRunner;
46    private PageEditStash $pageEditStash;
47    private SkinFactory $skinFactory;
48    private WikiPageFactory $wikiPageFactory;
49    private SpecialPageFactory $specialPageFactory;
50    private VisualEditorParsoidClientFactory $parsoidClientFactory;
51
52    public function __construct(
53        ApiMain $main,
54        string $name,
55        HookContainer $hookContainer,
56        IBufferingStatsdDataFactory $statsdDataFactory,
57        PageEditStash $pageEditStash,
58        SkinFactory $skinFactory,
59        WikiPageFactory $wikiPageFactory,
60        SpecialPageFactory $specialPageFactory,
61        VisualEditorParsoidClientFactory $parsoidClientFactory
62    ) {
63        parent::__construct( $main, $name );
64        $this->setLogger( LoggerFactory::getInstance( 'VisualEditor' ) );
65        $this->setStats( $statsdDataFactory );
66        $this->hookRunner = new VisualEditorHookRunner( $hookContainer );
67        $this->pageEditStash = $pageEditStash;
68        $this->skinFactory = $skinFactory;
69        $this->wikiPageFactory = $wikiPageFactory;
70        $this->specialPageFactory = $specialPageFactory;
71        $this->parsoidClientFactory = $parsoidClientFactory;
72    }
73
74    /**
75     * @inheritDoc
76     */
77    protected function getParsoidClient(): ParsoidClient {
78        return $this->parsoidClientFactory->createParsoidClient(
79            $this->getRequest()->getHeader( 'Cookie' )
80        );
81    }
82
83    /**
84     * Attempt to save a given page's wikitext to MediaWiki's storage layer via its API
85     *
86     * @param Title $title The title of the page to write
87     * @param string $wikitext The wikitext to write
88     * @param array $params The edit parameters
89     * @return mixed The result of the save attempt
90     */
91    protected function saveWikitext( Title $title, $wikitext, $params ) {
92        $apiParams = [
93            'action' => 'edit',
94            'title' => $title->getPrefixedDBkey(),
95            'text' => $wikitext,
96            'summary' => $params['summary'],
97            'basetimestamp' => $params['basetimestamp'],
98            'starttimestamp' => $params['starttimestamp'],
99            'token' => $params['token'],
100            'watchlist' => $params['watchlist'],
101            // NOTE: Must use getText() to work; PHP array from $params['tags'] is not understood
102            // by the edit API.
103            'tags' => $this->getRequest()->getText( 'tags' ),
104            'section' => $params['section'],
105            'sectiontitle' => $params['sectiontitle'],
106            'captchaid' => $params['captchaid'],
107            'captchaword' => $params['captchaword'],
108            'returnto' => $params['returnto'],
109            'returntoquery' => $params['returntoquery'],
110            'returntoanchor' => $params['returntoanchor'],
111            'errorformat' => 'html',
112            ( $params['minor'] !== null ? 'minor' : 'notminor' ) => true,
113        ];
114
115        // Pass any unrecognized query parameters to the internal action=edit API request. This is
116        // necessary to support extensions that add extra stuff to the edit form (e.g. FlaggedRevs)
117        // and allows passing any other query parameters to be used for edit tagging (e.g. T209132).
118        // Exclude other known params from here and ApiMain.
119        // TODO: This doesn't exclude params from the formatter
120        $allParams = $this->getRequest()->getValues();
121        $knownParams = array_keys( $this->getAllowedParams() + $this->getMain()->getAllowedParams() );
122        foreach ( $knownParams as $knownParam ) {
123            unset( $allParams[ $knownParam ] );
124        }
125
126        $context = new DerivativeContext( $this->getContext() );
127        $context->setRequest(
128            new DerivativeRequest(
129                $context->getRequest(),
130                $apiParams + $allParams,
131                /* was posted? */ true
132            )
133        );
134        $api = new ApiMain(
135            $context,
136            /* enable write? */ true
137        );
138
139        $api->execute();
140
141        return $api->getResult()->getResultData();
142    }
143
144    /**
145     * Load into an array the output of MediaWiki's parser for a given revision
146     *
147     * @param int $newRevId The revision to load
148     * @param array $params Original request params
149     * @return array Some properties haphazardly extracted from an action=parse API response
150     */
151    protected function parseWikitext( $newRevId, array $params ) {
152        $apiParams = [
153            'action' => 'parse',
154            'oldid' => $newRevId,
155            'prop' => 'text|revid|categorieshtml|sections|displaytitle|subtitle|modules|jsconfigvars',
156            'useskin' => $params['useskin'],
157        ];
158        // Boolean parameters must be omitted completely to be treated as false.
159        // Param is added by hook in MobileFrontend, so it may be unset.
160        if ( isset( $params['mobileformat'] ) && $params['mobileformat'] ) {
161            $apiParams['mobileformat'] = '1';
162        }
163
164        $context = new DerivativeContext( $this->getContext() );
165        $context->setRequest(
166            new DerivativeRequest(
167                $context->getRequest(),
168                $apiParams,
169                /* was posted? */ true
170            )
171        );
172        $api = new ApiMain(
173            $context,
174            /* enable write? */ true
175        );
176
177        $api->execute();
178        $result = $api->getResult()->getResultData( null, [
179            /* Transform content nodes to '*' */ 'BC' => [],
180            /* Add back-compat subelements */ 'Types' => [],
181            /* Remove any metadata keys from the links array */ 'Strip' => 'all',
182        ] );
183        $content = $result['parse']['text']['*'] ?? false;
184        $categorieshtml = $result['parse']['categorieshtml']['*'] ?? false;
185        $sections = isset( $result['parse']['showtoc'] ) ? $result['parse']['sections'] : [];
186        $displaytitle = $result['parse']['displaytitle'] ?? false;
187        $subtitle = $result['parse']['subtitle'] ?? false;
188        $modules = array_merge(
189            $result['parse']['modules'] ?? [],
190            $result['parse']['modulestyles'] ?? []
191        );
192        $jsconfigvars = $result['parse']['jsconfigvars'] ?? [];
193
194        if ( $displaytitle !== false ) {
195            // Escape entities as in OutputPage::setPageTitle()
196            $displaytitle = Sanitizer::removeSomeTags( $displaytitle );
197        }
198
199        return [
200            'content' => $content,
201            'categorieshtml' => $categorieshtml,
202            'sections' => $sections,
203            'displayTitleHtml' => $displaytitle,
204            'contentSub' => $subtitle,
205            'modules' => $modules,
206            'jsconfigvars' => $jsconfigvars
207        ];
208    }
209
210    /**
211     * Create and load the parsed wikitext of an edit, or from the serialisation cache if available.
212     *
213     * @param Title $title The title of the page
214     * @param array $params The edit parameters
215     * @param array $parserParams The parser parameters
216     * @return string The wikitext of the edit
217     */
218    protected function getWikitext( Title $title, $params, $parserParams ) {
219        if ( $params['cachekey'] !== null ) {
220            $wikitext = $this->trySerializationCache( $params['cachekey'] );
221            if ( !is_string( $wikitext ) ) {
222                $this->dieWithError( 'apierror-visualeditor-badcachekey', 'badcachekey' );
223            }
224        } else {
225            $wikitext = $this->getWikitextNoCache( $title, $params, $parserParams );
226        }
227        '@phan-var string $wikitext';
228        return $wikitext;
229    }
230
231    /**
232     * Create and load the parsed wikitext of an edit, ignoring the serialisation cache.
233     *
234     * @param Title $title The title of the page
235     * @param array $params The edit parameters
236     * @param array $parserParams The parser parameters
237     * @return string The wikitext of the edit
238     */
239    protected function getWikitextNoCache( Title $title, $params, $parserParams ) {
240        $this->requireOnlyOneParameter( $params, 'html' );
241        if ( Deflate::isDeflated( $params['html'] ) ) {
242            $status = Deflate::inflate( $params['html'] );
243            if ( !$status->isGood() ) {
244                $this->dieWithError( 'deflate-invaliddeflate', 'invaliddeflate' );
245            }
246            $html = $status->getValue();
247        } else {
248            $html = $params['html'];
249        }
250        $wikitext = $this->transformHTML(
251            $title, $html, $parserParams['oldid'] ?? null, $params['etag'] ?? null
252        )['body'];
253        return $wikitext;
254    }
255
256    /**
257     * Load the parsed wikitext of an edit into the serialisation cache.
258     *
259     * @param Title $title The title of the page
260     * @param string $wikitext The wikitext of the edit
261     * @return string|false The key of the wikitext in the serialisation cache
262     */
263    protected function storeInSerializationCache( Title $title, $wikitext ) {
264        if ( $wikitext === false ) {
265            return false;
266        }
267
268        $cache = ObjectCache::getLocalClusterInstance();
269
270        // Store the corresponding wikitext, referenceable by a new key
271        $hash = md5( $wikitext );
272        $key = $cache->makeKey( 'visualeditor', 'serialization', $hash );
273        $ok = $cache->set( $key, $wikitext, self::MAX_CACHE_TTL );
274        if ( $ok ) {
275            $this->pruneExcessStashedEntries( $cache, $this->getUser(), $key );
276        }
277
278        $status = $ok ? 'ok' : 'failed';
279        $this->getStats()->increment( "editstash.ve_serialization_cache.set_" . $status );
280
281        // Also parse and prepare the edit in case it might be saved later
282        $pageUpdater = $this->wikiPageFactory->newFromTitle( $title )->newPageUpdater( $this->getUser() );
283        $content = ContentHandler::makeContent( $wikitext, $title, CONTENT_MODEL_WIKITEXT );
284
285        $status = $this->pageEditStash->parseAndCache( $pageUpdater, $content, $this->getUser(), '' );
286        if ( $status === $this->pageEditStash::ERROR_NONE ) {
287            $logger = LoggerFactory::getInstance( 'StashEdit' );
288            $logger->debug( "Cached parser output for VE content key '$key'." );
289        }
290        $this->getStats()->increment( "editstash.ve_cache_stores.$status" );
291
292        return $hash;
293    }
294
295    /**
296     * @param BagOStuff $cache
297     * @param UserIdentity $user
298     * @param string $newKey
299     */
300    private function pruneExcessStashedEntries( BagOStuff $cache, UserIdentity $user, $newKey ) {
301        $key = $cache->makeKey( 'visualeditor-serialization-recent', $user->getName() );
302
303        $keyList = $cache->get( $key ) ?: [];
304        if ( count( $keyList ) >= self::MAX_CACHE_RECENT ) {
305            $oldestKey = array_shift( $keyList );
306            $cache->delete( $oldestKey );
307        }
308
309        $keyList[] = $newKey;
310        $cache->set( $key, $keyList, 2 * self::MAX_CACHE_TTL );
311    }
312
313    /**
314     * Load some parsed wikitext of an edit from the serialisation cache.
315     *
316     * @param string $hash The key of the wikitext in the serialisation cache
317     * @return string|null The wikitext
318     */
319    protected function trySerializationCache( $hash ) {
320        $cache = ObjectCache::getLocalClusterInstance();
321        $key = $cache->makeKey( 'visualeditor', 'serialization', $hash );
322        $value = $cache->get( $key );
323
324        $status = ( $value !== false ) ? 'hit' : 'miss';
325        $this->getStats()->increment( "editstash.ve_serialization_cache.get_$status" );
326
327        return $value;
328    }
329
330    /**
331     * Calculate the different between the wikitext of an edit and an existing revision.
332     *
333     * @param Title $title The title of the page
334     * @param int|null $fromId The existing revision of the page to compare with
335     * @param string $wikitext The wikitext to compare against
336     * @param int|null $section Whether the wikitext refers to a given section or the whole page
337     * @return array The comparison, or `[ 'result' => 'nochanges' ]` if there are none
338     */
339    protected function diffWikitext( Title $title, ?int $fromId, $wikitext, $section = null ) {
340        $apiParams = [
341            'action' => 'compare',
342            'prop' => 'diff',
343            // Because we're just providing wikitext, we only care about the main slot
344            'slots' => SlotRecord::MAIN,
345            'fromtitle' => $title->getPrefixedDBkey(),
346            'fromrev' => $fromId,
347            'fromsection' => $section,
348            'toslots' => SlotRecord::MAIN,
349            'totext-main' => $wikitext,
350            'topst' => true,
351        ];
352
353        $context = new DerivativeContext( $this->getContext() );
354        $context->setRequest(
355            new DerivativeRequest(
356                $context->getRequest(),
357                $apiParams,
358                /* was posted? */ true
359            )
360        );
361        $api = new ApiMain(
362            $context,
363            /* enable write? */ false
364        );
365        $api->execute();
366        $result = $api->getResult()->getResultData();
367
368        if ( !isset( $result['compare']['bodies'][SlotRecord::MAIN] ) ) {
369            $this->dieWithError( 'apierror-visualeditor-difffailed', 'difffailed' );
370        }
371        $diffRows = $result['compare']['bodies'][SlotRecord::MAIN];
372
373        $context = new DerivativeContext( $this->getContext() );
374        $context->setTitle( $title );
375        $engine = new DifferenceEngine( $context );
376        return [
377            'result' => 'success',
378            'diff' => $diffRows ? $engine->addHeader(
379                $diffRows,
380                $context->msg( 'currentrev' )->parse(),
381                $context->msg( 'yourtext' )->parse()
382            ) : ''
383        ];
384    }
385
386    /**
387     * @inheritDoc
388     */
389    public function execute() {
390        $user = $this->getUser();
391        $params = $this->extractRequestParams();
392
393        $result = [];
394        $title = Title::newFromText( $params['page'] );
395        if ( $title && $title->isSpecialPage() ) {
396            // Convert Special:CollabPad/MyPage to MyPage so we can serialize properly
397            [ $special, $subPage ] = $this->specialPageFactory->resolveAlias( $title->getDBkey() );
398            if ( $special === 'CollabPad' ) {
399                $title = Title::newFromText( $subPage );
400            }
401        }
402        if ( !$title ) {
403            $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] );
404        }
405        if ( !$title->canExist() ) {
406            $this->dieWithError( 'apierror-pagecannotexist' );
407        }
408        $this->getErrorFormatter()->setContextTitle( $title );
409
410        $parserParams = [];
411        if ( isset( $params['oldid'] ) ) {
412            $parserParams['oldid'] = $params['oldid'];
413        }
414
415        if ( isset( $params['wikitext'] ) ) {
416            $wikitext = str_replace( "\r\n", "\n", $params['wikitext'] );
417        } else {
418            $wikitext = $this->getWikitext( $title, $params, $parserParams );
419        }
420
421        if ( $params['paction'] === 'serialize' ) {
422            $result = [ 'result' => 'success', 'content' => $wikitext ];
423        } elseif ( $params['paction'] === 'serializeforcache' ) {
424            $key = $this->storeInSerializationCache(
425                $title,
426                $wikitext
427            );
428            $result = [ 'result' => 'success', 'cachekey' => $key ];
429        } elseif ( $params['paction'] === 'diff' ) {
430            $section = $params['section'] ?? null;
431            $result = $this->diffWikitext( $title, $params['oldid'], $wikitext, $section );
432        } elseif ( $params['paction'] === 'save' ) {
433            $pluginData = [];
434            foreach ( $params['plugins'] ?? [] as $plugin ) {
435                $pluginData[$plugin] = $params['data-' . $plugin];
436            }
437            $presaveHook = $this->hookRunner->onVisualEditorApiVisualEditorEditPreSave(
438                $title->toPageIdentity(),
439                $user,
440                $wikitext,
441                $params,
442                $pluginData,
443                $result
444            );
445
446            if ( $presaveHook === false ) {
447                $this->dieWithError( $result['message'], 'hookaborted', $result );
448            }
449
450            $saveresult = $this->saveWikitext( $title, $wikitext, $params );
451            $editStatus = $saveresult['edit']['result'];
452
453            // Error
454            if ( $editStatus !== 'Success' ) {
455                $result['result'] = 'error';
456                $result['edit'] = $saveresult['edit'];
457            } else {
458                // Success
459                $result['result'] = 'success';
460
461                if ( $params['nocontent'] ) {
462                    $result['nocontent'] = true;
463                } else {
464                    if ( isset( $saveresult['edit']['newrevid'] ) ) {
465                        $newRevId = intval( $saveresult['edit']['newrevid'] );
466                    } else {
467                        $newRevId = $title->getLatestRevID();
468                    }
469
470                    // Return result of parseWikitext instead of saveWikitext so that the
471                    // frontend can update the page rendering without a refresh.
472                    $parseWikitextResult = $this->parseWikitext( $newRevId, $params );
473
474                    $result = array_merge( $result, $parseWikitextResult );
475                }
476
477                $result['isRedirect'] = (string)$title->isRedirect();
478
479                if ( ExtensionRegistry::getInstance()->isLoaded( 'FlaggedRevs' ) ) {
480                    $newContext = new DerivativeContext( RequestContext::getMain() );
481                    // Defeat !$this->isPageView( $request ) || $request->getVal( 'oldid' ) check in setPageContent
482                    $newRequest = new DerivativeRequest(
483                        $this->getRequest(),
484                        [
485                            'diff' => null,
486                            'oldid' => '',
487                            'title' => $title->getPrefixedText(),
488                            'action' => 'view'
489                        ] + $this->getRequest()->getValues()
490                    );
491                    $newContext->setRequest( $newRequest );
492                    $newContext->setTitle( $title );
493
494                    // Must be after $globalContext->setTitle since FlaggedRevs constructor
495                    // inspects global Title
496                    $view = FlaggablePageView::newFromTitle( $title );
497                    // Most likely identical to $globalState, but not our concern
498                    $originalContext = $view->getContext();
499                    $view->setContext( $newContext );
500
501                    // The two parameters here are references but we don't care
502                    // about what FlaggedRevs does with them.
503                    $outputDone = null;
504                    $useParserCache = null;
505                    // @phan-suppress-next-line PhanTypeMismatchArgument
506                    $view->setPageContent( $outputDone, $useParserCache );
507                    $view->displayTag();
508                    $view->setContext( $originalContext );
509                }
510
511                $lang = $this->getLanguage();
512
513                if ( isset( $saveresult['edit']['newtimestamp'] ) ) {
514                    $ts = $saveresult['edit']['newtimestamp'];
515
516                    $result['lastModified'] = [
517                        'date' => $lang->userDate( $ts, $user ),
518                        'time' => $lang->userTime( $ts, $user )
519                    ];
520                }
521
522                if ( isset( $saveresult['edit']['newrevid'] ) ) {
523                    $result['newrevid'] = intval( $saveresult['edit']['newrevid'] );
524                }
525
526                if ( isset( $saveresult['edit']['tempusercreated'] ) ) {
527                    $result['tempusercreated'] = $saveresult['edit']['tempusercreated'];
528                }
529                if ( isset( $saveresult['edit']['tempusercreatedredirect'] ) ) {
530                    $result['tempusercreatedredirect'] = $saveresult['edit']['tempusercreatedredirect'];
531                }
532
533                $result['watched'] = $saveresult['edit']['watched'] ?? false;
534                $result['watchlistexpiry'] = $saveresult['edit']['watchlistexpiry'] ?? null;
535            }
536
537            // Refresh article ID (which is used by toPageIdentity()) in case we just created the page.
538            // Maybe it's not great to rely on this side-effect…
539            $title->getArticleID( IDBAccessObject::READ_LATEST );
540
541            $this->hookRunner->onVisualEditorApiVisualEditorEditPostSave(
542                $title->toPageIdentity(),
543                $user,
544                $wikitext,
545                $params,
546                $pluginData,
547                $saveresult,
548                $result
549            );
550        }
551        $this->getResult()->addValue( null, $this->getModuleName(), $result );
552    }
553
554    /**
555     * @inheritDoc
556     */
557    public function getAllowedParams() {
558        return [
559            'paction' => [
560                ParamValidator::PARAM_REQUIRED => true,
561                ParamValidator::PARAM_TYPE => [
562                    'serialize',
563                    'serializeforcache',
564                    'diff',
565                    'save',
566                ],
567            ],
568            'page' => [
569                ParamValidator::PARAM_REQUIRED => true,
570            ],
571            'token' => [
572                ParamValidator::PARAM_REQUIRED => true,
573            ],
574            'wikitext' => [
575                ParamValidator::PARAM_TYPE => 'text',
576                ParamValidator::PARAM_DEFAULT => null,
577            ],
578            'section' => null,
579            'sectiontitle' => null,
580            'basetimestamp' => [
581                ParamValidator::PARAM_TYPE => 'timestamp',
582            ],
583            'starttimestamp' => [
584                ParamValidator::PARAM_TYPE => 'timestamp',
585            ],
586            'oldid' => [
587                ParamValidator::PARAM_TYPE => 'integer',
588            ],
589            'minor' => null,
590            'watchlist' => null,
591            'html' => [
592                // Use the 'raw' type to avoid Unicode NFC normalization.
593                // This makes the parameter binary safe, so that (a) if
594                // we use client-side compression it is not mangled, and/or
595                // (b) deprecated Unicode sequences explicitly encoded in
596                // wikitext (ie, &#x2001;) are not mangled.  Wikitext is
597                // in Unicode Normal Form C, but because of explicit entities
598                // the output HTML is not guaranteed to be.
599                ParamValidator::PARAM_TYPE => 'raw',
600                ParamValidator::PARAM_DEFAULT => null,
601            ],
602            'etag' => null,
603            'summary' => null,
604            'captchaid' => null,
605            'captchaword' => null,
606            'cachekey' => null,
607            'nocontent' => false,
608            'returnto' => [
609                ParamValidator::PARAM_TYPE => 'title',
610                ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-returnto',
611            ],
612            'returntoquery' => [
613                ParamValidator::PARAM_TYPE => 'string',
614                ParamValidator::PARAM_DEFAULT => '',
615                ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-returntoquery',
616            ],
617            'returntoanchor' => [
618                ParamValidator::PARAM_TYPE => 'string',
619                ParamValidator::PARAM_DEFAULT => '',
620                ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-returntoanchor',
621            ],
622            'useskin' => [
623                ParamValidator::PARAM_TYPE => array_keys( $this->skinFactory->getInstalledSkins() ),
624                ApiBase::PARAM_HELP_MSG => 'apihelp-parse-param-useskin',
625            ],
626            'tags' => [
627                ParamValidator::PARAM_ISMULTI => true,
628            ],
629            'plugins' => [
630                ParamValidator::PARAM_ISMULTI => true,
631                ParamValidator::PARAM_TYPE => 'string',
632            ],
633            // Additional data sent by the client. Not used directly in the ApiVisualEditorEdit workflows, but
634            // is passed alongside the other parameters to implementations of onApiVisualEditorEditPostSave and
635            // onApiVisualEditorEditPreSave
636            'data-{plugin}' => [
637                ApiBase::PARAM_TEMPLATE_VARS => [ 'plugin' => 'plugins' ]
638            ]
639        ];
640    }
641
642    /**
643     * @inheritDoc
644     */
645    public function needsToken() {
646        return 'csrf';
647    }
648
649    /**
650     * @inheritDoc
651     */
652    public function isInternal() {
653        return true;
654    }
655
656    /**
657     * @inheritDoc
658     */
659    public function isWriteMode() {
660        return true;
661    }
662
663}