| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Parser\Parsoid; |
| 4 |
|
| 5 |
use Composer\Semver\Semver; |
| 6 |
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; |
| 7 |
use LogicException; |
| 8 |
use MediaWiki\Content\Content; |
| 9 |
use MediaWiki\Content\ContentHandler; |
| 10 |
use MediaWiki\Content\IContentHandlerFactory; |
| 11 |
use MediaWiki\Page\PageIdentity; |
| 12 |
use MediaWiki\Parser\Parsoid\Config\PageConfigFactory; |
| 13 |
use MediaWiki\Rest\HttpException; |
| 14 |
use MediaWiki\Rest\LocalizedHttpException; |
| 15 |
use MediaWiki\Revision\MutableRevisionRecord; |
| 16 |
use MediaWiki\Revision\RevisionAccessException; |
| 17 |
use MediaWiki\Revision\RevisionRecord; |
| 18 |
use MediaWiki\Revision\SlotRecord; |
| 19 |
use Wikimedia\Bcp47Code\Bcp47Code; |
| 20 |
use Wikimedia\Message\MessageValue; |
| 21 |
use Wikimedia\Parsoid\Config\PageConfig; |
| 22 |
use Wikimedia\Parsoid\Core\ClientError; |
| 23 |
use Wikimedia\Parsoid\Core\PageBundle; |
| 24 |
use Wikimedia\Parsoid\Core\ResourceLimitExceededException; |
| 25 |
use Wikimedia\Parsoid\Core\SelserData; |
| 26 |
use Wikimedia\Parsoid\DOM\Document; |
| 27 |
use Wikimedia\Parsoid\DOM\Element; |
| 28 |
use Wikimedia\Parsoid\Parsoid; |
| 29 |
use Wikimedia\Parsoid\Utils\ContentUtils; |
| 30 |
use Wikimedia\Parsoid\Utils\DOMCompat; |
| 31 |
use Wikimedia\Parsoid\Utils\DOMUtils; |
| 32 |
use Wikimedia\Stats\StatsFactory; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
class HtmlToContentTransform { |
| 41 |
private array $options = []; |
| 42 |
private ?int $oldid = null; |
| 43 |
private ?Bcp47Code $contentLanguage = null; |
| 44 |
private ?Content $originalContent = null; |
| 45 |
private ?RevisionRecord $originalRevision = null; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
private bool $docHasBeenProcessed = false; |
| 51 |
private ?Document $doc = null; |
| 52 |
private ?Element $originalBody = null; |
| 53 |
protected ?StatsFactory $metrics = null; |
| 54 |
private PageBundle $modifiedPageBundle; |
| 55 |
private PageBundle $originalPageBundle; |
| 56 |
private ?PageConfig $pageConfig = null; |
| 57 |
private Parsoid $parsoid; |
| 58 |
private array $parsoidSettings; |
| 59 |
private PageIdentity $page; |
| 60 |
private PageConfigFactory $pageConfigFactory; |
| 61 |
private IContentHandlerFactory $contentHandlerFactory; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public function __construct( |
| 72 |
string $modifiedHTML, |
| 73 |
PageIdentity $page, |
| 74 |
Parsoid $parsoid, |
| 75 |
array $parsoidSettings, |
| 76 |
PageConfigFactory $pageConfigFactory, |
| 77 |
IContentHandlerFactory $contentHandlerFactory |
| 78 |
) { |
| 79 |
$this->parsoid = $parsoid; |
| 80 |
$this->parsoidSettings = $parsoidSettings; |
| 81 |
$this->modifiedPageBundle = new PageBundle( $modifiedHTML ); |
| 82 |
$this->originalPageBundle = new PageBundle( '' ); |
| 83 |
$this->page = $page; |
| 84 |
$this->pageConfigFactory = $pageConfigFactory; |
| 85 |
$this->contentHandlerFactory = $contentHandlerFactory; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public function setMetrics( $metrics ): void { |
| 97 |
if ( $metrics instanceof StatsdDataFactoryInterface ) { |
| 98 |
wfDeprecated( __METHOD__ . ' with StatsdDataFactoryInterface', '1.43' ); |
| 99 |
return; |
| 100 |
} |
| 101 |
$this->metrics = $metrics; |
| 102 |
} |
| 103 |
|
| 104 |
private function incrementMetrics( string $key, array $labels, ?string $statsdKey ) { |
| 105 |
if ( $this->metrics ) { |
| 106 |
$counter = $this->metrics->getCounter( $key )->setLabels( $labels ); |
| 107 |
if ( $statsdKey ) { |
| 108 |
$counter = $counter->copyToStatsdAt( $statsdKey ); |
| 109 |
} |
| 110 |
$counter->increment(); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
public function setOptions( array $options ) { |
| 115 |
$this->options = $options; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public function setOriginalRevision( RevisionRecord $rev ): void { |
| 122 |
if ( $this->pageConfig ) { |
| 123 |
throw new LogicException( 'Cannot set revision after using the PageConfig' ); |
| 124 |
} |
| 125 |
if ( $this->originalRevision ) { |
| 126 |
throw new LogicException( 'Cannot set revision again' ); |
| 127 |
} |
| 128 |
|
| 129 |
$this->originalRevision = $rev; |
| 130 |
$this->oldid = $rev->getId(); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public function setOriginalRevisionId( int $oldid ): void { |
| 137 |
if ( $this->pageConfig ) { |
| 138 |
throw new LogicException( 'Cannot set revision ID after using the PageConfig' ); |
| 139 |
} |
| 140 |
if ( $this->originalRevision ) { |
| 141 |
throw new LogicException( 'Cannot set revision again' ); |
| 142 |
} |
| 143 |
|
| 144 |
$this->oldid = $oldid; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
public function setContentLanguage( Bcp47Code $lang ): void { |
| 151 |
if ( $this->pageConfig ) { |
| 152 |
throw new LogicException( 'Cannot set content language after using the PageConfig' ); |
| 153 |
} |
| 154 |
|
| 155 |
$this->contentLanguage = $lang; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public function setOriginalText( string $text ): void { |
| 164 |
$content = $this->getContentHandler()->unserializeContent( $text ); |
| 165 |
$this->setOriginalContent( $content ); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
public function setOriginalContent( Content $content ): void { |
| 174 |
if ( $this->pageConfig ) { |
| 175 |
throw new LogicException( 'Cannot set text after using the PageConfig' ); |
| 176 |
} |
| 177 |
if ( $this->originalRevision ) { |
| 178 |
throw new LogicException( 'Cannot set wikitext after using the PageConfig' ); |
| 179 |
} |
| 180 |
|
| 181 |
$this->options['contentmodel'] = $content->getModel(); |
| 182 |
$this->originalContent = $content; |
| 183 |
} |
| 184 |
|
| 185 |
private function validatePageBundle( PageBundle $pb ) { |
| 186 |
if ( !$pb->version ) { |
| 187 |
return; |
| 188 |
} |
| 189 |
|
| 190 |
$errorMessage = ''; |
| 191 |
if ( !$pb->validate( $pb->version, $errorMessage ) ) { |
| 192 |
throw new ClientError( $errorMessage ); |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
public function setModifiedDataMW( array $modifiedDataMW ): void { |
| 202 |
|
| 203 |
if ( !Semver::satisfies( $this->getSchemaVersion(), '^999.0.0' ) ) { |
| 204 |
throw new ClientError( 'Modified data-mw is not supported by schema version ' |
| 205 |
. $this->getSchemaVersion() ); |
| 206 |
} |
| 207 |
|
| 208 |
$this->modifiedPageBundle->mw = $modifiedDataMW; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
public function setOriginalSchemaVersion( string $originalSchemaVeraion ): void { |
| 215 |
$this->originalPageBundle->version = $originalSchemaVeraion; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
public function setOriginalHtml( string $originalHtml ): void { |
| 222 |
if ( $this->doc ) { |
| 223 |
throw new LogicException( __FUNCTION__ . ' cannot be called after' . |
| 224 |
' getModifiedDocument()' ); |
| 225 |
} |
| 226 |
|
| 227 |
$this->originalPageBundle->html = $originalHtml; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
public function setOriginalDataMW( array $originalDataMW ): void { |
| 234 |
if ( $this->doc ) { |
| 235 |
throw new LogicException( __FUNCTION__ . ' cannot be called after getModifiedDocument()' ); |
| 236 |
} |
| 237 |
|
| 238 |
$this->originalPageBundle->mw = $originalDataMW; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
if ( $this->modifiedPageBundle->mw === null ) { |
| 243 |
$this->modifiedPageBundle->mw = $originalDataMW; |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
public function setOriginalDataParsoid( array $originalDataParsoid ): void { |
| 251 |
if ( $this->doc ) { |
| 252 |
throw new LogicException( __FUNCTION__ . ' cannot be called after getModifiedDocument()' ); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
$this->originalPageBundle->parsoid = $originalDataParsoid; |
| 257 |
$this->modifiedPageBundle->parsoid = $originalDataParsoid; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
private function getPageConfig(): PageConfig { |
| 264 |
if ( !$this->pageConfig ) { |
| 265 |
|
| 266 |
|
| 267 |
if ( $this->originalContent !== null ) { |
| 268 |
|
| 269 |
|
| 270 |
$revision = new MutableRevisionRecord( $this->page ); |
| 271 |
if ( $this->oldid ) { |
| 272 |
$revision->setId( $this->oldid ); |
| 273 |
} |
| 274 |
|
| 275 |
$revision->setSlot( |
| 276 |
SlotRecord::newUnsaved( |
| 277 |
SlotRecord::MAIN, |
| 278 |
$this->originalContent |
| 279 |
) |
| 280 |
); |
| 281 |
} else { |
| 282 |
|
| 283 |
$revision = $this->originalRevision ?: $this->oldid; |
| 284 |
} |
| 285 |
|
| 286 |
try { |
| 287 |
$this->pageConfig = $this->pageConfigFactory->create( |
| 288 |
$this->page, |
| 289 |
null, |
| 290 |
$revision, |
| 291 |
null, |
| 292 |
$this->contentLanguage |
| 293 |
); |
| 294 |
} catch ( RevisionAccessException $exception ) { |
| 295 |
|
| 296 |
|
| 297 |
throw new LocalizedHttpException( new MessageValue( "rest-specified-revision-unavailable" ), 404 ); |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
return $this->pageConfig; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
public function getModifiedHtmlSize(): int { |
| 310 |
return mb_strlen( $this->modifiedPageBundle->html ); |
| 311 |
} |
| 312 |
|
| 313 |
private function getModifiedDocumentRaw(): Document { |
| 314 |
if ( !$this->doc ) { |
| 315 |
$this->doc = $this->parseHTML( $this->modifiedPageBundle->html, true ); |
| 316 |
$this->modifiedPageBundle->version = DOMUtils::extractInlinedContentVersion( $this->doc ); |
| 317 |
} |
| 318 |
|
| 319 |
return $this->doc; |
| 320 |
} |
| 321 |
|
| 322 |
public function getModifiedDocument(): Document { |
| 323 |
$doc = $this->getModifiedDocumentRaw(); |
| 324 |
|
| 325 |
if ( !$this->docHasBeenProcessed ) { |
| 326 |
$this->applyPageBundle( $this->doc, $this->modifiedPageBundle ); |
| 327 |
|
| 328 |
$this->docHasBeenProcessed = true; |
| 329 |
} |
| 330 |
|
| 331 |
return $doc; |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
public function hasOriginalHtml(): bool { |
| 341 |
return $this->originalPageBundle->html !== null && $this->originalPageBundle->html !== ''; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
public function hasOriginalDataParsoid(): bool { |
| 351 |
return $this->originalPageBundle->parsoid !== null; |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
public function getOriginalHtml(): string { |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
if ( !$this->originalPageBundle->version ) { |
| 366 |
throw new ClientError( |
| 367 |
'Content-type of original html is missing.' |
| 368 |
); |
| 369 |
} |
| 370 |
|
| 371 |
if ( !$this->originalBody ) { |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
if ( $this->hasOriginalDataParsoid() || $this->needsDowngrade( $this->originalPageBundle ) ) { |
| 378 |
$this->getOriginalBody(); |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
return $this->originalPageBundle->html ?: ''; |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
protected function parseHTML( string $html, bool $validateXMLNames = false ): Document { |
| 393 |
return DOMUtils::parseHTML( $html, $validateXMLNames ); |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
public function getOriginalBody(): Element { |
| 404 |
if ( !$this->hasOriginalHtml() ) { |
| 405 |
throw new LogicException( |
| 406 |
'No original data supplied, call hasOriginalHtml() first.' |
| 407 |
); |
| 408 |
} |
| 409 |
|
| 410 |
if ( $this->originalBody ) { |
| 411 |
return $this->originalBody; |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
if ( !$this->originalPageBundle->version ) { |
| 418 |
throw new ClientError( |
| 419 |
'Content-type of original html is missing.' |
| 420 |
); |
| 421 |
} |
| 422 |
|
| 423 |
if ( $this->needsDowngrade( $this->originalPageBundle ) ) { |
| 424 |
$this->downgradeOriginalData( $this->originalPageBundle, $this->getSchemaVersion() ); |
| 425 |
} |
| 426 |
|
| 427 |
$doc = $this->parseHTML( $this->originalPageBundle->html ); |
| 428 |
|
| 429 |
$this->applyPageBundle( $doc, $this->originalPageBundle ); |
| 430 |
|
| 431 |
$this->originalBody = DOMCompat::getBody( $doc ); |
| 432 |
|
| 433 |
|
| 434 |
$this->originalPageBundle->html = ContentUtils::toXML( $this->originalBody ); |
| 435 |
|
| 436 |
return $this->originalBody; |
| 437 |
} |
| 438 |
|
| 439 |
public function getOriginalSchemaVersion(): string { |
| 440 |
return $this->originalPageBundle->version ?: $this->getSchemaVersion(); |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
public function getSchemaVersion(): string { |
| 450 |
|
| 451 |
|
| 452 |
$this->getModifiedDocumentRaw(); |
| 453 |
$inputContentVersion = $this->modifiedPageBundle->version; |
| 454 |
|
| 455 |
if ( !$inputContentVersion ) { |
| 456 |
$this->incrementMetrics( |
| 457 |
'html2wt_original_version_total', |
| 458 |
[ 'input_content_version' => 'none' ], |
| 459 |
'html2wt.original.version.notinline' |
| 460 |
); |
| 461 |
$inputContentVersion = $this->originalPageBundle->version ?: Parsoid::defaultHTMLVersion(); |
| 462 |
} |
| 463 |
|
| 464 |
return $inputContentVersion; |
| 465 |
} |
| 466 |
|
| 467 |
public function getOriginalRevisionId(): ?int { |
| 468 |
return $this->oldid; |
| 469 |
} |
| 470 |
|
| 471 |
public function knowsOriginalContent(): bool { |
| 472 |
return $this->originalRevision || $this->oldid || $this->originalContent !== null; |
| 473 |
} |
| 474 |
|
| 475 |
public function getContentModel(): string { |
| 476 |
return $this->options['contentmodel'] ?? CONTENT_MODEL_WIKITEXT; |
| 477 |
} |
| 478 |
|
| 479 |
public function getOffsetType(): string { |
| 480 |
return $this->options['offsetType'] ?? 'byte'; |
| 481 |
} |
| 482 |
|
| 483 |
private function needsDowngrade( PageBundle $pb ): bool { |
| 484 |
$vOriginal = $pb->version; |
| 485 |
$vEdited = $this->getSchemaVersion(); |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
return $vOriginal !== null && !Semver::satisfies( $vOriginal, "^{$vEdited}" ); |
| 498 |
} |
| 499 |
|
| 500 |
private function downgradeOriginalData( PageBundle $pb, string $targetSchemaVersion ) { |
| 501 |
if ( $pb->version === null ) { |
| 502 |
throw new ClientError( 'Missing schema version' ); |
| 503 |
} |
| 504 |
|
| 505 |
if ( $targetSchemaVersion === $pb->version ) { |
| 506 |
|
| 507 |
return; |
| 508 |
} |
| 509 |
|
| 510 |
if ( !$pb->parsoid ) { |
| 511 |
|
| 512 |
|
| 513 |
return; |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
$downgrade = Parsoid::findDowngrade( $pb->version, $targetSchemaVersion ); |
| 518 |
|
| 519 |
if ( !$downgrade ) { |
| 520 |
throw new ClientError( |
| 521 |
"No downgrade possible from schema version {$pb->version} to {$targetSchemaVersion}." |
| 522 |
); |
| 523 |
} |
| 524 |
|
| 525 |
$this->incrementMetrics( |
| 526 |
"downgrade_total", |
| 527 |
[ 'from' => $downgrade['from'], 'to' => $downgrade['to'] ], |
| 528 |
"downgrade.from.{$downgrade['from']}.to.{$downgrade['to']}" |
| 529 |
); |
| 530 |
|
| 531 |
$downgradeTime = microtime( true ); |
| 532 |
Parsoid::downgrade( $downgrade, $pb ); |
| 533 |
if ( $this->metrics ) { |
| 534 |
$this->metrics |
| 535 |
->getTiming( 'downgrade_time_ms' ) |
| 536 |
->copyToStatsdAt( 'downgrade.time' ) |
| 537 |
->observe( ( microtime( true ) - $downgradeTime ) * 1000 ); |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
$this->originalBody = null; |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
private function applyPageBundle( Document $doc, PageBundle $pb ): void { |
| 553 |
if ( $pb->parsoid === null && $pb->mw === null ) { |
| 554 |
return; |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
if ( isset( $pb->parsoid['offsetType'] ) ) { |
| 561 |
$offsetType = $this->getOffsetType(); |
| 562 |
$origOffsetType = $pb->parsoid['offsetType'] ?? $offsetType; |
| 563 |
if ( $origOffsetType !== $offsetType ) { |
| 564 |
throw new ClientError( |
| 565 |
'DSR offsetType mismatch: ' . $origOffsetType . ' vs ' . $offsetType |
| 566 |
); |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
$this->validatePageBundle( $pb ); |
| 571 |
PageBundle::apply( $doc, $pb ); |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
private function getSelserData(): ?SelserData { |
| 582 |
$oldhtml = $this->hasOriginalHtml() ? $this->getOriginalHtml() : null; |
| 583 |
|
| 584 |
|
| 585 |
$knowsOriginal = $this->knowsOriginalContent(); |
| 586 |
|
| 587 |
if ( $knowsOriginal && !empty( $this->parsoidSettings['useSelser'] ) ) { |
| 588 |
if ( !$this->getPageConfig()->getRevisionContent() ) { |
| 589 |
throw new LocalizedHttpException( new MessageValue( "rest-previous-revision-unavailable" ), |
| 590 |
409 ); |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
$selserData = new SelserData( $this->getPageConfig()->getPageMainContent(), |
| 596 |
$oldhtml ); |
| 597 |
} else { |
| 598 |
$selserData = null; |
| 599 |
} |
| 600 |
|
| 601 |
return $selserData; |
| 602 |
} |
| 603 |
|
| 604 |
private function getContentHandler(): ContentHandler { |
| 605 |
$model = $this->getContentModel(); |
| 606 |
|
| 607 |
return $this->contentHandlerFactory |
| 608 |
->getContentHandler( $model ); |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
public function htmlToContent(): Content { |
| 617 |
$text = $this->htmlToText(); |
| 618 |
$content = $this->getContentHandler()->unserializeContent( $text ); |
| 619 |
|
| 620 |
return $content; |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
private function htmlToText(): string { |
| 631 |
$doc = $this->getModifiedDocument(); |
| 632 |
$htmlSize = $this->getModifiedHtmlSize(); |
| 633 |
$inputContentVersion = $this->getSchemaVersion(); |
| 634 |
$selserData = $this->getSelserData(); |
| 635 |
|
| 636 |
try { |
| 637 |
$text = $this->parsoid->dom2wikitext( $this->getPageConfig(), $doc, [ |
| 638 |
'inputContentVersion' => $inputContentVersion, |
| 639 |
'offsetType' => $this->getOffsetType(), |
| 640 |
'contentmodel' => $this->getContentModel(), |
| 641 |
'htmlSize' => $htmlSize, |
| 642 |
], $selserData ); |
| 643 |
} catch ( ClientError $e ) { |
| 644 |
throw new LocalizedHttpException( new MessageValue( "rest-parsoid-error", [ $e->getMessage() ] ), 400 ); |
| 645 |
} catch ( ResourceLimitExceededException $e ) { |
| 646 |
throw new LocalizedHttpException( |
| 647 |
new MessageValue( "rest-parsoid-resource-exceeded", [ $e->getMessage() ] ), 413 |
| 648 |
); |
| 649 |
} |
| 650 |
|
| 651 |
return $text; |
| 652 |
} |
| 653 |
|
| 654 |
} |