| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
namespace MediaWiki\Extension\VisualEditor; |
| 12 |
|
| 13 |
use Deflate; |
| 14 |
use DifferenceEngine; |
| 15 |
use FlaggablePageView; |
| 16 |
use MediaWiki\Api\ApiBase; |
| 17 |
use MediaWiki\Api\ApiMain; |
| 18 |
use MediaWiki\Content\ContentHandler; |
| 19 |
use MediaWiki\Context\DerivativeContext; |
| 20 |
use MediaWiki\Context\RequestContext; |
| 21 |
use MediaWiki\HookContainer\HookContainer; |
| 22 |
use MediaWiki\Logger\LoggerFactory; |
| 23 |
use MediaWiki\MediaWikiServices; |
| 24 |
use MediaWiki\Page\WikiPageFactory; |
| 25 |
use MediaWiki\Parser\Sanitizer; |
| 26 |
use MediaWiki\Registration\ExtensionRegistry; |
| 27 |
use MediaWiki\Request\DerivativeRequest; |
| 28 |
use MediaWiki\Revision\SlotRecord; |
| 29 |
use MediaWiki\SpecialPage\SpecialPageFactory; |
| 30 |
use MediaWiki\Storage\PageEditStash; |
| 31 |
use MediaWiki\Title\Title; |
| 32 |
use MediaWiki\User\UserIdentity; |
| 33 |
use SkinFactory; |
| 34 |
use Wikimedia\ObjectCache\BagOStuff; |
| 35 |
use Wikimedia\ParamValidator\ParamValidator; |
| 36 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 37 |
use Wikimedia\Stats\IBufferingStatsdDataFactory; |
| 38 |
|
| 39 |
class 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 |
|
| 76 |
|
| 77 |
protected function getParsoidClient(): ParsoidClient { |
| 78 |
return $this->parsoidClientFactory->createParsoidClient( |
| 79 |
$this->getRequest()->getHeader( 'Cookie' ) |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 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 |
|
| 102 |
|
| 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 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 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 |
true |
| 132 |
) |
| 133 |
); |
| 134 |
$api = new ApiMain( |
| 135 |
$context, |
| 136 |
true |
| 137 |
); |
| 138 |
|
| 139 |
$api->execute(); |
| 140 |
|
| 141 |
return $api->getResult()->getResultData(); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 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 |
'usearticle' => true, |
| 157 |
'useskin' => $params['useskin'], |
| 158 |
]; |
| 159 |
|
| 160 |
|
| 161 |
if ( isset( $params['mobileformat'] ) && $params['mobileformat'] ) { |
| 162 |
$apiParams['mobileformat'] = '1'; |
| 163 |
} |
| 164 |
|
| 165 |
$context = new DerivativeContext( $this->getContext() ); |
| 166 |
$context->setRequest( |
| 167 |
new DerivativeRequest( |
| 168 |
$context->getRequest(), |
| 169 |
$apiParams, |
| 170 |
true |
| 171 |
) |
| 172 |
); |
| 173 |
$api = new ApiMain( |
| 174 |
$context, |
| 175 |
true |
| 176 |
); |
| 177 |
|
| 178 |
$api->execute(); |
| 179 |
$result = $api->getResult()->getResultData( null, [ |
| 180 |
'BC' => [], |
| 181 |
'Types' => [], |
| 182 |
'Strip' => 'all', |
| 183 |
] ); |
| 184 |
$content = $result['parse']['text']['*'] ?? false; |
| 185 |
$categorieshtml = $result['parse']['categorieshtml']['*'] ?? false; |
| 186 |
$sections = isset( $result['parse']['showtoc'] ) ? $result['parse']['sections'] : []; |
| 187 |
$displaytitle = $result['parse']['displaytitle'] ?? false; |
| 188 |
$subtitle = $result['parse']['subtitle'] ?? false; |
| 189 |
$modules = array_merge( |
| 190 |
$result['parse']['modules'] ?? [], |
| 191 |
$result['parse']['modulestyles'] ?? [] |
| 192 |
); |
| 193 |
$jsconfigvars = $result['parse']['jsconfigvars'] ?? []; |
| 194 |
|
| 195 |
if ( $displaytitle !== false ) { |
| 196 |
|
| 197 |
$displaytitle = Sanitizer::removeSomeTags( $displaytitle ); |
| 198 |
} |
| 199 |
|
| 200 |
return [ |
| 201 |
'content' => $content, |
| 202 |
'categorieshtml' => $categorieshtml, |
| 203 |
'sections' => $sections, |
| 204 |
'displayTitleHtml' => $displaytitle, |
| 205 |
'contentSub' => $subtitle, |
| 206 |
'modules' => $modules, |
| 207 |
'jsconfigvars' => $jsconfigvars |
| 208 |
]; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
protected function getWikitext( Title $title, $params, $parserParams ) { |
| 220 |
if ( $params['cachekey'] !== null ) { |
| 221 |
$wikitext = $this->trySerializationCache( $params['cachekey'] ); |
| 222 |
if ( !is_string( $wikitext ) ) { |
| 223 |
$this->dieWithError( 'apierror-visualeditor-badcachekey', 'badcachekey' ); |
| 224 |
} |
| 225 |
} else { |
| 226 |
$wikitext = $this->getWikitextNoCache( $title, $params, $parserParams ); |
| 227 |
} |
| 228 |
'@phan-var string $wikitext'; |
| 229 |
return $wikitext; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
protected function getWikitextNoCache( Title $title, $params, $parserParams ) { |
| 241 |
$this->requireOnlyOneParameter( $params, 'html' ); |
| 242 |
if ( Deflate::isDeflated( $params['html'] ) ) { |
| 243 |
$status = Deflate::inflate( $params['html'] ); |
| 244 |
if ( !$status->isGood() ) { |
| 245 |
$this->dieWithError( 'deflate-invaliddeflate', 'invaliddeflate' ); |
| 246 |
} |
| 247 |
$html = $status->getValue(); |
| 248 |
} else { |
| 249 |
$html = $params['html']; |
| 250 |
} |
| 251 |
$wikitext = $this->transformHTML( |
| 252 |
$title, $html, $parserParams['oldid'] ?? null, $params['etag'] ?? null |
| 253 |
)['body']; |
| 254 |
return $wikitext; |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
protected function storeInSerializationCache( Title $title, $wikitext ) { |
| 265 |
if ( $wikitext === false ) { |
| 266 |
return false; |
| 267 |
} |
| 268 |
|
| 269 |
$cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); |
| 270 |
|
| 271 |
|
| 272 |
$hash = md5( $wikitext ); |
| 273 |
$key = $cache->makeKey( 'visualeditor', 'serialization', $hash ); |
| 274 |
$ok = $cache->set( $key, $wikitext, self::MAX_CACHE_TTL ); |
| 275 |
if ( $ok ) { |
| 276 |
$this->pruneExcessStashedEntries( $cache, $this->getUser(), $key ); |
| 277 |
} |
| 278 |
|
| 279 |
$status = $ok ? 'ok' : 'failed'; |
| 280 |
$this->getStats()->increment( "editstash.ve_serialization_cache.set_" . $status ); |
| 281 |
|
| 282 |
|
| 283 |
$pageUpdater = $this->wikiPageFactory->newFromTitle( $title )->newPageUpdater( $this->getUser() ); |
| 284 |
$content = ContentHandler::makeContent( $wikitext, $title, CONTENT_MODEL_WIKITEXT ); |
| 285 |
|
| 286 |
$status = $this->pageEditStash->parseAndCache( $pageUpdater, $content, $this->getUser(), '' ); |
| 287 |
if ( $status === $this->pageEditStash::ERROR_NONE ) { |
| 288 |
$logger = LoggerFactory::getInstance( 'StashEdit' ); |
| 289 |
$logger->debug( "Cached parser output for VE content key '$key'." ); |
| 290 |
} |
| 291 |
$this->getStats()->increment( "editstash.ve_cache_stores.$status" ); |
| 292 |
|
| 293 |
return $hash; |
| 294 |
} |
| 295 |
|
| 296 |
private function pruneExcessStashedEntries( BagOStuff $cache, UserIdentity $user, string $newKey ): void { |
| 297 |
$key = $cache->makeKey( 'visualeditor-serialization-recent', $user->getName() ); |
| 298 |
|
| 299 |
$keyList = $cache->get( $key ) ?: []; |
| 300 |
if ( count( $keyList ) >= self::MAX_CACHE_RECENT ) { |
| 301 |
$oldestKey = array_shift( $keyList ); |
| 302 |
$cache->delete( $oldestKey ); |
| 303 |
} |
| 304 |
|
| 305 |
$keyList[] = $newKey; |
| 306 |
$cache->set( $key, $keyList, 2 * self::MAX_CACHE_TTL ); |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
protected function trySerializationCache( $hash ) { |
| 316 |
$cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getLocalClusterInstance(); |
| 317 |
$key = $cache->makeKey( 'visualeditor', 'serialization', $hash ); |
| 318 |
$value = $cache->get( $key ); |
| 319 |
|
| 320 |
$status = ( $value !== false ) ? 'hit' : 'miss'; |
| 321 |
$this->getStats()->increment( "editstash.ve_serialization_cache.get_$status" ); |
| 322 |
|
| 323 |
return $value; |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
protected function diffWikitext( Title $title, ?int $fromId, $wikitext, $section = null ) { |
| 336 |
$apiParams = [ |
| 337 |
'action' => 'compare', |
| 338 |
'prop' => 'diff', |
| 339 |
|
| 340 |
'slots' => SlotRecord::MAIN, |
| 341 |
'fromtitle' => $title->getPrefixedDBkey(), |
| 342 |
'fromrev' => $fromId, |
| 343 |
'fromsection' => $section, |
| 344 |
'toslots' => SlotRecord::MAIN, |
| 345 |
'totext-main' => $wikitext, |
| 346 |
'topst' => true, |
| 347 |
]; |
| 348 |
|
| 349 |
$context = new DerivativeContext( $this->getContext() ); |
| 350 |
$context->setRequest( |
| 351 |
new DerivativeRequest( |
| 352 |
$context->getRequest(), |
| 353 |
$apiParams, |
| 354 |
true |
| 355 |
) |
| 356 |
); |
| 357 |
$api = new ApiMain( |
| 358 |
$context, |
| 359 |
false |
| 360 |
); |
| 361 |
$api->execute(); |
| 362 |
$result = $api->getResult()->getResultData(); |
| 363 |
|
| 364 |
if ( !isset( $result['compare']['bodies'][SlotRecord::MAIN] ) ) { |
| 365 |
$this->dieWithError( 'apierror-visualeditor-difffailed', 'difffailed' ); |
| 366 |
} |
| 367 |
$diffRows = $result['compare']['bodies'][SlotRecord::MAIN]; |
| 368 |
|
| 369 |
$context = new DerivativeContext( $this->getContext() ); |
| 370 |
$context->setTitle( $title ); |
| 371 |
$engine = new DifferenceEngine( $context ); |
| 372 |
return [ |
| 373 |
'result' => 'success', |
| 374 |
'diff' => $diffRows ? $engine->addHeader( |
| 375 |
$diffRows, |
| 376 |
$context->msg( 'currentrev' )->parse(), |
| 377 |
$context->msg( 'yourtext' )->parse() |
| 378 |
) : '' |
| 379 |
]; |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
public function execute() { |
| 386 |
$user = $this->getUser(); |
| 387 |
$params = $this->extractRequestParams(); |
| 388 |
|
| 389 |
$result = []; |
| 390 |
$title = Title::newFromText( $params['page'] ); |
| 391 |
if ( $title && $title->isSpecialPage() ) { |
| 392 |
|
| 393 |
[ $special, $subPage ] = $this->specialPageFactory->resolveAlias( $title->getDBkey() ); |
| 394 |
if ( $special === 'CollabPad' ) { |
| 395 |
$title = Title::newFromText( $subPage ); |
| 396 |
} |
| 397 |
} |
| 398 |
if ( !$title ) { |
| 399 |
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] ); |
| 400 |
} |
| 401 |
if ( !$title->canExist() ) { |
| 402 |
$this->dieWithError( 'apierror-pagecannotexist' ); |
| 403 |
} |
| 404 |
$this->getErrorFormatter()->setContextTitle( $title ); |
| 405 |
|
| 406 |
$parserParams = []; |
| 407 |
if ( isset( $params['oldid'] ) ) { |
| 408 |
$parserParams['oldid'] = $params['oldid']; |
| 409 |
} |
| 410 |
|
| 411 |
if ( isset( $params['wikitext'] ) ) { |
| 412 |
$wikitext = str_replace( "\r\n", "\n", $params['wikitext'] ); |
| 413 |
} else { |
| 414 |
$wikitext = $this->getWikitext( $title, $params, $parserParams ); |
| 415 |
} |
| 416 |
|
| 417 |
if ( $params['paction'] === 'serialize' ) { |
| 418 |
$result = [ 'result' => 'success', 'content' => $wikitext ]; |
| 419 |
} elseif ( $params['paction'] === 'serializeforcache' ) { |
| 420 |
$key = $this->storeInSerializationCache( |
| 421 |
$title, |
| 422 |
$wikitext |
| 423 |
); |
| 424 |
$result = [ 'result' => 'success', 'cachekey' => $key ]; |
| 425 |
} elseif ( $params['paction'] === 'diff' ) { |
| 426 |
$section = $params['section'] ?? null; |
| 427 |
$result = $this->diffWikitext( $title, $params['oldid'], $wikitext, $section ); |
| 428 |
} elseif ( $params['paction'] === 'save' ) { |
| 429 |
$pluginData = []; |
| 430 |
foreach ( $params['plugins'] ?? [] as $plugin ) { |
| 431 |
$pluginData[$plugin] = $params['data-' . $plugin]; |
| 432 |
} |
| 433 |
$presaveHook = $this->hookRunner->onVisualEditorApiVisualEditorEditPreSave( |
| 434 |
$title->toPageIdentity(), |
| 435 |
$user, |
| 436 |
$wikitext, |
| 437 |
$params, |
| 438 |
$pluginData, |
| 439 |
$result |
| 440 |
); |
| 441 |
|
| 442 |
if ( $presaveHook === false ) { |
| 443 |
$this->dieWithError( $result['message'], 'hookaborted', $result ); |
| 444 |
} |
| 445 |
|
| 446 |
$saveresult = $this->saveWikitext( $title, $wikitext, $params ); |
| 447 |
$editStatus = $saveresult['edit']['result']; |
| 448 |
|
| 449 |
|
| 450 |
if ( $editStatus !== 'Success' ) { |
| 451 |
$result['result'] = 'error'; |
| 452 |
$result['edit'] = $saveresult['edit']; |
| 453 |
} else { |
| 454 |
|
| 455 |
$result['result'] = 'success'; |
| 456 |
|
| 457 |
if ( $params['nocontent'] ) { |
| 458 |
$result['nocontent'] = true; |
| 459 |
} else { |
| 460 |
if ( isset( $saveresult['edit']['newrevid'] ) ) { |
| 461 |
$newRevId = intval( $saveresult['edit']['newrevid'] ); |
| 462 |
} else { |
| 463 |
$newRevId = $title->getLatestRevID(); |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
$parseWikitextResult = $this->parseWikitext( $newRevId, $params ); |
| 469 |
|
| 470 |
$result = array_merge( $result, $parseWikitextResult ); |
| 471 |
} |
| 472 |
|
| 473 |
$result['isRedirect'] = (string)$title->isRedirect(); |
| 474 |
|
| 475 |
if ( ExtensionRegistry::getInstance()->isLoaded( 'FlaggedRevs' ) ) { |
| 476 |
$newContext = new DerivativeContext( RequestContext::getMain() ); |
| 477 |
|
| 478 |
$newRequest = new DerivativeRequest( |
| 479 |
$this->getRequest(), |
| 480 |
[ |
| 481 |
'diff' => null, |
| 482 |
'oldid' => '', |
| 483 |
'title' => $title->getPrefixedText(), |
| 484 |
'action' => 'view' |
| 485 |
] + $this->getRequest()->getValues() |
| 486 |
); |
| 487 |
$newContext->setRequest( $newRequest ); |
| 488 |
$newContext->setTitle( $title ); |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
$view = FlaggablePageView::newFromTitle( $title ); |
| 493 |
|
| 494 |
$originalContext = $view->getContext(); |
| 495 |
$view->setContext( $newContext ); |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
$outputDone = null; |
| 500 |
$useParserCache = null; |
| 501 |
|
| 502 |
$view->setPageContent( $outputDone, $useParserCache ); |
| 503 |
$view->displayTag(); |
| 504 |
$view->setContext( $originalContext ); |
| 505 |
} |
| 506 |
|
| 507 |
$lang = $this->getLanguage(); |
| 508 |
|
| 509 |
if ( isset( $saveresult['edit']['newtimestamp'] ) ) { |
| 510 |
$ts = $saveresult['edit']['newtimestamp']; |
| 511 |
|
| 512 |
$date = $lang->userDate( $ts, $user ); |
| 513 |
$time = $lang->userTime( $ts, $user ); |
| 514 |
|
| 515 |
$result['lastModified'] = [ |
| 516 |
'date' => $date, |
| 517 |
'time' => $time, |
| 518 |
'message' => $this->msg( 'lastmodifiedat', $date, $time )->parse(), |
| 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 |
|
| 538 |
… |
| 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 |
|
| 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 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 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 |
|
| 634 |
|
| 635 |
|
| 636 |
'data-{plugin}' => [ |
| 637 |
ApiBase::PARAM_TEMPLATE_VARS => [ 'plugin' => 'plugins' ] |
| 638 |
] |
| 639 |
]; |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
public function needsToken() { |
| 646 |
return 'csrf'; |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
public function isInternal() { |
| 653 |
return true; |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
public function isWriteMode() { |
| 660 |
return true; |
| 661 |
} |
| 662 |
|
| 663 |
} |