| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Block\DatabaseBlock; |
| 22 |
use MediaWiki\Block\DatabaseBlockStore; |
| 23 |
use MediaWiki\CommentFormatter\CommentFormatter; |
| 24 |
use MediaWiki\Context\IContextSource; |
| 25 |
use MediaWiki\Context\RequestContext; |
| 26 |
use MediaWiki\EditPage\EditPage; |
| 27 |
use MediaWiki\HookContainer\HookRunner; |
| 28 |
use MediaWiki\HookContainer\ProtectedHookAccessorTrait; |
| 29 |
use MediaWiki\Html\Html; |
| 30 |
use MediaWiki\Language\Language; |
| 31 |
use MediaWiki\Linker\Linker; |
| 32 |
use MediaWiki\Linker\LinkRenderer; |
| 33 |
use MediaWiki\MainConfigNames; |
| 34 |
use MediaWiki\MediaWikiServices; |
| 35 |
use MediaWiki\Message\Message; |
| 36 |
use MediaWiki\Output\OutputPage; |
| 37 |
use MediaWiki\Page\ParserOutputAccess; |
| 38 |
use MediaWiki\Page\ProtectionForm; |
| 39 |
use MediaWiki\Page\WikiPageFactory; |
| 40 |
use MediaWiki\Parser\Parser; |
| 41 |
use MediaWiki\Parser\ParserOptions; |
| 42 |
use MediaWiki\Parser\ParserOutput; |
| 43 |
use MediaWiki\Permissions\Authority; |
| 44 |
use MediaWiki\Permissions\PermissionStatus; |
| 45 |
use MediaWiki\Permissions\RestrictionStore; |
| 46 |
use MediaWiki\Revision\ArchivedRevisionLookup; |
| 47 |
use MediaWiki\Revision\BadRevisionException; |
| 48 |
use MediaWiki\Revision\RevisionRecord; |
| 49 |
use MediaWiki\Revision\RevisionStore; |
| 50 |
use MediaWiki\Revision\SlotRecord; |
| 51 |
use MediaWiki\Status\Status; |
| 52 |
use MediaWiki\Title\Title; |
| 53 |
use MediaWiki\User\Options\UserOptionsLookup; |
| 54 |
use MediaWiki\User\User; |
| 55 |
use MediaWiki\User\UserIdentity; |
| 56 |
use MediaWiki\User\UserNameUtils; |
| 57 |
use MediaWiki\Xml\Xml; |
| 58 |
use Wikimedia\IPUtils; |
| 59 |
use Wikimedia\LightweightObjectStore\ExpirationAwareness; |
| 60 |
use Wikimedia\NonSerializable\NonSerializableTrait; |
| 61 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
class Article implements Page { |
| 73 |
use ProtectedHookAccessorTrait; |
| 74 |
use NonSerializableTrait; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
protected $mContext; |
| 82 |
|
| 83 |
|
| 84 |
protected $mPage; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public $mOldId; |
| 91 |
|
| 92 |
|
| 93 |
public $mRedirectedFrom = null; |
| 94 |
|
| 95 |
|
| 96 |
public $mRedirectUrl = false; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
private $fetchResult = null; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public $mParserOutput = null; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
protected $viewIsRenderAction = false; |
| 117 |
|
| 118 |
protected LinkRenderer $linkRenderer; |
| 119 |
private RevisionStore $revisionStore; |
| 120 |
private UserNameUtils $userNameUtils; |
| 121 |
private UserOptionsLookup $userOptionsLookup; |
| 122 |
private CommentFormatter $commentFormatter; |
| 123 |
private WikiPageFactory $wikiPageFactory; |
| 124 |
private JobQueueGroup $jobQueueGroup; |
| 125 |
private ArchivedRevisionLookup $archivedRevisionLookup; |
| 126 |
protected IConnectionProvider $dbProvider; |
| 127 |
protected DatabaseBlockStore $blockStore; |
| 128 |
|
| 129 |
protected RestrictionStore $restrictionStore; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
private $mRevisionRecord = null; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
public function __construct( Title $title, $oldId = null ) { |
| 144 |
$this->mOldId = $oldId; |
| 145 |
$this->mPage = $this->newPage( $title ); |
| 146 |
|
| 147 |
$services = MediaWikiServices::getInstance(); |
| 148 |
$this->linkRenderer = $services->getLinkRenderer(); |
| 149 |
$this->revisionStore = $services->getRevisionStore(); |
| 150 |
$this->userNameUtils = $services->getUserNameUtils(); |
| 151 |
$this->userOptionsLookup = $services->getUserOptionsLookup(); |
| 152 |
$this->commentFormatter = $services->getCommentFormatter(); |
| 153 |
$this->wikiPageFactory = $services->getWikiPageFactory(); |
| 154 |
$this->jobQueueGroup = $services->getJobQueueGroup(); |
| 155 |
$this->archivedRevisionLookup = $services->getArchivedRevisionLookup(); |
| 156 |
$this->dbProvider = $services->getConnectionProvider(); |
| 157 |
$this->blockStore = $services->getDatabaseBlockStore(); |
| 158 |
$this->restrictionStore = $services->getRestrictionStore(); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
protected function newPage( Title $title ) { |
| 166 |
return new WikiPage( $title ); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
public static function newFromID( $id ) { |
| 175 |
$t = Title::newFromID( $id ); |
| 176 |
return $t === null ? null : new static( $t ); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
public static function newFromTitle( $title, IContextSource $context ): self { |
| 187 |
if ( $title->getNamespace() === NS_MEDIA ) { |
| 188 |
|
| 189 |
$title = Title::makeTitle( NS_FILE, $title->getDBkey() ); |
| 190 |
} |
| 191 |
|
| 192 |
$page = null; |
| 193 |
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) ) |
| 194 |
|
| 195 |
->onArticleFromTitle( $title, $page, $context ); |
| 196 |
if ( !$page ) { |
| 197 |
switch ( $title->getNamespace() ) { |
| 198 |
case NS_FILE: |
| 199 |
$page = new ImagePage( $title ); |
| 200 |
break; |
| 201 |
case NS_CATEGORY: |
| 202 |
$page = new CategoryPage( $title ); |
| 203 |
break; |
| 204 |
default: |
| 205 |
$page = new Article( $title ); |
| 206 |
} |
| 207 |
} |
| 208 |
$page->setContext( $context ); |
| 209 |
|
| 210 |
return $page; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public static function newFromWikiPage( WikiPage $page, IContextSource $context ) { |
| 221 |
$article = self::newFromTitle( $page->getTitle(), $context ); |
| 222 |
$article->mPage = $page; |
| 223 |
return $article; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
public function getRedirectedFrom() { |
| 232 |
return $this->mRedirectedFrom; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
public function setRedirectedFrom( Title $from ) { |
| 241 |
$this->mRedirectedFrom = $from; |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
public function getTitle() { |
| 250 |
return $this->mPage->getTitle(); |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
public function getPage() { |
| 260 |
return $this->mPage; |
| 261 |
} |
| 262 |
|
| 263 |
public function clear() { |
| 264 |
$this->mRedirectedFrom = null; |
| 265 |
$this->mRedirectUrl = false; |
| 266 |
$this->mRevisionRecord = null; |
| 267 |
$this->fetchResult = null; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
$this->mPage->clear(); |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
public function getOldID() { |
| 282 |
if ( $this->mOldId === null ) { |
| 283 |
$this->mOldId = $this->getOldIDFromRequest(); |
| 284 |
} |
| 285 |
|
| 286 |
return $this->mOldId; |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
public function getOldIDFromRequest() { |
| 295 |
$this->mRedirectUrl = false; |
| 296 |
|
| 297 |
$request = $this->getContext()->getRequest(); |
| 298 |
$oldid = $request->getIntOrNull( 'oldid' ); |
| 299 |
|
| 300 |
if ( $oldid === null ) { |
| 301 |
return 0; |
| 302 |
} |
| 303 |
|
| 304 |
if ( $oldid !== 0 ) { |
| 305 |
|
| 306 |
|
| 307 |
if ( $oldid === $this->mPage->getLatest() ) { |
| 308 |
$this->mRevisionRecord = $this->mPage->getRevisionRecord(); |
| 309 |
} else { |
| 310 |
$this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid ); |
| 311 |
if ( $this->mRevisionRecord !== null ) { |
| 312 |
$revPageId = $this->mRevisionRecord->getPageId(); |
| 313 |
|
| 314 |
if ( $this->mPage->getId() !== $revPageId ) { |
| 315 |
$this->mPage = $this->wikiPageFactory->newFromID( $revPageId ); |
| 316 |
} |
| 317 |
} |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
$oldRev = $this->mRevisionRecord; |
| 322 |
if ( $request->getRawVal( 'direction' ) === 'next' ) { |
| 323 |
$nextid = 0; |
| 324 |
if ( $oldRev ) { |
| 325 |
$nextRev = $this->revisionStore->getNextRevision( $oldRev ); |
| 326 |
if ( $nextRev ) { |
| 327 |
$nextid = $nextRev->getId(); |
| 328 |
} |
| 329 |
} |
| 330 |
if ( $nextid ) { |
| 331 |
$oldid = $nextid; |
| 332 |
$this->mRevisionRecord = null; |
| 333 |
} else { |
| 334 |
$this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' ); |
| 335 |
} |
| 336 |
} elseif ( $request->getRawVal( 'direction' ) === 'prev' ) { |
| 337 |
$previd = 0; |
| 338 |
if ( $oldRev ) { |
| 339 |
$prevRev = $this->revisionStore->getPreviousRevision( $oldRev ); |
| 340 |
if ( $prevRev ) { |
| 341 |
$previd = $prevRev->getId(); |
| 342 |
} |
| 343 |
} |
| 344 |
if ( $previd ) { |
| 345 |
$oldid = $previd; |
| 346 |
$this->mRevisionRecord = null; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
return $oldid; |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
public function fetchRevisionRecord() { |
| 363 |
if ( $this->fetchResult ) { |
| 364 |
return $this->mRevisionRecord; |
| 365 |
} |
| 366 |
|
| 367 |
$oldid = $this->getOldID(); |
| 368 |
|
| 369 |
|
| 370 |
if ( !$this->mRevisionRecord ) { |
| 371 |
if ( !$oldid ) { |
| 372 |
$this->mRevisionRecord = $this->mPage->getRevisionRecord(); |
| 373 |
|
| 374 |
if ( !$this->mRevisionRecord ) { |
| 375 |
wfDebug( __METHOD__ . " failed to find page data for title " . |
| 376 |
$this->getTitle()->getPrefixedText() ); |
| 377 |
|
| 378 |
|
| 379 |
$this->fetchResult = Status::newFatal( 'noarticletext' ); |
| 380 |
return null; |
| 381 |
} |
| 382 |
} else { |
| 383 |
$this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid ); |
| 384 |
|
| 385 |
if ( !$this->mRevisionRecord ) { |
| 386 |
wfDebug( __METHOD__ . " failed to load revision, rev_id $oldid" ); |
| 387 |
|
| 388 |
$this->fetchResult = Status::newFatal( $this->getMissingRevisionMsg( $oldid ) ); |
| 389 |
return null; |
| 390 |
} |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
if ( !$this->mRevisionRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getContext()->getAuthority() ) ) { |
| 395 |
wfDebug( __METHOD__ . " failed to retrieve content of revision " . $this->mRevisionRecord->getId() ); |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
$this->fetchResult = new Status; |
| 400 |
$title = $this->getTitle()->getPrefixedDBkey(); |
| 401 |
|
| 402 |
if ( $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) { |
| 403 |
$this->fetchResult->fatal( 'rev-suppressed-text' ); |
| 404 |
} else { |
| 405 |
$this->fetchResult->fatal( 'rev-deleted-text-permission', $title ); |
| 406 |
} |
| 407 |
|
| 408 |
return null; |
| 409 |
} |
| 410 |
|
| 411 |
$this->fetchResult = Status::newGood( $this->mRevisionRecord ); |
| 412 |
return $this->mRevisionRecord; |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
public function isCurrent() { |
| 421 |
|
| 422 |
if ( $this->getOldID() == 0 ) { |
| 423 |
return true; |
| 424 |
} |
| 425 |
|
| 426 |
return $this->mPage->exists() && |
| 427 |
$this->mRevisionRecord && |
| 428 |
$this->mRevisionRecord->isCurrent(); |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
public function getRevIdFetched() { |
| 440 |
if ( $this->fetchResult && $this->fetchResult->isOK() ) { |
| 441 |
|
| 442 |
$rev = $this->fetchResult->getValue(); |
| 443 |
return $rev->getId(); |
| 444 |
} else { |
| 445 |
return $this->mPage->getLatest(); |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
public function view() { |
| 454 |
$context = $this->getContext(); |
| 455 |
$useFileCache = $context->getConfig()->get( MainConfigNames::UseFileCache ); |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
$oldid = $this->getOldID(); |
| 462 |
|
| 463 |
$authority = $context->getAuthority(); |
| 464 |
|
| 465 |
$permissionStatus = PermissionStatus::newEmpty(); |
| 466 |
if ( !$authority |
| 467 |
->authorizeRead( 'read', $this->getTitle(), $permissionStatus ) |
| 468 |
) { |
| 469 |
wfDebug( __METHOD__ . ": denied on secondary read check" ); |
| 470 |
throw new PermissionsError( 'read', $permissionStatus ); |
| 471 |
} |
| 472 |
|
| 473 |
$outputPage = $context->getOutput(); |
| 474 |
|
| 475 |
if ( $this->mRedirectUrl ) { |
| 476 |
$outputPage->redirect( $this->mRedirectUrl ); |
| 477 |
wfDebug( __METHOD__ . ": redirecting due to oldid" ); |
| 478 |
|
| 479 |
return; |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
if ( $context->getRequest()->getCheck( 'diff' ) ) { |
| 484 |
wfDebug( __METHOD__ . ": showing diff page" ); |
| 485 |
$this->showDiffPage(); |
| 486 |
|
| 487 |
return; |
| 488 |
} |
| 489 |
|
| 490 |
$this->showProtectionIndicator(); |
| 491 |
|
| 492 |
|
| 493 |
$outputPage->setPageTitle( Parser::formatPageTitle( |
| 494 |
str_replace( '_', ' ', $this->getTitle()->getNsText() ), |
| 495 |
':', |
| 496 |
$this->getTitle()->getText() |
| 497 |
) ); |
| 498 |
|
| 499 |
$outputPage->setArticleFlag( true ); |
| 500 |
|
| 501 |
$outputPage->getMetadata()->setPreventClickjacking( false ); |
| 502 |
|
| 503 |
$parserOptions = $this->getParserOptions(); |
| 504 |
|
| 505 |
$poOptions = []; |
| 506 |
|
| 507 |
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) ) |
| 508 |
->onArticleParserOptions( $this, $parserOptions ); |
| 509 |
|
| 510 |
if ( $outputPage->isPrintable() ) { |
| 511 |
$parserOptions->setIsPrintable( true ); |
| 512 |
$poOptions['enableSectionEditLinks'] = false; |
| 513 |
$outputPage->prependHTML( |
| 514 |
Html::warningBox( |
| 515 |
$outputPage->msg( 'printableversion-deprecated-warning' )->escaped() |
| 516 |
) |
| 517 |
); |
| 518 |
} elseif ( $this->viewIsRenderAction || !$this->isCurrent() || |
| 519 |
!$authority->probablyCan( 'edit', $this->getTitle() ) |
| 520 |
) { |
| 521 |
$poOptions['enableSectionEditLinks'] = false; |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
if ( $oldid === 0 && $this->mPage->checkTouched() ) { |
| 526 |
|
| 527 |
if ( $useFileCache && $this->tryFileCache() ) { |
| 528 |
wfDebug( __METHOD__ . ": done file cache" ); |
| 529 |
|
| 530 |
$outputPage->disable(); |
| 531 |
$this->mPage->doViewUpdates( $authority, $oldid ); |
| 532 |
|
| 533 |
return; |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
$this->showRedirectedFromHeader(); |
| 538 |
$this->showNamespaceHeader(); |
| 539 |
|
| 540 |
if ( $this->viewIsRenderAction ) { |
| 541 |
$poOptions += [ 'absoluteURLs' => true ]; |
| 542 |
} |
| 543 |
$poOptions += [ 'includeDebugInfo' => true ]; |
| 544 |
|
| 545 |
try { |
| 546 |
$continue = |
| 547 |
$this->generateContentOutput( $authority, $parserOptions, $oldid, $outputPage, $poOptions ); |
| 548 |
} catch ( BadRevisionException $e ) { |
| 549 |
$continue = false; |
| 550 |
$this->showViewError( wfMessage( 'badrevision' )->text() ); |
| 551 |
} |
| 552 |
|
| 553 |
if ( !$continue ) { |
| 554 |
return; |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
if ( $this->getTitle()->isMainPage() ) { |
| 562 |
$msg = $context->msg( 'pagetitle-view-mainpage' )->inContentLanguage(); |
| 563 |
if ( !$msg->isDisabled() ) { |
| 564 |
$outputPage->setHTMLTitle( $msg->text() ); |
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
$outputPage->adaptCdnTTL( $this->mPage->getTimestamp(), ExpirationAwareness::TTL_DAY ); |
| 571 |
|
| 572 |
$this->showViewFooter(); |
| 573 |
$this->mPage->doViewUpdates( $authority, $oldid, $this->fetchRevisionRecord() ); |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
$request = $context->getRequest(); |
| 578 |
$cookieKey = EditPage::POST_EDIT_COOKIE_KEY_PREFIX . $this->getRevIdFetched(); |
| 579 |
$postEdit = $request->getCookie( $cookieKey ); |
| 580 |
if ( $postEdit ) { |
| 581 |
|
| 582 |
$request->response()->clearCookie( $cookieKey ); |
| 583 |
$outputPage->addJsConfigVars( 'wgPostEdit', $postEdit ); |
| 584 |
$outputPage->addModules( 'mediawiki.action.view.postEdit' ); |
| 585 |
if ( $this->getContext()->getConfig()->get( MainConfigNames::EnableEditRecovery ) |
| 586 |
&& $this->userOptionsLookup->getOption( $this->getContext()->getUser(), 'editrecovery' ) |
| 587 |
) { |
| 588 |
$outputPage->addModules( 'mediawiki.editRecovery.postEdit' ); |
| 589 |
} |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
public function showProtectionIndicator(): void { |
| 597 |
$title = $this->getTitle(); |
| 598 |
$context = $this->getContext(); |
| 599 |
$outputPage = $context->getOutput(); |
| 600 |
|
| 601 |
$protectionIndicatorsAreEnabled = $context->getConfig() |
| 602 |
->get( MainConfigNames::EnableProtectionIndicators ); |
| 603 |
|
| 604 |
if ( !$protectionIndicatorsAreEnabled || $title->isMainPage() ) { |
| 605 |
return; |
| 606 |
} |
| 607 |
|
| 608 |
$protection = $this->restrictionStore->getRestrictions( $title, 'edit' ); |
| 609 |
|
| 610 |
$cascadeProtection = $this->restrictionStore->getCascadeProtectionSources( $title )[1]; |
| 611 |
|
| 612 |
$isCascadeProtected = array_key_exists( 'edit', $cascadeProtection ); |
| 613 |
|
| 614 |
if ( !$protection && !$isCascadeProtected ) { |
| 615 |
return; |
| 616 |
} |
| 617 |
|
| 618 |
if ( $isCascadeProtected ) { |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
$protectionLevel = $cascadeProtection['edit'][0]; |
| 623 |
} else { |
| 624 |
$protectionLevel = $protection[0]; |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
$protectionLevel = htmlspecialchars( $protectionLevel ); |
| 632 |
|
| 633 |
$protectionExpiry = $this->restrictionStore->getRestrictionExpiry( $title, 'edit' ); |
| 634 |
$formattedProtectionExpiry = $context->getLanguage() |
| 635 |
->formatExpiry( $protectionExpiry ?? '' ); |
| 636 |
|
| 637 |
$protectionMsg = 'protection-indicator-title'; |
| 638 |
if ( $protectionExpiry === 'infinity' || !$protectionExpiry ) { |
| 639 |
$protectionMsg .= '-infinity'; |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
$protectionIndicatorId = 'protection-' . $protectionLevel; |
| 648 |
$protectionIndicatorId .= ( $isCascadeProtected ? '-cascade' : '' ); |
| 649 |
|
| 650 |
|
| 651 |
$protectionMsg = $outputPage->msg( $protectionMsg, $protectionLevel, $formattedProtectionExpiry )->text(); |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
$protectionHelpLink = $outputPage->msg( $protectionIndicatorId . '-helppage' ); |
| 656 |
if ( $protectionHelpLink->isDisabled() ) { |
| 657 |
$protectionHelpLink = 'https://mediawiki.org/wiki/Special:MyLanguage/Help:Protection'; |
| 658 |
} else { |
| 659 |
$protectionHelpLink = Skin::makeInternalOrExternalUrl( $protectionHelpLink->text() ); |
| 660 |
} |
| 661 |
|
| 662 |
$outputPage->setIndicators( [ |
| 663 |
$protectionIndicatorId => Html::rawElement( 'a', [ |
| 664 |
'class' => 'mw-protection-indicator-icon--lock', |
| 665 |
'title' => $protectionMsg, |
| 666 |
'href' => $protectionHelpLink |
| 667 |
], |
| 668 |
|
| 669 |
|
| 670 |
Html::element( 'span', [], $protectionMsg ) ) |
| 671 |
] ); |
| 672 |
|
| 673 |
$outputPage->addModuleStyles( 'mediawiki.protectionIndicators.styles' ); |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
private function generateContentOutput( |
| 689 |
Authority $performer, |
| 690 |
ParserOptions $parserOptions, |
| 691 |
int $oldid, |
| 692 |
OutputPage $outputPage, |
| 693 |
array $textOptions |
| 694 |
): bool { |
| 695 |
|
| 696 |
$useParserCache = true; |
| 697 |
$pOutput = null; |
| 698 |
$parserOutputAccess = MediaWikiServices::getInstance()->getParserOutputAccess(); |
| 699 |
|
| 700 |
|
| 701 |
$this->getHookRunner()->onArticleViewHeader( $this, $outputDone, $useParserCache ); |
| 702 |
if ( $outputDone ) { |
| 703 |
if ( $outputDone instanceof ParserOutput ) { |
| 704 |
$pOutput = $outputDone; |
| 705 |
} |
| 706 |
|
| 707 |
if ( $pOutput ) { |
| 708 |
$this->doOutputMetaData( $pOutput, $outputPage ); |
| 709 |
} |
| 710 |
return true; |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
if ( !$this->mPage->exists() ) { |
| 715 |
wfDebug( __METHOD__ . ": showing missing article" ); |
| 716 |
$this->showMissingArticle(); |
| 717 |
$this->mPage->doViewUpdates( $performer ); |
| 718 |
return false; |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
if ( $useParserCache && !$oldid ) { |
| 724 |
$pOutput = $parserOutputAccess->getCachedParserOutput( |
| 725 |
$this->getPage(), |
| 726 |
$parserOptions, |
| 727 |
null, |
| 728 |
ParserOutputAccess::OPT_NO_AUDIENCE_CHECK |
| 729 |
); |
| 730 |
|
| 731 |
if ( $pOutput ) { |
| 732 |
$this->doOutputFromParserCache( $pOutput, $outputPage, $textOptions ); |
| 733 |
$this->doOutputMetaData( $pOutput, $outputPage ); |
| 734 |
return true; |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
$rev = $this->fetchRevisionRecord(); |
| 739 |
if ( !$this->fetchResult->isOK() ) { |
| 740 |
$this->showViewError( $this->fetchResult->getWikiText( |
| 741 |
false, false, $this->getContext()->getLanguage() |
| 742 |
) ); |
| 743 |
return true; |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
if ( $oldid ) { |
| 748 |
$this->setOldSubtitle( $oldid ); |
| 749 |
|
| 750 |
if ( !$this->showDeletedRevisionHeader() ) { |
| 751 |
wfDebug( __METHOD__ . ": cannot view deleted revision" ); |
| 752 |
return false; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
if ( $useParserCache ) { |
| 759 |
$pOutput = $parserOutputAccess->getCachedParserOutput( |
| 760 |
$this->getPage(), |
| 761 |
$parserOptions, |
| 762 |
$rev, |
| 763 |
ParserOutputAccess::OPT_NO_AUDIENCE_CHECK |
| 764 |
); |
| 765 |
|
| 766 |
if ( $pOutput ) { |
| 767 |
$this->doOutputFromParserCache( $pOutput, $outputPage, $textOptions ); |
| 768 |
$this->doOutputMetaData( $pOutput, $outputPage ); |
| 769 |
return true; |
| 770 |
} |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
$outputPage->setRevisionId( $this->getRevIdFetched() ); |
| 777 |
$outputPage->setRevisionIsCurrent( $rev->isCurrent() ); |
| 778 |
|
| 779 |
$outputPage->setRevisionTimestamp( $rev->getTimestamp() ); |
| 780 |
|
| 781 |
|
| 782 |
if ( $this->getTitle()->isSiteConfigPage() || $this->getTitle()->isUserConfigPage() ) { |
| 783 |
$dir = $this->getContext()->getLanguage()->getDir(); |
| 784 |
$lang = $this->getContext()->getLanguage()->getHtmlCode(); |
| 785 |
|
| 786 |
$outputPage->wrapWikiMsg( |
| 787 |
"<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>", |
| 788 |
'clearyourcache' |
| 789 |
); |
| 790 |
$outputPage->addModuleStyles( 'mediawiki.action.styles' ); |
| 791 |
} elseif ( !$this->getHookRunner()->onArticleRevisionViewCustom( |
| 792 |
$rev, |
| 793 |
$this->getTitle(), |
| 794 |
$oldid, |
| 795 |
$outputPage ) |
| 796 |
) { |
| 797 |
|
| 798 |
|
| 799 |
$this->doOutputMetaData( $pOutput, $outputPage ); |
| 800 |
return true; |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
wfDebug( __METHOD__ . ": doing uncached parse" ); |
| 805 |
|
| 806 |
$opt = 0; |
| 807 |
|
| 808 |
|
| 809 |
$opt |= ParserOutputAccess::OPT_NO_CHECK_CACHE; |
| 810 |
|
| 811 |
|
| 812 |
$opt |= ParserOutputAccess::OPT_NO_AUDIENCE_CHECK; |
| 813 |
|
| 814 |
|
| 815 |
$opt |= ParserOutputAccess::OPT_FOR_ARTICLE_VIEW; |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
$opt |= ParserOutputAccess::OPT_LINKS_UPDATE; |
| 821 |
|
| 822 |
if ( !$rev->getId() || !$useParserCache ) { |
| 823 |
|
| 824 |
$opt |= ParserOutputAccess::OPT_NO_CACHE; |
| 825 |
} |
| 826 |
|
| 827 |
$renderStatus = $parserOutputAccess->getParserOutput( |
| 828 |
$this->getPage(), |
| 829 |
$parserOptions, |
| 830 |
$rev, |
| 831 |
$opt |
| 832 |
); |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
if ( $oldid === 0 || $oldid === $this->getPage()->getLatest() ) { |
| 850 |
$parsoidCacheWarmingEnabled = $this->getContext()->getConfig() |
| 851 |
->get( MainConfigNames::ParsoidCacheConfig )['WarmParsoidParserCache']; |
| 852 |
|
| 853 |
if ( $parsoidCacheWarmingEnabled ) { |
| 854 |
$parsoidJobSpec = ParsoidCachePrewarmJob::newSpec( |
| 855 |
$rev->getId(), |
| 856 |
$this->getPage()->toPageRecord(), |
| 857 |
[ 'causeAction' => 'view' ] |
| 858 |
); |
| 859 |
$this->jobQueueGroup->lazyPush( $parsoidJobSpec ); |
| 860 |
} |
| 861 |
} |
| 862 |
|
| 863 |
$this->doOutputFromRenderStatus( |
| 864 |
$rev, |
| 865 |
$renderStatus, |
| 866 |
$outputPage, |
| 867 |
$textOptions |
| 868 |
); |
| 869 |
|
| 870 |
if ( !$renderStatus->isOK() ) { |
| 871 |
return true; |
| 872 |
} |
| 873 |
|
| 874 |
$pOutput = $renderStatus->getValue(); |
| 875 |
$this->doOutputMetaData( $pOutput, $outputPage ); |
| 876 |
return true; |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
private function doOutputMetaData( ?ParserOutput $pOutput, OutputPage $outputPage ) { |
| 884 |
|
| 885 |
if ( $pOutput ) { |
| 886 |
$this->adjustDisplayTitle( $pOutput ); |
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
$pageLang = $pOutput->getLanguage(); |
| 893 |
if ( $pageLang ) { |
| 894 |
$outputPage->setContentLangForJS( $pageLang ); |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
$policy = $this->getRobotPolicy( 'view', $pOutput ?: null ); |
| 900 |
$outputPage->getMetadata()->setIndexPolicy( $policy['index'] ); |
| 901 |
$outputPage->setFollowPolicy( $policy['follow'] ); |
| 902 |
|
| 903 |
$this->mParserOutput = $pOutput; |
| 904 |
} |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
private function doOutputFromParserCache( |
| 912 |
ParserOutput $pOutput, |
| 913 |
OutputPage $outputPage, |
| 914 |
array $textOptions |
| 915 |
) { |
| 916 |
|
| 917 |
|
| 918 |
$oldid = $pOutput->getCacheRevisionId() ?? $this->getRevIdFetched(); |
| 919 |
$outputPage->setRevisionId( $oldid ); |
| 920 |
$outputPage->setRevisionIsCurrent( $oldid === $this->mPage->getLatest() ); |
| 921 |
$outputPage->addParserOutput( $pOutput, $textOptions ); |
| 922 |
|
| 923 |
$cachedTimestamp = $pOutput->getRevisionTimestamp(); |
| 924 |
if ( $cachedTimestamp !== null ) { |
| 925 |
$outputPage->setRevisionTimestamp( $cachedTimestamp ); |
| 926 |
$this->mPage->setTimestamp( $cachedTimestamp ); |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
private function doOutputFromRenderStatus( |
| 937 |
RevisionRecord $rev, |
| 938 |
Status $renderStatus, |
| 939 |
OutputPage $outputPage, |
| 940 |
array $textOptions |
| 941 |
) { |
| 942 |
$context = $this->getContext(); |
| 943 |
if ( !$renderStatus->isOK() ) { |
| 944 |
$this->showViewError( $renderStatus->getWikiText( |
| 945 |
false, 'view-pool-error', $context->getLanguage() |
| 946 |
) ); |
| 947 |
return; |
| 948 |
} |
| 949 |
|
| 950 |
$pOutput = $renderStatus->getValue(); |
| 951 |
|
| 952 |
|
| 953 |
if ( $renderStatus->hasMessage( 'view-pool-dirty-output' ) ) { |
| 954 |
$outputPage->lowerCdnMaxage( $context->getConfig()->get( MainConfigNames::CdnMaxageStale ) ); |
| 955 |
$outputPage->setLastModified( $pOutput->getCacheTime() ); |
| 956 |
$staleReason = $renderStatus->hasMessage( 'view-pool-contention' ) |
| 957 |
? $context->msg( 'view-pool-contention' )->escaped() |
| 958 |
: $context->msg( 'view-pool-timeout' )->escaped(); |
| 959 |
$outputPage->addHTML( "<!-- parser cache is expired, " . |
| 960 |
"sending anyway due to $staleReason-->\n" ); |
| 961 |
|
| 962 |
|
| 963 |
$cachedId = $pOutput->getCacheRevisionId(); |
| 964 |
if ( $cachedId !== null ) { |
| 965 |
$outputPage->setRevisionId( $cachedId ); |
| 966 |
$outputPage->setRevisionTimestamp( $pOutput->getTimestamp() ); |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
$outputPage->addParserOutput( $pOutput, $textOptions ); |
| 971 |
|
| 972 |
if ( $this->getRevisionRedirectTarget( $rev ) ) { |
| 973 |
$outputPage->addSubtitle( "<span id=\"redirectsub\">" . |
| 974 |
$context->msg( 'redirectpagesub' )->parse() . "</span>" ); |
| 975 |
} |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
private function getRevisionRedirectTarget( RevisionRecord $revision ) { |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
$content = $revision->getContent( SlotRecord::MAIN ); |
| 987 |
return $content ? $content->getRedirectTarget() : null; |
| 988 |
} |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
public function adjustDisplayTitle( ParserOutput $pOutput ) { |
| 995 |
$out = $this->getContext()->getOutput(); |
| 996 |
|
| 997 |
|
| 998 |
$titleText = $pOutput->getTitleText(); |
| 999 |
if ( strval( $titleText ) !== '' ) { |
| 1000 |
$out->setPageTitle( $titleText ); |
| 1001 |
$out->setDisplayTitle( $titleText ); |
| 1002 |
} |
| 1003 |
} |
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
protected function showDiffPage() { |
| 1010 |
$context = $this->getContext(); |
| 1011 |
$outputPage = $context->getOutput(); |
| 1012 |
$outputPage->addBodyClasses( 'mw-article-diff' ); |
| 1013 |
$request = $context->getRequest(); |
| 1014 |
$diff = $request->getVal( 'diff' ); |
| 1015 |
$rcid = $request->getInt( 'rcid' ); |
| 1016 |
$purge = $request->getRawVal( 'action' ) === 'purge'; |
| 1017 |
$unhide = $request->getInt( 'unhide' ) === 1; |
| 1018 |
$oldid = $this->getOldID(); |
| 1019 |
|
| 1020 |
$rev = $this->fetchRevisionRecord(); |
| 1021 |
|
| 1022 |
if ( !$rev ) { |
| 1023 |
|
| 1024 |
|
| 1025 |
$rev = $this->revisionStore->getRevisionById( $oldid ); |
| 1026 |
if ( $rev ) { |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
} else { |
| 1031 |
$outputPage->setPageTitleMsg( $context->msg( 'errorpagetitle' ) ); |
| 1032 |
$msg = $context->msg( 'difference-missing-revision' ) |
| 1033 |
->params( $oldid ) |
| 1034 |
->numParams( 1 ) |
| 1035 |
->parseAsBlock(); |
| 1036 |
$outputPage->addHTML( $msg ); |
| 1037 |
return; |
| 1038 |
} |
| 1039 |
} |
| 1040 |
|
| 1041 |
$services = MediaWikiServices::getInstance(); |
| 1042 |
|
| 1043 |
$contentHandler = $services |
| 1044 |
->getContentHandlerFactory() |
| 1045 |
->getContentHandler( |
| 1046 |
$rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel() |
| 1047 |
); |
| 1048 |
$de = $contentHandler->createDifferenceEngine( |
| 1049 |
$context, |
| 1050 |
$oldid, |
| 1051 |
$diff, |
| 1052 |
$rcid, |
| 1053 |
$purge, |
| 1054 |
$unhide |
| 1055 |
); |
| 1056 |
|
| 1057 |
$diffType = $request->getVal( 'diff-type' ); |
| 1058 |
|
| 1059 |
if ( $diffType === null ) { |
| 1060 |
$diffType = $this->userOptionsLookup |
| 1061 |
->getOption( $context->getUser(), 'diff-type' ); |
| 1062 |
} else { |
| 1063 |
$de->setExtraQueryParams( [ 'diff-type' => $diffType ] ); |
| 1064 |
} |
| 1065 |
|
| 1066 |
$de->setSlotDiffOptions( [ |
| 1067 |
'diff-type' => $diffType, |
| 1068 |
'expand-url' => $this->viewIsRenderAction, |
| 1069 |
'inline-toggle' => true, |
| 1070 |
] ); |
| 1071 |
$de->showDiffPage( $this->isDiffOnlyView() ); |
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
[ , $new ] = $de->mapDiffPrevNext( $oldid, $diff ); |
| 1076 |
|
| 1077 |
$this->mPage->doViewUpdates( $context->getAuthority(), (int)$new ); |
| 1078 |
|
| 1079 |
|
| 1080 |
$context->getOutput()->addHelpLink( 'Help:Diff' ); |
| 1081 |
} |
| 1082 |
|
| 1083 |
protected function isDiffOnlyView() { |
| 1084 |
return $this->getContext()->getRequest()->getBool( |
| 1085 |
'diffonly', |
| 1086 |
$this->userOptionsLookup->getBoolOption( $this->getContext()->getUser(), 'diffonly' ) |
| 1087 |
); |
| 1088 |
} |
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
public function getRobotPolicy( $action, ?ParserOutput $pOutput = null ) { |
| 1098 |
$context = $this->getContext(); |
| 1099 |
$mainConfig = $context->getConfig(); |
| 1100 |
$articleRobotPolicies = $mainConfig->get( MainConfigNames::ArticleRobotPolicies ); |
| 1101 |
$namespaceRobotPolicies = $mainConfig->get( MainConfigNames::NamespaceRobotPolicies ); |
| 1102 |
$defaultRobotPolicy = $mainConfig->get( MainConfigNames::DefaultRobotPolicy ); |
| 1103 |
$title = $this->getTitle(); |
| 1104 |
$ns = $title->getNamespace(); |
| 1105 |
|
| 1106 |
|
| 1107 |
if ( $ns === NS_USER || $ns === NS_USER_TALK ) { |
| 1108 |
$specificTarget = null; |
| 1109 |
$vagueTarget = null; |
| 1110 |
$titleText = $title->getText(); |
| 1111 |
if ( IPUtils::isValid( $titleText ) ) { |
| 1112 |
$vagueTarget = $titleText; |
| 1113 |
} else { |
| 1114 |
$specificTarget = $title->getRootText(); |
| 1115 |
} |
| 1116 |
if ( $this->blockStore->newFromTarget( $specificTarget, $vagueTarget ) instanceof DatabaseBlock ) { |
| 1117 |
return [ |
| 1118 |
'index' => 'noindex', |
| 1119 |
'follow' => 'nofollow' |
| 1120 |
]; |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
if ( $this->mPage->getId() === 0 || $this->getOldID() ) { |
| 1125 |
|
| 1126 |
return [ |
| 1127 |
'index' => 'noindex', |
| 1128 |
'follow' => 'nofollow' |
| 1129 |
]; |
| 1130 |
} elseif ( $context->getOutput()->isPrintable() ) { |
| 1131 |
|
| 1132 |
return [ |
| 1133 |
'index' => 'noindex', |
| 1134 |
'follow' => 'follow' |
| 1135 |
]; |
| 1136 |
} elseif ( $context->getRequest()->getInt( 'curid' ) ) { |
| 1137 |
|
| 1138 |
return [ |
| 1139 |
'index' => 'noindex', |
| 1140 |
'follow' => 'follow' |
| 1141 |
]; |
| 1142 |
} |
| 1143 |
|
| 1144 |
|
| 1145 |
$policy = self::formatRobotPolicy( $defaultRobotPolicy ); |
| 1146 |
|
| 1147 |
if ( isset( $namespaceRobotPolicies[$ns] ) ) { |
| 1148 |
|
| 1149 |
$policy = array_merge( |
| 1150 |
$policy, |
| 1151 |
self::formatRobotPolicy( $namespaceRobotPolicies[$ns] ) |
| 1152 |
); |
| 1153 |
} |
| 1154 |
if ( $title->canUseNoindex() && $pOutput && $pOutput->getIndexPolicy() ) { |
| 1155 |
|
| 1156 |
|
| 1157 |
$policy = array_merge( |
| 1158 |
$policy, |
| 1159 |
[ 'index' => $pOutput->getIndexPolicy() ] |
| 1160 |
); |
| 1161 |
} |
| 1162 |
|
| 1163 |
if ( isset( $articleRobotPolicies[$title->getPrefixedText()] ) ) { |
| 1164 |
|
| 1165 |
$policy = array_merge( |
| 1166 |
$policy, |
| 1167 |
self::formatRobotPolicy( $articleRobotPolicies[$title->getPrefixedText()] ) |
| 1168 |
); |
| 1169 |
} |
| 1170 |
|
| 1171 |
return $policy; |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
public static function formatRobotPolicy( $policy ) { |
| 1182 |
if ( is_array( $policy ) ) { |
| 1183 |
return $policy; |
| 1184 |
} elseif ( !$policy ) { |
| 1185 |
return []; |
| 1186 |
} |
| 1187 |
|
| 1188 |
$arr = []; |
| 1189 |
foreach ( explode( ',', $policy ) as $var ) { |
| 1190 |
$var = trim( $var ); |
| 1191 |
if ( $var === 'index' || $var === 'noindex' ) { |
| 1192 |
$arr['index'] = $var; |
| 1193 |
} elseif ( $var === 'follow' || $var === 'nofollow' ) { |
| 1194 |
$arr['follow'] = $var; |
| 1195 |
} |
| 1196 |
} |
| 1197 |
|
| 1198 |
return $arr; |
| 1199 |
} |
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
public function showRedirectedFromHeader() { |
| 1209 |
$context = $this->getContext(); |
| 1210 |
$redirectSources = $context->getConfig()->get( MainConfigNames::RedirectSources ); |
| 1211 |
$outputPage = $context->getOutput(); |
| 1212 |
$request = $context->getRequest(); |
| 1213 |
$rdfrom = $request->getVal( 'rdfrom' ); |
| 1214 |
|
| 1215 |
|
| 1216 |
$query = $request->getValues(); |
| 1217 |
unset( $query['rdfrom'] ); |
| 1218 |
unset( $query['title'] ); |
| 1219 |
if ( $this->getTitle()->isRedirect() ) { |
| 1220 |
|
| 1221 |
$query['redirect'] = 'no'; |
| 1222 |
} |
| 1223 |
$redirectTargetUrl = $this->getTitle()->getLinkURL( $query ); |
| 1224 |
|
| 1225 |
if ( isset( $this->mRedirectedFrom ) ) { |
| 1226 |
|
| 1227 |
|
| 1228 |
if ( $this->getHookRunner()->onArticleViewRedirect( $this ) ) { |
| 1229 |
$redir = $this->linkRenderer->makeKnownLink( |
| 1230 |
$this->mRedirectedFrom, |
| 1231 |
null, |
| 1232 |
[], |
| 1233 |
[ 'redirect' => 'no' ] |
| 1234 |
); |
| 1235 |
|
| 1236 |
$outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" . |
| 1237 |
$context->msg( 'redirectedfrom' )->rawParams( $redir )->parse() |
| 1238 |
. "</span>" ); |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
$outputPage->addJsConfigVars( [ |
| 1243 |
'wgInternalRedirectTargetUrl' => $redirectTargetUrl, |
| 1244 |
] ); |
| 1245 |
$outputPage->addModules( 'mediawiki.action.view.redirect' ); |
| 1246 |
|
| 1247 |
|
| 1248 |
$outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() ); |
| 1249 |
|
| 1250 |
|
| 1251 |
$outputPage->setRedirectedFrom( $this->mRedirectedFrom ); |
| 1252 |
|
| 1253 |
return true; |
| 1254 |
} |
| 1255 |
} elseif ( $rdfrom ) { |
| 1256 |
|
| 1257 |
|
| 1258 |
if ( $redirectSources && preg_match( $redirectSources, $rdfrom ) ) { |
| 1259 |
$redir = $this->linkRenderer->makeExternalLink( $rdfrom, $rdfrom, $this->getTitle() ); |
| 1260 |
$outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" . |
| 1261 |
$context->msg( 'redirectedfrom' )->rawParams( $redir )->parse() |
| 1262 |
. "</span>" ); |
| 1263 |
|
| 1264 |
|
| 1265 |
$outputPage->addJsConfigVars( [ |
| 1266 |
'wgInternalRedirectTargetUrl' => $redirectTargetUrl, |
| 1267 |
] ); |
| 1268 |
$outputPage->addModules( 'mediawiki.action.view.redirect' ); |
| 1269 |
|
| 1270 |
return true; |
| 1271 |
} |
| 1272 |
} |
| 1273 |
|
| 1274 |
return false; |
| 1275 |
} |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
public function showNamespaceHeader() { |
| 1282 |
if ( $this->getTitle()->isTalkPage() && !$this->getContext()->msg( 'talkpageheader' )->isDisabled() ) { |
| 1283 |
$this->getContext()->getOutput()->wrapWikiMsg( |
| 1284 |
"<div class=\"mw-talkpageheader\">\n$1\n</div>", |
| 1285 |
[ 'talkpageheader' ] |
| 1286 |
); |
| 1287 |
} |
| 1288 |
} |
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
public function showViewFooter() { |
| 1294 |
|
| 1295 |
if ( $this->getTitle()->getNamespace() === NS_USER_TALK |
| 1296 |
&& IPUtils::isValid( $this->getTitle()->getText() ) |
| 1297 |
) { |
| 1298 |
$this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' ); |
| 1299 |
} |
| 1300 |
|
| 1301 |
|
| 1302 |
$patrolFooterShown = $this->showPatrolFooter(); |
| 1303 |
|
| 1304 |
$this->getHookRunner()->onArticleViewFooter( $this, $patrolFooterShown ); |
| 1305 |
} |
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
public function showPatrolFooter() { |
| 1318 |
$context = $this->getContext(); |
| 1319 |
$mainConfig = $context->getConfig(); |
| 1320 |
$useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol ); |
| 1321 |
$useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol ); |
| 1322 |
$useFilePatrol = $mainConfig->get( MainConfigNames::UseFilePatrol ); |
| 1323 |
|
| 1324 |
if ( !$this->getHookRunner()->onArticleShowPatrolFooter( $this ) ) { |
| 1325 |
return false; |
| 1326 |
} |
| 1327 |
|
| 1328 |
$outputPage = $context->getOutput(); |
| 1329 |
$user = $context->getUser(); |
| 1330 |
$title = $this->getTitle(); |
| 1331 |
$rc = false; |
| 1332 |
|
| 1333 |
if ( !$context->getAuthority()->probablyCan( 'patrol', $title ) |
| 1334 |
|| !( $useRCPatrol || $useNPPatrol |
| 1335 |
|| ( $useFilePatrol && $title->inNamespace( NS_FILE ) ) ) |
| 1336 |
) { |
| 1337 |
|
| 1338 |
return false; |
| 1339 |
} |
| 1340 |
|
| 1341 |
if ( $this->mRevisionRecord |
| 1342 |
&& !RecentChange::isInRCLifespan( $this->mRevisionRecord->getTimestamp(), 21600 ) |
| 1343 |
) { |
| 1344 |
|
| 1345 |
|
| 1346 |
return false; |
| 1347 |
} |
| 1348 |
|
| 1349 |
|
| 1350 |
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
| 1351 |
$key = $cache->makeKey( 'unpatrollable-page', $title->getArticleID() ); |
| 1352 |
if ( $cache->get( $key ) ) { |
| 1353 |
return false; |
| 1354 |
} |
| 1355 |
|
| 1356 |
$dbr = $this->dbProvider->getReplicaDatabase(); |
| 1357 |
$oldestRevisionRow = $dbr->newSelectQueryBuilder() |
| 1358 |
->select( [ 'rev_id', 'rev_timestamp' ] ) |
| 1359 |
->from( 'revision' ) |
| 1360 |
->where( [ 'rev_page' => $title->getArticleID() ] ) |
| 1361 |
->orderBy( [ 'rev_timestamp', 'rev_id' ] ) |
| 1362 |
->caller( __METHOD__ )->fetchRow(); |
| 1363 |
$oldestRevisionTimestamp = $oldestRevisionRow ? $oldestRevisionRow->rev_timestamp : false; |
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
$recentPageCreation = false; |
| 1370 |
if ( $oldestRevisionTimestamp |
| 1371 |
&& RecentChange::isInRCLifespan( $oldestRevisionTimestamp, 21600 ) |
| 1372 |
) { |
| 1373 |
|
| 1374 |
$recentPageCreation = true; |
| 1375 |
$rc = RecentChange::newFromConds( |
| 1376 |
[ |
| 1377 |
'rc_this_oldid' => intval( $oldestRevisionRow->rev_id ), |
| 1378 |
|
| 1379 |
'rc_type' => RC_NEW, |
| 1380 |
], |
| 1381 |
__METHOD__ |
| 1382 |
); |
| 1383 |
if ( $rc ) { |
| 1384 |
|
| 1385 |
$markPatrolledMsg = $context->msg( 'markaspatrolledtext' ); |
| 1386 |
} |
| 1387 |
} |
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
$recentFileUpload = false; |
| 1394 |
if ( ( !$rc || $rc->getAttribute( 'rc_patrolled' ) ) && $useFilePatrol |
| 1395 |
&& $title->getNamespace() === NS_FILE ) { |
| 1396 |
|
| 1397 |
$newestUploadTimestamp = $dbr->newSelectQueryBuilder() |
| 1398 |
->select( 'img_timestamp' ) |
| 1399 |
->from( 'image' ) |
| 1400 |
->where( [ 'img_name' => $title->getDBkey() ] ) |
| 1401 |
->caller( __METHOD__ )->fetchField(); |
| 1402 |
if ( $newestUploadTimestamp |
| 1403 |
&& RecentChange::isInRCLifespan( $newestUploadTimestamp, 21600 ) |
| 1404 |
) { |
| 1405 |
|
| 1406 |
$recentFileUpload = true; |
| 1407 |
$rc = RecentChange::newFromConds( |
| 1408 |
[ |
| 1409 |
'rc_type' => RC_LOG, |
| 1410 |
'rc_log_type' => 'upload', |
| 1411 |
'rc_timestamp' => $newestUploadTimestamp, |
| 1412 |
'rc_namespace' => NS_FILE, |
| 1413 |
'rc_cur_id' => $title->getArticleID() |
| 1414 |
], |
| 1415 |
__METHOD__ |
| 1416 |
); |
| 1417 |
if ( $rc ) { |
| 1418 |
|
| 1419 |
$markPatrolledMsg = $context->msg( 'markaspatrolledtext-file' ); |
| 1420 |
} |
| 1421 |
} |
| 1422 |
} |
| 1423 |
|
| 1424 |
if ( !$recentPageCreation && !$recentFileUpload ) { |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
$cache->set( $key, '1' ); |
| 1430 |
|
| 1431 |
return false; |
| 1432 |
} |
| 1433 |
|
| 1434 |
if ( !$rc ) { |
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
return false; |
| 1439 |
} |
| 1440 |
|
| 1441 |
if ( $rc->getAttribute( 'rc_patrolled' ) ) { |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
$cache->set( $key, '1' ); |
| 1447 |
|
| 1448 |
return false; |
| 1449 |
} |
| 1450 |
|
| 1451 |
if ( $rc->getPerformerIdentity()->equals( $user ) ) { |
| 1452 |
|
| 1453 |
|
| 1454 |
return false; |
| 1455 |
} |
| 1456 |
|
| 1457 |
$outputPage->getMetadata()->setPreventClickjacking( true ); |
| 1458 |
$outputPage->addModules( 'mediawiki.misc-authed-curate' ); |
| 1459 |
|
| 1460 |
$link = $this->linkRenderer->makeKnownLink( |
| 1461 |
$title, |
| 1462 |
new HtmlArmor( '<button class="cdx-button cdx-button--action-progressive">' |
| 1463 |
|
| 1464 |
. $markPatrolledMsg->escaped() . '</button>' ), |
| 1465 |
[], |
| 1466 |
[ |
| 1467 |
'action' => 'markpatrolled', |
| 1468 |
'rcid' => $rc->getAttribute( 'rc_id' ), |
| 1469 |
] |
| 1470 |
); |
| 1471 |
|
| 1472 |
$outputPage->addModuleStyles( 'mediawiki.action.styles' ); |
| 1473 |
$outputPage->addHTML( "<div class='patrollink' data-mw='interface'>$link</div>" ); |
| 1474 |
|
| 1475 |
return true; |
| 1476 |
} |
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
public static function purgePatrolFooterCache( $articleID ) { |
| 1485 |
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
| 1486 |
$cache->delete( $cache->makeKey( 'unpatrollable-page', $articleID ) ); |
| 1487 |
} |
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
public function showMissingArticle() { |
| 1494 |
$context = $this->getContext(); |
| 1495 |
$send404Code = $context->getConfig()->get( MainConfigNames::Send404Code ); |
| 1496 |
|
| 1497 |
$outputPage = $context->getOutput(); |
| 1498 |
|
| 1499 |
$validUserPage = false; |
| 1500 |
|
| 1501 |
$title = $this->getTitle(); |
| 1502 |
|
| 1503 |
$services = MediaWikiServices::getInstance(); |
| 1504 |
|
| 1505 |
$contextUser = $context->getUser(); |
| 1506 |
|
| 1507 |
|
| 1508 |
if ( $title->getNamespace() === NS_USER |
| 1509 |
|| $title->getNamespace() === NS_USER_TALK |
| 1510 |
) { |
| 1511 |
$rootPart = $title->getRootText(); |
| 1512 |
$user = User::newFromName( $rootPart, false ); |
| 1513 |
$ip = $this->userNameUtils->isIP( $rootPart ); |
| 1514 |
$block = $this->blockStore->newFromTarget( $user, $user ); |
| 1515 |
|
| 1516 |
if ( $user && $user->isRegistered() && $user->isHidden() && |
| 1517 |
!$context->getAuthority()->isAllowed( 'hideuser' ) |
| 1518 |
) { |
| 1519 |
|
| 1520 |
|
| 1521 |
$user = false; |
| 1522 |
} |
| 1523 |
|
| 1524 |
if ( !( $user && $user->isRegistered() ) && !$ip ) { |
| 1525 |
|
| 1526 |
$outputPage->addHTML( Html::warningBox( |
| 1527 |
$context->msg( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) )->parse(), |
| 1528 |
'mw-userpage-userdoesnotexist' |
| 1529 |
) ); |
| 1530 |
|
| 1531 |
|
| 1532 |
LogEventsList::showLogExtract( |
| 1533 |
$outputPage, |
| 1534 |
'renameuser', |
| 1535 |
Title::makeTitleSafe( NS_USER, $rootPart ), |
| 1536 |
'', |
| 1537 |
[ |
| 1538 |
'lim' => 10, |
| 1539 |
'showIfEmpty' => false, |
| 1540 |
'msgKey' => [ 'renameuser-renamed-notice', $title->getBaseText() ] |
| 1541 |
] |
| 1542 |
); |
| 1543 |
} elseif ( |
| 1544 |
$block !== null && |
| 1545 |
$block->getType() != DatabaseBlock::TYPE_AUTO && |
| 1546 |
( |
| 1547 |
$block->isSitewide() || |
| 1548 |
$services->getPermissionManager()->isBlockedFrom( $user, $title, true ) |
| 1549 |
) |
| 1550 |
) { |
| 1551 |
|
| 1552 |
|
| 1553 |
LogEventsList::showLogExtract( |
| 1554 |
$outputPage, |
| 1555 |
'block', |
| 1556 |
$services->getNamespaceInfo()->getCanonicalName( NS_USER ) . ':' . |
| 1557 |
$block->getTargetName(), |
| 1558 |
'', |
| 1559 |
[ |
| 1560 |
'lim' => 1, |
| 1561 |
'showIfEmpty' => false, |
| 1562 |
'msgKey' => [ |
| 1563 |
'blocked-notice-logextract', |
| 1564 |
$user->getName() |
| 1565 |
] |
| 1566 |
] |
| 1567 |
); |
| 1568 |
$validUserPage = !$title->isSubpage(); |
| 1569 |
} else { |
| 1570 |
$validUserPage = !$title->isSubpage(); |
| 1571 |
} |
| 1572 |
} |
| 1573 |
|
| 1574 |
$this->getHookRunner()->onShowMissingArticle( $this ); |
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
$dbCache = MediaWikiServices::getInstance()->getMainObjectStash(); |
| 1580 |
$key = $dbCache->makeKey( 'page-recent-delete', md5( $title->getPrefixedText() ) ); |
| 1581 |
$isRegistered = $contextUser->isRegistered(); |
| 1582 |
$sessionExists = $context->getRequest()->getSession()->isPersistent(); |
| 1583 |
|
| 1584 |
if ( $isRegistered || $dbCache->get( $key ) || $sessionExists ) { |
| 1585 |
$logTypes = [ 'delete', 'move', 'protect', 'merge' ]; |
| 1586 |
|
| 1587 |
$dbr = $this->dbProvider->getReplicaDatabase(); |
| 1588 |
|
| 1589 |
$conds = [ $dbr->expr( 'log_action', '!=', 'revision' ) ]; |
| 1590 |
|
| 1591 |
$this->getHookRunner()->onArticle__MissingArticleConditions( $conds, $logTypes ); |
| 1592 |
LogEventsList::showLogExtract( |
| 1593 |
$outputPage, |
| 1594 |
$logTypes, |
| 1595 |
$title, |
| 1596 |
'', |
| 1597 |
[ |
| 1598 |
'lim' => 10, |
| 1599 |
'conds' => $conds, |
| 1600 |
'showIfEmpty' => false, |
| 1601 |
'msgKey' => [ $isRegistered || $sessionExists |
| 1602 |
? 'moveddeleted-notice' |
| 1603 |
: 'moveddeleted-notice-recent' |
| 1604 |
] |
| 1605 |
] |
| 1606 |
); |
| 1607 |
} |
| 1608 |
|
| 1609 |
if ( !$this->mPage->hasViewableContent() && $send404Code && !$validUserPage ) { |
| 1610 |
|
| 1611 |
|
| 1612 |
$context->getRequest()->response()->statusHeader( 404 ); |
| 1613 |
} |
| 1614 |
|
| 1615 |
|
| 1616 |
$policy = $this->getRobotPolicy( 'view' ); |
| 1617 |
$outputPage->getMetadata()->setIndexPolicy( $policy['index'] ); |
| 1618 |
$outputPage->setFollowPolicy( $policy['follow'] ); |
| 1619 |
|
| 1620 |
$hookResult = $this->getHookRunner()->onBeforeDisplayNoArticleText( $this ); |
| 1621 |
|
| 1622 |
if ( !$hookResult ) { |
| 1623 |
return; |
| 1624 |
} |
| 1625 |
|
| 1626 |
|
| 1627 |
$oldid = $this->getOldID(); |
| 1628 |
if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI && $title->hasSourceText() ) { |
| 1629 |
$text = $this->getTitle()->getDefaultMessageText() ?? ''; |
| 1630 |
$outputPage->addWikiTextAsContent( $text ); |
| 1631 |
} else { |
| 1632 |
if ( $oldid ) { |
| 1633 |
$text = $this->getMissingRevisionMsg( $oldid )->plain(); |
| 1634 |
} elseif ( $context->getAuthority()->probablyCan( 'edit', $title ) ) { |
| 1635 |
$message = $isRegistered ? 'noarticletext' : 'noarticletextanon'; |
| 1636 |
$text = $context->msg( $message )->plain(); |
| 1637 |
} else { |
| 1638 |
$text = $context->msg( 'noarticletext-nopermission' )->plain(); |
| 1639 |
} |
| 1640 |
|
| 1641 |
$dir = $context->getLanguage()->getDir(); |
| 1642 |
$lang = $context->getLanguage()->getHtmlCode(); |
| 1643 |
$outputPage->addWikiTextAsInterface( Xml::openElement( 'div', [ |
| 1644 |
'class' => "noarticletext mw-content-$dir", |
| 1645 |
'dir' => $dir, |
| 1646 |
'lang' => $lang, |
| 1647 |
] ) . "\n$text\n</div>" ); |
| 1648 |
} |
| 1649 |
} |
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
private function showViewError( string $errortext ) { |
| 1656 |
$outputPage = $this->getContext()->getOutput(); |
| 1657 |
$outputPage->setPageTitleMsg( $this->getContext()->msg( 'errorpagetitle' ) ); |
| 1658 |
$outputPage->disableClientCache(); |
| 1659 |
$outputPage->setRobotPolicy( 'noindex,nofollow' ); |
| 1660 |
$outputPage->clearHTML(); |
| 1661 |
$outputPage->addHTML( Html::errorBox( $outputPage->parseAsContent( $errortext ) ) ); |
| 1662 |
} |
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
public function showDeletedRevisionHeader() { |
| 1671 |
if ( !$this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) { |
| 1672 |
|
| 1673 |
return true; |
| 1674 |
} |
| 1675 |
$outputPage = $this->getContext()->getOutput(); |
| 1676 |
|
| 1677 |
$titleText = $this->getTitle()->getPrefixedDBkey(); |
| 1678 |
|
| 1679 |
if ( !$this->mRevisionRecord->userCan( |
| 1680 |
RevisionRecord::DELETED_TEXT, |
| 1681 |
$this->getContext()->getAuthority() |
| 1682 |
) ) { |
| 1683 |
$outputPage->addHTML( |
| 1684 |
Html::warningBox( |
| 1685 |
$outputPage->msg( 'rev-deleted-text-permission', $titleText )->parse(), |
| 1686 |
'plainlinks' |
| 1687 |
) |
| 1688 |
); |
| 1689 |
|
| 1690 |
return false; |
| 1691 |
|
| 1692 |
} elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) !== 1 ) { |
| 1693 |
|
| 1694 |
$oldid = intval( $this->getOldID() ); |
| 1695 |
$link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" ); |
| 1696 |
$msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ? |
| 1697 |
'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide'; |
| 1698 |
$outputPage->addHTML( |
| 1699 |
Html::warningBox( |
| 1700 |
$outputPage->msg( $msg, $link )->parse(), |
| 1701 |
'plainlinks' |
| 1702 |
) |
| 1703 |
); |
| 1704 |
|
| 1705 |
return false; |
| 1706 |
|
| 1707 |
} else { |
| 1708 |
$msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) |
| 1709 |
? [ 'rev-suppressed-text-view', $titleText ] |
| 1710 |
: [ 'rev-deleted-text-view', $titleText ]; |
| 1711 |
$outputPage->addHTML( |
| 1712 |
Html::warningBox( |
| 1713 |
$outputPage->msg( $msg[0], $msg[1] )->parse(), |
| 1714 |
'plainlinks' |
| 1715 |
) |
| 1716 |
); |
| 1717 |
|
| 1718 |
return true; |
| 1719 |
} |
| 1720 |
} |
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
public function setOldSubtitle( $oldid = 0 ) { |
| 1731 |
if ( !$this->getHookRunner()->onDisplayOldSubtitle( $this, $oldid ) ) { |
| 1732 |
return; |
| 1733 |
} |
| 1734 |
|
| 1735 |
$context = $this->getContext(); |
| 1736 |
$unhide = $context->getRequest()->getInt( 'unhide' ) === 1; |
| 1737 |
|
| 1738 |
|
| 1739 |
$extraParams = []; |
| 1740 |
if ( $unhide ) { |
| 1741 |
$extraParams['unhide'] = 1; |
| 1742 |
} |
| 1743 |
|
| 1744 |
if ( $this->mRevisionRecord && $this->mRevisionRecord->getId() === $oldid ) { |
| 1745 |
$revisionRecord = $this->mRevisionRecord; |
| 1746 |
} else { |
| 1747 |
$revisionRecord = $this->revisionStore->getRevisionById( $oldid ); |
| 1748 |
} |
| 1749 |
if ( !$revisionRecord ) { |
| 1750 |
throw new LogicException( 'There should be a revision record at this point.' ); |
| 1751 |
} |
| 1752 |
|
| 1753 |
$timestamp = $revisionRecord->getTimestamp(); |
| 1754 |
|
| 1755 |
$current = ( $oldid == $this->mPage->getLatest() ); |
| 1756 |
$language = $context->getLanguage(); |
| 1757 |
$user = $context->getUser(); |
| 1758 |
|
| 1759 |
$td = $language->userTimeAndDate( $timestamp, $user ); |
| 1760 |
$tddate = $language->userDate( $timestamp, $user ); |
| 1761 |
$tdtime = $language->userTime( $timestamp, $user ); |
| 1762 |
|
| 1763 |
|
| 1764 |
$userlinks = Linker::revUserTools( $revisionRecord, !$unhide ); |
| 1765 |
|
| 1766 |
$infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled() |
| 1767 |
? 'revision-info-current' |
| 1768 |
: 'revision-info'; |
| 1769 |
|
| 1770 |
$outputPage = $context->getOutput(); |
| 1771 |
$outputPage->addModuleStyles( [ |
| 1772 |
'mediawiki.codex.messagebox.styles', |
| 1773 |
'mediawiki.action.styles', |
| 1774 |
'mediawiki.interface.helpers.styles' |
| 1775 |
] ); |
| 1776 |
|
| 1777 |
$revisionUser = $revisionRecord->getUser(); |
| 1778 |
$revisionInfo = "<div id=\"mw-{$infomsg}\">" . |
| 1779 |
$context->msg( $infomsg, $td ) |
| 1780 |
->rawParams( $userlinks ) |
| 1781 |
->params( |
| 1782 |
$revisionRecord->getId(), |
| 1783 |
$tddate, |
| 1784 |
$tdtime, |
| 1785 |
$revisionUser ? $revisionUser->getName() : '' |
| 1786 |
) |
| 1787 |
->rawParams( $this->commentFormatter->formatRevision( |
| 1788 |
$revisionRecord, |
| 1789 |
$user, |
| 1790 |
true, |
| 1791 |
!$unhide |
| 1792 |
) ) |
| 1793 |
->parse() . |
| 1794 |
"</div>"; |
| 1795 |
|
| 1796 |
$lnk = $current |
| 1797 |
? $context->msg( 'currentrevisionlink' )->escaped() |
| 1798 |
: $this->linkRenderer->makeKnownLink( |
| 1799 |
$this->getTitle(), |
| 1800 |
$context->msg( 'currentrevisionlink' )->text(), |
| 1801 |
[], |
| 1802 |
$extraParams |
| 1803 |
); |
| 1804 |
$curdiff = $current |
| 1805 |
? $context->msg( 'diff' )->escaped() |
| 1806 |
: $this->linkRenderer->makeKnownLink( |
| 1807 |
$this->getTitle(), |
| 1808 |
$context->msg( 'diff' )->text(), |
| 1809 |
[], |
| 1810 |
[ |
| 1811 |
'diff' => 'cur', |
| 1812 |
'oldid' => $oldid |
| 1813 |
] + $extraParams |
| 1814 |
); |
| 1815 |
$prevExist = (bool)$this->revisionStore->getPreviousRevision( $revisionRecord ); |
| 1816 |
$prevlink = $prevExist |
| 1817 |
? $this->linkRenderer->makeKnownLink( |
| 1818 |
$this->getTitle(), |
| 1819 |
$context->msg( 'previousrevision' )->text(), |
| 1820 |
[], |
| 1821 |
[ |
| 1822 |
'direction' => 'prev', |
| 1823 |
'oldid' => $oldid |
| 1824 |
] + $extraParams |
| 1825 |
) |
| 1826 |
: $context->msg( 'previousrevision' )->escaped(); |
| 1827 |
$prevdiff = $prevExist |
| 1828 |
? $this->linkRenderer->makeKnownLink( |
| 1829 |
$this->getTitle(), |
| 1830 |
$context->msg( 'diff' )->text(), |
| 1831 |
[], |
| 1832 |
[ |
| 1833 |
'diff' => 'prev', |
| 1834 |
'oldid' => $oldid |
| 1835 |
] + $extraParams |
| 1836 |
) |
| 1837 |
: $context->msg( 'diff' )->escaped(); |
| 1838 |
$nextlink = $current |
| 1839 |
? $context->msg( 'nextrevision' )->escaped() |
| 1840 |
: $this->linkRenderer->makeKnownLink( |
| 1841 |
$this->getTitle(), |
| 1842 |
$context->msg( 'nextrevision' )->text(), |
| 1843 |
[], |
| 1844 |
[ |
| 1845 |
'direction' => 'next', |
| 1846 |
'oldid' => $oldid |
| 1847 |
] + $extraParams |
| 1848 |
); |
| 1849 |
$nextdiff = $current |
| 1850 |
? $context->msg( 'diff' )->escaped() |
| 1851 |
: $this->linkRenderer->makeKnownLink( |
| 1852 |
$this->getTitle(), |
| 1853 |
$context->msg( 'diff' )->text(), |
| 1854 |
[], |
| 1855 |
[ |
| 1856 |
'diff' => 'next', |
| 1857 |
'oldid' => $oldid |
| 1858 |
] + $extraParams |
| 1859 |
); |
| 1860 |
|
| 1861 |
$cdel = Linker::getRevDeleteLink( |
| 1862 |
$context->getAuthority(), |
| 1863 |
$revisionRecord, |
| 1864 |
$this->getTitle() |
| 1865 |
); |
| 1866 |
if ( $cdel !== '' ) { |
| 1867 |
$cdel .= ' '; |
| 1868 |
} |
| 1869 |
|
| 1870 |
|
| 1871 |
$outputPage->addSubtitle( |
| 1872 |
Html::warningBox( |
| 1873 |
$revisionInfo . |
| 1874 |
"<div id=\"mw-revision-nav\">" . $cdel . |
| 1875 |
$context->msg( 'revision-nav' )->rawParams( |
| 1876 |
$prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff |
| 1877 |
)->escaped() . "</div>", |
| 1878 |
'mw-revision' |
| 1879 |
) |
| 1880 |
); |
| 1881 |
} |
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
public static function getRedirectHeaderHtml( Language $lang, Title $target, $forceKnown = false ) { |
| 1897 |
wfDeprecated( __METHOD__, '1.41' ); |
| 1898 |
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); |
| 1899 |
return $linkRenderer->makeRedirectHeader( $lang, $target, $forceKnown ); |
| 1900 |
} |
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
public function addHelpLink( $to, $overrideBaseUrl = false ) { |
| 1911 |
$out = $this->getContext()->getOutput(); |
| 1912 |
$msg = $out->msg( 'namespace-' . $this->getTitle()->getNamespace() . '-helppage' ); |
| 1913 |
|
| 1914 |
if ( !$msg->isDisabled() ) { |
| 1915 |
$title = Title::newFromText( $msg->plain() ); |
| 1916 |
if ( $title instanceof Title ) { |
| 1917 |
$out->addHelpLink( $title->getLocalURL(), true ); |
| 1918 |
} |
| 1919 |
} else { |
| 1920 |
$out->addHelpLink( $to, $overrideBaseUrl ); |
| 1921 |
} |
| 1922 |
} |
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
public function render() { |
| 1928 |
$this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' ); |
| 1929 |
$this->getContext()->getOutput()->setArticleBodyOnly( true ); |
| 1930 |
|
| 1931 |
$this->viewIsRenderAction = true; |
| 1932 |
$this->view(); |
| 1933 |
} |
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
public function protect() { |
| 1939 |
$form = new ProtectionForm( $this ); |
| 1940 |
$form->execute(); |
| 1941 |
} |
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
public function unprotect() { |
| 1947 |
$this->protect(); |
| 1948 |
} |
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
protected function tryFileCache() { |
| 1960 |
static $called = false; |
| 1961 |
|
| 1962 |
if ( $called ) { |
| 1963 |
wfDebug( "Article::tryFileCache(): called twice!?" ); |
| 1964 |
return false; |
| 1965 |
} |
| 1966 |
|
| 1967 |
$called = true; |
| 1968 |
if ( $this->isFileCacheable() ) { |
| 1969 |
$cache = new HTMLFileCache( $this->getTitle(), 'view' ); |
| 1970 |
if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) { |
| 1971 |
wfDebug( "Article::tryFileCache(): about to load file" ); |
| 1972 |
$cache->loadFromFileCache( $this->getContext() ); |
| 1973 |
return true; |
| 1974 |
} else { |
| 1975 |
wfDebug( "Article::tryFileCache(): starting buffer" ); |
| 1976 |
ob_start( [ &$cache, 'saveToFileCache' ] ); |
| 1977 |
} |
| 1978 |
} else { |
| 1979 |
wfDebug( "Article::tryFileCache(): not cacheable" ); |
| 1980 |
} |
| 1981 |
|
| 1982 |
return false; |
| 1983 |
} |
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
public function isFileCacheable( $mode = HTMLFileCache::MODE_NORMAL ) { |
| 1991 |
$cacheable = false; |
| 1992 |
|
| 1993 |
if ( HTMLFileCache::useFileCache( $this->getContext(), $mode ) ) { |
| 1994 |
$cacheable = $this->mPage->getId() |
| 1995 |
&& !$this->mRedirectedFrom && !$this->getTitle()->isRedirect(); |
| 1996 |
|
| 1997 |
if ( $cacheable ) { |
| 1998 |
$cacheable = $this->getHookRunner()->onIsFileCacheable( $this ) ?? false; |
| 1999 |
} |
| 2000 |
} |
| 2001 |
|
| 2002 |
return $cacheable; |
| 2003 |
} |
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
public function getParserOutput( $oldid = null, ?UserIdentity $user = null ) { |
| 2017 |
if ( $user === null ) { |
| 2018 |
$parserOptions = $this->getParserOptions(); |
| 2019 |
} else { |
| 2020 |
$parserOptions = $this->mPage->makeParserOptions( $user ); |
| 2021 |
$parserOptions->setRenderReason( 'page-view' ); |
| 2022 |
} |
| 2023 |
|
| 2024 |
return $this->mPage->getParserOutput( $parserOptions, $oldid ); |
| 2025 |
} |
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
public function getParserOptions() { |
| 2032 |
$parserOptions = $this->mPage->makeParserOptions( $this->getContext() ); |
| 2033 |
$parserOptions->setRenderReason( 'page-view' ); |
| 2034 |
return $parserOptions; |
| 2035 |
} |
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
public function setContext( $context ) { |
| 2044 |
$this->mContext = $context; |
| 2045 |
} |
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
public function getContext(): IContextSource { |
| 2054 |
if ( $this->mContext instanceof IContextSource ) { |
| 2055 |
return $this->mContext; |
| 2056 |
} else { |
| 2057 |
wfDebug( __METHOD__ . " called and \$mContext is null. " . |
| 2058 |
"Return RequestContext::getMain()" ); |
| 2059 |
return RequestContext::getMain(); |
| 2060 |
} |
| 2061 |
} |
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
public function getActionOverrides() { |
| 2069 |
return $this->mPage->getActionOverrides(); |
| 2070 |
} |
| 2071 |
|
| 2072 |
private function getMissingRevisionMsg( int $oldid ): Message { |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
$context = $this->getContext(); |
| 2077 |
$revRecord = $this->archivedRevisionLookup->getArchivedRevisionRecord( null, $oldid ); |
| 2078 |
if ( |
| 2079 |
$revRecord && |
| 2080 |
$revRecord->userCan( |
| 2081 |
RevisionRecord::DELETED_TEXT, |
| 2082 |
$context->getAuthority() |
| 2083 |
) && |
| 2084 |
$context->getAuthority()->isAllowedAny( 'deletedtext', 'undelete' ) |
| 2085 |
) { |
| 2086 |
return $context->msg( |
| 2087 |
'missing-revision-permission', |
| 2088 |
$oldid, |
| 2089 |
$revRecord->getTimestamp(), |
| 2090 |
Title::newFromPageIdentity( $revRecord->getPage() )->getPrefixedDBkey() |
| 2091 |
); |
| 2092 |
} |
| 2093 |
return $context->msg( 'missing-revision', $oldid ); |
| 2094 |
} |
| 2095 |
} |