| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\EditPage; |
| 22 |
|
| 23 |
use Article; |
| 24 |
use BadMethodCallException; |
| 25 |
use CategoryPage; |
| 26 |
use ErrorPageError; |
| 27 |
use LogPage; |
| 28 |
use ManualLogEntry; |
| 29 |
use MediaWiki\Auth\AuthManager; |
| 30 |
use MediaWiki\Block\BlockErrorFormatter; |
| 31 |
use MediaWiki\Cache\LinkBatchFactory; |
| 32 |
use MediaWiki\CommentStore\CommentStore; |
| 33 |
use MediaWiki\CommentStore\CommentStoreComment; |
| 34 |
use MediaWiki\Config\Config; |
| 35 |
use MediaWiki\Content\Content; |
| 36 |
use MediaWiki\Content\ContentHandler; |
| 37 |
use MediaWiki\Content\IContentHandlerFactory; |
| 38 |
use MediaWiki\Content\TextContent; |
| 39 |
use MediaWiki\Context\DerivativeContext; |
| 40 |
use MediaWiki\Context\IContextSource; |
| 41 |
use MediaWiki\Debug\DeprecationHelper; |
| 42 |
use MediaWiki\Deferred\DeferredUpdates; |
| 43 |
use MediaWiki\EditPage\Constraint\AccidentalRecreationConstraint; |
| 44 |
use MediaWiki\EditPage\Constraint\ChangeTagsConstraint; |
| 45 |
use MediaWiki\EditPage\Constraint\ContentModelChangeConstraint; |
| 46 |
use MediaWiki\EditPage\Constraint\DefaultTextConstraint; |
| 47 |
use MediaWiki\EditPage\Constraint\EditConstraintFactory; |
| 48 |
use MediaWiki\EditPage\Constraint\EditConstraintRunner; |
| 49 |
use MediaWiki\EditPage\Constraint\EditFilterMergedContentHookConstraint; |
| 50 |
use MediaWiki\EditPage\Constraint\ExistingSectionEditConstraint; |
| 51 |
use MediaWiki\EditPage\Constraint\IEditConstraint; |
| 52 |
use MediaWiki\EditPage\Constraint\ImageRedirectConstraint; |
| 53 |
use MediaWiki\EditPage\Constraint\MissingCommentConstraint; |
| 54 |
use MediaWiki\EditPage\Constraint\NewSectionMissingSubjectConstraint; |
| 55 |
use MediaWiki\EditPage\Constraint\PageSizeConstraint; |
| 56 |
use MediaWiki\EditPage\Constraint\SelfRedirectConstraint; |
| 57 |
use MediaWiki\EditPage\Constraint\SpamRegexConstraint; |
| 58 |
use MediaWiki\EditPage\Constraint\UnicodeConstraint; |
| 59 |
use MediaWiki\EditPage\Constraint\UserBlockConstraint; |
| 60 |
use MediaWiki\HookContainer\HookRunner; |
| 61 |
use MediaWiki\HookContainer\ProtectedHookAccessorTrait; |
| 62 |
use MediaWiki\Html\Html; |
| 63 |
use MediaWiki\Language\RawMessage; |
| 64 |
use MediaWiki\Linker\Linker; |
| 65 |
use MediaWiki\Linker\LinkRenderer; |
| 66 |
use MediaWiki\Logger\LoggerFactory; |
| 67 |
use MediaWiki\MainConfigNames; |
| 68 |
use MediaWiki\MediaWikiServices; |
| 69 |
use MediaWiki\Message\Message; |
| 70 |
use MediaWiki\Page\PageIdentity; |
| 71 |
use MediaWiki\Page\PageReference; |
| 72 |
use MediaWiki\Page\RedirectLookup; |
| 73 |
use MediaWiki\Page\WikiPageFactory; |
| 74 |
use MediaWiki\Parser\ParserOptions; |
| 75 |
use MediaWiki\Parser\ParserOutput; |
| 76 |
use MediaWiki\Permissions\Authority; |
| 77 |
use MediaWiki\Permissions\PermissionManager; |
| 78 |
use MediaWiki\Permissions\PermissionStatus; |
| 79 |
use MediaWiki\Permissions\RestrictionStore; |
| 80 |
use MediaWiki\Request\WebRequest; |
| 81 |
use MediaWiki\Revision\RevisionRecord; |
| 82 |
use MediaWiki\Revision\RevisionStore; |
| 83 |
use MediaWiki\Revision\RevisionStoreRecord; |
| 84 |
use MediaWiki\Revision\SlotRecord; |
| 85 |
use MediaWiki\Status\Status; |
| 86 |
use MediaWiki\Storage\EditResult; |
| 87 |
use MediaWiki\Title\Title; |
| 88 |
use MediaWiki\User\ExternalUserNames; |
| 89 |
use MediaWiki\User\Options\UserOptionsLookup; |
| 90 |
use MediaWiki\User\TempUser\CreateStatus; |
| 91 |
use MediaWiki\User\TempUser\TempUserCreator; |
| 92 |
use MediaWiki\User\User; |
| 93 |
use MediaWiki\User\UserFactory; |
| 94 |
use MediaWiki\User\UserIdentity; |
| 95 |
use MediaWiki\User\UserNameUtils; |
| 96 |
use MediaWiki\Watchlist\WatchedItemStoreInterface; |
| 97 |
use MediaWiki\Watchlist\WatchlistManager; |
| 98 |
use MessageLocalizer; |
| 99 |
use MWContentSerializationException; |
| 100 |
use MWException; |
| 101 |
use MWUnknownContentModelException; |
| 102 |
use OOUI; |
| 103 |
use OOUI\ButtonWidget; |
| 104 |
use OOUI\CheckboxInputWidget; |
| 105 |
use OOUI\DropdownInputWidget; |
| 106 |
use OOUI\FieldLayout; |
| 107 |
use PermissionsError; |
| 108 |
use ReadOnlyError; |
| 109 |
use RecentChange; |
| 110 |
use RuntimeException; |
| 111 |
use Skin; |
| 112 |
use stdClass; |
| 113 |
use ThrottledError; |
| 114 |
use UserBlockedError; |
| 115 |
use WatchAction; |
| 116 |
use Wikimedia\Assert\Assert; |
| 117 |
use Wikimedia\Message\MessageValue; |
| 118 |
use Wikimedia\ParamValidator\TypeDef\ExpiryDef; |
| 119 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 120 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 121 |
use Wikimedia\Rdbms\SelectQueryBuilder; |
| 122 |
use WikiPage; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
#[\AllowDynamicProperties] |
| 147 |
class EditPage implements IEditObject { |
| 148 |
use DeprecationHelper; |
| 149 |
use ProtectedHookAccessorTrait; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public const UNICODE_CHECK = UnicodeConstraint::VALID_UNICODE; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
public const EDITFORM_ID = 'editform'; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public const POST_EDIT_COOKIE_KEY_PREFIX = 'PostEditRevision'; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public const POST_EDIT_COOKIE_DURATION = 1200; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
private $mArticle; |
| 189 |
|
| 190 |
|
| 191 |
private $page; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
private $mTitle; |
| 197 |
|
| 198 |
|
| 199 |
private $mContextTitle = null; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
public $action = 'submit'; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
public $isConflict = false; |
| 212 |
|
| 213 |
|
| 214 |
private $isNew = false; |
| 215 |
|
| 216 |
|
| 217 |
private $deletedSinceEdit; |
| 218 |
|
| 219 |
|
| 220 |
public $formtype; |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public $firsttime; |
| 227 |
|
| 228 |
|
| 229 |
private $lastDelete; |
| 230 |
|
| 231 |
|
| 232 |
private $mTokenOk = false; |
| 233 |
|
| 234 |
|
| 235 |
private $mTriedSave = false; |
| 236 |
|
| 237 |
|
| 238 |
private $incompleteForm = false; |
| 239 |
|
| 240 |
|
| 241 |
private $tooBig = false; |
| 242 |
|
| 243 |
|
| 244 |
private $missingComment = false; |
| 245 |
|
| 246 |
|
| 247 |
private $missingSummary = false; |
| 248 |
|
| 249 |
|
| 250 |
private $allowBlankSummary = false; |
| 251 |
|
| 252 |
|
| 253 |
protected $blankArticle = false; |
| 254 |
|
| 255 |
|
| 256 |
private $allowBlankArticle = false; |
| 257 |
|
| 258 |
|
| 259 |
private $selfRedirect = false; |
| 260 |
|
| 261 |
|
| 262 |
private $allowSelfRedirect = false; |
| 263 |
|
| 264 |
|
| 265 |
private $autoSumm = ''; |
| 266 |
|
| 267 |
|
| 268 |
private $hookError = ''; |
| 269 |
|
| 270 |
|
| 271 |
private $mParserOutput; |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
private $mExpectedParentRevision = false; |
| 279 |
|
| 280 |
|
| 281 |
public $mShowSummaryField = true; |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
public $save = false; |
| 287 |
|
| 288 |
|
| 289 |
public $preview = false; |
| 290 |
|
| 291 |
|
| 292 |
private $diff = false; |
| 293 |
|
| 294 |
|
| 295 |
private $minoredit = false; |
| 296 |
|
| 297 |
|
| 298 |
private $watchthis = false; |
| 299 |
|
| 300 |
|
| 301 |
private $watchlistExpiryEnabled; |
| 302 |
|
| 303 |
private WatchedItemStoreInterface $watchedItemStore; |
| 304 |
|
| 305 |
|
| 306 |
private $watchlistExpiry; |
| 307 |
|
| 308 |
|
| 309 |
private $recreate = false; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
public $textbox1 = ''; |
| 315 |
|
| 316 |
|
| 317 |
public $textbox2 = ''; |
| 318 |
|
| 319 |
|
| 320 |
public $summary = ''; |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
private $nosummary = false; |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
public $edittime = ''; |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
private $editRevId = null; |
| 346 |
|
| 347 |
|
| 348 |
public $section = ''; |
| 349 |
|
| 350 |
|
| 351 |
public $sectiontitle = null; |
| 352 |
|
| 353 |
|
| 354 |
private $newSectionAnchor = null; |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
public $starttime = ''; |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
public $oldid = 0; |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
private $parentRevId = 0; |
| 375 |
|
| 376 |
|
| 377 |
private $scrolltop = null; |
| 378 |
|
| 379 |
|
| 380 |
private $markAsBot = true; |
| 381 |
|
| 382 |
|
| 383 |
public $contentModel; |
| 384 |
|
| 385 |
|
| 386 |
public $contentFormat = null; |
| 387 |
|
| 388 |
|
| 389 |
private $changeTags = null; |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
public $editFormPageTop = ''; |
| 396 |
|
| 397 |
public $editFormTextTop = ''; |
| 398 |
|
| 399 |
public $editFormTextBeforeContent = ''; |
| 400 |
|
| 401 |
public $editFormTextAfterWarn = ''; |
| 402 |
|
| 403 |
public $editFormTextAfterTools = ''; |
| 404 |
|
| 405 |
public $editFormTextBottom = ''; |
| 406 |
|
| 407 |
public $editFormTextAfterContent = ''; |
| 408 |
|
| 409 |
public $previewTextAfterContent = ''; |
| 410 |
|
| 411 |
|
| 412 |
public $didSave = false; |
| 413 |
|
| 414 |
public $undidRev = 0; |
| 415 |
|
| 416 |
private $undoAfter = 0; |
| 417 |
|
| 418 |
|
| 419 |
public $suppressIntro = false; |
| 420 |
|
| 421 |
|
| 422 |
private $edit; |
| 423 |
|
| 424 |
|
| 425 |
private $contentLength = false; |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
private $enableApiEditOverride = false; |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
protected $context; |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
private $isOldRev = false; |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
private $unicodeCheck; |
| 446 |
|
| 447 |
|
| 448 |
private $editConflictHelperFactory = null; |
| 449 |
private ?TextConflictHelper $editConflictHelper = null; |
| 450 |
|
| 451 |
private IContentHandlerFactory $contentHandlerFactory; |
| 452 |
private PermissionManager $permManager; |
| 453 |
private RevisionStore $revisionStore; |
| 454 |
private WikiPageFactory $wikiPageFactory; |
| 455 |
private WatchlistManager $watchlistManager; |
| 456 |
private UserNameUtils $userNameUtils; |
| 457 |
private RedirectLookup $redirectLookup; |
| 458 |
private UserOptionsLookup $userOptionsLookup; |
| 459 |
private TempUserCreator $tempUserCreator; |
| 460 |
private UserFactory $userFactory; |
| 461 |
private IConnectionProvider $connectionProvider; |
| 462 |
private BlockErrorFormatter $blockErrorFormatter; |
| 463 |
private AuthManager $authManager; |
| 464 |
|
| 465 |
|
| 466 |
private $placeholderTempUser; |
| 467 |
|
| 468 |
|
| 469 |
private $unsavedTempUser; |
| 470 |
|
| 471 |
|
| 472 |
private $savedTempUser; |
| 473 |
|
| 474 |
|
| 475 |
private $tempUserCreateActive = false; |
| 476 |
|
| 477 |
|
| 478 |
private $tempUserName; |
| 479 |
|
| 480 |
|
| 481 |
private $tempUserCreateDone = false; |
| 482 |
|
| 483 |
|
| 484 |
private $unableToAcquireTempName = false; |
| 485 |
|
| 486 |
private LinkRenderer $linkRenderer; |
| 487 |
private LinkBatchFactory $linkBatchFactory; |
| 488 |
private RestrictionStore $restrictionStore; |
| 489 |
private CommentStore $commentStore; |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
public function __construct( Article $article ) { |
| 496 |
$this->mArticle = $article; |
| 497 |
$this->page = $article->getPage(); |
| 498 |
$this->mTitle = $article->getTitle(); |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
$this->context = new DerivativeContext( $article->getContext() ); |
| 506 |
$this->context->setWikiPage( $this->page ); |
| 507 |
$this->context->setTitle( $this->mTitle ); |
| 508 |
|
| 509 |
$this->contentModel = $this->mTitle->getContentModel(); |
| 510 |
|
| 511 |
$services = MediaWikiServices::getInstance(); |
| 512 |
$this->contentHandlerFactory = $services->getContentHandlerFactory(); |
| 513 |
$this->contentFormat = $this->contentHandlerFactory |
| 514 |
->getContentHandler( $this->contentModel ) |
| 515 |
->getDefaultFormat(); |
| 516 |
$this->permManager = $services->getPermissionManager(); |
| 517 |
$this->revisionStore = $services->getRevisionStore(); |
| 518 |
$this->watchlistExpiryEnabled = $this->getContext()->getConfig() instanceof Config |
| 519 |
&& $this->getContext()->getConfig()->get( MainConfigNames::WatchlistExpiry ); |
| 520 |
$this->watchedItemStore = $services->getWatchedItemStore(); |
| 521 |
$this->wikiPageFactory = $services->getWikiPageFactory(); |
| 522 |
$this->watchlistManager = $services->getWatchlistManager(); |
| 523 |
$this->userNameUtils = $services->getUserNameUtils(); |
| 524 |
$this->redirectLookup = $services->getRedirectLookup(); |
| 525 |
$this->userOptionsLookup = $services->getUserOptionsLookup(); |
| 526 |
$this->tempUserCreator = $services->getTempUserCreator(); |
| 527 |
$this->userFactory = $services->getUserFactory(); |
| 528 |
$this->linkRenderer = $services->getLinkRenderer(); |
| 529 |
$this->linkBatchFactory = $services->getLinkBatchFactory(); |
| 530 |
$this->restrictionStore = $services->getRestrictionStore(); |
| 531 |
$this->commentStore = $services->getCommentStore(); |
| 532 |
$this->connectionProvider = $services->getConnectionProvider(); |
| 533 |
$this->blockErrorFormatter = $services->getFormatterFactory() |
| 534 |
->getBlockErrorFormatter( $this->context ); |
| 535 |
$this->authManager = $services->getAuthManager(); |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
public function getArticle() { |
| 545 |
return $this->mArticle; |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
public function getContext() { |
| 553 |
return $this->context; |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
public function getTitle() { |
| 561 |
return $this->mTitle; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
public function setContextTitle( $title ) { |
| 568 |
$this->mContextTitle = $title; |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
public function getContextTitle() { |
| 576 |
if ( $this->mContextTitle === null ) { |
| 577 |
throw new RuntimeException( "EditPage does not have a context title set" ); |
| 578 |
} else { |
| 579 |
return $this->mContextTitle; |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
private function isSupportedContentModel( string $modelId ): bool { |
| 591 |
return $this->enableApiEditOverride === true || |
| 592 |
$this->contentHandlerFactory->getContentHandler( $modelId )->supportsDirectEditing(); |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
public function setApiEditOverride( $enableOverride ) { |
| 603 |
$this->enableApiEditOverride = $enableOverride; |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
public function edit() { |
| 618 |
|
| 619 |
if ( !$this->getHookRunner()->onAlternateEdit( $this ) ) { |
| 620 |
return; |
| 621 |
} |
| 622 |
|
| 623 |
wfDebug( __METHOD__ . ": enter" ); |
| 624 |
|
| 625 |
$request = $this->context->getRequest(); |
| 626 |
|
| 627 |
if ( $request->getBool( 'redlink' ) && $this->mTitle->exists() ) { |
| 628 |
$this->context->getOutput()->redirect( $this->mTitle->getFullURL() ); |
| 629 |
return; |
| 630 |
} |
| 631 |
|
| 632 |
$this->importFormData( $request ); |
| 633 |
$this->firsttime = false; |
| 634 |
|
| 635 |
$readOnlyMode = MediaWikiServices::getInstance()->getReadOnlyMode(); |
| 636 |
if ( $this->save && $readOnlyMode->isReadOnly() ) { |
| 637 |
|
| 638 |
$this->save = false; |
| 639 |
$this->preview = true; |
| 640 |
} |
| 641 |
|
| 642 |
if ( $this->save ) { |
| 643 |
$this->formtype = 'save'; |
| 644 |
} elseif ( $this->preview ) { |
| 645 |
$this->formtype = 'preview'; |
| 646 |
} elseif ( $this->diff ) { |
| 647 |
$this->formtype = 'diff'; |
| 648 |
} else { |
| 649 |
$this->firsttime = true; |
| 650 |
if ( $this->previewOnOpen() ) { |
| 651 |
$this->formtype = 'preview'; |
| 652 |
} else { |
| 653 |
$this->formtype = 'initial'; |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
$this->unableToAcquireTempName = !$this->maybeActivateTempUserCreate( !$this->firsttime )->isOK(); |
| 662 |
|
| 663 |
$status = $this->getEditPermissionStatus( |
| 664 |
$this->save ? PermissionManager::RIGOR_SECURE : PermissionManager::RIGOR_FULL |
| 665 |
); |
| 666 |
if ( !$status->isGood() ) { |
| 667 |
wfDebug( __METHOD__ . ": User can't edit" ); |
| 668 |
|
| 669 |
$user = $this->context->getUser(); |
| 670 |
if ( $user->getBlock() && !$readOnlyMode->isReadOnly() ) { |
| 671 |
|
| 672 |
DeferredUpdates::addCallableUpdate( static function () use ( $user ) { |
| 673 |
$user->spreadAnyEditBlock(); |
| 674 |
} ); |
| 675 |
} |
| 676 |
$this->displayPermissionStatus( $status ); |
| 677 |
|
| 678 |
return; |
| 679 |
} |
| 680 |
|
| 681 |
$revRecord = $this->mArticle->fetchRevisionRecord(); |
| 682 |
|
| 683 |
|
| 684 |
$revContentModel = $revRecord ? |
| 685 |
$revRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel() : |
| 686 |
false; |
| 687 |
if ( $revContentModel && $revContentModel !== $this->contentModel ) { |
| 688 |
$prevRevRecord = null; |
| 689 |
$prevContentModel = false; |
| 690 |
if ( $this->undidRev ) { |
| 691 |
$undidRevRecord = $this->revisionStore |
| 692 |
->getRevisionById( $this->undidRev ); |
| 693 |
$prevRevRecord = $undidRevRecord ? |
| 694 |
$this->revisionStore->getPreviousRevision( $undidRevRecord ) : |
| 695 |
null; |
| 696 |
|
| 697 |
$prevContentModel = $prevRevRecord ? |
| 698 |
$prevRevRecord |
| 699 |
->getSlot( SlotRecord::MAIN, RevisionRecord::RAW ) |
| 700 |
->getModel() : |
| 701 |
''; |
| 702 |
} |
| 703 |
|
| 704 |
if ( !$this->undidRev |
| 705 |
|| !$prevRevRecord |
| 706 |
|| $prevContentModel !== $this->contentModel |
| 707 |
) { |
| 708 |
$this->displayViewSourcePage( |
| 709 |
$this->getContentObject(), |
| 710 |
$this->context->msg( |
| 711 |
'contentmodelediterror', |
| 712 |
$revContentModel, |
| 713 |
$this->contentModel |
| 714 |
)->plain() |
| 715 |
); |
| 716 |
return; |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
$this->isConflict = false; |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
if ( $this->formtype === 'save' ) { |
| 728 |
$resultDetails = null; |
| 729 |
$status = $this->attemptSave( $resultDetails ); |
| 730 |
if ( !$this->handleStatus( $status, $resultDetails ) ) { |
| 731 |
return; |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
if ( $this->formtype === 'initial' || $this->firsttime ) { |
| 738 |
if ( !$this->initialiseForm() ) { |
| 739 |
return; |
| 740 |
} |
| 741 |
|
| 742 |
if ( $this->mTitle->getArticleID() ) { |
| 743 |
$this->getHookRunner()->onEditFormInitialText( $this ); |
| 744 |
} |
| 745 |
} |
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
$curRevisionRecord = $this->page->getRevisionRecord(); |
| 754 |
if ( $curRevisionRecord |
| 755 |
&& $revRecord |
| 756 |
&& $curRevisionRecord->getId() !== $revRecord->getId() |
| 757 |
&& ( WikiPage::hasDifferencesOutsideMainSlot( |
| 758 |
$revRecord, |
| 759 |
$curRevisionRecord |
| 760 |
) || !$this->isSupportedContentModel( |
| 761 |
$revRecord->getSlot( |
| 762 |
SlotRecord::MAIN, |
| 763 |
RevisionRecord::RAW |
| 764 |
)->getModel() |
| 765 |
) ) |
| 766 |
) { |
| 767 |
$restoreLink = $this->mTitle->getFullURL( |
| 768 |
[ |
| 769 |
'action' => 'mcrrestore', |
| 770 |
'restore' => $revRecord->getId(), |
| 771 |
] |
| 772 |
); |
| 773 |
$this->displayViewSourcePage( |
| 774 |
$this->getContentObject(), |
| 775 |
$this->context->msg( |
| 776 |
'nonmain-slot-differences-therefore-readonly', |
| 777 |
$restoreLink |
| 778 |
)->plain() |
| 779 |
); |
| 780 |
return; |
| 781 |
} |
| 782 |
|
| 783 |
$this->showEditForm(); |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
public function maybeActivateTempUserCreate( $doAcquire ): Status { |
| 796 |
if ( $this->tempUserCreateActive ) { |
| 797 |
|
| 798 |
return Status::newGood(); |
| 799 |
} |
| 800 |
$user = $this->context->getUser(); |
| 801 |
if ( $this->tempUserCreator->shouldAutoCreate( $user, 'edit' ) ) { |
| 802 |
if ( $doAcquire ) { |
| 803 |
$name = $this->tempUserCreator->acquireAndStashName( |
| 804 |
$this->context->getRequest()->getSession() ); |
| 805 |
if ( $name === null ) { |
| 806 |
$status = Status::newFatal( 'temp-user-unable-to-acquire' ); |
| 807 |
$status->value = self::AS_UNABLE_TO_ACQUIRE_TEMP_ACCOUNT; |
| 808 |
return $status; |
| 809 |
} |
| 810 |
$this->unsavedTempUser = $this->userFactory->newUnsavedTempUser( $name ); |
| 811 |
$this->tempUserName = $name; |
| 812 |
} else { |
| 813 |
$this->placeholderTempUser = $this->userFactory->newTempPlaceholder(); |
| 814 |
} |
| 815 |
$this->tempUserCreateActive = true; |
| 816 |
} |
| 817 |
return Status::newGood(); |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
private function createTempUser(): Status { |
| 830 |
if ( !$this->tempUserCreateActive ) { |
| 831 |
return Status::newGood(); |
| 832 |
} |
| 833 |
$status = $this->tempUserCreator->create( |
| 834 |
$this->tempUserName, |
| 835 |
$this->context->getRequest() |
| 836 |
); |
| 837 |
if ( $status->isOK() ) { |
| 838 |
$this->placeholderTempUser = null; |
| 839 |
$this->unsavedTempUser = null; |
| 840 |
$this->savedTempUser = $status->getUser(); |
| 841 |
$this->authManager->setRequestContextUserFromSessionUser(); |
| 842 |
$this->tempUserCreateDone = true; |
| 843 |
} |
| 844 |
return $status; |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
private function getAuthority(): Authority { |
| 859 |
return $this->getUserForPermissions(); |
| 860 |
} |
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
private function getUserForPermissions() { |
| 869 |
if ( $this->savedTempUser ) { |
| 870 |
return $this->savedTempUser; |
| 871 |
} elseif ( $this->unsavedTempUser ) { |
| 872 |
return $this->unsavedTempUser; |
| 873 |
} elseif ( $this->placeholderTempUser ) { |
| 874 |
return $this->placeholderTempUser; |
| 875 |
} else { |
| 876 |
return $this->context->getUser(); |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
private function getUserForPreview() { |
| 887 |
if ( $this->savedTempUser ) { |
| 888 |
return $this->savedTempUser; |
| 889 |
} elseif ( $this->unsavedTempUser ) { |
| 890 |
return $this->unsavedTempUser; |
| 891 |
} elseif ( $this->firsttime && $this->placeholderTempUser ) { |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
return $this->placeholderTempUser; |
| 896 |
} elseif ( $this->tempUserCreateActive ) { |
| 897 |
throw new BadMethodCallException( |
| 898 |
"Can't use the request user for preview with IP masking enabled" ); |
| 899 |
} else { |
| 900 |
return $this->context->getUser(); |
| 901 |
} |
| 902 |
} |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
private function getUserForSave() { |
| 911 |
if ( $this->savedTempUser ) { |
| 912 |
return $this->savedTempUser; |
| 913 |
} elseif ( $this->tempUserCreateActive ) { |
| 914 |
throw new BadMethodCallException( |
| 915 |
"Can't use the request user for storage with IP masking enabled" ); |
| 916 |
} else { |
| 917 |
return $this->context->getUser(); |
| 918 |
} |
| 919 |
} |
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
private function getEditPermissionStatus( string $rigor = PermissionManager::RIGOR_SECURE ): PermissionStatus { |
| 926 |
$user = $this->getUserForPermissions(); |
| 927 |
return $this->permManager->getPermissionStatus( |
| 928 |
'edit', |
| 929 |
$user, |
| 930 |
$this->mTitle, |
| 931 |
$rigor |
| 932 |
); |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
private function displayPermissionStatus( PermissionStatus $status ): void { |
| 947 |
$out = $this->context->getOutput(); |
| 948 |
if ( $this->context->getRequest()->getBool( 'redlink' ) ) { |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
$out->redirect( $this->mTitle->getFullURL() ); |
| 953 |
return; |
| 954 |
} |
| 955 |
|
| 956 |
$content = $this->getContentObject(); |
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
if ( !$content || ( $this->firsttime && $content->isEmpty() ) ) { |
| 963 |
$action = $this->mTitle->exists() ? 'edit' : |
| 964 |
( $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage' ); |
| 965 |
throw new PermissionsError( $action, $status ); |
| 966 |
} |
| 967 |
|
| 968 |
$this->displayViewSourcePage( |
| 969 |
$content, |
| 970 |
$out->formatPermissionStatus( $status, 'edit' ) |
| 971 |
); |
| 972 |
} |
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
private function displayViewSourcePage( Content $content, string $errorMessage ): void { |
| 980 |
$out = $this->context->getOutput(); |
| 981 |
$this->getHookRunner()->onEditPage__showReadOnlyForm_initial( $this, $out ); |
| 982 |
|
| 983 |
$out->setRobotPolicy( 'noindex,nofollow' ); |
| 984 |
$out->setPageTitleMsg( $this->context->msg( |
| 985 |
'viewsource-title' |
| 986 |
)->plaintextParams( |
| 987 |
$this->getContextTitle()->getPrefixedText() |
| 988 |
) ); |
| 989 |
$out->addBacklinkSubtitle( $this->getContextTitle() ); |
| 990 |
$out->addHTML( $this->editFormPageTop ); |
| 991 |
$out->addHTML( $this->editFormTextTop ); |
| 992 |
|
| 993 |
if ( $errorMessage !== '' ) { |
| 994 |
$out->addWikiTextAsInterface( $errorMessage ); |
| 995 |
$out->addHTML( "<hr />\n" ); |
| 996 |
} |
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
if ( !$this->firsttime ) { |
| 1001 |
$text = $this->textbox1; |
| 1002 |
$out->addWikiMsg( 'viewyourtext' ); |
| 1003 |
} else { |
| 1004 |
try { |
| 1005 |
$text = $this->toEditText( $content ); |
| 1006 |
} catch ( MWException $e ) { |
| 1007 |
|
| 1008 |
|
| 1009 |
$text = $content->serialize(); |
| 1010 |
} |
| 1011 |
$out->addWikiMsg( 'viewsourcetext' ); |
| 1012 |
} |
| 1013 |
|
| 1014 |
$out->addHTML( $this->editFormTextBeforeContent ); |
| 1015 |
$this->showTextbox( $text, 'wpTextbox1', [ 'readonly' ] ); |
| 1016 |
$out->addHTML( $this->editFormTextAfterContent ); |
| 1017 |
|
| 1018 |
$out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) ); |
| 1019 |
|
| 1020 |
$out->addModules( 'mediawiki.action.edit.collapsibleFooter' ); |
| 1021 |
|
| 1022 |
$out->addHTML( $this->editFormTextBottom ); |
| 1023 |
if ( $this->mTitle->exists() ) { |
| 1024 |
$out->returnToMain( null, $this->mTitle ); |
| 1025 |
} |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
protected function previewOnOpen() { |
| 1034 |
$config = $this->context->getConfig(); |
| 1035 |
$previewOnOpenNamespaces = $config->get( MainConfigNames::PreviewOnOpenNamespaces ); |
| 1036 |
$request = $this->context->getRequest(); |
| 1037 |
if ( $config->get( MainConfigNames::RawHtml ) ) { |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
return false; |
| 1042 |
} |
| 1043 |
if ( $request->getVal( 'preview' ) === 'yes' ) { |
| 1044 |
|
| 1045 |
return true; |
| 1046 |
} elseif ( $request->getVal( 'preview' ) === 'no' ) { |
| 1047 |
|
| 1048 |
return false; |
| 1049 |
} elseif ( $this->section === 'new' ) { |
| 1050 |
|
| 1051 |
return false; |
| 1052 |
} elseif ( ( $request->getCheck( 'preload' ) || $this->mTitle->exists() ) |
| 1053 |
&& $this->userOptionsLookup->getOption( $this->context->getUser(), 'previewonfirst' ) |
| 1054 |
) { |
| 1055 |
|
| 1056 |
return true; |
| 1057 |
} elseif ( !$this->mTitle->exists() |
| 1058 |
&& isset( $previewOnOpenNamespaces[$this->mTitle->getNamespace()] ) |
| 1059 |
&& $previewOnOpenNamespaces[$this->mTitle->getNamespace()] |
| 1060 |
) { |
| 1061 |
|
| 1062 |
return true; |
| 1063 |
} else { |
| 1064 |
return false; |
| 1065 |
} |
| 1066 |
} |
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
private function isSectionEditSupported(): bool { |
| 1075 |
$currentRev = $this->page->getRevisionRecord(); |
| 1076 |
|
| 1077 |
|
| 1078 |
$revContentModel = $currentRev |
| 1079 |
? $currentRev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel() |
| 1080 |
: $this->page->getContentModel(); |
| 1081 |
|
| 1082 |
return ( |
| 1083 |
( $this->mArticle->getRevIdFetched() === $this->page->getLatest() ) && |
| 1084 |
$this->contentHandlerFactory->getContentHandler( $revContentModel )->supportsSections() |
| 1085 |
); |
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
public function importFormData( &$request ) { |
| 1094 |
|
| 1095 |
$this->section = $request->getVal( 'wpSection', $request->getVal( 'section', '' ) ); |
| 1096 |
|
| 1097 |
if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) { |
| 1098 |
throw new ErrorPageError( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' ); |
| 1099 |
} |
| 1100 |
|
| 1101 |
$this->isNew = !$this->mTitle->exists() || $this->section === 'new'; |
| 1102 |
|
| 1103 |
if ( $request->wasPosted() ) { |
| 1104 |
$this->importFormDataPosted( $request ); |
| 1105 |
} else { |
| 1106 |
|
| 1107 |
wfDebug( __METHOD__ . ": Not a posted form." ); |
| 1108 |
$this->textbox1 = ''; |
| 1109 |
$this->summary = ''; |
| 1110 |
$this->sectiontitle = null; |
| 1111 |
$this->edittime = ''; |
| 1112 |
$this->editRevId = null; |
| 1113 |
$this->starttime = wfTimestampNow(); |
| 1114 |
$this->edit = false; |
| 1115 |
$this->preview = false; |
| 1116 |
$this->save = false; |
| 1117 |
$this->diff = false; |
| 1118 |
$this->minoredit = false; |
| 1119 |
|
| 1120 |
$this->watchthis = $request->getBool( 'watchthis', false ); |
| 1121 |
if ( $this->watchlistExpiryEnabled ) { |
| 1122 |
$this->watchlistExpiry = null; |
| 1123 |
} |
| 1124 |
$this->recreate = false; |
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
if ( $this->section === 'new' && $request->getCheck( 'preloadtitle' ) ) { |
| 1129 |
$this->sectiontitle = $request->getVal( 'preloadtitle' ); |
| 1130 |
$this->setNewSectionSummary(); |
| 1131 |
} elseif ( $this->section !== 'new' && $request->getVal( 'summary' ) !== '' ) { |
| 1132 |
$this->summary = $request->getText( 'summary' ); |
| 1133 |
if ( $this->summary !== '' ) { |
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
$this->autoSumm = md5( '' ); |
| 1138 |
} |
| 1139 |
} |
| 1140 |
|
| 1141 |
if ( $request->getVal( 'minor' ) ) { |
| 1142 |
$this->minoredit = true; |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
$this->oldid = $request->getInt( 'oldid' ); |
| 1147 |
$this->parentRevId = $request->getInt( 'parentRevId' ); |
| 1148 |
|
| 1149 |
$this->markAsBot = $request->getBool( 'bot', true ); |
| 1150 |
$this->nosummary = $request->getBool( 'nosummary' ); |
| 1151 |
|
| 1152 |
|
| 1153 |
$this->contentModel = $request->getText( 'model', $this->contentModel ); |
| 1154 |
|
| 1155 |
$this->contentFormat = $request->getText( 'format', $this->contentFormat ); |
| 1156 |
|
| 1157 |
try { |
| 1158 |
$handler = $this->contentHandlerFactory->getContentHandler( $this->contentModel ); |
| 1159 |
} catch ( MWUnknownContentModelException $e ) { |
| 1160 |
throw new ErrorPageError( |
| 1161 |
'editpage-invalidcontentmodel-title', |
| 1162 |
'editpage-invalidcontentmodel-text', |
| 1163 |
[ wfEscapeWikiText( $this->contentModel ) ] |
| 1164 |
); |
| 1165 |
} |
| 1166 |
|
| 1167 |
if ( !$handler->isSupportedFormat( $this->contentFormat ) ) { |
| 1168 |
throw new ErrorPageError( |
| 1169 |
'editpage-notsupportedcontentformat-title', |
| 1170 |
'editpage-notsupportedcontentformat-text', |
| 1171 |
[ |
| 1172 |
wfEscapeWikiText( $this->contentFormat ), |
| 1173 |
wfEscapeWikiText( ContentHandler::getLocalizedName( $this->contentModel ) ) |
| 1174 |
] |
| 1175 |
); |
| 1176 |
} |
| 1177 |
|
| 1178 |
|
| 1179 |
$this->getHookRunner()->onEditPage__importFormData( $this, $request ); |
| 1180 |
} |
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
private function importFormDataPosted( WebRequest $request ): void { |
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
$this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) ); |
| 1190 |
if ( !$request->getCheck( 'wpTextbox2' ) ) { |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
$textbox1 = $this->importContentFormData( $request ); |
| 1195 |
if ( $textbox1 !== null ) { |
| 1196 |
$this->textbox1 = $textbox1; |
| 1197 |
} |
| 1198 |
} |
| 1199 |
|
| 1200 |
$this->unicodeCheck = $request->getText( 'wpUnicodeCheck' ); |
| 1201 |
|
| 1202 |
if ( $this->section === 'new' ) { |
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
if ( $request->getCheck( 'wpSectionTitle' ) ) { |
| 1209 |
$this->sectiontitle = $request->getText( 'wpSectionTitle' ); |
| 1210 |
if ( $request->getCheck( 'wpSummary' ) ) { |
| 1211 |
$this->summary = $request->getText( 'wpSummary' ); |
| 1212 |
} |
| 1213 |
} else { |
| 1214 |
$this->sectiontitle = $request->getText( 'wpSummary' ); |
| 1215 |
} |
| 1216 |
} else { |
| 1217 |
$this->sectiontitle = null; |
| 1218 |
$this->summary = $request->getText( 'wpSummary' ); |
| 1219 |
} |
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
$this->summary = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary ); |
| 1227 |
if ( $this->sectiontitle !== null ) { |
| 1228 |
$this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle ); |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
if ( $this->section === 'new' ) { |
| 1233 |
$this->setNewSectionSummary(); |
| 1234 |
} |
| 1235 |
|
| 1236 |
$this->edittime = $request->getVal( 'wpEdittime' ); |
| 1237 |
$this->editRevId = $request->getIntOrNull( 'editRevId' ); |
| 1238 |
$this->starttime = $request->getVal( 'wpStarttime' ); |
| 1239 |
|
| 1240 |
$undidRev = $request->getInt( 'wpUndidRevision' ); |
| 1241 |
if ( $undidRev ) { |
| 1242 |
$this->undidRev = $undidRev; |
| 1243 |
} |
| 1244 |
$undoAfter = $request->getInt( 'wpUndoAfter' ); |
| 1245 |
if ( $undoAfter ) { |
| 1246 |
$this->undoAfter = $undoAfter; |
| 1247 |
} |
| 1248 |
|
| 1249 |
$this->scrolltop = $request->getIntOrNull( 'wpScrolltop' ); |
| 1250 |
|
| 1251 |
if ( $this->textbox1 === '' && !$request->getCheck( 'wpTextbox1' ) ) { |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
$this->incompleteForm = true; |
| 1256 |
} else { |
| 1257 |
|
| 1258 |
|
| 1259 |
$this->incompleteForm = !$request->getVal( 'wpUltimateParam' ); |
| 1260 |
} |
| 1261 |
if ( $this->incompleteForm ) { |
| 1262 |
|
| 1263 |
wfDebug( __METHOD__ . ": Form data appears to be incomplete" ); |
| 1264 |
wfDebug( "POST DATA: " . var_export( $request->getPostValues(), true ) ); |
| 1265 |
$this->preview = true; |
| 1266 |
} else { |
| 1267 |
$this->preview = $request->getCheck( 'wpPreview' ); |
| 1268 |
$this->diff = $request->getCheck( 'wpDiff' ); |
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
$this->mTriedSave = !$this->preview; |
| 1273 |
|
| 1274 |
if ( $this->tokenOk( $request ) ) { |
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
wfDebug( __METHOD__ . ": Passed token check." ); |
| 1280 |
} elseif ( $this->diff ) { |
| 1281 |
|
| 1282 |
wfDebug( __METHOD__ . ": Failed token check; Show Changes requested." ); |
| 1283 |
} else { |
| 1284 |
|
| 1285 |
|
| 1286 |
wfDebug( __METHOD__ . ": Failed token check; forcing preview" ); |
| 1287 |
$this->preview = true; |
| 1288 |
} |
| 1289 |
} |
| 1290 |
$this->save = !$this->preview && !$this->diff; |
| 1291 |
if ( !$this->edittime || !preg_match( '/^\d{14}$/', $this->edittime ) ) { |
| 1292 |
$this->edittime = null; |
| 1293 |
} |
| 1294 |
|
| 1295 |
if ( !$this->starttime || !preg_match( '/^\d{14}$/', $this->starttime ) ) { |
| 1296 |
$this->starttime = null; |
| 1297 |
} |
| 1298 |
|
| 1299 |
$this->recreate = $request->getCheck( 'wpRecreate' ); |
| 1300 |
|
| 1301 |
$user = $this->context->getUser(); |
| 1302 |
|
| 1303 |
$this->minoredit = $request->getCheck( 'wpMinoredit' ); |
| 1304 |
$this->watchthis = $request->getCheck( 'wpWatchthis' ); |
| 1305 |
$expiry = $request->getText( 'wpWatchlistExpiry' ); |
| 1306 |
if ( $this->watchlistExpiryEnabled && $expiry !== '' ) { |
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
$expiry = ExpiryDef::normalizeExpiry( $expiry, TS_ISO_8601 ); |
| 1312 |
if ( $expiry !== false ) { |
| 1313 |
$this->watchlistExpiry = $expiry; |
| 1314 |
} |
| 1315 |
} |
| 1316 |
|
| 1317 |
|
| 1318 |
if ( ( $this->mTitle->getNamespace() === NS_USER || $this->mTitle->getNamespace() === NS_USER_TALK ) |
| 1319 |
&& $this->mTitle->getText() === $user->getName() |
| 1320 |
) { |
| 1321 |
$this->allowBlankSummary = true; |
| 1322 |
} else { |
| 1323 |
$this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' ) |
| 1324 |
|| !$this->userOptionsLookup->getOption( $user, 'forceeditsummary' ); |
| 1325 |
} |
| 1326 |
|
| 1327 |
$this->autoSumm = $request->getText( 'wpAutoSummary' ); |
| 1328 |
|
| 1329 |
$this->allowBlankArticle = $request->getBool( 'wpIgnoreBlankArticle' ); |
| 1330 |
$this->allowSelfRedirect = $request->getBool( 'wpIgnoreSelfRedirect' ); |
| 1331 |
|
| 1332 |
$changeTags = $request->getVal( 'wpChangeTags' ); |
| 1333 |
if ( $changeTags === null || $changeTags === '' ) { |
| 1334 |
$this->changeTags = []; |
| 1335 |
} else { |
| 1336 |
$this->changeTags = array_filter( |
| 1337 |
array_map( |
| 1338 |
'trim', |
| 1339 |
explode( ',', $changeTags ) |
| 1340 |
) |
| 1341 |
); |
| 1342 |
} |
| 1343 |
} |
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
protected function importContentFormData( &$request ) { |
| 1355 |
return null; |
| 1356 |
} |
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
private function initialiseForm(): bool { |
| 1364 |
$this->edittime = $this->page->getTimestamp(); |
| 1365 |
$this->editRevId = $this->page->getLatest(); |
| 1366 |
|
| 1367 |
$dummy = $this->contentHandlerFactory |
| 1368 |
->getContentHandler( $this->contentModel ) |
| 1369 |
->makeEmptyContent(); |
| 1370 |
$content = $this->getContentObject( $dummy ); |
| 1371 |
if ( $content === $dummy ) { |
| 1372 |
$this->noSuchSectionPage(); |
| 1373 |
return false; |
| 1374 |
} |
| 1375 |
|
| 1376 |
if ( !$content ) { |
| 1377 |
$out = $this->context->getOutput(); |
| 1378 |
$this->editFormPageTop .= Html::errorBox( |
| 1379 |
$out->parseAsInterface( $this->context->msg( 'missing-revision-content', |
| 1380 |
$this->oldid, |
| 1381 |
Message::plaintextParam( $this->mTitle->getPrefixedText() ) |
| 1382 |
) ) |
| 1383 |
); |
| 1384 |
} elseif ( !$this->isSupportedContentModel( $content->getModel() ) ) { |
| 1385 |
$modelMsg = $this->getContext()->msg( 'content-model-' . $content->getModel() ); |
| 1386 |
$modelName = $modelMsg->exists() ? $modelMsg->text() : $content->getModel(); |
| 1387 |
|
| 1388 |
$out = $this->context->getOutput(); |
| 1389 |
$out->showErrorPage( |
| 1390 |
'modeleditnotsupported-title', |
| 1391 |
'modeleditnotsupported-text', |
| 1392 |
[ $modelName ] |
| 1393 |
); |
| 1394 |
return false; |
| 1395 |
} |
| 1396 |
|
| 1397 |
try { |
| 1398 |
$this->textbox1 = $this->toEditText( $content ); |
| 1399 |
} catch ( MWException ) { |
| 1400 |
|
| 1401 |
$this->textbox1 = $content->serialize(); |
| 1402 |
} |
| 1403 |
|
| 1404 |
$user = $this->context->getUser(); |
| 1405 |
|
| 1406 |
|
| 1407 |
if ( $this->userOptionsLookup->getOption( $user, 'watchdefault' ) ) { |
| 1408 |
|
| 1409 |
$this->watchthis = true; |
| 1410 |
} elseif ( $this->userOptionsLookup->getOption( $user, 'watchcreations' ) && !$this->mTitle->exists() ) { |
| 1411 |
|
| 1412 |
$this->watchthis = true; |
| 1413 |
} elseif ( $this->watchlistManager->isWatched( $user, $this->mTitle ) ) { |
| 1414 |
|
| 1415 |
$this->watchthis = true; |
| 1416 |
} |
| 1417 |
if ( $this->watchthis && $this->watchlistExpiryEnabled ) { |
| 1418 |
$watchedItem = $this->watchedItemStore->getWatchedItem( $user, $this->getTitle() ); |
| 1419 |
$this->watchlistExpiry = $watchedItem ? $watchedItem->getExpiry() : null; |
| 1420 |
} |
| 1421 |
if ( !$this->isNew && $this->userOptionsLookup->getOption( $user, 'minordefault' ) ) { |
| 1422 |
$this->minoredit = true; |
| 1423 |
} |
| 1424 |
if ( $this->textbox1 === false ) { |
| 1425 |
return false; |
| 1426 |
} |
| 1427 |
return true; |
| 1428 |
} |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
protected function getContentObject( $defaultContent = null ) { |
| 1436 |
$services = MediaWikiServices::getInstance(); |
| 1437 |
$request = $this->context->getRequest(); |
| 1438 |
|
| 1439 |
$content = false; |
| 1440 |
|
| 1441 |
|
| 1442 |
if ( !$this->mTitle->exists() || $this->section === 'new' ) { |
| 1443 |
$content = $services->getPreloadedContentBuilder()->getPreloadedContent( |
| 1444 |
$this->mTitle->toPageIdentity(), |
| 1445 |
$this->context->getUser(), |
| 1446 |
$request->getVal( 'preload' ), |
| 1447 |
$request->getArray( 'preloadparams', [] ), |
| 1448 |
$request->getVal( 'section' ) |
| 1449 |
); |
| 1450 |
|
| 1451 |
} elseif ( $this->section !== '' ) { |
| 1452 |
|
| 1453 |
$orig = $this->getOriginalContent( $this->getAuthority() ); |
| 1454 |
$content = $orig ? $orig->getSection( $this->section ) : null; |
| 1455 |
|
| 1456 |
if ( !$content ) { |
| 1457 |
$content = $defaultContent; |
| 1458 |
} |
| 1459 |
} else { |
| 1460 |
$undoafter = $request->getInt( 'undoafter' ); |
| 1461 |
$undo = $request->getInt( 'undo' ); |
| 1462 |
|
| 1463 |
if ( $undo > 0 && $undoafter > 0 ) { |
| 1464 |
|
| 1465 |
|
| 1466 |
$undorev = $this->revisionStore->getRevisionByTitle( $this->mTitle, $undo ); |
| 1467 |
$oldrev = $this->revisionStore->getRevisionByTitle( $this->mTitle, $undoafter ); |
| 1468 |
$undoMsg = null; |
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
if ( $undorev !== null && $oldrev !== null && |
| 1474 |
!$undorev->isDeleted( RevisionRecord::DELETED_TEXT ) && |
| 1475 |
!$oldrev->isDeleted( RevisionRecord::DELETED_TEXT ) |
| 1476 |
) { |
| 1477 |
if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev ) |
| 1478 |
|| !$this->isSupportedContentModel( |
| 1479 |
$oldrev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel() |
| 1480 |
) |
| 1481 |
) { |
| 1482 |
|
| 1483 |
$this->context->getOutput()->redirect( $this->mTitle->getFullURL( [ |
| 1484 |
'action' => 'mcrundo', |
| 1485 |
'undo' => $undo, |
| 1486 |
'undoafter' => $undoafter, |
| 1487 |
] ) ); |
| 1488 |
return false; |
| 1489 |
} else { |
| 1490 |
$content = $this->getUndoContent( $undorev, $oldrev, $undoMsg ); |
| 1491 |
} |
| 1492 |
|
| 1493 |
if ( $undoMsg === null ) { |
| 1494 |
$oldContent = $this->page->getContent( RevisionRecord::RAW ); |
| 1495 |
$parserOptions = ParserOptions::newFromUserAndLang( |
| 1496 |
$this->getUserForPreview(), |
| 1497 |
$services->getContentLanguage() |
| 1498 |
); |
| 1499 |
$contentTransformer = $services->getContentTransformer(); |
| 1500 |
$newContent = $contentTransformer->preSaveTransform( |
| 1501 |
$content, $this->mTitle, $this->getUserForPreview(), $parserOptions |
| 1502 |
); |
| 1503 |
|
| 1504 |
if ( $newContent->getModel() !== $oldContent->getModel() ) { |
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
$this->contentModel = $newContent->getModel(); |
| 1510 |
$oldMainSlot = $oldrev->getSlot( |
| 1511 |
SlotRecord::MAIN, |
| 1512 |
RevisionRecord::RAW |
| 1513 |
); |
| 1514 |
$this->contentFormat = $oldMainSlot->getFormat(); |
| 1515 |
if ( $this->contentFormat === null ) { |
| 1516 |
$this->contentFormat = $this->contentHandlerFactory |
| 1517 |
->getContentHandler( $oldMainSlot->getModel() ) |
| 1518 |
->getDefaultFormat(); |
| 1519 |
} |
| 1520 |
} |
| 1521 |
|
| 1522 |
if ( $newContent->equals( $oldContent ) ) { |
| 1523 |
|
| 1524 |
|
| 1525 |
$undoMsg = 'nochange'; |
| 1526 |
$content = false; |
| 1527 |
} else { |
| 1528 |
|
| 1529 |
$undoMsg = 'success'; |
| 1530 |
$this->generateUndoEditSummary( $oldrev, $undo, $undorev, $services ); |
| 1531 |
$this->undidRev = $undo; |
| 1532 |
$this->undoAfter = $undoafter; |
| 1533 |
$this->formtype = 'diff'; |
| 1534 |
} |
| 1535 |
} |
| 1536 |
} else { |
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
$undoMsg = 'norev'; |
| 1541 |
} |
| 1542 |
|
| 1543 |
$out = $this->context->getOutput(); |
| 1544 |
|
| 1545 |
|
| 1546 |
$class = ( $undoMsg === 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}"; |
| 1547 |
$this->editFormPageTop .= Html::rawElement( |
| 1548 |
'div', |
| 1549 |
[ 'class' => $class ], |
| 1550 |
$out->parseAsInterface( |
| 1551 |
$this->context->msg( 'undo-' . $undoMsg )->plain() |
| 1552 |
) |
| 1553 |
); |
| 1554 |
} |
| 1555 |
|
| 1556 |
if ( $content === false ) { |
| 1557 |
$content = $this->getOriginalContent( $this->getAuthority() ); |
| 1558 |
} |
| 1559 |
} |
| 1560 |
|
| 1561 |
return $content; |
| 1562 |
} |
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
private function generateUndoEditSummary( ?RevisionRecord $oldrev, int $undo, |
| 1575 |
?RevisionRecord $undorev, MediaWikiServices $services |
| 1576 |
) { |
| 1577 |
|
| 1578 |
$firstrev = $this->revisionStore->getNextRevision( $oldrev ); |
| 1579 |
if ( $firstrev && $firstrev->getId() == $undo ) { |
| 1580 |
$userText = $undorev->getUser() ? |
| 1581 |
$undorev->getUser()->getName() : |
| 1582 |
''; |
| 1583 |
if ( $userText === '' ) { |
| 1584 |
$undoSummary = $this->context->msg( |
| 1585 |
'undo-summary-username-hidden', |
| 1586 |
$undo |
| 1587 |
)->inContentLanguage()->text(); |
| 1588 |
|
| 1589 |
} elseif ( ExternalUserNames::isExternal( $userText ) ) { |
| 1590 |
$userLinkTitle = ExternalUserNames::getUserLinkTitle( $userText ); |
| 1591 |
if ( $userLinkTitle ) { |
| 1592 |
$userLink = $userLinkTitle->getPrefixedText(); |
| 1593 |
$undoSummary = $this->context->msg( |
| 1594 |
'undo-summary-import', |
| 1595 |
$undo, |
| 1596 |
$userLink, |
| 1597 |
$userText |
| 1598 |
)->inContentLanguage()->text(); |
| 1599 |
} else { |
| 1600 |
$undoSummary = $this->context->msg( |
| 1601 |
'undo-summary-import2', |
| 1602 |
$undo, |
| 1603 |
$userText |
| 1604 |
)->inContentLanguage()->text(); |
| 1605 |
} |
| 1606 |
} else { |
| 1607 |
$undoIsAnon = |
| 1608 |
!$undorev->getUser() || |
| 1609 |
!$undorev->getUser()->isRegistered(); |
| 1610 |
$disableAnonTalk = $services->getMainConfig()->get( MainConfigNames::DisableAnonTalk ); |
| 1611 |
$undoMessage = ( $undoIsAnon && $disableAnonTalk ) ? |
| 1612 |
'undo-summary-anon' : |
| 1613 |
'undo-summary'; |
| 1614 |
$undoSummary = $this->context->msg( |
| 1615 |
$undoMessage, |
| 1616 |
$undo, |
| 1617 |
$userText |
| 1618 |
)->inContentLanguage()->text(); |
| 1619 |
} |
| 1620 |
if ( $this->summary === '' ) { |
| 1621 |
$this->summary = $undoSummary; |
| 1622 |
} else { |
| 1623 |
$this->summary = $undoSummary . $this->context->msg( 'colon-separator' ) |
| 1624 |
->inContentLanguage()->text() . $this->summary; |
| 1625 |
} |
| 1626 |
} |
| 1627 |
} |
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
private function getUndoContent( RevisionRecord $undoRev, RevisionRecord $oldRev, &$error ) { |
| 1643 |
$handler = $this->contentHandlerFactory |
| 1644 |
->getContentHandler( $undoRev->getSlot( |
| 1645 |
SlotRecord::MAIN, |
| 1646 |
RevisionRecord::RAW |
| 1647 |
)->getModel() ); |
| 1648 |
$currentContent = $this->page->getRevisionRecord() |
| 1649 |
->getContent( SlotRecord::MAIN ); |
| 1650 |
$undoContent = $undoRev->getContent( SlotRecord::MAIN ); |
| 1651 |
$undoAfterContent = $oldRev->getContent( SlotRecord::MAIN ); |
| 1652 |
$undoIsLatest = $this->page->getRevisionRecord()->getId() === $undoRev->getId(); |
| 1653 |
if ( $currentContent === null |
| 1654 |
|| $undoContent === null |
| 1655 |
|| $undoAfterContent === null |
| 1656 |
) { |
| 1657 |
$error = 'norev'; |
| 1658 |
return false; |
| 1659 |
} |
| 1660 |
|
| 1661 |
$content = $handler->getUndoContent( |
| 1662 |
$currentContent, |
| 1663 |
$undoContent, |
| 1664 |
$undoAfterContent, |
| 1665 |
$undoIsLatest |
| 1666 |
); |
| 1667 |
if ( $content === false ) { |
| 1668 |
$error = 'failure'; |
| 1669 |
} |
| 1670 |
return $content; |
| 1671 |
} |
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
private function getOriginalContent( Authority $performer ): ?Content { |
| 1688 |
if ( $this->section === 'new' ) { |
| 1689 |
return $this->getCurrentContent(); |
| 1690 |
} |
| 1691 |
$revRecord = $this->mArticle->fetchRevisionRecord(); |
| 1692 |
if ( $revRecord === null ) { |
| 1693 |
return $this->contentHandlerFactory |
| 1694 |
->getContentHandler( $this->contentModel ) |
| 1695 |
->makeEmptyContent(); |
| 1696 |
} |
| 1697 |
return $revRecord->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $performer ); |
| 1698 |
} |
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
private function getParentRevId() { |
| 1712 |
if ( $this->parentRevId ) { |
| 1713 |
return $this->parentRevId; |
| 1714 |
} else { |
| 1715 |
return $this->mArticle->getRevIdFetched(); |
| 1716 |
} |
| 1717 |
} |
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
protected function getCurrentContent() { |
| 1728 |
$revRecord = $this->page->getRevisionRecord(); |
| 1729 |
$content = $revRecord ? $revRecord->getContent( |
| 1730 |
SlotRecord::MAIN, |
| 1731 |
RevisionRecord::RAW |
| 1732 |
) : null; |
| 1733 |
|
| 1734 |
if ( $content === null ) { |
| 1735 |
return $this->contentHandlerFactory |
| 1736 |
->getContentHandler( $this->contentModel ) |
| 1737 |
->makeEmptyContent(); |
| 1738 |
} |
| 1739 |
|
| 1740 |
return $content; |
| 1741 |
} |
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
private function tokenOk( WebRequest $request ): bool { |
| 1750 |
$token = $request->getVal( 'wpEditToken' ); |
| 1751 |
$user = $this->context->getUser(); |
| 1752 |
$this->mTokenOk = $user->matchEditToken( $token ); |
| 1753 |
return $this->mTokenOk; |
| 1754 |
} |
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
private function setPostEditCookie( int $statusValue ): void { |
| 1771 |
$revisionId = $this->page->getLatest(); |
| 1772 |
$postEditKey = self::POST_EDIT_COOKIE_KEY_PREFIX . $revisionId; |
| 1773 |
|
| 1774 |
$val = 'saved'; |
| 1775 |
if ( $statusValue === self::AS_SUCCESS_NEW_ARTICLE ) { |
| 1776 |
$val = 'created'; |
| 1777 |
} elseif ( $this->oldid ) { |
| 1778 |
$val = 'restored'; |
| 1779 |
} |
| 1780 |
if ( $this->tempUserCreateDone ) { |
| 1781 |
$val .= '+tempuser'; |
| 1782 |
} |
| 1783 |
|
| 1784 |
$response = $this->context->getRequest()->response(); |
| 1785 |
$response->setCookie( $postEditKey, $val, time() + self::POST_EDIT_COOKIE_DURATION ); |
| 1786 |
} |
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
public function attemptSave( &$resultDetails = false ) { |
| 1795 |
|
| 1796 |
$markAsBot = $this->markAsBot |
| 1797 |
&& $this->getAuthority()->isAllowed( 'bot' ); |
| 1798 |
|
| 1799 |
|
| 1800 |
$markAsMinor = $this->minoredit && !$this->isNew |
| 1801 |
&& $this->getAuthority()->isAllowed( 'minoredit' ); |
| 1802 |
|
| 1803 |
$status = $this->internalAttemptSavePrivate( $resultDetails, $markAsBot, $markAsMinor ); |
| 1804 |
|
| 1805 |
$this->getHookRunner()->onEditPage__attemptSave_after( $this, $status, $resultDetails ); |
| 1806 |
|
| 1807 |
return $status; |
| 1808 |
} |
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
private function incrementResolvedConflicts(): void { |
| 1814 |
if ( $this->context->getRequest()->getText( 'mode' ) !== 'conflict' ) { |
| 1815 |
return; |
| 1816 |
} |
| 1817 |
|
| 1818 |
$this->getEditConflictHelper()->incrementResolvedStats( $this->context->getUser() ); |
| 1819 |
} |
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
private function handleStatus( Status $status, $resultDetails ): bool { |
| 1831 |
$statusValue = is_int( $status->value ) ? $status->value : 0; |
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
if ( $statusValue === self::AS_SUCCESS_UPDATE |
| 1838 |
|| $statusValue === self::AS_SUCCESS_NEW_ARTICLE |
| 1839 |
) { |
| 1840 |
$this->incrementResolvedConflicts(); |
| 1841 |
|
| 1842 |
$this->didSave = true; |
| 1843 |
if ( !$resultDetails['nullEdit'] ) { |
| 1844 |
$this->setPostEditCookie( $statusValue ); |
| 1845 |
} |
| 1846 |
} |
| 1847 |
|
| 1848 |
$out = $this->context->getOutput(); |
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
$request = $this->context->getRequest(); |
| 1853 |
$extraQueryRedirect = $request->getVal( 'wpExtraQueryRedirect' ); |
| 1854 |
|
| 1855 |
switch ( $statusValue ) { |
| 1856 |
case self::AS_HOOK_ERROR_EXPECTED: |
| 1857 |
case self::AS_CONTENT_TOO_BIG: |
| 1858 |
case self::AS_ARTICLE_WAS_DELETED: |
| 1859 |
case self::AS_CONFLICT_DETECTED: |
| 1860 |
case self::AS_SUMMARY_NEEDED: |
| 1861 |
case self::AS_TEXTBOX_EMPTY: |
| 1862 |
case self::AS_MAX_ARTICLE_SIZE_EXCEEDED: |
| 1863 |
case self::AS_END: |
| 1864 |
case self::AS_BLANK_ARTICLE: |
| 1865 |
case self::AS_SELF_REDIRECT: |
| 1866 |
case self::AS_REVISION_WAS_DELETED: |
| 1867 |
return true; |
| 1868 |
|
| 1869 |
case self::AS_HOOK_ERROR: |
| 1870 |
return false; |
| 1871 |
|
| 1872 |
case self::AS_PARSE_ERROR: |
| 1873 |
case self::AS_UNICODE_NOT_SUPPORTED: |
| 1874 |
case self::AS_UNABLE_TO_ACQUIRE_TEMP_ACCOUNT: |
| 1875 |
$out->wrapWikiTextAsInterface( 'error', |
| 1876 |
$status->getWikiText( false, false, $this->context->getLanguage() ) |
| 1877 |
); |
| 1878 |
return true; |
| 1879 |
|
| 1880 |
case self::AS_SUCCESS_NEW_ARTICLE: |
| 1881 |
$queryParts = []; |
| 1882 |
if ( $resultDetails['redirect'] ) { |
| 1883 |
$queryParts[] = 'redirect=no'; |
| 1884 |
} |
| 1885 |
if ( $extraQueryRedirect ) { |
| 1886 |
$queryParts[] = $extraQueryRedirect; |
| 1887 |
} |
| 1888 |
$anchor = $resultDetails['sectionanchor'] ?? ''; |
| 1889 |
$this->doPostEditRedirect( implode( '&', $queryParts ), $anchor ); |
| 1890 |
return false; |
| 1891 |
|
| 1892 |
case self::AS_SUCCESS_UPDATE: |
| 1893 |
$extraQuery = ''; |
| 1894 |
$sectionanchor = $resultDetails['sectionanchor']; |
| 1895 |
|
| 1896 |
$this->getHookRunner()->onArticleUpdateBeforeRedirect( $this->mArticle, |
| 1897 |
$sectionanchor, $extraQuery ); |
| 1898 |
|
| 1899 |
$queryParts = []; |
| 1900 |
if ( $resultDetails['redirect'] ) { |
| 1901 |
$queryParts[] = 'redirect=no'; |
| 1902 |
} |
| 1903 |
if ( $extraQuery ) { |
| 1904 |
$queryParts[] = $extraQuery; |
| 1905 |
} |
| 1906 |
if ( $extraQueryRedirect ) { |
| 1907 |
$queryParts[] = $extraQueryRedirect; |
| 1908 |
} |
| 1909 |
$this->doPostEditRedirect( implode( '&', $queryParts ), $sectionanchor ); |
| 1910 |
return false; |
| 1911 |
|
| 1912 |
case self::AS_SPAM_ERROR: |
| 1913 |
$this->spamPageWithContent( $resultDetails['spam'] ?? false ); |
| 1914 |
return false; |
| 1915 |
|
| 1916 |
case self::AS_BLOCKED_PAGE_FOR_USER: |
| 1917 |
throw new UserBlockedError( |
| 1918 |
|
| 1919 |
$this->context->getUser()->getBlock(), |
| 1920 |
$this->context->getUser(), |
| 1921 |
$this->context->getLanguage(), |
| 1922 |
$request->getIP() |
| 1923 |
); |
| 1924 |
|
| 1925 |
case self::AS_IMAGE_REDIRECT_ANON: |
| 1926 |
case self::AS_IMAGE_REDIRECT_LOGGED: |
| 1927 |
throw new PermissionsError( 'upload' ); |
| 1928 |
|
| 1929 |
case self::AS_READ_ONLY_PAGE_ANON: |
| 1930 |
case self::AS_READ_ONLY_PAGE_LOGGED: |
| 1931 |
throw new PermissionsError( 'edit' ); |
| 1932 |
|
| 1933 |
case self::AS_READ_ONLY_PAGE: |
| 1934 |
throw new ReadOnlyError; |
| 1935 |
|
| 1936 |
case self::AS_RATE_LIMITED: |
| 1937 |
$out->wrapWikiTextAsInterface( 'error', |
| 1938 |
wfMessage( 'actionthrottledtext' )->plain() |
| 1939 |
); |
| 1940 |
return true; |
| 1941 |
|
| 1942 |
case self::AS_NO_CREATE_PERMISSION: |
| 1943 |
$permission = $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage'; |
| 1944 |
throw new PermissionsError( $permission ); |
| 1945 |
|
| 1946 |
case self::AS_NO_CHANGE_CONTENT_MODEL: |
| 1947 |
throw new PermissionsError( 'editcontentmodel' ); |
| 1948 |
|
| 1949 |
default: |
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
$this->hookError = Html::errorBox( |
| 1955 |
"\n" . $status->getWikiText( false, false, $this->context->getLanguage() ) |
| 1956 |
); |
| 1957 |
return true; |
| 1958 |
} |
| 1959 |
} |
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
private function doPostEditRedirect( $query, $anchor ) { |
| 1969 |
$out = $this->context->getOutput(); |
| 1970 |
$url = $this->mTitle->getFullURL( $query ) . $anchor; |
| 1971 |
$user = $this->getUserForSave(); |
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
$shouldRedirectForTempUser = $this->tempUserCreateDone || |
| 1981 |
( $user->isTemp() && ( $user->getEditCount() === 0 ) ); |
| 1982 |
if ( $shouldRedirectForTempUser ) { |
| 1983 |
$this->getHookRunner()->onTempUserCreatedRedirect( |
| 1984 |
$this->context->getRequest()->getSession(), |
| 1985 |
$user, |
| 1986 |
$this->mTitle->getPrefixedDBkey(), |
| 1987 |
$query, |
| 1988 |
$anchor, |
| 1989 |
$url |
| 1990 |
); |
| 1991 |
} |
| 1992 |
$out->redirect( $url ); |
| 1993 |
} |
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
private function setNewSectionSummary(): void { |
| 1999 |
Assert::precondition( $this->section === 'new', 'This method can only be called for new sections' ); |
| 2000 |
Assert::precondition( $this->sectiontitle !== null, 'This method can only be called for new sections' ); |
| 2001 |
|
| 2002 |
$services = MediaWikiServices::getInstance(); |
| 2003 |
$parser = $services->getParser(); |
| 2004 |
$textFormatter = $services->getMessageFormatterFactory()->getTextFormatter( |
| 2005 |
$services->getContentLanguage()->getCode() |
| 2006 |
); |
| 2007 |
|
| 2008 |
if ( $this->sectiontitle !== '' ) { |
| 2009 |
$this->newSectionAnchor = $this->guessSectionName( $this->sectiontitle ); |
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
if ( $this->summary === '' ) { |
| 2014 |
$messageValue = MessageValue::new( 'newsectionsummary' ) |
| 2015 |
->plaintextParams( $parser->stripSectionName( $this->sectiontitle ) ); |
| 2016 |
$this->summary = $textFormatter->format( $messageValue ); |
| 2017 |
} |
| 2018 |
} else { |
| 2019 |
$this->newSectionAnchor = ''; |
| 2020 |
} |
| 2021 |
} |
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
public function internalAttemptSave( &$result, $markAsBot = false, $markAsMinor = false ) { |
| 2034 |
wfDeprecated( __METHOD__, '1.43' ); |
| 2035 |
return $this->internalAttemptSavePrivate( $result, $markAsBot, $markAsMinor ); |
| 2036 |
} |
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
private function internalAttemptSavePrivate( &$result, $markAsBot = false, $markAsMinor = false ) { |
| 2065 |
|
| 2066 |
if ( $this->unableToAcquireTempName ) { |
| 2067 |
$status = Status::newFatal( 'temp-user-unable-to-acquire' ); |
| 2068 |
$status->value = self::AS_UNABLE_TO_ACQUIRE_TEMP_ACCOUNT; |
| 2069 |
return $status; |
| 2070 |
} |
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
$tempAccountStatus = $this->createTempUser(); |
| 2078 |
if ( !$tempAccountStatus->isOK() ) { |
| 2079 |
return $tempAccountStatus; |
| 2080 |
} |
| 2081 |
if ( $tempAccountStatus instanceof CreateStatus ) { |
| 2082 |
$result['savedTempUser'] = $tempAccountStatus->getUser(); |
| 2083 |
} |
| 2084 |
|
| 2085 |
$useNPPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseNPPatrol ); |
| 2086 |
$useRCPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseRCPatrol ); |
| 2087 |
if ( !$this->getHookRunner()->onEditPage__attemptSave( $this ) ) { |
| 2088 |
wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" ); |
| 2089 |
$status = Status::newFatal( 'hookaborted' ); |
| 2090 |
$status->value = self::AS_HOOK_ERROR; |
| 2091 |
return $status; |
| 2092 |
} |
| 2093 |
|
| 2094 |
if ( !$this->getHookRunner()->onEditFilter( $this, $this->textbox1, $this->section, |
| 2095 |
$this->hookError, $this->summary ) |
| 2096 |
) { |
| 2097 |
|
| 2098 |
$status = Status::newFatal( 'hookaborted' ); |
| 2099 |
$status->value = self::AS_HOOK_ERROR; |
| 2100 |
return $status; |
| 2101 |
} elseif ( $this->hookError ) { |
| 2102 |
|
| 2103 |
$status = Status::newFatal( 'hookaborted' ); |
| 2104 |
$status->value = self::AS_HOOK_ERROR_EXPECTED; |
| 2105 |
return $status; |
| 2106 |
} |
| 2107 |
|
| 2108 |
try { |
| 2109 |
|
| 2110 |
$textbox_content = $this->toEditContent( $this->textbox1 ); |
| 2111 |
} catch ( MWContentSerializationException $ex ) { |
| 2112 |
$status = Status::newFatal( |
| 2113 |
'content-failed-to-parse', |
| 2114 |
$this->contentModel, |
| 2115 |
$this->contentFormat, |
| 2116 |
$ex->getMessage() |
| 2117 |
); |
| 2118 |
$status->value = self::AS_PARSE_ERROR; |
| 2119 |
return $status; |
| 2120 |
} |
| 2121 |
|
| 2122 |
$this->contentLength = strlen( $this->textbox1 ); |
| 2123 |
|
| 2124 |
$requestUser = $this->context->getUser(); |
| 2125 |
$authority = $this->getAuthority(); |
| 2126 |
$pstUser = $this->getUserForPreview(); |
| 2127 |
|
| 2128 |
$changingContentModel = false; |
| 2129 |
if ( $this->contentModel !== $this->mTitle->getContentModel() ) { |
| 2130 |
$changingContentModel = true; |
| 2131 |
$oldContentModel = $this->mTitle->getContentModel(); |
| 2132 |
} |
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
$constraintFactory = MediaWikiServices::getInstance()->getService( '_EditConstraintFactory' ); |
| 2137 |
$constraintRunner = new EditConstraintRunner(); |
| 2138 |
|
| 2139 |
|
| 2140 |
$constraintRunner->addConstraint( |
| 2141 |
new UnicodeConstraint( $this->unicodeCheck ) |
| 2142 |
); |
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
$constraintRunner->addConstraint( |
| 2148 |
$constraintFactory->newSimpleAntiSpamConstraint( |
| 2149 |
$this->context->getRequest()->getText( 'wpAntispam' ), |
| 2150 |
$requestUser, |
| 2151 |
$this->mTitle |
| 2152 |
) |
| 2153 |
); |
| 2154 |
|
| 2155 |
|
| 2156 |
$constraintRunner->addConstraint( |
| 2157 |
$constraintFactory->newSpamRegexConstraint( |
| 2158 |
$this->summary, |
| 2159 |
$this->sectiontitle, |
| 2160 |
$this->textbox1, |
| 2161 |
$this->context->getRequest()->getIP(), |
| 2162 |
$this->mTitle |
| 2163 |
) |
| 2164 |
); |
| 2165 |
$constraintRunner->addConstraint( |
| 2166 |
new ImageRedirectConstraint( |
| 2167 |
$textbox_content, |
| 2168 |
$this->mTitle, |
| 2169 |
$authority |
| 2170 |
) |
| 2171 |
); |
| 2172 |
$constraintRunner->addConstraint( |
| 2173 |
$constraintFactory->newUserBlockConstraint( $this->mTitle, $requestUser ) |
| 2174 |
); |
| 2175 |
$constraintRunner->addConstraint( |
| 2176 |
new ContentModelChangeConstraint( |
| 2177 |
$authority, |
| 2178 |
$this->mTitle, |
| 2179 |
$this->contentModel |
| 2180 |
) |
| 2181 |
); |
| 2182 |
|
| 2183 |
$constraintRunner->addConstraint( |
| 2184 |
$constraintFactory->newReadOnlyConstraint() |
| 2185 |
); |
| 2186 |
$constraintRunner->addConstraint( |
| 2187 |
$constraintFactory->newUserRateLimitConstraint( |
| 2188 |
$requestUser->toRateLimitSubject(), |
| 2189 |
$this->mTitle->getContentModel(), |
| 2190 |
$this->contentModel |
| 2191 |
) |
| 2192 |
); |
| 2193 |
$constraintRunner->addConstraint( |
| 2194 |
|
| 2195 |
|
| 2196 |
$constraintFactory->newPageSizeConstraint( |
| 2197 |
$this->contentLength, |
| 2198 |
PageSizeConstraint::BEFORE_MERGE |
| 2199 |
) |
| 2200 |
); |
| 2201 |
$constraintRunner->addConstraint( |
| 2202 |
new ChangeTagsConstraint( $authority, $this->changeTags ) |
| 2203 |
); |
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
$constraintRunner->addConstraint( |
| 2208 |
new AccidentalRecreationConstraint( |
| 2209 |
$this->wasDeletedSinceLastEdit(), |
| 2210 |
$this->recreate |
| 2211 |
) |
| 2212 |
); |
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
$this->page->loadPageData( IDBAccessObject::READ_LATEST ); |
| 2217 |
$new = !$this->page->exists(); |
| 2218 |
|
| 2219 |
|
| 2220 |
$constraintRunner->addConstraint( |
| 2221 |
$constraintFactory->newEditRightConstraint( $this->getUserForPermissions(), $this->mTitle, $new ) |
| 2222 |
); |
| 2223 |
|
| 2224 |
|
| 2225 |
if ( !$constraintRunner->checkConstraints() ) { |
| 2226 |
$failed = $constraintRunner->getFailedConstraint(); |
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
if ( $failed instanceof SpamRegexConstraint ) { |
| 2231 |
$result['spam'] = $failed->getMatch(); |
| 2232 |
} else { |
| 2233 |
$this->handleFailedConstraint( $failed ); |
| 2234 |
} |
| 2235 |
|
| 2236 |
return Status::wrap( $failed->getLegacyStatus() ); |
| 2237 |
} |
| 2238 |
|
| 2239 |
|
| 2240 |
$flags = EDIT_AUTOSUMMARY | |
| 2241 |
( $new ? EDIT_NEW : EDIT_UPDATE ) | |
| 2242 |
( $markAsMinor ? EDIT_MINOR : 0 ) | |
| 2243 |
( $markAsBot ? EDIT_FORCE_BOT : 0 ); |
| 2244 |
|
| 2245 |
if ( $new ) { |
| 2246 |
$content = $textbox_content; |
| 2247 |
|
| 2248 |
$result['sectionanchor'] = ''; |
| 2249 |
if ( $this->section === 'new' ) { |
| 2250 |
if ( $this->sectiontitle !== null ) { |
| 2251 |
|
| 2252 |
$content = $content->addSectionHeader( $this->sectiontitle ); |
| 2253 |
} |
| 2254 |
$result['sectionanchor'] = $this->newSectionAnchor; |
| 2255 |
} |
| 2256 |
|
| 2257 |
$pageUpdater = $this->page->newPageUpdater( $pstUser ) |
| 2258 |
|
| 2259 |
->setContent( SlotRecord::MAIN, $content ); |
| 2260 |
$pageUpdater->prepareUpdate( $flags ); |
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
$constraintRunner = new EditConstraintRunner(); |
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
$constraintRunner->addConstraint( |
| 2270 |
new DefaultTextConstraint( |
| 2271 |
$this->mTitle, |
| 2272 |
$this->allowBlankArticle, |
| 2273 |
$this->textbox1 |
| 2274 |
) |
| 2275 |
); |
| 2276 |
|
| 2277 |
$constraintRunner->addConstraint( |
| 2278 |
$constraintFactory->newEditFilterMergedContentHookConstraint( |
| 2279 |
$content, |
| 2280 |
$this->context, |
| 2281 |
$this->summary, |
| 2282 |
$markAsMinor, |
| 2283 |
$this->context->getLanguage(), |
| 2284 |
$pstUser |
| 2285 |
) |
| 2286 |
); |
| 2287 |
|
| 2288 |
|
| 2289 |
if ( !$constraintRunner->checkConstraints() ) { |
| 2290 |
$failed = $constraintRunner->getFailedConstraint(); |
| 2291 |
$this->handleFailedConstraint( $failed ); |
| 2292 |
return Status::wrap( $failed->getLegacyStatus() ); |
| 2293 |
} |
| 2294 |
|
| 2295 |
} else { |
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
$timestamp = $this->page->getTimestamp(); |
| 2300 |
$latest = $this->page->getLatest(); |
| 2301 |
|
| 2302 |
wfDebug( "timestamp: {$timestamp}, edittime: {$this->edittime}" ); |
| 2303 |
wfDebug( "revision: {$latest}, editRevId: {$this->editRevId}" ); |
| 2304 |
|
| 2305 |
$editConflictLogger = LoggerFactory::getInstance( 'EditConflict' ); |
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
if ( ( $this->edittime !== null && $this->edittime != $timestamp ) |
| 2311 |
|| ( $this->editRevId !== null && $this->editRevId != $latest ) |
| 2312 |
) { |
| 2313 |
$this->isConflict = true; |
| 2314 |
if ( $this->section === 'new' ) { |
| 2315 |
if ( $this->page->getUserText() === $requestUser->getName() && |
| 2316 |
$this->page->getComment() === $this->summary |
| 2317 |
) { |
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
$editConflictLogger->debug( |
| 2322 |
'Duplicate new section submission; trigger edit conflict!' |
| 2323 |
); |
| 2324 |
} else { |
| 2325 |
|
| 2326 |
$this->isConflict = false; |
| 2327 |
$editConflictLogger->debug( 'Conflict suppressed; new section' ); |
| 2328 |
} |
| 2329 |
} elseif ( $this->section === '' |
| 2330 |
&& $this->edittime |
| 2331 |
&& $this->revisionStore->userWasLastToEdit( |
| 2332 |
$this->connectionProvider->getPrimaryDatabase(), |
| 2333 |
$this->mTitle->getArticleID(), |
| 2334 |
$requestUser->getId(), |
| 2335 |
$this->edittime |
| 2336 |
) |
| 2337 |
) { |
| 2338 |
|
| 2339 |
$editConflictLogger->debug( 'Suppressing edit conflict, same user.' ); |
| 2340 |
$this->isConflict = false; |
| 2341 |
} |
| 2342 |
} |
| 2343 |
|
| 2344 |
if ( $this->isConflict ) { |
| 2345 |
$editConflictLogger->debug( |
| 2346 |
'Conflict! Getting section {section} for time {editTime}' |
| 2347 |
. ' (id {editRevId}, article time {timestamp})', |
| 2348 |
[ |
| 2349 |
'section' => $this->section, |
| 2350 |
'editTime' => $this->edittime, |
| 2351 |
'editRevId' => $this->editRevId, |
| 2352 |
'timestamp' => $timestamp, |
| 2353 |
] |
| 2354 |
); |
| 2355 |
|
| 2356 |
|
| 2357 |
if ( $this->editRevId !== null ) { |
| 2358 |
$content = $this->page->replaceSectionAtRev( |
| 2359 |
$this->section, |
| 2360 |
$textbox_content, |
| 2361 |
$this->sectiontitle, |
| 2362 |
$this->editRevId |
| 2363 |
); |
| 2364 |
} else { |
| 2365 |
$content = $this->page->replaceSectionContent( |
| 2366 |
$this->section, |
| 2367 |
$textbox_content, |
| 2368 |
$this->sectiontitle, |
| 2369 |
$this->edittime |
| 2370 |
); |
| 2371 |
} |
| 2372 |
} else { |
| 2373 |
$editConflictLogger->debug( |
| 2374 |
'Getting section {section}', |
| 2375 |
[ 'section' => $this->section ] |
| 2376 |
); |
| 2377 |
$content = $this->page->replaceSectionAtRev( |
| 2378 |
$this->section, |
| 2379 |
$textbox_content, |
| 2380 |
$this->sectiontitle |
| 2381 |
); |
| 2382 |
} |
| 2383 |
|
| 2384 |
if ( $content === null ) { |
| 2385 |
$editConflictLogger->debug( 'Activating conflict; section replace failed.' ); |
| 2386 |
$this->isConflict = true; |
| 2387 |
$content = $textbox_content; |
| 2388 |
} elseif ( $this->isConflict ) { |
| 2389 |
|
| 2390 |
$mergedChange = $this->mergeChangesIntoContent( $content ); |
| 2391 |
if ( $mergedChange !== false ) { |
| 2392 |
|
| 2393 |
$content = $mergedChange[0]; |
| 2394 |
$this->parentRevId = $mergedChange[1]; |
| 2395 |
$this->isConflict = false; |
| 2396 |
$editConflictLogger->debug( 'Suppressing edit conflict, successful merge.' ); |
| 2397 |
} else { |
| 2398 |
$this->section = ''; |
| 2399 |
$this->textbox1 = ( $content instanceof TextContent ) ? $content->getText() : ''; |
| 2400 |
$editConflictLogger->debug( 'Keeping edit conflict, failed merge.' ); |
| 2401 |
} |
| 2402 |
} |
| 2403 |
|
| 2404 |
if ( $this->isConflict ) { |
| 2405 |
return Status::newGood( self::AS_CONFLICT_DETECTED )->setOK( false ); |
| 2406 |
} |
| 2407 |
|
| 2408 |
$pageUpdater = $this->page->newPageUpdater( $pstUser ) |
| 2409 |
->setContent( SlotRecord::MAIN, $content ); |
| 2410 |
$pageUpdater->prepareUpdate( $flags ); |
| 2411 |
|
| 2412 |
|
| 2413 |
|
| 2414 |
$constraintRunner = new EditConstraintRunner(); |
| 2415 |
$constraintRunner->addConstraint( |
| 2416 |
$constraintFactory->newEditFilterMergedContentHookConstraint( |
| 2417 |
$content, |
| 2418 |
$this->context, |
| 2419 |
$this->summary, |
| 2420 |
$markAsMinor, |
| 2421 |
$this->context->getLanguage(), |
| 2422 |
$pstUser |
| 2423 |
) |
| 2424 |
); |
| 2425 |
$constraintRunner->addConstraint( |
| 2426 |
new NewSectionMissingSubjectConstraint( |
| 2427 |
$this->section, |
| 2428 |
$this->sectiontitle ?? '', |
| 2429 |
$this->allowBlankSummary |
| 2430 |
) |
| 2431 |
); |
| 2432 |
$constraintRunner->addConstraint( |
| 2433 |
new MissingCommentConstraint( $this->section, $this->textbox1 ) |
| 2434 |
); |
| 2435 |
$constraintRunner->addConstraint( |
| 2436 |
new ExistingSectionEditConstraint( |
| 2437 |
$this->section, |
| 2438 |
$this->summary, |
| 2439 |
$this->autoSumm, |
| 2440 |
$this->allowBlankSummary, |
| 2441 |
$content, |
| 2442 |
$this->getOriginalContent( $authority ) |
| 2443 |
) |
| 2444 |
); |
| 2445 |
|
| 2446 |
if ( !$constraintRunner->checkConstraints() ) { |
| 2447 |
$failed = $constraintRunner->getFailedConstraint(); |
| 2448 |
$this->handleFailedConstraint( $failed ); |
| 2449 |
return Status::wrap( $failed->getLegacyStatus() ); |
| 2450 |
} |
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
$sectionAnchor = ''; |
| 2455 |
if ( $this->section === 'new' ) { |
| 2456 |
$sectionAnchor = $this->newSectionAnchor; |
| 2457 |
} elseif ( $this->section !== '' ) { |
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
$hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches ); |
| 2463 |
|
| 2464 |
|
| 2465 |
if ( $hasmatch && $matches[2] !== '' ) { |
| 2466 |
$sectionAnchor = $this->guessSectionName( $matches[2] ); |
| 2467 |
} |
| 2468 |
} |
| 2469 |
$result['sectionanchor'] = $sectionAnchor; |
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
$this->textbox1 = $this->toEditText( $content ); |
| 2476 |
$this->section = ''; |
| 2477 |
} |
| 2478 |
|
| 2479 |
|
| 2480 |
$this->contentLength = strlen( $this->toEditText( $content ) ); |
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
$constraintRunner = new EditConstraintRunner(); |
| 2485 |
$constraintRunner->addConstraint( |
| 2486 |
new SelfRedirectConstraint( |
| 2487 |
$this->allowSelfRedirect, |
| 2488 |
$content, |
| 2489 |
$this->getCurrentContent(), |
| 2490 |
$this->getTitle() |
| 2491 |
) |
| 2492 |
); |
| 2493 |
$constraintRunner->addConstraint( |
| 2494 |
|
| 2495 |
|
| 2496 |
$constraintFactory->newPageSizeConstraint( |
| 2497 |
$this->contentLength, |
| 2498 |
PageSizeConstraint::AFTER_MERGE |
| 2499 |
) |
| 2500 |
); |
| 2501 |
|
| 2502 |
if ( !$constraintRunner->checkConstraints() ) { |
| 2503 |
$failed = $constraintRunner->getFailedConstraint(); |
| 2504 |
$this->handleFailedConstraint( $failed ); |
| 2505 |
return Status::wrap( $failed->getLegacyStatus() ); |
| 2506 |
} |
| 2507 |
|
| 2508 |
|
| 2509 |
if ( $this->undidRev && $this->isUndoClean( $content ) ) { |
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
$pageUpdater |
| 2514 |
->setOriginalRevisionId( $this->undoAfter ?: false ) |
| 2515 |
->markAsRevert( |
| 2516 |
EditResult::REVERT_UNDO, |
| 2517 |
$this->undidRev, |
| 2518 |
$this->undoAfter ?: null |
| 2519 |
); |
| 2520 |
} |
| 2521 |
|
| 2522 |
$needsPatrol = $useRCPatrol || ( $useNPPatrol && !$this->page->exists() ); |
| 2523 |
if ( $needsPatrol && $authority->authorizeWrite( 'autopatrol', $this->getTitle() ) ) { |
| 2524 |
$pageUpdater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED ); |
| 2525 |
} |
| 2526 |
|
| 2527 |
$pageUpdater |
| 2528 |
->addTags( $this->changeTags ) |
| 2529 |
->saveRevision( |
| 2530 |
CommentStoreComment::newUnsavedComment( trim( $this->summary ) ), |
| 2531 |
$flags |
| 2532 |
); |
| 2533 |
$doEditStatus = $pageUpdater->getStatus(); |
| 2534 |
|
| 2535 |
if ( !$doEditStatus->isOK() ) { |
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
if ( |
| 2540 |
$doEditStatus->failedBecausePageMissing() || |
| 2541 |
$doEditStatus->failedBecausePageExists() || |
| 2542 |
$doEditStatus->failedBecauseOfConflict() |
| 2543 |
) { |
| 2544 |
$this->isConflict = true; |
| 2545 |
|
| 2546 |
$doEditStatus->value = self::AS_END; |
| 2547 |
} |
| 2548 |
return $doEditStatus; |
| 2549 |
} |
| 2550 |
|
| 2551 |
$result['nullEdit'] = !$doEditStatus->wasRevisionCreated(); |
| 2552 |
if ( $result['nullEdit'] ) { |
| 2553 |
|
| 2554 |
$limitSubject = $requestUser->toRateLimitSubject(); |
| 2555 |
MediaWikiServices::getInstance()->getRateLimiter()->limit( $limitSubject, 'linkpurge' ); |
| 2556 |
} |
| 2557 |
$result['redirect'] = $content->isRedirect(); |
| 2558 |
|
| 2559 |
$this->updateWatchlist(); |
| 2560 |
|
| 2561 |
|
| 2562 |
if ( $changingContentModel ) { |
| 2563 |
$this->addContentModelChangeLogEntry( |
| 2564 |
$this->getUserForSave(), |
| 2565 |
|
| 2566 |
|
| 2567 |
$new ? false : $oldContentModel, |
| 2568 |
$this->contentModel, |
| 2569 |
$this->summary |
| 2570 |
); |
| 2571 |
} |
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
$statusCode = ( $new ? self::AS_SUCCESS_NEW_ARTICLE : self::AS_SUCCESS_UPDATE ); |
| 2577 |
return Status::newGood( $statusCode ); |
| 2578 |
} |
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
private function handleFailedConstraint( IEditConstraint $failed ): void { |
| 2589 |
if ( $failed instanceof PageSizeConstraint ) { |
| 2590 |
|
| 2591 |
$this->tooBig = true; |
| 2592 |
} elseif ( $failed instanceof UserBlockConstraint ) { |
| 2593 |
|
| 2594 |
if ( !MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) { |
| 2595 |
$this->context->getUser()->spreadAnyEditBlock(); |
| 2596 |
} |
| 2597 |
} elseif ( $failed instanceof DefaultTextConstraint ) { |
| 2598 |
$this->blankArticle = true; |
| 2599 |
} elseif ( $failed instanceof EditFilterMergedContentHookConstraint ) { |
| 2600 |
$this->hookError = $failed->getHookError(); |
| 2601 |
} elseif ( |
| 2602 |
|
| 2603 |
|
| 2604 |
( |
| 2605 |
$failed instanceof ExistingSectionEditConstraint |
| 2606 |
&& $failed->getLegacyStatus()->value === self::AS_SUMMARY_NEEDED |
| 2607 |
) || |
| 2608 |
$failed instanceof NewSectionMissingSubjectConstraint |
| 2609 |
) { |
| 2610 |
$this->missingSummary = true; |
| 2611 |
} elseif ( $failed instanceof MissingCommentConstraint ) { |
| 2612 |
$this->missingComment = true; |
| 2613 |
} elseif ( $failed instanceof SelfRedirectConstraint ) { |
| 2614 |
$this->selfRedirect = true; |
| 2615 |
} |
| 2616 |
} |
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
private function isUndoClean( Content $content ): bool { |
| 2629 |
|
| 2630 |
|
| 2631 |
$undoRev = $this->revisionStore->getRevisionById( $this->undidRev ); |
| 2632 |
if ( $undoRev === null ) { |
| 2633 |
return false; |
| 2634 |
} |
| 2635 |
|
| 2636 |
if ( $this->undoAfter ) { |
| 2637 |
$oldRev = $this->revisionStore->getRevisionById( $this->undoAfter ); |
| 2638 |
} else { |
| 2639 |
$oldRev = $this->revisionStore->getPreviousRevision( $undoRev ); |
| 2640 |
} |
| 2641 |
|
| 2642 |
if ( $oldRev === null || |
| 2643 |
$undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) || |
| 2644 |
$oldRev->isDeleted( RevisionRecord::DELETED_TEXT ) |
| 2645 |
) { |
| 2646 |
return false; |
| 2647 |
} |
| 2648 |
|
| 2649 |
$undoContent = $this->getUndoContent( $undoRev, $oldRev, $undoError ); |
| 2650 |
if ( !$undoContent ) { |
| 2651 |
return false; |
| 2652 |
} |
| 2653 |
|
| 2654 |
|
| 2655 |
$services = MediaWikiServices::getInstance(); |
| 2656 |
$contentLanguage = $services->getContentLanguage(); |
| 2657 |
$user = $this->getUserForPreview(); |
| 2658 |
$parserOptions = ParserOptions::newFromUserAndLang( $user, $contentLanguage ); |
| 2659 |
$contentTransformer = $services->getContentTransformer(); |
| 2660 |
$undoContent = $contentTransformer->preSaveTransform( $undoContent, $this->mTitle, $user, $parserOptions ); |
| 2661 |
|
| 2662 |
if ( $undoContent->equals( $content ) ) { |
| 2663 |
return true; |
| 2664 |
} |
| 2665 |
return false; |
| 2666 |
} |
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
private function addContentModelChangeLogEntry( UserIdentity $user, $oldModel, $newModel, $reason = "" ): void { |
| 2675 |
$new = $oldModel === false; |
| 2676 |
$log = new ManualLogEntry( 'contentmodel', $new ? 'new' : 'change' ); |
| 2677 |
$log->setPerformer( $user ); |
| 2678 |
$log->setTarget( $this->mTitle ); |
| 2679 |
$log->setComment( is_string( $reason ) ? $reason : "" ); |
| 2680 |
$log->setParameters( [ |
| 2681 |
'4::oldmodel' => $oldModel, |
| 2682 |
'5::newmodel' => $newModel |
| 2683 |
] ); |
| 2684 |
$logid = $log->insert(); |
| 2685 |
$log->publish( $logid ); |
| 2686 |
} |
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
|
| 2691 |
private function updateWatchlist(): void { |
| 2692 |
if ( $this->tempUserCreateActive ) { |
| 2693 |
return; |
| 2694 |
} |
| 2695 |
$user = $this->getUserForSave(); |
| 2696 |
if ( !$user->isNamed() ) { |
| 2697 |
return; |
| 2698 |
} |
| 2699 |
|
| 2700 |
$title = $this->mTitle; |
| 2701 |
$watch = $this->watchthis; |
| 2702 |
$watchlistExpiry = $this->watchlistExpiry; |
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
$this->watchlistManager->setWatch( $watch, $user, $title, $watchlistExpiry ); |
| 2708 |
|
| 2709 |
$this->watchedItemStore->maybeEnqueueWatchlistExpiryJob(); |
| 2710 |
} |
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
private function mergeChangesIntoContent( Content $editContent ) { |
| 2723 |
|
| 2724 |
|
| 2725 |
$baseRevRecord = $this->getExpectedParentRevision(); |
| 2726 |
$baseContent = $baseRevRecord ? |
| 2727 |
$baseRevRecord->getContent( SlotRecord::MAIN ) : |
| 2728 |
null; |
| 2729 |
|
| 2730 |
if ( $baseContent === null ) { |
| 2731 |
return false; |
| 2732 |
} elseif ( $baseRevRecord->isCurrent() ) { |
| 2733 |
|
| 2734 |
|
| 2735 |
return [ $editContent, $baseRevRecord->getId() ]; |
| 2736 |
} |
| 2737 |
|
| 2738 |
|
| 2739 |
$currentRevisionRecord = $this->revisionStore->getRevisionByTitle( |
| 2740 |
$this->mTitle, |
| 2741 |
0, |
| 2742 |
IDBAccessObject::READ_LATEST |
| 2743 |
); |
| 2744 |
$currentContent = $currentRevisionRecord |
| 2745 |
? $currentRevisionRecord->getContent( SlotRecord::MAIN ) |
| 2746 |
: null; |
| 2747 |
|
| 2748 |
if ( $currentContent === null ) { |
| 2749 |
return false; |
| 2750 |
} |
| 2751 |
|
| 2752 |
$mergedContent = $this->contentHandlerFactory |
| 2753 |
->getContentHandler( $baseContent->getModel() ) |
| 2754 |
->merge3( $baseContent, $editContent, $currentContent ); |
| 2755 |
|
| 2756 |
if ( $mergedContent ) { |
| 2757 |
|
| 2758 |
return [ $mergedContent, $currentRevisionRecord->getId() ]; |
| 2759 |
} |
| 2760 |
|
| 2761 |
return false; |
| 2762 |
} |
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
public function getExpectedParentRevision() { |
| 2772 |
if ( $this->mExpectedParentRevision === false ) { |
| 2773 |
$revRecord = null; |
| 2774 |
if ( $this->editRevId ) { |
| 2775 |
$revRecord = $this->revisionStore->getRevisionById( |
| 2776 |
$this->editRevId, |
| 2777 |
IDBAccessObject::READ_LATEST |
| 2778 |
); |
| 2779 |
} elseif ( $this->edittime ) { |
| 2780 |
$revRecord = $this->revisionStore->getRevisionByTimestamp( |
| 2781 |
$this->getTitle(), |
| 2782 |
$this->edittime, |
| 2783 |
IDBAccessObject::READ_LATEST |
| 2784 |
); |
| 2785 |
} |
| 2786 |
$this->mExpectedParentRevision = $revRecord; |
| 2787 |
} |
| 2788 |
return $this->mExpectedParentRevision; |
| 2789 |
} |
| 2790 |
|
| 2791 |
public function setHeaders() { |
| 2792 |
$out = $this->context->getOutput(); |
| 2793 |
|
| 2794 |
$out->addModules( 'mediawiki.action.edit' ); |
| 2795 |
$out->addModuleStyles( 'mediawiki.action.edit.styles' ); |
| 2796 |
$out->addModuleStyles( 'mediawiki.editfont.styles' ); |
| 2797 |
$out->addModuleStyles( 'mediawiki.interface.helpers.styles' ); |
| 2798 |
|
| 2799 |
$user = $this->context->getUser(); |
| 2800 |
|
| 2801 |
if ( $this->userOptionsLookup->getOption( $user, 'uselivepreview' ) ) { |
| 2802 |
$out->addModules( 'mediawiki.action.edit.preview' ); |
| 2803 |
} |
| 2804 |
|
| 2805 |
if ( $this->userOptionsLookup->getOption( $user, 'useeditwarning' ) ) { |
| 2806 |
$out->addModules( 'mediawiki.action.edit.editWarning' ); |
| 2807 |
} |
| 2808 |
|
| 2809 |
if ( $this->context->getConfig()->get( MainConfigNames::EnableEditRecovery ) |
| 2810 |
&& $this->userOptionsLookup->getOption( $user, 'editrecovery' ) |
| 2811 |
) { |
| 2812 |
$wasPosted = $this->getContext()->getRequest()->getMethod() === 'POST'; |
| 2813 |
$out->addJsConfigVars( 'wgEditRecoveryWasPosted', $wasPosted ); |
| 2814 |
$out->addModules( 'mediawiki.editRecovery.edit' ); |
| 2815 |
} |
| 2816 |
|
| 2817 |
|
| 2818 |
$out->setArticleRelated( true ); |
| 2819 |
|
| 2820 |
$contextTitle = $this->getContextTitle(); |
| 2821 |
if ( $this->isConflict ) { |
| 2822 |
$msg = 'editconflict'; |
| 2823 |
} elseif ( $contextTitle->exists() && $this->section != '' ) { |
| 2824 |
$msg = $this->section === 'new' ? 'editingcomment' : 'editingsection'; |
| 2825 |
} else { |
| 2826 |
$msg = $contextTitle->exists() |
| 2827 |
|| ( $contextTitle->getNamespace() === NS_MEDIAWIKI |
| 2828 |
&& $contextTitle->getDefaultMessageText() !== false |
| 2829 |
) |
| 2830 |
? 'editing' |
| 2831 |
: 'creating'; |
| 2832 |
} |
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
$displayTitle = isset( $this->mParserOutput ) ? $this->mParserOutput->getDisplayTitle() : false; |
| 2839 |
if ( $displayTitle === false ) { |
| 2840 |
$displayTitle = htmlspecialchars( |
| 2841 |
$contextTitle->getPrefixedText(), ENT_QUOTES, 'UTF-8', false |
| 2842 |
); |
| 2843 |
} else { |
| 2844 |
$out->setDisplayTitle( $displayTitle ); |
| 2845 |
} |
| 2846 |
|
| 2847 |
|
| 2848 |
|
| 2849 |
$displayTitle = Html::rawElement( 'span', [ 'id' => 'firstHeadingTitle' ], $displayTitle ); |
| 2850 |
|
| 2851 |
$out->setPageTitleMsg( $this->context->msg( $msg )->rawParams( $displayTitle ) ); |
| 2852 |
|
| 2853 |
$config = $this->context->getConfig(); |
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
$out->addJsConfigVars( [ |
| 2859 |
'wgEditMessage' => $msg, |
| 2860 |
] ); |
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
$out->addJsConfigVars( |
| 2865 |
'wgEditSubmitButtonLabelPublish', |
| 2866 |
$config->get( MainConfigNames::EditSubmitButtonLabelPublish ) |
| 2867 |
); |
| 2868 |
} |
| 2869 |
|
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 2873 |
private function showIntro(): void { |
| 2874 |
$services = MediaWikiServices::getInstance(); |
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
$skip = $this->suppressIntro ? [ |
| 2883 |
'editintro', |
| 2884 |
'code-editing-intro', |
| 2885 |
'sharedupload-desc-create', |
| 2886 |
'sharedupload-desc-edit', |
| 2887 |
'userpage-userdoesnotexist', |
| 2888 |
'blocked-notice-logextract', |
| 2889 |
'newarticletext', |
| 2890 |
'newarticletextanon', |
| 2891 |
'recreate-moveddeleted-warn', |
| 2892 |
] : []; |
| 2893 |
|
| 2894 |
$messages = $services->getIntroMessageBuilder()->getIntroMessages( |
| 2895 |
IntroMessageBuilder::MORE_FRAMES, |
| 2896 |
$skip, |
| 2897 |
$this->context, |
| 2898 |
$this->mTitle->toPageIdentity(), |
| 2899 |
$this->mArticle->fetchRevisionRecord(), |
| 2900 |
$this->context->getUser(), |
| 2901 |
$this->context->getRequest()->getVal( 'editintro' ), |
| 2902 |
wfArrayToCgi( |
| 2903 |
array_diff_key( |
| 2904 |
$this->context->getRequest()->getValues(), |
| 2905 |
[ 'title' => true, 'returnto' => true, 'returntoquery' => true ] |
| 2906 |
) |
| 2907 |
), |
| 2908 |
!$this->firsttime, |
| 2909 |
$this->section !== '' ? $this->section : null |
| 2910 |
); |
| 2911 |
|
| 2912 |
foreach ( $messages as $message ) { |
| 2913 |
$this->context->getOutput()->addHTML( $message ); |
| 2914 |
} |
| 2915 |
} |
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
|
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
private function toEditText( $content ) { |
| 2936 |
if ( $content === null || $content === false ) { |
| 2937 |
return ''; |
| 2938 |
} |
| 2939 |
if ( is_string( $content ) ) { |
| 2940 |
return $content; |
| 2941 |
} |
| 2942 |
|
| 2943 |
if ( !$this->isSupportedContentModel( $content->getModel() ) ) { |
| 2944 |
throw new MWException( 'This content model is not supported: ' . $content->getModel() ); |
| 2945 |
} |
| 2946 |
|
| 2947 |
return $content->serialize( $this->contentFormat ); |
| 2948 |
} |
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
protected function toEditContent( $text ) { |
| 2967 |
if ( $text === false || $text === null ) { |
| 2968 |
return $text; |
| 2969 |
} |
| 2970 |
|
| 2971 |
$content = ContentHandler::makeContent( $text, $this->getTitle(), |
| 2972 |
$this->contentModel, $this->contentFormat ); |
| 2973 |
|
| 2974 |
if ( !$this->isSupportedContentModel( $content->getModel() ) ) { |
| 2975 |
throw new MWException( 'This content model is not supported: ' . $content->getModel() ); |
| 2976 |
} |
| 2977 |
|
| 2978 |
return $content; |
| 2979 |
} |
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
public function showEditForm() { |
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
$previewOutput = ''; |
| 2990 |
if ( $this->formtype === 'preview' ) { |
| 2991 |
$previewOutput = $this->getPreviewText(); |
| 2992 |
} |
| 2993 |
|
| 2994 |
$out = $this->context->getOutput(); |
| 2995 |
|
| 2996 |
|
| 2997 |
$this->getHookRunner()->onEditPage__showEditForm_initial( $this, $out ); |
| 2998 |
|
| 2999 |
$this->setHeaders(); |
| 3000 |
|
| 3001 |
|
| 3002 |
$this->showIntro(); |
| 3003 |
|
| 3004 |
if ( !$this->isConflict && |
| 3005 |
$this->section !== '' && |
| 3006 |
!$this->isSectionEditSupported() |
| 3007 |
) { |
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
$out->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' ); |
| 3012 |
return; |
| 3013 |
} |
| 3014 |
|
| 3015 |
$this->showHeader(); |
| 3016 |
|
| 3017 |
$out->addHTML( $this->editFormPageTop ); |
| 3018 |
|
| 3019 |
$user = $this->context->getUser(); |
| 3020 |
if ( $this->userOptionsLookup->getOption( $user, 'previewontop' ) ) { |
| 3021 |
$this->displayPreviewArea( $previewOutput, true ); |
| 3022 |
} |
| 3023 |
|
| 3024 |
$out->addHTML( $this->editFormTextTop ); |
| 3025 |
|
| 3026 |
if ( $this->formtype !== 'save' && $this->wasDeletedSinceLastEdit() ) { |
| 3027 |
$out->addHTML( Html::errorBox( |
| 3028 |
$out->msg( 'deletedwhileediting' )->parse(), |
| 3029 |
'', |
| 3030 |
'mw-deleted-while-editing' |
| 3031 |
) ); |
| 3032 |
} |
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
$out->addHTML( Html::openElement( |
| 3037 |
'form', |
| 3038 |
[ |
| 3039 |
'class' => 'mw-editform', |
| 3040 |
'id' => self::EDITFORM_ID, |
| 3041 |
'name' => self::EDITFORM_ID, |
| 3042 |
'method' => 'post', |
| 3043 |
'action' => $this->getActionURL( $this->getContextTitle() ), |
| 3044 |
'enctype' => 'multipart/form-data', |
| 3045 |
'data-mw-editform-type' => $this->formtype |
| 3046 |
] |
| 3047 |
) ); |
| 3048 |
|
| 3049 |
|
| 3050 |
$out->addHTML( Html::hidden( 'wpUnicodeCheck', self::UNICODE_CHECK ) ); |
| 3051 |
|
| 3052 |
|
| 3053 |
$out->addHTML( |
| 3054 |
Html::openElement( 'div', [ 'id' => 'antispam-container', 'style' => 'display: none;' ] ) |
| 3055 |
. Html::rawElement( |
| 3056 |
'label', |
| 3057 |
[ 'for' => 'wpAntispam' ], |
| 3058 |
$this->context->msg( 'simpleantispam-label' )->parse() |
| 3059 |
) |
| 3060 |
. Html::element( |
| 3061 |
'input', |
| 3062 |
[ |
| 3063 |
'type' => 'text', |
| 3064 |
'name' => 'wpAntispam', |
| 3065 |
'id' => 'wpAntispam', |
| 3066 |
'value' => '' |
| 3067 |
] |
| 3068 |
) |
| 3069 |
. Html::closeElement( 'div' ) |
| 3070 |
); |
| 3071 |
|
| 3072 |
$this->getHookRunner()->onEditPage__showEditForm_fields( $this, $out ); |
| 3073 |
|
| 3074 |
|
| 3075 |
$this->showFormBeforeText(); |
| 3076 |
|
| 3077 |
if ( $this->formtype === 'save' && $this->wasDeletedSinceLastEdit() ) { |
| 3078 |
$username = $this->lastDelete->actor_name; |
| 3079 |
$comment = $this->commentStore->getComment( 'log_comment', $this->lastDelete )->text; |
| 3080 |
|
| 3081 |
|
| 3082 |
|
| 3083 |
$key = $comment === '' |
| 3084 |
? 'confirmrecreate-noreason' |
| 3085 |
: 'confirmrecreate'; |
| 3086 |
$out->addHTML( Html::rawElement( |
| 3087 |
'div', |
| 3088 |
[ 'class' => 'mw-confirm-recreate' ], |
| 3089 |
$this->context->msg( $key ) |
| 3090 |
->params( $username ) |
| 3091 |
->plaintextParams( $comment ) |
| 3092 |
->parse() . |
| 3093 |
Html::rawElement( |
| 3094 |
'div', |
| 3095 |
[], |
| 3096 |
Html::check( |
| 3097 |
'wpRecreate', |
| 3098 |
false, |
| 3099 |
[ 'title' => Linker::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' ] |
| 3100 |
) |
| 3101 |
. "\u{00A0}" . |
| 3102 |
Html::label( |
| 3103 |
$this->context->msg( 'recreate' )->text(), |
| 3104 |
'wpRecreate', |
| 3105 |
[ 'title' => Linker::titleAttrib( 'recreate' ) ] |
| 3106 |
) |
| 3107 |
) |
| 3108 |
) ); |
| 3109 |
} |
| 3110 |
|
| 3111 |
|
| 3112 |
if ( $this->nosummary ) { |
| 3113 |
$out->addHTML( Html::hidden( 'nosummary', true ) ); |
| 3114 |
} |
| 3115 |
|
| 3116 |
|
| 3117 |
|
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
|
| 3122 |
|
| 3123 |
if ( |
| 3124 |
$this->missingSummary || |
| 3125 |
|
| 3126 |
( $this->section === 'new' && $this->nosummary ) || |
| 3127 |
$this->allowBlankSummary |
| 3128 |
) { |
| 3129 |
$out->addHTML( Html::hidden( 'wpIgnoreBlankSummary', true ) ); |
| 3130 |
} |
| 3131 |
|
| 3132 |
if ( $this->undidRev ) { |
| 3133 |
$out->addHTML( Html::hidden( 'wpUndidRevision', $this->undidRev ) ); |
| 3134 |
} |
| 3135 |
if ( $this->undoAfter ) { |
| 3136 |
$out->addHTML( Html::hidden( 'wpUndoAfter', $this->undoAfter ) ); |
| 3137 |
} |
| 3138 |
|
| 3139 |
if ( $this->selfRedirect ) { |
| 3140 |
$out->addHTML( Html::hidden( 'wpIgnoreSelfRedirect', true ) ); |
| 3141 |
} |
| 3142 |
|
| 3143 |
$autosumm = $this->autoSumm !== '' ? $this->autoSumm : md5( $this->summary ); |
| 3144 |
$out->addHTML( Html::hidden( 'wpAutoSummary', $autosumm ) ); |
| 3145 |
|
| 3146 |
$out->addHTML( Html::hidden( 'oldid', $this->oldid ) ); |
| 3147 |
$out->addHTML( Html::hidden( 'parentRevId', $this->getParentRevId() ) ); |
| 3148 |
|
| 3149 |
$out->addHTML( Html::hidden( 'format', $this->contentFormat ) ); |
| 3150 |
$out->addHTML( Html::hidden( 'model', $this->contentModel ) ); |
| 3151 |
|
| 3152 |
$out->enableOOUI(); |
| 3153 |
|
| 3154 |
if ( $this->section === 'new' ) { |
| 3155 |
$this->showSummaryInput( true ); |
| 3156 |
$out->addHTML( $this->getSummaryPreview( true ) ); |
| 3157 |
} |
| 3158 |
|
| 3159 |
$out->addHTML( $this->editFormTextBeforeContent ); |
| 3160 |
if ( $this->isConflict ) { |
| 3161 |
$currentText = $this->toEditText( $this->getCurrentContent() ); |
| 3162 |
|
| 3163 |
$editConflictHelper = $this->getEditConflictHelper(); |
| 3164 |
$editConflictHelper->setTextboxes( $this->textbox1, $currentText ); |
| 3165 |
$editConflictHelper->setContentModel( $this->contentModel ); |
| 3166 |
$editConflictHelper->setContentFormat( $this->contentFormat ); |
| 3167 |
$out->addHTML( $editConflictHelper->getEditFormHtmlBeforeContent() ); |
| 3168 |
|
| 3169 |
$this->textbox2 = $this->textbox1; |
| 3170 |
$this->textbox1 = $currentText; |
| 3171 |
} |
| 3172 |
|
| 3173 |
if ( !$this->mTitle->isUserConfigPage() ) { |
| 3174 |
$out->addHTML( self::getEditToolbar() ); |
| 3175 |
} |
| 3176 |
|
| 3177 |
if ( $this->blankArticle ) { |
| 3178 |
$out->addHTML( Html::hidden( 'wpIgnoreBlankArticle', true ) ); |
| 3179 |
} |
| 3180 |
|
| 3181 |
if ( $this->isConflict ) { |
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
$conflictTextBoxAttribs = []; |
| 3187 |
if ( $this->wasDeletedSinceLastEdit() ) { |
| 3188 |
$conflictTextBoxAttribs['style'] = 'display:none;'; |
| 3189 |
} elseif ( $this->isOldRev ) { |
| 3190 |
$conflictTextBoxAttribs['class'] = 'mw-textarea-oldrev'; |
| 3191 |
} |
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
$out->addHTML( $editConflictHelper->getEditConflictMainTextBox( $conflictTextBoxAttribs ) ); |
| 3196 |
|
| 3197 |
|
| 3198 |
$out->addHTML( $editConflictHelper->getEditFormHtmlAfterContent() ); |
| 3199 |
} else { |
| 3200 |
$this->showContentForm(); |
| 3201 |
} |
| 3202 |
|
| 3203 |
$out->addHTML( $this->editFormTextAfterContent ); |
| 3204 |
|
| 3205 |
$this->showStandardInputs(); |
| 3206 |
|
| 3207 |
$this->showFormAfterText(); |
| 3208 |
|
| 3209 |
$this->showTosSummary(); |
| 3210 |
|
| 3211 |
$this->showEditTools(); |
| 3212 |
|
| 3213 |
$out->addHTML( $this->editFormTextAfterTools . "\n" ); |
| 3214 |
|
| 3215 |
$out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) ); |
| 3216 |
|
| 3217 |
$out->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ], |
| 3218 |
Linker::formatHiddenCategories( $this->page->getHiddenCategories() ) ) ); |
| 3219 |
|
| 3220 |
$out->addHTML( Html::rawElement( 'div', [ 'class' => 'limitreport' ], |
| 3221 |
self::getPreviewLimitReport( $this->mParserOutput ) ) ); |
| 3222 |
|
| 3223 |
$out->addModules( 'mediawiki.action.edit.collapsibleFooter' ); |
| 3224 |
|
| 3225 |
if ( $this->isConflict ) { |
| 3226 |
try { |
| 3227 |
$this->showConflict(); |
| 3228 |
} catch ( MWContentSerializationException $ex ) { |
| 3229 |
|
| 3230 |
$msg = $this->context->msg( |
| 3231 |
'content-failed-to-parse', |
| 3232 |
$this->contentModel, |
| 3233 |
$this->contentFormat, |
| 3234 |
$ex->getMessage() |
| 3235 |
); |
| 3236 |
$out->wrapWikiTextAsInterface( 'error', $msg->plain() ); |
| 3237 |
} |
| 3238 |
} |
| 3239 |
|
| 3240 |
|
| 3241 |
if ( $this->isConflict ) { |
| 3242 |
$mode = 'conflict'; |
| 3243 |
} elseif ( $this->preview ) { |
| 3244 |
$mode = 'preview'; |
| 3245 |
} elseif ( $this->diff ) { |
| 3246 |
$mode = 'diff'; |
| 3247 |
} else { |
| 3248 |
$mode = 'text'; |
| 3249 |
} |
| 3250 |
$out->addHTML( Html::hidden( 'mode', $mode, [ 'id' => 'mw-edit-mode' ] ) ); |
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
$out->addHTML( Html::hidden( 'wpUltimateParam', true ) ); |
| 3255 |
$out->addHTML( $this->editFormTextBottom . "\n</form>\n" ); |
| 3256 |
|
| 3257 |
if ( !$this->userOptionsLookup->getOption( $user, 'previewontop' ) ) { |
| 3258 |
$this->displayPreviewArea( $previewOutput, false ); |
| 3259 |
} |
| 3260 |
} |
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
public function makeTemplatesOnThisPageList( array $templates ) { |
| 3270 |
$templateListFormatter = new TemplatesOnThisPageFormatter( |
| 3271 |
$this->context, |
| 3272 |
$this->linkRenderer, |
| 3273 |
$this->linkBatchFactory, |
| 3274 |
$this->restrictionStore |
| 3275 |
); |
| 3276 |
|
| 3277 |
|
| 3278 |
$type = false; |
| 3279 |
if ( $this->preview ) { |
| 3280 |
$type = 'preview'; |
| 3281 |
} elseif ( $this->section !== '' ) { |
| 3282 |
$type = 'section'; |
| 3283 |
} |
| 3284 |
|
| 3285 |
return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ], |
| 3286 |
$templateListFormatter->format( $templates, $type ) |
| 3287 |
); |
| 3288 |
} |
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
private static function extractSectionTitle( $text ) { |
| 3297 |
if ( preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches ) ) { |
| 3298 |
return MediaWikiServices::getInstance()->getParser() |
| 3299 |
->stripSectionName( trim( $matches[2] ) ); |
| 3300 |
} else { |
| 3301 |
return false; |
| 3302 |
} |
| 3303 |
} |
| 3304 |
|
| 3305 |
private function showHeader(): void { |
| 3306 |
$out = $this->context->getOutput(); |
| 3307 |
$user = $this->context->getUser(); |
| 3308 |
if ( $this->isConflict ) { |
| 3309 |
$this->addExplainConflictHeader(); |
| 3310 |
$this->editRevId = $this->page->getLatest(); |
| 3311 |
} else { |
| 3312 |
if ( $this->section !== '' && $this->section !== 'new' && $this->summary === '' && |
| 3313 |
!$this->preview && !$this->diff |
| 3314 |
) { |
| 3315 |
$sectionTitle = self::extractSectionTitle( $this->textbox1 ); |
| 3316 |
if ( $sectionTitle !== false ) { |
| 3317 |
$this->summary = "/* $sectionTitle */ "; |
| 3318 |
} |
| 3319 |
} |
| 3320 |
|
| 3321 |
$buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text(); |
| 3322 |
|
| 3323 |
if ( $this->missingComment ) { |
| 3324 |
$out->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' ); |
| 3325 |
} |
| 3326 |
|
| 3327 |
if ( $this->missingSummary && $this->section !== 'new' ) { |
| 3328 |
$out->wrapWikiMsg( |
| 3329 |
"<div id='mw-missingsummary'>\n$1\n</div>", |
| 3330 |
[ 'missingsummary', $buttonLabel ] |
| 3331 |
); |
| 3332 |
} |
| 3333 |
|
| 3334 |
if ( $this->missingSummary && $this->section === 'new' ) { |
| 3335 |
$out->wrapWikiMsg( |
| 3336 |
"<div id='mw-missingcommentheader'>\n$1\n</div>", |
| 3337 |
[ 'missingcommentheader', $buttonLabel ] |
| 3338 |
); |
| 3339 |
} |
| 3340 |
|
| 3341 |
if ( $this->blankArticle ) { |
| 3342 |
$out->wrapWikiMsg( |
| 3343 |
"<div id='mw-blankarticle'>\n$1\n</div>", |
| 3344 |
[ 'blankarticle', $buttonLabel ] |
| 3345 |
); |
| 3346 |
} |
| 3347 |
|
| 3348 |
if ( $this->selfRedirect ) { |
| 3349 |
$out->wrapWikiMsg( |
| 3350 |
"<div id='mw-selfredirect'>\n$1\n</div>", |
| 3351 |
[ 'selfredirect', $buttonLabel ] |
| 3352 |
); |
| 3353 |
} |
| 3354 |
|
| 3355 |
if ( $this->hookError !== '' ) { |
| 3356 |
$out->addWikiTextAsInterface( $this->hookError ); |
| 3357 |
} |
| 3358 |
|
| 3359 |
if ( $this->section != 'new' ) { |
| 3360 |
$revRecord = $this->mArticle->fetchRevisionRecord(); |
| 3361 |
if ( $revRecord && $revRecord instanceof RevisionStoreRecord ) { |
| 3362 |
|
| 3363 |
|
| 3364 |
if ( !$revRecord->userCan( RevisionRecord::DELETED_TEXT, $user ) ) { |
| 3365 |
$out->addHTML( |
| 3366 |
Html::warningBox( |
| 3367 |
$out->msg( 'rev-deleted-text-permission', $this->mTitle->getPrefixedDBkey() )->parse(), |
| 3368 |
'plainlinks' |
| 3369 |
) |
| 3370 |
); |
| 3371 |
} elseif ( $revRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) { |
| 3372 |
$out->addHTML( |
| 3373 |
Html::warningBox( |
| 3374 |
|
| 3375 |
$out->msg( 'rev-deleted-text-view', $this->mTitle->getPrefixedDBkey() )->parse(), |
| 3376 |
'plainlinks' |
| 3377 |
) |
| 3378 |
); |
| 3379 |
} |
| 3380 |
|
| 3381 |
if ( !$revRecord->isCurrent() ) { |
| 3382 |
$this->mArticle->setOldSubtitle( $revRecord->getId() ); |
| 3383 |
$this->isOldRev = true; |
| 3384 |
} |
| 3385 |
} elseif ( $this->mTitle->exists() ) { |
| 3386 |
|
| 3387 |
|
| 3388 |
$out->addHTML( |
| 3389 |
Html::errorBox( |
| 3390 |
$out->msg( 'missing-revision', $this->oldid )->parse() |
| 3391 |
) |
| 3392 |
); |
| 3393 |
} |
| 3394 |
} |
| 3395 |
} |
| 3396 |
|
| 3397 |
$this->addLongPageWarningHeader(); |
| 3398 |
} |
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
private function getSummaryInputAttributes( array $inputAttrs ): array { |
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
return $inputAttrs + [ |
| 3412 |
'id' => 'wpSummary', |
| 3413 |
'name' => 'wpSummary', |
| 3414 |
'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT, |
| 3415 |
'tabindex' => 1, |
| 3416 |
'size' => 60, |
| 3417 |
'spellcheck' => 'true', |
| 3418 |
]; |
| 3419 |
} |
| 3420 |
|
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
private function getSummaryInputWidget( $summary, string $labelText, array $inputAttrs ): FieldLayout { |
| 3431 |
$inputAttrs = OOUI\Element::configFromHtmlAttributes( |
| 3432 |
$this->getSummaryInputAttributes( $inputAttrs ) |
| 3433 |
); |
| 3434 |
$inputAttrs += [ |
| 3435 |
'title' => Linker::titleAttrib( 'summary' ), |
| 3436 |
'accessKey' => Linker::accesskey( 'summary' ), |
| 3437 |
]; |
| 3438 |
|
| 3439 |
|
| 3440 |
$inputAttrs['inputId'] = $inputAttrs['id']; |
| 3441 |
$inputAttrs['id'] = 'wpSummaryWidget'; |
| 3442 |
|
| 3443 |
return new OOUI\FieldLayout( |
| 3444 |
new OOUI\TextInputWidget( [ |
| 3445 |
'value' => $summary, |
| 3446 |
'infusable' => true, |
| 3447 |
] + $inputAttrs ), |
| 3448 |
[ |
| 3449 |
'label' => new OOUI\HtmlSnippet( $labelText ), |
| 3450 |
'align' => 'top', |
| 3451 |
'id' => 'wpSummaryLabel', |
| 3452 |
'classes' => [ $this->missingSummary ? 'mw-summarymissed' : 'mw-summary' ], |
| 3453 |
] |
| 3454 |
); |
| 3455 |
} |
| 3456 |
|
| 3457 |
|
| 3458 |
|
| 3459 |
|
| 3460 |
|
| 3461 |
|
| 3462 |
private function showSummaryInput( bool $isSubjectPreview ): void { |
| 3463 |
|
| 3464 |
$summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary'; |
| 3465 |
if ( $isSubjectPreview ) { |
| 3466 |
if ( $this->nosummary ) { |
| 3467 |
return; |
| 3468 |
} |
| 3469 |
} elseif ( !$this->mShowSummaryField ) { |
| 3470 |
return; |
| 3471 |
} |
| 3472 |
|
| 3473 |
$labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse(); |
| 3474 |
$this->context->getOutput()->addHTML( |
| 3475 |
$this->getSummaryInputWidget( |
| 3476 |
$isSubjectPreview ? $this->sectiontitle : $this->summary, |
| 3477 |
$labelText, |
| 3478 |
[ 'class' => $summaryClass ] |
| 3479 |
) |
| 3480 |
); |
| 3481 |
} |
| 3482 |
|
| 3483 |
|
| 3484 |
|
| 3485 |
|
| 3486 |
|
| 3487 |
|
| 3488 |
|
| 3489 |
private function getSummaryPreview( bool $isSubjectPreview ): string { |
| 3490 |
|
| 3491 |
$summary = trim( $this->summary ); |
| 3492 |
if ( $summary === '' || ( !$this->preview && !$this->diff ) ) { |
| 3493 |
return ""; |
| 3494 |
} |
| 3495 |
|
| 3496 |
$commentFormatter = MediaWikiServices::getInstance()->getCommentFormatter(); |
| 3497 |
$summary = $this->context->msg( 'summary-preview' )->parse() |
| 3498 |
. $commentFormatter->formatBlock( $summary, $this->mTitle, $isSubjectPreview ); |
| 3499 |
return Html::rawElement( 'div', [ 'class' => 'mw-summary-preview' ], $summary ); |
| 3500 |
} |
| 3501 |
|
| 3502 |
private function showFormBeforeText(): void { |
| 3503 |
$out = $this->context->getOutput(); |
| 3504 |
$out->addHTML( Html::hidden( 'wpSection', $this->section ) ); |
| 3505 |
$out->addHTML( Html::hidden( 'wpStarttime', $this->starttime ) ); |
| 3506 |
$out->addHTML( Html::hidden( 'wpEdittime', $this->edittime ) ); |
| 3507 |
$out->addHTML( Html::hidden( 'editRevId', $this->editRevId ) ); |
| 3508 |
$out->addHTML( Html::hidden( 'wpScrolltop', $this->scrolltop, [ 'id' => 'wpScrolltop' ] ) ); |
| 3509 |
} |
| 3510 |
|
| 3511 |
protected function showFormAfterText() { |
| 3512 |
|
| 3513 |
|
| 3514 |
|
| 3515 |
|
| 3516 |
|
| 3517 |
|
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
$this->context->getOutput()->addHTML( |
| 3525 |
"\n" . |
| 3526 |
Html::hidden( "wpEditToken", $this->context->getUser()->getEditToken() ) . |
| 3527 |
"\n" |
| 3528 |
); |
| 3529 |
} |
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
|
| 3535 |
|
| 3536 |
|
| 3537 |
|
| 3538 |
|
| 3539 |
protected function showContentForm() { |
| 3540 |
$this->showTextbox1(); |
| 3541 |
} |
| 3542 |
|
| 3543 |
private function showTextbox1(): void { |
| 3544 |
if ( $this->formtype === 'save' && $this->wasDeletedSinceLastEdit() ) { |
| 3545 |
$attribs = [ 'style' => 'display:none;' ]; |
| 3546 |
} else { |
| 3547 |
$builder = new TextboxBuilder(); |
| 3548 |
$classes = $builder->getTextboxProtectionCSSClasses( $this->getTitle() ); |
| 3549 |
|
| 3550 |
|
| 3551 |
if ( $this->isOldRev ) { |
| 3552 |
$classes[] = 'mw-textarea-oldrev'; |
| 3553 |
} |
| 3554 |
|
| 3555 |
$attribs = [ |
| 3556 |
'aria-label' => $this->context->msg( 'edit-textarea-aria-label' )->text(), |
| 3557 |
'tabindex' => 1 |
| 3558 |
]; |
| 3559 |
|
| 3560 |
$attribs = $builder->mergeClassesIntoAttributes( $classes, $attribs ); |
| 3561 |
} |
| 3562 |
|
| 3563 |
$this->showTextbox( |
| 3564 |
$this->textbox1, |
| 3565 |
'wpTextbox1', |
| 3566 |
$attribs |
| 3567 |
); |
| 3568 |
} |
| 3569 |
|
| 3570 |
protected function showTextbox( $text, $name, $customAttribs = [] ) { |
| 3571 |
$builder = new TextboxBuilder(); |
| 3572 |
$attribs = $builder->buildTextboxAttribs( |
| 3573 |
$name, |
| 3574 |
$customAttribs, |
| 3575 |
$this->context->getUser(), |
| 3576 |
$this->mTitle |
| 3577 |
); |
| 3578 |
|
| 3579 |
$this->context->getOutput()->addHTML( |
| 3580 |
Html::textarea( $name, $builder->addNewLineAtEnd( $text ), $attribs ) |
| 3581 |
); |
| 3582 |
} |
| 3583 |
|
| 3584 |
private function displayPreviewArea( string $previewOutput, bool $isOnTop ): void { |
| 3585 |
$attribs = [ 'id' => 'wikiPreview' ]; |
| 3586 |
if ( $isOnTop ) { |
| 3587 |
$attribs['class'] = 'ontop'; |
| 3588 |
} |
| 3589 |
if ( $this->formtype !== 'preview' ) { |
| 3590 |
$attribs['style'] = 'display: none;'; |
| 3591 |
} |
| 3592 |
|
| 3593 |
$out = $this->context->getOutput(); |
| 3594 |
$out->addHTML( Html::openElement( 'div', $attribs ) ); |
| 3595 |
|
| 3596 |
if ( $this->formtype === 'preview' ) { |
| 3597 |
$this->showPreview( $previewOutput ); |
| 3598 |
} |
| 3599 |
|
| 3600 |
$out->addHTML( '</div>' ); |
| 3601 |
|
| 3602 |
if ( $this->formtype === 'diff' ) { |
| 3603 |
try { |
| 3604 |
$this->showDiff(); |
| 3605 |
} catch ( MWContentSerializationException $ex ) { |
| 3606 |
$msg = $this->context->msg( |
| 3607 |
'content-failed-to-parse', |
| 3608 |
$this->contentModel, |
| 3609 |
$this->contentFormat, |
| 3610 |
$ex->getMessage() |
| 3611 |
); |
| 3612 |
$out->wrapWikiTextAsInterface( 'error', $msg->plain() ); |
| 3613 |
} |
| 3614 |
} |
| 3615 |
} |
| 3616 |
|
| 3617 |
|
| 3618 |
|
| 3619 |
|
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
private function showPreview( string $text ): void { |
| 3624 |
if ( $this->mArticle instanceof CategoryPage ) { |
| 3625 |
$this->mArticle->openShowCategory(); |
| 3626 |
} |
| 3627 |
|
| 3628 |
|
| 3629 |
$out = $this->context->getOutput(); |
| 3630 |
$this->getHookRunner()->onOutputPageBeforeHTML( $out, $text ); |
| 3631 |
$out->addHTML( $text ); |
| 3632 |
if ( $this->mArticle instanceof CategoryPage ) { |
| 3633 |
$this->mArticle->closeShowCategory(); |
| 3634 |
} |
| 3635 |
} |
| 3636 |
|
| 3637 |
|
| 3638 |
|
| 3639 |
|
| 3640 |
|
| 3641 |
|
| 3642 |
|
| 3643 |
|
| 3644 |
public function showDiff() { |
| 3645 |
$oldtitlemsg = 'currentrev'; |
| 3646 |
|
| 3647 |
if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && !$this->mTitle->exists() ) { |
| 3648 |
$oldtext = $this->mTitle->getDefaultMessageText(); |
| 3649 |
if ( $oldtext !== false ) { |
| 3650 |
$oldtitlemsg = 'defaultmessagetext'; |
| 3651 |
$oldContent = $this->toEditContent( $oldtext ); |
| 3652 |
} else { |
| 3653 |
$oldContent = null; |
| 3654 |
} |
| 3655 |
} else { |
| 3656 |
$oldContent = $this->getCurrentContent(); |
| 3657 |
} |
| 3658 |
|
| 3659 |
$textboxContent = $this->toEditContent( $this->textbox1 ); |
| 3660 |
if ( $this->editRevId !== null ) { |
| 3661 |
$newContent = $this->page->replaceSectionAtRev( |
| 3662 |
$this->section, $textboxContent, $this->sectiontitle, $this->editRevId |
| 3663 |
); |
| 3664 |
} else { |
| 3665 |
$newContent = $this->page->replaceSectionContent( |
| 3666 |
$this->section, $textboxContent, $this->sectiontitle, $this->edittime |
| 3667 |
); |
| 3668 |
} |
| 3669 |
|
| 3670 |
if ( $newContent ) { |
| 3671 |
$this->getHookRunner()->onEditPageGetDiffContent( $this, $newContent ); |
| 3672 |
|
| 3673 |
$user = $this->getUserForPreview(); |
| 3674 |
$parserOptions = ParserOptions::newFromUserAndLang( $user, |
| 3675 |
MediaWikiServices::getInstance()->getContentLanguage() ); |
| 3676 |
$services = MediaWikiServices::getInstance(); |
| 3677 |
$contentTransformer = $services->getContentTransformer(); |
| 3678 |
$newContent = $contentTransformer->preSaveTransform( $newContent, $this->mTitle, $user, $parserOptions ); |
| 3679 |
} |
| 3680 |
|
| 3681 |
if ( ( $oldContent && !$oldContent->isEmpty() ) || ( $newContent && !$newContent->isEmpty() ) ) { |
| 3682 |
$oldtitle = $this->context->msg( $oldtitlemsg )->parse(); |
| 3683 |
$newtitle = $this->context->msg( 'yourtext' )->parse(); |
| 3684 |
|
| 3685 |
if ( !$oldContent ) { |
| 3686 |
$oldContent = $newContent->getContentHandler()->makeEmptyContent(); |
| 3687 |
} |
| 3688 |
|
| 3689 |
if ( !$newContent ) { |
| 3690 |
$newContent = $oldContent->getContentHandler()->makeEmptyContent(); |
| 3691 |
} |
| 3692 |
|
| 3693 |
$de = $oldContent->getContentHandler()->createDifferenceEngine( $this->context ); |
| 3694 |
$de->setContent( $oldContent, $newContent ); |
| 3695 |
|
| 3696 |
$difftext = $de->getDiff( $oldtitle, $newtitle ); |
| 3697 |
$de->showDiffStyle(); |
| 3698 |
} else { |
| 3699 |
$difftext = ''; |
| 3700 |
} |
| 3701 |
|
| 3702 |
$this->context->getOutput()->addHTML( Html::rawElement( 'div', [ 'id' => 'wikiDiff' ], $difftext ) ); |
| 3703 |
} |
| 3704 |
|
| 3705 |
|
| 3706 |
|
| 3707 |
|
| 3708 |
|
| 3709 |
|
| 3710 |
|
| 3711 |
|
| 3712 |
|
| 3713 |
private function showTosSummary(): void { |
| 3714 |
$msgKey = 'editpage-tos-summary'; |
| 3715 |
$this->getHookRunner()->onEditPageTosSummary( $this->mTitle, $msgKey ); |
| 3716 |
$msg = $this->context->msg( $msgKey ); |
| 3717 |
if ( !$msg->isDisabled() ) { |
| 3718 |
$this->context->getOutput()->addHTML( Html::rawElement( |
| 3719 |
'div', |
| 3720 |
[ 'class' => 'mw-tos-summary' ], |
| 3721 |
$msg->parseAsBlock() |
| 3722 |
) ); |
| 3723 |
} |
| 3724 |
} |
| 3725 |
|
| 3726 |
|
| 3727 |
|
| 3728 |
|
| 3729 |
|
| 3730 |
private function showEditTools(): void { |
| 3731 |
$this->context->getOutput()->addHTML( Html::rawElement( |
| 3732 |
'div', |
| 3733 |
[ 'class' => 'mw-editTools' ], |
| 3734 |
$this->context->msg( 'edittools' )->inContentLanguage()->parse() |
| 3735 |
) ); |
| 3736 |
} |
| 3737 |
|
| 3738 |
|
| 3739 |
|
| 3740 |
|
| 3741 |
|
| 3742 |
|
| 3743 |
|
| 3744 |
|
| 3745 |
|
| 3746 |
|
| 3747 |
public static function getCopyrightWarning( PageReference $page, string $format, MessageLocalizer $localizer ) { |
| 3748 |
$services = MediaWikiServices::getInstance(); |
| 3749 |
$rightsText = $services->getMainConfig()->get( MainConfigNames::RightsText ); |
| 3750 |
if ( $rightsText ) { |
| 3751 |
$copywarnMsg = [ 'copyrightwarning', |
| 3752 |
'[[' . $localizer->msg( 'copyrightpage' )->inContentLanguage()->text() . ']]', |
| 3753 |
$rightsText ]; |
| 3754 |
} else { |
| 3755 |
$copywarnMsg = [ 'copyrightwarning2', |
| 3756 |
'[[' . $localizer->msg( 'copyrightpage' )->inContentLanguage()->text() . ']]' ]; |
| 3757 |
} |
| 3758 |
|
| 3759 |
$title = Title::newFromPageReference( $page ); |
| 3760 |
( new HookRunner( $services->getHookContainer() ) )->onEditPageCopyrightWarning( $title, $copywarnMsg ); |
| 3761 |
if ( !$copywarnMsg ) { |
| 3762 |
return ''; |
| 3763 |
} |
| 3764 |
|
| 3765 |
$msg = $localizer->msg( ...$copywarnMsg )->page( $page ); |
| 3766 |
return Html::rawElement( 'div', [ 'id' => 'editpage-copywarn' ], $msg->$format() ); |
| 3767 |
} |
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
|
| 3772 |
|
| 3773 |
|
| 3774 |
|
| 3775 |
|
| 3776 |
public static function getPreviewLimitReport( ?ParserOutput $output = null ) { |
| 3777 |
if ( !$output || !$output->getLimitReportData() ) { |
| 3778 |
return ''; |
| 3779 |
} |
| 3780 |
|
| 3781 |
$limitReport = Html::rawElement( 'div', [ 'class' => 'mw-limitReportExplanation' ], |
| 3782 |
wfMessage( 'limitreport-title' )->parseAsBlock() |
| 3783 |
); |
| 3784 |
|
| 3785 |
|
| 3786 |
$limitReport .= Html::openElement( 'div', [ 'class' => 'preview-limit-report-wrapper' ] ); |
| 3787 |
|
| 3788 |
$limitReport .= Html::openElement( 'table', [ |
| 3789 |
'class' => 'preview-limit-report wikitable' |
| 3790 |
] ) . |
| 3791 |
Html::openElement( 'tbody' ); |
| 3792 |
|
| 3793 |
$hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ); |
| 3794 |
foreach ( $output->getLimitReportData() as $key => $value ) { |
| 3795 |
if ( $hookRunner->onParserLimitReportFormat( $key, $value, $limitReport, true, true ) ) { |
| 3796 |
$keyMsg = wfMessage( $key ); |
| 3797 |
$valueMsg = wfMessage( [ "$key-value-html", "$key-value" ] ); |
| 3798 |
if ( !$valueMsg->exists() ) { |
| 3799 |
|
| 3800 |
|
| 3801 |
|
| 3802 |
$valueMsg = ( new RawMessage( '$1' ) )->params( $value ); |
| 3803 |
} else { |
| 3804 |
|
| 3805 |
|
| 3806 |
$valueMsg = $valueMsg->numParams( $value ); |
| 3807 |
} |
| 3808 |
if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) { |
| 3809 |
$limitReport .= Html::openElement( 'tr' ) . |
| 3810 |
Html::rawElement( 'th', [], $keyMsg->parse() ) . |
| 3811 |
Html::rawElement( 'td', [], $valueMsg->parse() ) . |
| 3812 |
Html::closeElement( 'tr' ); |
| 3813 |
} |
| 3814 |
} |
| 3815 |
} |
| 3816 |
|
| 3817 |
$limitReport .= Html::closeElement( 'tbody' ) . |
| 3818 |
Html::closeElement( 'table' ) . |
| 3819 |
Html::closeElement( 'div' ); |
| 3820 |
|
| 3821 |
return $limitReport; |
| 3822 |
} |
| 3823 |
|
| 3824 |
protected function showStandardInputs( &$tabindex = 2 ) { |
| 3825 |
$out = $this->context->getOutput(); |
| 3826 |
$out->addHTML( "<div class='editOptions'>\n" ); |
| 3827 |
|
| 3828 |
if ( $this->section !== 'new' ) { |
| 3829 |
$this->showSummaryInput( false ); |
| 3830 |
$out->addHTML( $this->getSummaryPreview( false ) ); |
| 3831 |
} |
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
$expiryFromRequest = null; |
| 3837 |
if ( $this->preview || $this->diff || $this->isConflict ) { |
| 3838 |
$expiryFromRequest = $this->getContext()->getRequest()->getText( 'wpWatchlistExpiry' ); |
| 3839 |
} |
| 3840 |
|
| 3841 |
$checkboxes = $this->getCheckboxesWidget( |
| 3842 |
$tabindex, |
| 3843 |
[ 'minor' => $this->minoredit, 'watch' => $this->watchthis, 'wpWatchlistExpiry' => $expiryFromRequest ] |
| 3844 |
); |
| 3845 |
$checkboxesHTML = new OOUI\HorizontalLayout( [ 'items' => array_values( $checkboxes ) ] ); |
| 3846 |
|
| 3847 |
$out->addHTML( "<div class='editCheckboxes'>" . $checkboxesHTML . "</div>\n" ); |
| 3848 |
|
| 3849 |
|
| 3850 |
$out->addHTML( self::getCopyrightWarning( $this->mTitle, 'parse', $this->context ) ); |
| 3851 |
$out->addHTML( $this->editFormTextAfterWarn ); |
| 3852 |
|
| 3853 |
$out->addHTML( "<div class='editButtons'>\n" ); |
| 3854 |
$out->addHTML( implode( "\n", $this->getEditButtons( $tabindex ) ) . "\n" ); |
| 3855 |
|
| 3856 |
$cancel = $this->getCancelLink( $tabindex++ ); |
| 3857 |
|
| 3858 |
$edithelp = $this->getHelpLink() . |
| 3859 |
$this->context->msg( 'word-separator' )->escaped() . |
| 3860 |
$this->context->msg( 'newwindow' )->parse(); |
| 3861 |
|
| 3862 |
$out->addHTML( " <span class='cancelLink'>{$cancel}</span>\n" ); |
| 3863 |
$out->addHTML( " <span class='editHelp'>{$edithelp}</span>\n" ); |
| 3864 |
$out->addHTML( "</div><!-- editButtons -->\n" ); |
| 3865 |
|
| 3866 |
$this->getHookRunner()->onEditPage__showStandardInputs_options( $this, $out, $tabindex ); |
| 3867 |
|
| 3868 |
$out->addHTML( "</div><!-- editOptions -->\n" ); |
| 3869 |
} |
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
private function showConflict(): void { |
| 3876 |
$out = $this->context->getOutput(); |
| 3877 |
if ( $this->getHookRunner()->onEditPageBeforeConflictDiff( $this, $out ) ) { |
| 3878 |
$this->incrementConflictStats(); |
| 3879 |
|
| 3880 |
$this->getEditConflictHelper()->showEditFormTextAfterFooters(); |
| 3881 |
} |
| 3882 |
} |
| 3883 |
|
| 3884 |
private function incrementConflictStats(): void { |
| 3885 |
$this->getEditConflictHelper()->incrementConflictStats( $this->context->getUser() ); |
| 3886 |
} |
| 3887 |
|
| 3888 |
|
| 3889 |
|
| 3890 |
|
| 3891 |
private function getHelpLink(): string { |
| 3892 |
$message = $this->context->msg( 'edithelppage' )->inContentLanguage()->text(); |
| 3893 |
$editHelpUrl = Skin::makeInternalOrExternalUrl( $message ); |
| 3894 |
return Html::element( 'a', [ |
| 3895 |
'href' => $editHelpUrl, |
| 3896 |
'target' => 'helpwindow' |
| 3897 |
], $this->context->msg( 'edithelp' )->text() ); |
| 3898 |
} |
| 3899 |
|
| 3900 |
|
| 3901 |
|
| 3902 |
|
| 3903 |
|
| 3904 |
private function getCancelLink( int $tabindex ): ButtonWidget { |
| 3905 |
$cancelParams = []; |
| 3906 |
if ( !$this->isConflict && $this->oldid > 0 ) { |
| 3907 |
$cancelParams['oldid'] = $this->oldid; |
| 3908 |
} elseif ( $this->getContextTitle()->isRedirect() ) { |
| 3909 |
$cancelParams['redirect'] = 'no'; |
| 3910 |
} |
| 3911 |
|
| 3912 |
return new OOUI\ButtonWidget( [ |
| 3913 |
'id' => 'mw-editform-cancel', |
| 3914 |
'tabIndex' => $tabindex, |
| 3915 |
'href' => $this->getContextTitle()->getLinkURL( $cancelParams ), |
| 3916 |
'label' => new OOUI\HtmlSnippet( $this->context->msg( 'cancel' )->parse() ), |
| 3917 |
'framed' => false, |
| 3918 |
'infusable' => true, |
| 3919 |
'flags' => 'destructive', |
| 3920 |
] ); |
| 3921 |
} |
| 3922 |
|
| 3923 |
|
| 3924 |
|
| 3925 |
|
| 3926 |
|
| 3927 |
|
| 3928 |
|
| 3929 |
|
| 3930 |
|
| 3931 |
|
| 3932 |
protected function getActionURL( Title $title ) { |
| 3933 |
return $title->getLocalURL( [ 'action' => $this->action ] ); |
| 3934 |
} |
| 3935 |
|
| 3936 |
|
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
private function wasDeletedSinceLastEdit(): bool { |
| 3944 |
if ( $this->deletedSinceEdit !== null ) { |
| 3945 |
return $this->deletedSinceEdit; |
| 3946 |
} |
| 3947 |
|
| 3948 |
$this->deletedSinceEdit = false; |
| 3949 |
|
| 3950 |
if ( !$this->mTitle->exists() && $this->mTitle->hasDeletedEdits() ) { |
| 3951 |
$this->lastDelete = $this->getLastDelete(); |
| 3952 |
if ( $this->lastDelete ) { |
| 3953 |
$deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp ); |
| 3954 |
if ( $deleteTime > $this->starttime ) { |
| 3955 |
$this->deletedSinceEdit = true; |
| 3956 |
} |
| 3957 |
} |
| 3958 |
} |
| 3959 |
|
| 3960 |
return $this->deletedSinceEdit; |
| 3961 |
} |
| 3962 |
|
| 3963 |
|
| 3964 |
|
| 3965 |
|
| 3966 |
|
| 3967 |
|
| 3968 |
private function getLastDelete(): ?stdClass { |
| 3969 |
$dbr = $this->connectionProvider->getReplicaDatabase(); |
| 3970 |
$commentQuery = $this->commentStore->getJoin( 'log_comment' ); |
| 3971 |
$data = $dbr->newSelectQueryBuilder() |
| 3972 |
->select( [ |
| 3973 |
'log_type', |
| 3974 |
'log_action', |
| 3975 |
'log_timestamp', |
| 3976 |
'log_namespace', |
| 3977 |
'log_title', |
| 3978 |
'log_params', |
| 3979 |
'log_deleted', |
| 3980 |
'actor_name' |
| 3981 |
] ) |
| 3982 |
->from( 'logging' ) |
| 3983 |
->join( 'actor', null, 'actor_id=log_actor' ) |
| 3984 |
->where( [ |
| 3985 |
'log_namespace' => $this->mTitle->getNamespace(), |
| 3986 |
'log_title' => $this->mTitle->getDBkey(), |
| 3987 |
'log_type' => 'delete', |
| 3988 |
'log_action' => 'delete', |
| 3989 |
] ) |
| 3990 |
->orderBy( [ 'log_timestamp', 'log_id' ], SelectQueryBuilder::SORT_DESC ) |
| 3991 |
->queryInfo( $commentQuery ) |
| 3992 |
->caller( __METHOD__ ) |
| 3993 |
->fetchRow(); |
| 3994 |
|
| 3995 |
if ( $data !== false ) { |
| 3996 |
if ( $data->log_deleted & LogPage::DELETED_USER ) { |
| 3997 |
$data->actor_name = $this->context->msg( 'rev-deleted-user' )->escaped(); |
| 3998 |
} |
| 3999 |
|
| 4000 |
if ( $data->log_deleted & LogPage::DELETED_COMMENT ) { |
| 4001 |
$data->log_comment_text = $this->context->msg( 'rev-deleted-comment' )->escaped(); |
| 4002 |
$data->log_comment_data = null; |
| 4003 |
} |
| 4004 |
} |
| 4005 |
|
| 4006 |
return $data ?: null; |
| 4007 |
} |
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
|
| 4014 |
public function getPreviewText() { |
| 4015 |
$out = $this->context->getOutput(); |
| 4016 |
$config = $this->context->getConfig(); |
| 4017 |
|
| 4018 |
if ( $config->get( MainConfigNames::RawHtml ) && !$this->mTokenOk ) { |
| 4019 |
|
| 4020 |
|
| 4021 |
$parsedNote = ''; |
| 4022 |
if ( $this->textbox1 !== '' ) { |
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
$parsedNote = Html::rawElement( 'div', [ 'class' => 'previewnote' ], |
| 4027 |
$out->parseAsInterface( |
| 4028 |
$this->context->msg( 'session_fail_preview_html' )->plain() |
| 4029 |
) ); |
| 4030 |
} |
| 4031 |
$this->incrementEditFailureStats( 'session_loss' ); |
| 4032 |
return $parsedNote; |
| 4033 |
} |
| 4034 |
|
| 4035 |
$note = ''; |
| 4036 |
|
| 4037 |
try { |
| 4038 |
$content = $this->toEditContent( $this->textbox1 ); |
| 4039 |
|
| 4040 |
$previewHTML = ''; |
| 4041 |
if ( !$this->getHookRunner()->onAlternateEditPreview( |
| 4042 |
$this, $content, $previewHTML, $this->mParserOutput ) |
| 4043 |
) { |
| 4044 |
return $previewHTML; |
| 4045 |
} |
| 4046 |
|
| 4047 |
|
| 4048 |
$continueEditing = '<span class="mw-continue-editing">' . |
| 4049 |
'[[#' . self::EDITFORM_ID . '|' . |
| 4050 |
$this->context->getLanguage()->getArrow() . ' ' . |
| 4051 |
$this->context->msg( 'continue-editing' )->text() . ']]</span>'; |
| 4052 |
if ( $this->mTriedSave && !$this->mTokenOk ) { |
| 4053 |
$note = $this->context->msg( 'session_fail_preview' )->plain(); |
| 4054 |
$this->incrementEditFailureStats( 'session_loss' ); |
| 4055 |
} elseif ( $this->incompleteForm ) { |
| 4056 |
$note = $this->context->msg( 'edit_form_incomplete' )->plain(); |
| 4057 |
if ( $this->mTriedSave ) { |
| 4058 |
$this->incrementEditFailureStats( 'incomplete_form' ); |
| 4059 |
} |
| 4060 |
} else { |
| 4061 |
$note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing; |
| 4062 |
} |
| 4063 |
|
| 4064 |
|
| 4065 |
if ( $this->mTitle->isUserConfigPage() || $this->mTitle->isSiteConfigPage() ) { |
| 4066 |
if ( $this->mTitle->isUserConfigPage() ) { |
| 4067 |
$level = 'user'; |
| 4068 |
} elseif ( $this->mTitle->isSiteConfigPage() ) { |
| 4069 |
$level = 'site'; |
| 4070 |
} else { |
| 4071 |
$level = false; |
| 4072 |
} |
| 4073 |
|
| 4074 |
if ( $content->getModel() === CONTENT_MODEL_CSS ) { |
| 4075 |
$format = 'css'; |
| 4076 |
if ( $level === 'user' && !$config->get( MainConfigNames::AllowUserCss ) ) { |
| 4077 |
$format = false; |
| 4078 |
} |
| 4079 |
} elseif ( $content->getModel() === CONTENT_MODEL_JSON ) { |
| 4080 |
$format = 'json'; |
| 4081 |
if ( $level === 'user' ) { |
| 4082 |
$format = false; |
| 4083 |
} |
| 4084 |
} elseif ( $content->getModel() === CONTENT_MODEL_JAVASCRIPT ) { |
| 4085 |
$format = 'js'; |
| 4086 |
if ( $level === 'user' && !$config->get( MainConfigNames::AllowUserJs ) ) { |
| 4087 |
$format = false; |
| 4088 |
} |
| 4089 |
} else { |
| 4090 |
$format = false; |
| 4091 |
} |
| 4092 |
|
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
if ( $level && $format ) { |
| 4097 |
$note = "<div id='mw-{$level}{$format}preview'>" . |
| 4098 |
$this->context->msg( "{$level}{$format}preview" )->plain() . |
| 4099 |
' ' . $continueEditing . "</div>"; |
| 4100 |
} |
| 4101 |
} |
| 4102 |
|
| 4103 |
if ( $this->section === "new" ) { |
| 4104 |
$content = $content->addSectionHeader( $this->sectiontitle ); |
| 4105 |
} |
| 4106 |
|
| 4107 |
|
| 4108 |
$this->getHookRunner()->onEditPageGetPreviewContent( $this, $content ); |
| 4109 |
|
| 4110 |
$parserResult = $this->doPreviewParse( $content ); |
| 4111 |
$parserOutput = $parserResult['parserOutput']; |
| 4112 |
$previewHTML = $parserResult['html']; |
| 4113 |
$this->mParserOutput = $parserOutput; |
| 4114 |
$out->addParserOutputMetadata( $parserOutput ); |
| 4115 |
if ( $out->userCanPreview() ) { |
| 4116 |
$out->addContentOverride( $this->getTitle(), $content ); |
| 4117 |
} |
| 4118 |
|
| 4119 |
if ( count( $parserOutput->getWarnings() ) ) { |
| 4120 |
$note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() ); |
| 4121 |
} |
| 4122 |
|
| 4123 |
} catch ( MWContentSerializationException $ex ) { |
| 4124 |
$m = $this->context->msg( |
| 4125 |
'content-failed-to-parse', |
| 4126 |
$this->contentModel, |
| 4127 |
$this->contentFormat, |
| 4128 |
$ex->getMessage() |
| 4129 |
); |
| 4130 |
$note .= "\n\n" . $m->plain(); |
| 4131 |
$previewHTML = ''; |
| 4132 |
} |
| 4133 |
|
| 4134 |
if ( $this->isConflict ) { |
| 4135 |
$conflict = Html::warningBox( |
| 4136 |
$this->context->msg( 'previewconflict' )->escaped(), |
| 4137 |
'mw-previewconflict' |
| 4138 |
); |
| 4139 |
} else { |
| 4140 |
$conflict = ''; |
| 4141 |
} |
| 4142 |
|
| 4143 |
$previewhead = Html::rawElement( |
| 4144 |
'div', [ 'class' => 'previewnote' ], |
| 4145 |
Html::rawElement( |
| 4146 |
'h2', [ 'id' => 'mw-previewheader' ], |
| 4147 |
$this->context->msg( 'preview' )->escaped() |
| 4148 |
) . |
| 4149 |
Html::warningBox( |
| 4150 |
$out->parseAsInterface( $note ) |
| 4151 |
) . $conflict |
| 4152 |
); |
| 4153 |
|
| 4154 |
return $previewhead . $previewHTML . $this->previewTextAfterContent; |
| 4155 |
} |
| 4156 |
|
| 4157 |
private function incrementEditFailureStats( string $failureType ): void { |
| 4158 |
MediaWikiServices::getInstance()->getStatsFactory() |
| 4159 |
->getCounter( 'edit_failure_total' ) |
| 4160 |
->setLabel( 'cause', $failureType ) |
| 4161 |
->setLabel( 'namespace', 'n/a' ) |
| 4162 |
->setLabel( 'user_bucket', 'n/a' ) |
| 4163 |
->copyToStatsdAt( 'edit.failures.' . $failureType ) |
| 4164 |
->increment(); |
| 4165 |
} |
| 4166 |
|
| 4167 |
|
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
protected function getPreviewParserOptions() { |
| 4172 |
$parserOptions = $this->page->makeParserOptions( $this->context ); |
| 4173 |
$parserOptions->setRenderReason( 'page-preview' ); |
| 4174 |
$parserOptions->setIsPreview( true ); |
| 4175 |
$parserOptions->setIsSectionPreview( $this->section !== null && $this->section !== '' ); |
| 4176 |
|
| 4177 |
|
| 4178 |
|
| 4179 |
|
| 4180 |
|
| 4181 |
|
| 4182 |
return $parserOptions; |
| 4183 |
} |
| 4184 |
|
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
protected function doPreviewParse( Content $content ) { |
| 4195 |
$user = $this->getUserForPreview(); |
| 4196 |
$parserOptions = $this->getPreviewParserOptions(); |
| 4197 |
|
| 4198 |
|
| 4199 |
|
| 4200 |
|
| 4201 |
|
| 4202 |
|
| 4203 |
$services = MediaWikiServices::getInstance(); |
| 4204 |
$contentTransformer = $services->getContentTransformer(); |
| 4205 |
$contentRenderer = $services->getContentRenderer(); |
| 4206 |
$pstContent = $contentTransformer->preSaveTransform( $content, $this->mTitle, $user, $parserOptions ); |
| 4207 |
$parserOutput = $contentRenderer->getParserOutput( $pstContent, $this->mTitle, null, $parserOptions ); |
| 4208 |
$out = $this->context->getOutput(); |
| 4209 |
$skin = $out->getSkin(); |
| 4210 |
$skinOptions = $skin->getOptions(); |
| 4211 |
|
| 4212 |
|
| 4213 |
$oldHtml = $parserOutput->getRawText(); |
| 4214 |
$html = $parserOutput->runOutputPipeline( $parserOptions, [ |
| 4215 |
'allowClone' => 'false', |
| 4216 |
'userLang' => $skin->getLanguage(), |
| 4217 |
'injectTOC' => $skinOptions['toc'], |
| 4218 |
'enableSectionEditLinks' => false, |
| 4219 |
'includeDebugInfo' => true, |
| 4220 |
] )->getContentHolderText(); |
| 4221 |
$parserOutput->setRawText( $oldHtml ); |
| 4222 |
return [ |
| 4223 |
'parserOutput' => $parserOutput, |
| 4224 |
'html' => $html |
| 4225 |
]; |
| 4226 |
} |
| 4227 |
|
| 4228 |
|
| 4229 |
|
| 4230 |
|
| 4231 |
public function getTemplates() { |
| 4232 |
if ( $this->preview || $this->section !== '' ) { |
| 4233 |
$templates = []; |
| 4234 |
if ( !isset( $this->mParserOutput ) ) { |
| 4235 |
return $templates; |
| 4236 |
} |
| 4237 |
foreach ( $this->mParserOutput->getTemplates() as $ns => $template ) { |
| 4238 |
foreach ( $template as $dbk => $_ ) { |
| 4239 |
$templates[] = Title::makeTitle( $ns, $dbk ); |
| 4240 |
} |
| 4241 |
} |
| 4242 |
return $templates; |
| 4243 |
} else { |
| 4244 |
return $this->mTitle->getTemplateLinksFrom(); |
| 4245 |
} |
| 4246 |
} |
| 4247 |
|
| 4248 |
|
| 4249 |
|
| 4250 |
|
| 4251 |
|
| 4252 |
|
| 4253 |
public static function getEditToolbar() { |
| 4254 |
$startingToolbar = '<div id="toolbar"></div>'; |
| 4255 |
$toolbar = $startingToolbar; |
| 4256 |
|
| 4257 |
$hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ); |
| 4258 |
if ( !$hookRunner->onEditPageBeforeEditToolbar( $toolbar ) ) { |
| 4259 |
return null; |
| 4260 |
} |
| 4261 |
|
| 4262 |
return ( $toolbar === $startingToolbar ) ? null : $toolbar; |
| 4263 |
} |
| 4264 |
|
| 4265 |
|
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
|
| 4272 |
|
| 4273 |
|
| 4274 |
|
| 4275 |
|
| 4276 |
|
| 4277 |
|
| 4278 |
|
| 4279 |
|
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
|
| 4285 |
|
| 4286 |
|
| 4287 |
|
| 4288 |
|
| 4289 |
|
| 4290 |
public function getCheckboxesDefinition( $values ) { |
| 4291 |
$checkboxes = []; |
| 4292 |
|
| 4293 |
$user = $this->context->getUser(); |
| 4294 |
|
| 4295 |
if ( !$this->isNew && $this->permManager->userHasRight( $user, 'minoredit' ) ) { |
| 4296 |
$checkboxes['wpMinoredit'] = [ |
| 4297 |
'id' => 'wpMinoredit', |
| 4298 |
'label-message' => 'minoredit', |
| 4299 |
|
| 4300 |
'tooltip' => 'minoredit', |
| 4301 |
'label-id' => 'mw-editpage-minoredit', |
| 4302 |
'legacy-name' => 'minor', |
| 4303 |
'default' => $values['minor'], |
| 4304 |
]; |
| 4305 |
} |
| 4306 |
|
| 4307 |
if ( $user->isNamed() ) { |
| 4308 |
$checkboxes = array_merge( |
| 4309 |
$checkboxes, |
| 4310 |
$this->getCheckboxesDefinitionForWatchlist( $values['watch'], $values['wpWatchlistExpiry'] ?? null ) |
| 4311 |
); |
| 4312 |
} |
| 4313 |
|
| 4314 |
$this->getHookRunner()->onEditPageGetCheckboxesDefinition( $this, $checkboxes ); |
| 4315 |
|
| 4316 |
return $checkboxes; |
| 4317 |
} |
| 4318 |
|
| 4319 |
|
| 4320 |
|
| 4321 |
|
| 4322 |
|
| 4323 |
|
| 4324 |
|
| 4325 |
|
| 4326 |
private function getCheckboxesDefinitionForWatchlist( $watch, $watchexpiry ): array { |
| 4327 |
$fieldDefs = [ |
| 4328 |
'wpWatchthis' => [ |
| 4329 |
'id' => 'wpWatchthis', |
| 4330 |
'label-message' => 'watchthis', |
| 4331 |
|
| 4332 |
'tooltip' => 'watch', |
| 4333 |
'label-id' => 'mw-editpage-watch', |
| 4334 |
'legacy-name' => 'watch', |
| 4335 |
'default' => $watch, |
| 4336 |
] |
| 4337 |
]; |
| 4338 |
if ( $this->watchlistExpiryEnabled ) { |
| 4339 |
$watchedItem = $this->watchedItemStore->getWatchedItem( $this->getContext()->getUser(), $this->getTitle() ); |
| 4340 |
$expiryOptions = WatchAction::getExpiryOptions( $this->getContext(), $watchedItem ); |
| 4341 |
if ( $watchexpiry && in_array( $watchexpiry, $expiryOptions['options'] ) ) { |
| 4342 |
$expiryOptions['default'] = $watchexpiry; |
| 4343 |
} |
| 4344 |
|
| 4345 |
$options = []; |
| 4346 |
foreach ( $expiryOptions['options'] as $label => $value ) { |
| 4347 |
$options[] = [ 'data' => $value, 'label' => $label ]; |
| 4348 |
} |
| 4349 |
$fieldDefs['wpWatchlistExpiry'] = [ |
| 4350 |
'id' => 'wpWatchlistExpiry', |
| 4351 |
'label-message' => 'confirm-watch-label', |
| 4352 |
|
| 4353 |
'tooltip' => 'watchlist-expiry', |
| 4354 |
'label-id' => 'mw-editpage-watchlist-expiry', |
| 4355 |
'default' => $expiryOptions['default'], |
| 4356 |
'value-attr' => 'value', |
| 4357 |
'class' => DropdownInputWidget::class, |
| 4358 |
'options' => $options, |
| 4359 |
'invisibleLabel' => true, |
| 4360 |
]; |
| 4361 |
} |
| 4362 |
return $fieldDefs; |
| 4363 |
} |
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
|
| 4371 |
|
| 4372 |
|
| 4373 |
|
| 4374 |
|
| 4375 |
public function getCheckboxesWidget( &$tabindex, $values ) { |
| 4376 |
$checkboxes = []; |
| 4377 |
$checkboxesDef = $this->getCheckboxesDefinition( $values ); |
| 4378 |
|
| 4379 |
foreach ( $checkboxesDef as $name => $options ) { |
| 4380 |
$legacyName = $options['legacy-name'] ?? $name; |
| 4381 |
|
| 4382 |
$title = null; |
| 4383 |
$accesskey = null; |
| 4384 |
if ( isset( $options['tooltip'] ) ) { |
| 4385 |
$accesskey = $this->context->msg( "accesskey-{$options['tooltip']}" )->text(); |
| 4386 |
$title = Linker::titleAttrib( $options['tooltip'] ); |
| 4387 |
} |
| 4388 |
if ( isset( $options['title-message'] ) ) { |
| 4389 |
$title = $this->context->msg( $options['title-message'] )->text(); |
| 4390 |
} |
| 4391 |
|
| 4392 |
|
| 4393 |
$className = $options['class'] ?? CheckboxInputWidget::class; |
| 4394 |
$valueAttr = $options['value-attr'] ?? 'selected'; |
| 4395 |
$checkboxes[ $legacyName ] = new FieldLayout( |
| 4396 |
new $className( [ |
| 4397 |
'tabIndex' => ++$tabindex, |
| 4398 |
'accessKey' => $accesskey, |
| 4399 |
'id' => $options['id'] . 'Widget', |
| 4400 |
'inputId' => $options['id'], |
| 4401 |
'name' => $name, |
| 4402 |
$valueAttr => $options['default'], |
| 4403 |
'infusable' => true, |
| 4404 |
'options' => $options['options'] ?? null, |
| 4405 |
] ), |
| 4406 |
[ |
| 4407 |
'align' => 'inline', |
| 4408 |
'label' => new OOUI\HtmlSnippet( $this->context->msg( $options['label-message'] )->parse() ), |
| 4409 |
'title' => $title, |
| 4410 |
'id' => $options['label-id'] ?? null, |
| 4411 |
'invisibleLabel' => $options['invisibleLabel'] ?? null, |
| 4412 |
] |
| 4413 |
); |
| 4414 |
} |
| 4415 |
|
| 4416 |
return $checkboxes; |
| 4417 |
} |
| 4418 |
|
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
|
| 4424 |
private function getSubmitButtonLabel(): string { |
| 4425 |
$labelAsPublish = |
| 4426 |
$this->context->getConfig()->get( MainConfigNames::EditSubmitButtonLabelPublish ); |
| 4427 |
|
| 4428 |
|
| 4429 |
$newPage = !$this->mTitle->exists(); |
| 4430 |
|
| 4431 |
if ( $labelAsPublish ) { |
| 4432 |
$buttonLabelKey = $newPage ? 'publishpage' : 'publishchanges'; |
| 4433 |
} else { |
| 4434 |
$buttonLabelKey = $newPage ? 'savearticle' : 'savechanges'; |
| 4435 |
} |
| 4436 |
|
| 4437 |
return $buttonLabelKey; |
| 4438 |
} |
| 4439 |
|
| 4440 |
|
| 4441 |
|
| 4442 |
|
| 4443 |
|
| 4444 |
|
| 4445 |
|
| 4446 |
|
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
public function getEditButtons( &$tabindex ) { |
| 4451 |
$buttons = []; |
| 4452 |
|
| 4453 |
$labelAsPublish = |
| 4454 |
$this->context->getConfig()->get( MainConfigNames::EditSubmitButtonLabelPublish ); |
| 4455 |
|
| 4456 |
$buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text(); |
| 4457 |
$buttonTooltip = $labelAsPublish ? 'publish' : 'save'; |
| 4458 |
|
| 4459 |
$buttons['save'] = new OOUI\ButtonInputWidget( [ |
| 4460 |
'name' => 'wpSave', |
| 4461 |
'tabIndex' => ++$tabindex, |
| 4462 |
'id' => 'wpSaveWidget', |
| 4463 |
'inputId' => 'wpSave', |
| 4464 |
ked |
| 4465 |
'useInputTag' => true, |
| 4466 |
'flags' => [ 'progressive', 'primary' ], |
| 4467 |
'label' => $buttonLabel, |
| 4468 |
'infusable' => true, |
| 4469 |
'type' => 'submit', |
| 4470 |
|
| 4471 |
'title' => Linker::titleAttrib( $buttonTooltip ), |
| 4472 |
|
| 4473 |
'accessKey' => Linker::accesskey( $buttonTooltip ), |
| 4474 |
] ); |
| 4475 |
|
| 4476 |
$buttons['preview'] = new OOUI\ButtonInputWidget( [ |
| 4477 |
'name' => 'wpPreview', |
| 4478 |
'tabIndex' => ++$tabindex, |
| 4479 |
'id' => 'wpPreviewWidget', |
| 4480 |
'inputId' => 'wpPreview', |
| 4481 |
ked |
| 4482 |
'useInputTag' => true, |
| 4483 |
'label' => $this->context->msg( 'showpreview' )->text(), |
| 4484 |
'infusable' => true, |
| 4485 |
'type' => 'submit', |
| 4486 |
|
| 4487 |
'formNoValidate' => true, |
| 4488 |
|
| 4489 |
'title' => Linker::titleAttrib( 'preview' ), |
| 4490 |
|
| 4491 |
'accessKey' => Linker::accesskey( 'preview' ), |
| 4492 |
] ); |
| 4493 |
|
| 4494 |
$buttons['diff'] = new OOUI\ButtonInputWidget( [ |
| 4495 |
'name' => 'wpDiff', |
| 4496 |
'tabIndex' => ++$tabindex, |
| 4497 |
'id' => 'wpDiffWidget', |
| 4498 |
'inputId' => 'wpDiff', |
| 4499 |
ked |
| 4500 |
'useInputTag' => true, |
| 4501 |
'label' => $this->context->msg( 'showdiff' )->text(), |
| 4502 |
'infusable' => true, |
| 4503 |
'type' => 'submit', |
| 4504 |
|
| 4505 |
'formNoValidate' => true, |
| 4506 |
|
| 4507 |
'title' => Linker::titleAttrib( 'diff' ), |
| 4508 |
|
| 4509 |
'accessKey' => Linker::accesskey( 'diff' ), |
| 4510 |
] ); |
| 4511 |
|
| 4512 |
$this->getHookRunner()->onEditPageBeforeEditButtons( $this, $buttons, $tabindex ); |
| 4513 |
|
| 4514 |
return $buttons; |
| 4515 |
} |
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
|
| 4520 |
|
| 4521 |
private function noSuchSectionPage(): void { |
| 4522 |
$out = $this->context->getOutput(); |
| 4523 |
$out->prepareErrorPage(); |
| 4524 |
$out->setPageTitleMsg( $this->context->msg( 'nosuchsectiontitle' ) ); |
| 4525 |
|
| 4526 |
$res = $this->context->msg( 'nosuchsectiontext', $this->section )->parseAsBlock(); |
| 4527 |
|
| 4528 |
$this->getHookRunner()->onEditPageNoSuchSection( $this, $res ); |
| 4529 |
$out->addHTML( $res ); |
| 4530 |
|
| 4531 |
$out->returnToMain( false, $this->mTitle ); |
| 4532 |
} |
| 4533 |
|
| 4534 |
|
| 4535 |
|
| 4536 |
|
| 4537 |
|
| 4538 |
|
| 4539 |
public function spamPageWithContent( $match = false ) { |
| 4540 |
$this->textbox2 = $this->textbox1; |
| 4541 |
|
| 4542 |
$out = $this->context->getOutput(); |
| 4543 |
$out->prepareErrorPage(); |
| 4544 |
$out->setPageTitleMsg( $this->context->msg( 'spamprotectiontitle' ) ); |
| 4545 |
|
| 4546 |
$spamText = $this->context->msg( 'spamprotectiontext' )->parseAsBlock(); |
| 4547 |
|
| 4548 |
if ( $match ) { |
| 4549 |
if ( is_array( $match ) ) { |
| 4550 |
$matchText = $this->context->getLanguage()->listToText( array_map( 'wfEscapeWikiText', $match ) ); |
| 4551 |
} else { |
| 4552 |
$matchText = wfEscapeWikiText( $match ); |
| 4553 |
} |
| 4554 |
|
| 4555 |
$spamText .= $this->context->msg( 'spamprotectionmatch' ) |
| 4556 |
->params( $matchText ) |
| 4557 |
->parseAsBlock(); |
| 4558 |
} |
| 4559 |
$out->addHTML( Html::rawElement( |
| 4560 |
'div', |
| 4561 |
[ 'id' => 'spamprotected' ], |
| 4562 |
$spamText |
| 4563 |
) ); |
| 4564 |
|
| 4565 |
$out->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" ); |
| 4566 |
$this->showDiff(); |
| 4567 |
|
| 4568 |
$out->wrapWikiMsg( '<h2>$1</h2>', "yourtext" ); |
| 4569 |
$this->showTextbox( $this->textbox2, 'wpTextbox2', [ 'tabindex' => 6, 'readonly' ] ); |
| 4570 |
|
| 4571 |
$out->addReturnTo( $this->getContextTitle(), [ 'action' => 'edit' ] ); |
| 4572 |
} |
| 4573 |
|
| 4574 |
private function addLongPageWarningHeader(): void { |
| 4575 |
if ( $this->contentLength === false ) { |
| 4576 |
$this->contentLength = strlen( $this->textbox1 ); |
| 4577 |
} |
| 4578 |
|
| 4579 |
$out = $this->context->getOutput(); |
| 4580 |
$maxArticleSize = $this->context->getConfig()->get( MainConfigNames::MaxArticleSize ); |
| 4581 |
if ( $this->tooBig || $this->contentLength > $maxArticleSize * 1024 ) { |
| 4582 |
$lang = $this->context->getLanguage(); |
| 4583 |
$out->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>", |
| 4584 |
[ |
| 4585 |
'longpageerror', |
| 4586 |
$lang->formatNum( round( $this->contentLength / 1024, 3 ) ), |
| 4587 |
$lang->formatNum( $maxArticleSize ) |
| 4588 |
] |
| 4589 |
); |
| 4590 |
} else { |
| 4591 |
$longPageHint = $this->context->msg( 'longpage-hint' ); |
| 4592 |
if ( !$longPageHint->isDisabled() ) { |
| 4593 |
$msgText = trim( $longPageHint->sizeParams( $this->contentLength ) |
| 4594 |
->params( $this->contentLength ) |
| 4595 |
->text() ); |
| 4596 |
if ( $msgText !== '' && $msgText !== '-' ) { |
| 4597 |
$out->addWikiTextAsInterface( "<div id='mw-edit-longpage-hint'>\n$msgText\n</div>" ); |
| 4598 |
} |
| 4599 |
} |
| 4600 |
} |
| 4601 |
} |
| 4602 |
|
| 4603 |
private function addExplainConflictHeader(): void { |
| 4604 |
$this->context->getOutput()->addHTML( |
| 4605 |
$this->getEditConflictHelper()->getExplainHeader() |
| 4606 |
); |
| 4607 |
} |
| 4608 |
|
| 4609 |
|
| 4610 |
|
| 4611 |
|
| 4612 |
|
| 4613 |
|
| 4614 |
|
| 4615 |
|
| 4616 |
|
| 4617 |
|
| 4618 |
|
| 4619 |
private function guessSectionName( $text ): string { |
| 4620 |
|
| 4621 |
$userAgent = $this->context->getRequest()->getHeader( 'User-Agent' ); |
| 4622 |
$parser = MediaWikiServices::getInstance()->getParser(); |
| 4623 |
if ( $userAgent && preg_match( '/MSIE|Edge/', $userAgent ) ) { |
| 4624 |
|
| 4625 |
return $parser->guessLegacySectionNameFromWikiText( $text ); |
| 4626 |
} |
| 4627 |
|
| 4628 |
$name = $parser->guessSectionNameFromWikiText( $text ); |
| 4629 |
|
| 4630 |
|
| 4631 |
return '#' . urlencode( mb_substr( $name, 1 ) ); |
| 4632 |
} |
| 4633 |
|
| 4634 |
|
| 4635 |
|
| 4636 |
|
| 4637 |
|
| 4638 |
public function setEditConflictHelperFactory( callable $factory ) { |
| 4639 |
Assert::precondition( !$this->editConflictHelperFactory, |
| 4640 |
'Can only have one extension that resolves edit conflicts' ); |
| 4641 |
$this->editConflictHelperFactory = $factory; |
| 4642 |
} |
| 4643 |
|
| 4644 |
private function getEditConflictHelper(): TextConflictHelper { |
| 4645 |
if ( !$this->editConflictHelper ) { |
| 4646 |
$label = $this->getSubmitButtonLabel(); |
| 4647 |
if ( $this->editConflictHelperFactory ) { |
| 4648 |
$this->editConflictHelper = ( $this->editConflictHelperFactory )( $label ); |
| 4649 |
} else { |
| 4650 |
$this->editConflictHelper = new TextConflictHelper( |
| 4651 |
$this->getTitle(), |
| 4652 |
$this->getContext()->getOutput(), |
| 4653 |
MediaWikiServices::getInstance()->getStatsFactory(), |
| 4654 |
$label, |
| 4655 |
MediaWikiServices::getInstance()->getContentHandlerFactory() |
| 4656 |
); |
| 4657 |
} |
| 4658 |
} |
| 4659 |
return $this->editConflictHelper; |
| 4660 |
} |
| 4661 |
} |
| 4662 |
|
| 4663 |
|
| 4664 |
class_alias( EditPage::class, 'EditPage' ); |