| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Cache\BacklinkCacheFactory; |
| 22 |
use MediaWiki\CommentStore\CommentStore; |
| 23 |
use MediaWiki\Context\IContextSource; |
| 24 |
use MediaWiki\Html\Html; |
| 25 |
use MediaWiki\HTMLForm\HTMLForm; |
| 26 |
use MediaWiki\Linker\LinkRenderer; |
| 27 |
use MediaWiki\MainConfigNames; |
| 28 |
use MediaWiki\MediaWikiServices; |
| 29 |
use MediaWiki\Message\Message; |
| 30 |
use MediaWiki\Page\DeletePage; |
| 31 |
use MediaWiki\Page\DeletePageFactory; |
| 32 |
use MediaWiki\Revision\RevisionRecord; |
| 33 |
use MediaWiki\Session\CsrfTokenSet; |
| 34 |
use MediaWiki\Status\Status; |
| 35 |
use MediaWiki\Title\NamespaceInfo; |
| 36 |
use MediaWiki\Title\TitleFactory; |
| 37 |
use MediaWiki\Title\TitleFormatter; |
| 38 |
use MediaWiki\User\Options\UserOptionsLookup; |
| 39 |
use MediaWiki\Watchlist\WatchlistManager; |
| 40 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 41 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 42 |
use Wikimedia\Rdbms\ReadOnlyMode; |
| 43 |
use Wikimedia\RequestTimeout\TimeoutException; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
class DeleteAction extends FormAction { |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
protected const MSG_REASON_DROPDOWN = 'reason-dropdown'; |
| 56 |
protected const MSG_REASON_DROPDOWN_SUPPRESS = 'reason-dropdown-suppress'; |
| 57 |
protected const MSG_REASON_DROPDOWN_OTHER = 'reason-dropdown-other'; |
| 58 |
protected const MSG_COMMENT = 'comment'; |
| 59 |
protected const MSG_REASON_OTHER = 'reason-other'; |
| 60 |
protected const MSG_SUBMIT = 'submit'; |
| 61 |
protected const MSG_LEGEND = 'legend'; |
| 62 |
protected const MSG_EDIT_REASONS = 'edit-reasons'; |
| 63 |
protected const MSG_EDIT_REASONS_SUPPRESS = 'edit-reasons-suppress'; |
| 64 |
|
| 65 |
protected WatchlistManager $watchlistManager; |
| 66 |
protected LinkRenderer $linkRenderer; |
| 67 |
private BacklinkCacheFactory $backlinkCacheFactory; |
| 68 |
protected ReadOnlyMode $readOnlyMode; |
| 69 |
protected UserOptionsLookup $userOptionsLookup; |
| 70 |
private DeletePageFactory $deletePageFactory; |
| 71 |
private int $deleteRevisionsLimit; |
| 72 |
private NamespaceInfo $namespaceInfo; |
| 73 |
private TitleFormatter $titleFormatter; |
| 74 |
private TitleFactory $titleFactory; |
| 75 |
|
| 76 |
private IConnectionProvider $dbProvider; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function __construct( Article $article, IContextSource $context ) { |
| 82 |
parent::__construct( $article, $context ); |
| 83 |
$services = MediaWikiServices::getInstance(); |
| 84 |
$this->watchlistManager = $services->getWatchlistManager(); |
| 85 |
$this->linkRenderer = $services->getLinkRenderer(); |
| 86 |
$this->backlinkCacheFactory = $services->getBacklinkCacheFactory(); |
| 87 |
$this->readOnlyMode = $services->getReadOnlyMode(); |
| 88 |
$this->userOptionsLookup = $services->getUserOptionsLookup(); |
| 89 |
$this->deletePageFactory = $services->getDeletePageFactory(); |
| 90 |
$this->deleteRevisionsLimit = $services->getMainConfig()->get( MainConfigNames::DeleteRevisionsLimit ); |
| 91 |
$this->namespaceInfo = $services->getNamespaceInfo(); |
| 92 |
$this->titleFormatter = $services->getTitleFormatter(); |
| 93 |
$this->titleFactory = $services->getTitleFactory(); |
| 94 |
$this->dbProvider = $services->getConnectionProvider(); |
| 95 |
} |
| 96 |
|
| 97 |
public function getName() { |
| 98 |
return 'delete'; |
| 99 |
} |
| 100 |
|
| 101 |
public function onSubmit( $data ) { |
| 102 |
return false; |
| 103 |
} |
| 104 |
|
| 105 |
public function onSuccess() { |
| 106 |
return false; |
| 107 |
} |
| 108 |
|
| 109 |
protected function usesOOUI() { |
| 110 |
return true; |
| 111 |
} |
| 112 |
|
| 113 |
protected function getPageTitle() { |
| 114 |
$title = $this->getTitle(); |
| 115 |
return $this->msg( 'delete-confirm' )->plaintextParams( $title->getPrefixedText() ); |
| 116 |
} |
| 117 |
|
| 118 |
public function getRestriction() { |
| 119 |
return 'delete'; |
| 120 |
} |
| 121 |
|
| 122 |
protected function alterForm( HTMLForm $form ) { |
| 123 |
$title = $this->getTitle(); |
| 124 |
$form |
| 125 |
->setAction( $this->getFormAction() ) |
| 126 |
->setWrapperLegendMsg( $this->getFormMsg( self::MSG_LEGEND ) ) |
| 127 |
->setWrapperAttributes( [ 'id' => 'mw-delete-table' ] ) |
| 128 |
->suppressDefaultSubmit() |
| 129 |
->setId( 'deleteconfirm' ) |
| 130 |
->setTokenSalt( [ 'delete', $title->getPrefixedText() ] ); |
| 131 |
} |
| 132 |
|
| 133 |
public function show() { |
| 134 |
$this->setHeaders(); |
| 135 |
$this->useTransactionalTimeLimit(); |
| 136 |
$this->addHelpLink( 'Help:Sysop deleting and undeleting' ); |
| 137 |
|
| 138 |
|
| 139 |
$this->checkCanExecute( $this->getUser() ); |
| 140 |
|
| 141 |
$this->tempDelete(); |
| 142 |
} |
| 143 |
|
| 144 |
protected function tempDelete() { |
| 145 |
$article = $this->getArticle(); |
| 146 |
$title = $this->getTitle(); |
| 147 |
$context = $this->getContext(); |
| 148 |
$user = $context->getUser(); |
| 149 |
$request = $context->getRequest(); |
| 150 |
$outputPage = $context->getOutput(); |
| 151 |
|
| 152 |
|
| 153 |
$article->getPage()->loadPageData( |
| 154 |
$request->wasPosted() ? IDBAccessObject::READ_LATEST : IDBAccessObject::READ_NORMAL |
| 155 |
); |
| 156 |
if ( !$article->getPage()->exists() ) { |
| 157 |
$outputPage->setPageTitleMsg( |
| 158 |
$context->msg( 'cannotdelete-title' )->plaintextParams( $title->getPrefixedText() ) |
| 159 |
); |
| 160 |
$outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>", |
| 161 |
[ 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) ] |
| 162 |
); |
| 163 |
$this->showLogEntries(); |
| 164 |
|
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
$hasValidCsrfToken = $this->getContext() |
| 169 |
->getCsrfTokenSet() |
| 170 |
->matchTokenField( |
| 171 |
CsrfTokenSet::DEFAULT_FIELD_NAME, |
| 172 |
[ 'delete', $title->getPrefixedText() ] |
| 173 |
); |
| 174 |
|
| 175 |
|
| 176 |
if ( !$request->wasPosted() || !$hasValidCsrfToken ) { |
| 177 |
$this->tempConfirmDelete(); |
| 178 |
return; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
if ( $article->getRevIdFetched() !== $request->getIntOrNull( 'wpConfirmationRevId' ) ) { |
| 183 |
$this->showEditedWarning(); |
| 184 |
$this->tempConfirmDelete(); |
| 185 |
return; |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
$suppress = $request->getCheck( 'wpSuppress' ) && |
| 190 |
$context->getAuthority()->isAllowed( 'suppressrevision' ); |
| 191 |
|
| 192 |
$context = $this->getContext(); |
| 193 |
$deletePage = $this->deletePageFactory->newDeletePage( |
| 194 |
$this->getWikiPage(), |
| 195 |
$context->getAuthority() |
| 196 |
); |
| 197 |
$shouldDeleteTalk = $request->getCheck( 'wpDeleteTalk' ) && |
| 198 |
$deletePage->canProbablyDeleteAssociatedTalk()->isGood(); |
| 199 |
$deletePage->setDeleteAssociatedTalk( $shouldDeleteTalk ); |
| 200 |
$status = $deletePage |
| 201 |
->setSuppress( $suppress ) |
| 202 |
->deleteIfAllowed( $this->getDeleteReason() ); |
| 203 |
|
| 204 |
if ( $status->isOK() ) { |
| 205 |
$outputPage->setPageTitleMsg( $this->msg( 'actioncomplete' ) ); |
| 206 |
$outputPage->setRobotPolicy( 'noindex,nofollow' ); |
| 207 |
|
| 208 |
if ( !$status->isGood() ) { |
| 209 |
|
| 210 |
|
| 211 |
$outputPage->addHTML( |
| 212 |
Html::warningBox( |
| 213 |
$outputPage->parseAsContent( |
| 214 |
Status::wrap( $status )->getWikiText( |
| 215 |
false, |
| 216 |
false, |
| 217 |
$context->getLanguage() |
| 218 |
) |
| 219 |
) |
| 220 |
) |
| 221 |
); |
| 222 |
} |
| 223 |
|
| 224 |
$this->showSuccessMessages( |
| 225 |
$deletePage->getSuccessfulDeletionsIDs(), |
| 226 |
$deletePage->deletionsWereScheduled() |
| 227 |
); |
| 228 |
|
| 229 |
if ( !$status->isGood() ) { |
| 230 |
$this->showLogEntries(); |
| 231 |
} |
| 232 |
$outputPage->returnToMain(); |
| 233 |
} else { |
| 234 |
$outputPage->setPageTitleMsg( |
| 235 |
$this->msg( 'cannotdelete-title' )->plaintextParams( $this->getTitle()->getPrefixedText() ) |
| 236 |
); |
| 237 |
|
| 238 |
$outputPage->wrapWikiTextAsInterface( |
| 239 |
'error mw-error-cannotdelete', |
| 240 |
Status::wrap( $status )->getWikiText( false, false, $context->getLanguage() ) |
| 241 |
); |
| 242 |
$this->showLogEntries(); |
| 243 |
} |
| 244 |
|
| 245 |
$this->watchlistManager->setWatch( $request->getCheck( 'wpWatch' ), $context->getAuthority(), $title ); |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
private function showSuccessMessages( array $deleted, array $scheduled ): void { |
| 256 |
$outputPage = $this->getContext()->getOutput(); |
| 257 |
$loglink = '[[Special:Log/delete|' . $this->msg( 'deletionlog' )->text() . ']]'; |
| 258 |
$pageBaseDisplayTitle = wfEscapeWikiText( $this->getTitle()->getPrefixedText() ); |
| 259 |
$pageTalkDisplayTitle = wfEscapeWikiText( $this->titleFormatter->getPrefixedText( |
| 260 |
$this->namespaceInfo->getTalkPage( $this->getTitle() ) |
| 261 |
) ); |
| 262 |
|
| 263 |
$deletedTalk = $deleted[DeletePage::PAGE_TALK] ?? false; |
| 264 |
$deletedBase = $deleted[DeletePage::PAGE_BASE]; |
| 265 |
$scheduledTalk = $scheduled[DeletePage::PAGE_TALK] ?? false; |
| 266 |
$scheduledBase = $scheduled[DeletePage::PAGE_BASE]; |
| 267 |
|
| 268 |
if ( $deletedBase && $deletedTalk ) { |
| 269 |
$outputPage->addWikiMsg( 'deleted-page-and-talkpage', |
| 270 |
$pageBaseDisplayTitle, |
| 271 |
$pageTalkDisplayTitle, |
| 272 |
$loglink ); |
| 273 |
} elseif ( $deletedBase ) { |
| 274 |
$outputPage->addWikiMsg( 'deletedtext', $pageBaseDisplayTitle, $loglink ); |
| 275 |
} elseif ( $deletedTalk ) { |
| 276 |
$outputPage->addWikiMsg( 'deletedtext', $pageTalkDisplayTitle, $loglink ); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
if ( $deletedBase ) { |
| 281 |
$this->getHookRunner()->onArticleDeleteAfterSuccess( $this->getTitle(), $outputPage ); |
| 282 |
} |
| 283 |
|
| 284 |
if ( $scheduledBase ) { |
| 285 |
$outputPage->addWikiMsg( 'delete-scheduled', $pageBaseDisplayTitle ); |
| 286 |
} |
| 287 |
|
| 288 |
if ( $scheduledTalk ) { |
| 289 |
$outputPage->addWikiMsg( 'delete-scheduled', $pageTalkDisplayTitle ); |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
protected function showEditedWarning(): void { |
| 294 |
$this->getOutput()->addHTML( |
| 295 |
Html::warningBox( $this->getContext()->msg( 'editedwhiledeleting' )->parse() ) |
| 296 |
); |
| 297 |
} |
| 298 |
|
| 299 |
private function showHistoryWarnings(): void { |
| 300 |
$context = $this->getContext(); |
| 301 |
$title = $this->getTitle(); |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
$revisions = (int)$this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder() |
| 309 |
->select( 'COUNT(rev_page)' ) |
| 310 |
->from( 'revision' ) |
| 311 |
->where( [ 'rev_page' => $title->getArticleID() ] ) |
| 312 |
->caller( __METHOD__ ) |
| 313 |
->fetchField(); |
| 314 |
|
| 315 |
|
| 316 |
$context->getOutput()->addHTML( |
| 317 |
'<strong class="mw-delete-warning-revisions">' . |
| 318 |
$context->msg( 'historywarning' )->numParams( $revisions )->parse() . |
| 319 |
$context->msg( 'word-separator' )->escaped() . $this->linkRenderer->makeKnownLink( |
| 320 |
$title, |
| 321 |
$context->msg( 'history' )->text(), |
| 322 |
[], |
| 323 |
[ 'action' => 'history' ] ) . |
| 324 |
'</strong>' |
| 325 |
); |
| 326 |
|
| 327 |
if ( $title->isBigDeletion() ) { |
| 328 |
$context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", |
| 329 |
[ |
| 330 |
'delete-warning-toobig', |
| 331 |
$context->getLanguage()->formatNum( $this->deleteRevisionsLimit ) |
| 332 |
] |
| 333 |
); |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
protected function showFormWarnings(): void { |
| 338 |
$this->showBacklinksWarning(); |
| 339 |
$this->showSubpagesWarnings(); |
| 340 |
} |
| 341 |
|
| 342 |
private function showBacklinksWarning(): void { |
| 343 |
$backlinkCache = $this->backlinkCacheFactory->getBacklinkCache( $this->getTitle() ); |
| 344 |
if ( $backlinkCache->hasLinks( 'pagelinks' ) || $backlinkCache->hasLinks( 'templatelinks' ) ) { |
| 345 |
$this->getOutput()->addHTML( |
| 346 |
Html::warningBox( |
| 347 |
$this->msg( 'deleting-backlinks-warning' )->parse(), |
| 348 |
'plainlinks' |
| 349 |
) |
| 350 |
); |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
protected function showSubpagesWarnings(): void { |
| 355 |
$title = $this->getTitle(); |
| 356 |
$subpageCount = count( $title->getSubpages( 51 ) ); |
| 357 |
if ( $subpageCount ) { |
| 358 |
$this->getOutput()->addHTML( |
| 359 |
Html::warningBox( |
| 360 |
$this->msg( 'deleting-subpages-warning' )->numParams( $subpageCount )->parse(), |
| 361 |
'plainlinks' |
| 362 |
) |
| 363 |
); |
| 364 |
} |
| 365 |
|
| 366 |
if ( !$title->isTalkPage() ) { |
| 367 |
$talkPageTitle = $this->titleFactory->newFromLinkTarget( $this->namespaceInfo->getTalkPage( $title ) ); |
| 368 |
$subpageCount = count( $talkPageTitle->getSubpages( 51 ) ); |
| 369 |
if ( $subpageCount ) { |
| 370 |
$this->getOutput()->addHTML( |
| 371 |
Html::warningBox( |
| 372 |
$this->msg( 'deleting-talkpage-subpages-warning' )->numParams( $subpageCount )->parse(), |
| 373 |
'plainlinks' |
| 374 |
) |
| 375 |
); |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
private function tempConfirmDelete(): void { |
| 381 |
$this->prepareOutputForForm(); |
| 382 |
$context = $this->getContext(); |
| 383 |
$outputPage = $context->getOutput(); |
| 384 |
$article = $this->getArticle(); |
| 385 |
|
| 386 |
$reason = $this->getDefaultReason(); |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
$oldid = $context->getRequest()->getIntOrNull( 'oldid' ); |
| 392 |
if ( $oldid !== null && $oldid !== $article->getRevIdFetched() ) { |
| 393 |
$this->showEditedWarning(); |
| 394 |
} |
| 395 |
|
| 396 |
if ( $this->pageHasHistory() ) { |
| 397 |
$this->showHistoryWarnings(); |
| 398 |
} |
| 399 |
$this->showFormWarnings(); |
| 400 |
|
| 401 |
$outputPage->addWikiMsg( 'confirmdeletetext' ); |
| 402 |
|
| 403 |
|
| 404 |
$this->getHookRunner()->onArticleConfirmDelete( $this->getArticle(), $outputPage, $reason ); |
| 405 |
|
| 406 |
$form = $this->getForm(); |
| 407 |
if ( $form->show() ) { |
| 408 |
$this->onSuccess(); |
| 409 |
} |
| 410 |
|
| 411 |
$this->showEditReasonsLinks(); |
| 412 |
$this->showLogEntries(); |
| 413 |
} |
| 414 |
|
| 415 |
protected function showEditReasonsLinks(): void { |
| 416 |
if ( $this->getAuthority()->isAllowed( 'editinterface' ) ) { |
| 417 |
$link = ''; |
| 418 |
if ( $this->isSuppressionAllowed() ) { |
| 419 |
$link .= $this->linkRenderer->makeKnownLink( |
| 420 |
$this->getFormMsg( self::MSG_REASON_DROPDOWN_SUPPRESS )->inContentLanguage()->getTitle(), |
| 421 |
$this->getFormMsg( self::MSG_EDIT_REASONS_SUPPRESS )->text(), |
| 422 |
[], |
| 423 |
[ 'action' => 'edit' ] |
| 424 |
); |
| 425 |
$link .= $this->msg( 'pipe-separator' )->escaped(); |
| 426 |
} |
| 427 |
$link .= $this->linkRenderer->makeKnownLink( |
| 428 |
$this->getFormMsg( self::MSG_REASON_DROPDOWN )->inContentLanguage()->getTitle(), |
| 429 |
$this->getFormMsg( self::MSG_EDIT_REASONS )->text(), |
| 430 |
[], |
| 431 |
[ 'action' => 'edit' ] |
| 432 |
); |
| 433 |
$this->getOutput()->addHTML( '<p class="mw-delete-editreasons">' . $link . '</p>' ); |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
protected function isSuppressionAllowed(): bool { |
| 441 |
return $this->getAuthority()->isAllowed( 'suppressrevision' ); |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
protected function getFormFields(): array { |
| 448 |
$user = $this->getUser(); |
| 449 |
$title = $this->getTitle(); |
| 450 |
$article = $this->getArticle(); |
| 451 |
|
| 452 |
$fields = []; |
| 453 |
|
| 454 |
$dropdownReason = $this->getFormMsg( self::MSG_REASON_DROPDOWN )->inContentLanguage()->text(); |
| 455 |
|
| 456 |
if ( $this->isSuppressionAllowed() ) { |
| 457 |
$dropdownReason .= "\n" . $this->getFormMsg( self::MSG_REASON_DROPDOWN_SUPPRESS ) |
| 458 |
->inContentLanguage()->text(); |
| 459 |
} |
| 460 |
|
| 461 |
$options = Html::listDropdownOptions( |
| 462 |
$dropdownReason, |
| 463 |
[ 'other' => $this->getFormMsg( self::MSG_REASON_DROPDOWN_OTHER )->text() ] |
| 464 |
); |
| 465 |
|
| 466 |
$fields['DeleteReasonList'] = [ |
| 467 |
'type' => 'select', |
| 468 |
'id' => 'wpDeleteReasonList', |
| 469 |
'tabindex' => 1, |
| 470 |
'infusable' => true, |
| 471 |
'options' => $options, |
| 472 |
'label' => $this->getFormMsg( self::MSG_COMMENT )->text(), |
| 473 |
]; |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
$fields['Reason'] = [ |
| 479 |
'type' => 'text', |
| 480 |
'id' => 'wpReason', |
| 481 |
'tabindex' => 2, |
| 482 |
'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT, |
| 483 |
'infusable' => true, |
| 484 |
'default' => $this->getDefaultReason(), |
| 485 |
'autofocus' => true, |
| 486 |
'label' => $this->getFormMsg( self::MSG_REASON_OTHER )->text(), |
| 487 |
]; |
| 488 |
|
| 489 |
$delPage = $this->deletePageFactory->newDeletePage( $this->getWikiPage(), $this->getAuthority() ); |
| 490 |
if ( $delPage->canProbablyDeleteAssociatedTalk()->isGood() ) { |
| 491 |
$fields['DeleteTalk'] = [ |
| 492 |
'type' => 'check', |
| 493 |
'id' => 'wpDeleteTalk', |
| 494 |
'tabindex' => 3, |
| 495 |
'default' => false, |
| 496 |
'label-message' => 'deletepage-deletetalk', |
| 497 |
]; |
| 498 |
} |
| 499 |
|
| 500 |
if ( $user->isRegistered() ) { |
| 501 |
$checkWatch = $this->userOptionsLookup->getBoolOption( $user, 'watchdeletion' ) || |
| 502 |
$this->watchlistManager->isWatched( $user, $title ); |
| 503 |
$fields['Watch'] = [ |
| 504 |
'type' => 'check', |
| 505 |
'id' => 'wpWatch', |
| 506 |
'tabindex' => 4, |
| 507 |
'default' => $checkWatch, |
| 508 |
'label-message' => 'watchthis', |
| 509 |
]; |
| 510 |
} |
| 511 |
if ( $this->isSuppressionAllowed() ) { |
| 512 |
$fields['Suppress'] = [ |
| 513 |
'type' => 'check', |
| 514 |
'id' => 'wpSuppress', |
| 515 |
'tabindex' => 5, |
| 516 |
'default' => false, |
| 517 |
'label-message' => 'revdelete-suppress', |
| 518 |
]; |
| 519 |
} |
| 520 |
|
| 521 |
$fields['ConfirmB'] = [ |
| 522 |
'type' => 'submit', |
| 523 |
'id' => 'wpConfirmB', |
| 524 |
'tabindex' => 6, |
| 525 |
'buttonlabel' => $this->getFormMsg( self::MSG_SUBMIT )->text(), |
| 526 |
'flags' => [ 'primary', 'destructive' ], |
| 527 |
]; |
| 528 |
|
| 529 |
$fields['ConfirmationRevId'] = [ |
| 530 |
'type' => 'hidden', |
| 531 |
'id' => 'wpConfirmationRevId', |
| 532 |
'default' => $article->getRevIdFetched(), |
| 533 |
]; |
| 534 |
|
| 535 |
return $fields; |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
protected function getDeleteReason(): string { |
| 542 |
$deleteReasonList = $this->getRequest()->getText( 'wpDeleteReasonList', 'other' ); |
| 543 |
$deleteReason = $this->getRequest()->getText( 'wpReason' ); |
| 544 |
|
| 545 |
if ( $deleteReasonList === 'other' ) { |
| 546 |
return $deleteReason; |
| 547 |
} elseif ( $deleteReason !== '' ) { |
| 548 |
|
| 549 |
$colonseparator = $this->msg( 'colon-separator' )->inContentLanguage()->text(); |
| 550 |
return $deleteReasonList . $colonseparator . $deleteReason; |
| 551 |
} else { |
| 552 |
return $deleteReasonList; |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
protected function showLogEntries(): void { |
| 560 |
$deleteLogPage = new LogPage( 'delete' ); |
| 561 |
$outputPage = $this->getContext()->getOutput(); |
| 562 |
$outputPage->addHTML( Html::element( 'h2', [], $deleteLogPage->getName()->text() ) ); |
| 563 |
LogEventsList::showLogExtract( $outputPage, 'delete', $this->getTitle() ); |
| 564 |
} |
| 565 |
|
| 566 |
protected function prepareOutputForForm(): void { |
| 567 |
$outputPage = $this->getOutput(); |
| 568 |
$outputPage->addModules( 'mediawiki.misc-authed-ooui' ); |
| 569 |
$outputPage->addModuleStyles( 'mediawiki.action.styles' ); |
| 570 |
$outputPage->enableOOUI(); |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
protected function getFormMessages(): array { |
| 577 |
return [ |
| 578 |
self::MSG_REASON_DROPDOWN => 'deletereason-dropdown', |
| 579 |
self::MSG_REASON_DROPDOWN_SUPPRESS => 'deletereason-dropdown-suppress', |
| 580 |
self::MSG_REASON_DROPDOWN_OTHER => 'deletereasonotherlist', |
| 581 |
self::MSG_COMMENT => 'deletecomment', |
| 582 |
self::MSG_REASON_OTHER => 'deleteotherreason', |
| 583 |
self::MSG_SUBMIT => 'deletepage-submit', |
| 584 |
self::MSG_LEGEND => 'delete-legend', |
| 585 |
self::MSG_EDIT_REASONS => 'delete-edit-reasonlist', |
| 586 |
self::MSG_EDIT_REASONS_SUPPRESS => 'delete-edit-reasonlist-suppress', |
| 587 |
]; |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
protected function getFormMsg( string $field ): Message { |
| 595 |
$messages = $this->getFormMessages(); |
| 596 |
if ( !isset( $messages[$field] ) ) { |
| 597 |
throw new InvalidArgumentException( "Invalid field $field" ); |
| 598 |
} |
| 599 |
return $this->msg( $messages[$field] ); |
| 600 |
} |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
protected function getFormAction(): string { |
| 606 |
return $this->getTitle()->getLocalURL( 'action=delete' ); |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
protected function getDefaultReason(): string { |
| 615 |
$requestReason = $this->getRequest()->getText( 'wpReason' ); |
| 616 |
if ( $requestReason ) { |
| 617 |
return $requestReason; |
| 618 |
} |
| 619 |
|
| 620 |
try { |
| 621 |
return $this->getArticle()->getPage()->getAutoDeleteReason(); |
| 622 |
} catch ( TimeoutException $e ) { |
| 623 |
throw $e; |
| 624 |
} catch ( Exception $e ) { |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
MWExceptionHandler::logException( $e ); |
| 630 |
return ''; |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
private function pageHasHistory(): bool { |
| 640 |
$dbr = $this->dbProvider->getReplicaDatabase(); |
| 641 |
$res = $dbr->newSelectQueryBuilder() |
| 642 |
->select( '*' ) |
| 643 |
->from( 'revision' ) |
| 644 |
->where( [ 'rev_page' => $this->getTitle()->getArticleID() ] ) |
| 645 |
->andWhere( |
| 646 |
[ $dbr->bitAnd( 'rev_deleted', RevisionRecord::DELETED_USER ) . ' = 0' ] |
| 647 |
)->limit( 2 ) |
| 648 |
->caller( __METHOD__ ) |
| 649 |
->fetchRowCount(); |
| 650 |
|
| 651 |
return $res > 1; |
| 652 |
} |
| 653 |
} |