| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Actions; |
| 4 |
|
| 5 |
use Action; |
| 6 |
use Article; |
| 7 |
use BadTitleError; |
| 8 |
use ErrorPageError; |
| 9 |
use HTMLFileCache; |
| 10 |
use HttpError; |
| 11 |
use MediaWiki\Context\RequestContext; |
| 12 |
use MediaWiki\Logger\LoggerFactory; |
| 13 |
use MediaWiki\MainConfigNames; |
| 14 |
use MediaWiki\MediaWikiEntryPoint; |
| 15 |
use MediaWiki\Output\OutputPage; |
| 16 |
use MediaWiki\Permissions\PermissionStatus; |
| 17 |
use MediaWiki\Profiler\ProfilingContext; |
| 18 |
use MediaWiki\Request\DerivativeRequest; |
| 19 |
use MediaWiki\Request\FauxRequest; |
| 20 |
use MediaWiki\Request\WebRequest; |
| 21 |
use MediaWiki\SpecialPage\RedirectSpecialPage; |
| 22 |
use MediaWiki\SpecialPage\SpecialPage; |
| 23 |
use MediaWiki\Title\MalformedTitleException; |
| 24 |
use MediaWiki\Title\Title; |
| 25 |
use MediaWiki\User\User; |
| 26 |
use MWExceptionRenderer; |
| 27 |
use PermissionsError; |
| 28 |
use Profiler; |
| 29 |
use Throwable; |
| 30 |
use UnexpectedValueException; |
| 31 |
use ViewAction; |
| 32 |
use WikiFilePage; |
| 33 |
use Wikimedia\Rdbms\DBConnectionError; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
class ActionEntryPoint extends MediaWikiEntryPoint { |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
protected function getContext(): RequestContext { |
| 49 |
|
| 50 |
$context = parent::getContext(); |
| 51 |
|
| 52 |
|
| 53 |
return $context; |
| 54 |
} |
| 55 |
|
| 56 |
protected function getOutput(): OutputPage { |
| 57 |
return $this->getContext()->getOutput(); |
| 58 |
} |
| 59 |
|
| 60 |
protected function getUser(): User { |
| 61 |
return $this->getContext()->getUser(); |
| 62 |
} |
| 63 |
|
| 64 |
protected function handleTopLevelError( Throwable $e ) { |
| 65 |
$context = $this->getContext(); |
| 66 |
$action = $context->getRequest()->getRawVal( 'action' ) ?? 'view'; |
| 67 |
if ( |
| 68 |
$e instanceof DBConnectionError && |
| 69 |
$context->hasTitle() && |
| 70 |
$context->getTitle()->canExist() && |
| 71 |
in_array( $action, [ 'view', 'history' ], true ) && |
| 72 |
HTMLFileCache::useFileCache( $context, HTMLFileCache::MODE_OUTAGE ) |
| 73 |
) { |
| 74 |
|
| 75 |
$cache = new HTMLFileCache( $context->getTitle(), $action ); |
| 76 |
if ( $cache->isCached() ) { |
| 77 |
$cache->loadFromFileCache( $context, HTMLFileCache::MODE_OUTAGE ); |
| 78 |
$this->print( MWExceptionRenderer::getHTML( $e ) ); |
| 79 |
$this->exit(); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
parent::handleTopLevelError( $e ); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
protected function execute() { |
| 90 |
|
| 91 |
global $wgTitle; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
$title = $this->getTitle(); |
| 96 |
$wgTitle = $title; |
| 97 |
|
| 98 |
$request = $this->getContext()->getRequest(); |
| 99 |
|
| 100 |
$trxLimits = $this->getConfig( MainConfigNames::TrxProfilerLimits ); |
| 101 |
$trxProfiler = Profiler::instance()->getTransactionProfiler(); |
| 102 |
$trxProfiler->setLogger( LoggerFactory::getInstance( 'rdbms' ) ); |
| 103 |
$trxProfiler->setStatsFactory( $this->getStatsFactory() ); |
| 104 |
$trxProfiler->setRequestMethod( $request->getMethod() ); |
| 105 |
if ( $request->hasSafeMethod() ) { |
| 106 |
$trxProfiler->setExpectations( $trxLimits['GET'], __METHOD__ ); |
| 107 |
} else { |
| 108 |
$trxProfiler->setExpectations( $trxLimits['POST'], __METHOD__ ); |
| 109 |
} |
| 110 |
|
| 111 |
if ( $this->maybeDoHttpsRedirect() ) { |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
$context = $this->getContext(); |
| 116 |
$output = $context->getOutput(); |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
if ( $title->canExist() && HTMLFileCache::useFileCache( $context ) ) { |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
$action = $this->getAction(); |
| 127 |
|
| 128 |
$cache = new HTMLFileCache( $title, $action ); |
| 129 |
if ( $cache->isCacheGood( ) ) { |
| 130 |
|
| 131 |
$timestamp = $cache->cacheTimestamp(); |
| 132 |
if ( !$output->checkLastModified( $timestamp ) ) { |
| 133 |
$cache->loadFromFileCache( $context ); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
$context->getWikiPage()->doViewUpdates( $context->getAuthority() ); |
| 138 |
|
| 139 |
$output->disable(); |
| 140 |
|
| 141 |
return; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
try { |
| 146 |
|
| 147 |
$this->performRequest(); |
| 148 |
} catch ( ErrorPageError $e ) { |
| 149 |
|
| 150 |
$e->report( ErrorPageError::STAGE_OUTPUT ); |
| 151 |
$output->considerCacheSettingsFinal(); |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
$this->prepareForOutput(); |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
$output = $context->getOutput(); |
| 164 |
$this->outputResponsePayload( $output->output( true ) ); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
protected function maybeDoHttpsRedirect() { |
| 177 |
if ( !$this->shouldDoHttpRedirect() ) { |
| 178 |
return false; |
| 179 |
} |
| 180 |
|
| 181 |
$context = $this->getContext(); |
| 182 |
$request = $context->getRequest(); |
| 183 |
$oldUrl = $request->getFullRequestURL(); |
| 184 |
$redirUrl = preg_replace( '#^http://#', 'https://', $oldUrl ); |
| 185 |
|
| 186 |
if ( $request->wasPosted() ) { |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
wfDebugLog( 'RedirectedPosts', "Redirected from HTTP to HTTPS: $oldUrl" ); |
| 196 |
} |
| 197 |
|
| 198 |
$title = Title::newFromText( 'REDIR', NS_MAIN ); |
| 199 |
$context->setTitle( $title ); |
| 200 |
|
| 201 |
$output = $context->getOutput(); |
| 202 |
$output->addVaryHeader( 'X-Forwarded-Proto' ); |
| 203 |
$output->redirect( $redirUrl ); |
| 204 |
$output->output(); |
| 205 |
|
| 206 |
return true; |
| 207 |
} |
| 208 |
|
| 209 |
protected function doPrepareForOutput() { |
| 210 |
parent::doPrepareForOutput(); |
| 211 |
|
| 212 |
|
| 213 |
$this->schedulePostSendJobs(); |
| 214 |
} |
| 215 |
|
| 216 |
protected function schedulePostSendJobs() { |
| 217 |
|
| 218 |
if ( $this->getTitle()->isSpecial( 'RunJobs' ) ) { |
| 219 |
return; |
| 220 |
} |
| 221 |
|
| 222 |
parent::schedulePostSendJobs(); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
protected function parseTitle( $request ) { |
| 233 |
$curid = $request->getInt( 'curid' ); |
| 234 |
$title = $request->getText( 'title' ); |
| 235 |
|
| 236 |
$ret = null; |
| 237 |
if ( $curid ) { |
| 238 |
|
| 239 |
$ret = Title::newFromID( $curid ); |
| 240 |
} |
| 241 |
if ( $ret === null ) { |
| 242 |
$ret = Title::newFromURL( $title ); |
| 243 |
if ( $ret !== null ) { |
| 244 |
|
| 245 |
|
| 246 |
if ( $ret->getNamespace() === NS_MEDIA ) { |
| 247 |
$ret = Title::makeTitle( NS_FILE, $ret->getDBkey() ); |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
$services = $this->getServiceContainer(); |
| 252 |
$languageConverter = $services |
| 253 |
->getLanguageConverterFactory() |
| 254 |
->getLanguageConverter( $services->getContentLanguage() ); |
| 255 |
if ( $languageConverter->hasVariants() && !$ret->exists() ) { |
| 256 |
$languageConverter->findVariantLink( $title, $ret ); |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
if ( $ret === null || !$ret->isSpecialPage() ) { |
| 266 |
|
| 267 |
$oldid = $request->getInt( 'oldid' ); |
| 268 |
$oldid = $oldid ?: $request->getInt( 'diff' ); |
| 269 |
|
| 270 |
if ( $oldid ) { |
| 271 |
$revRecord = $this->getServiceContainer() |
| 272 |
->getRevisionLookup() |
| 273 |
->getRevisionById( $oldid ); |
| 274 |
if ( $revRecord ) { |
| 275 |
$ret = Title::newFromLinkTarget( |
| 276 |
$revRecord->getPageAsLinkTarget() |
| 277 |
); |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
if ( $ret === null && $request->getCheck( 'search' ) ) { |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
$ret = SpecialPage::getTitleFor( 'Search' ); |
| 287 |
} |
| 288 |
|
| 289 |
if ( $ret === null || !$ret->isSpecialPage() ) { |
| 290 |
|
| 291 |
$actionName = $request->getRawVal( 'action' ); |
| 292 |
if ( |
| 293 |
$actionName === 'revisiondelete' || |
| 294 |
( $actionName === 'historysubmit' && $request->getBool( 'revisiondelete' ) ) |
| 295 |
) { |
| 296 |
$ret = SpecialPage::getTitleFor( 'Revisiondelete' ); |
| 297 |
} elseif ( |
| 298 |
$actionName === 'editchangetags' || |
| 299 |
( $actionName === 'historysubmit' && $request->getBool( 'editchangetags' ) ) |
| 300 |
) { |
| 301 |
$ret = SpecialPage::getTitleFor( 'EditTags' ); |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
if ( $ret === null |
| 307 |
&& strval( $title ) === '' |
| 308 |
&& !$request->getCheck( 'curid' ) |
| 309 |
&& $request->getRawVal( 'action' ) !== 'delete' |
| 310 |
) { |
| 311 |
$ret = Title::newMainPage(); |
| 312 |
} |
| 313 |
|
| 314 |
if ( $ret === null || ( $ret->getDBkey() == '' && !$ret->isExternal() ) ) { |
| 315 |
|
| 316 |
|
| 317 |
Title::newFromTextThrow( $title ); |
| 318 |
throw new MalformedTitleException( 'badtitletext', $title ); |
| 319 |
} |
| 320 |
|
| 321 |
return $ret; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
public function getTitle() { |
| 329 |
$context = $this->getContext(); |
| 330 |
|
| 331 |
if ( !$context->hasTitle() ) { |
| 332 |
try { |
| 333 |
$context->setTitle( $this->parseTitle( $context->getRequest() ) ); |
| 334 |
} catch ( MalformedTitleException $ex ) { |
| 335 |
$context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) ); |
| 336 |
} |
| 337 |
} |
| 338 |
return $context->getTitle(); |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
public function getAction(): string { |
| 350 |
return $this->getContext()->getActionName(); |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
protected function performRequest() { |
| 366 |
|
| 367 |
global $wgTitle; |
| 368 |
|
| 369 |
$context = $this->getContext(); |
| 370 |
|
| 371 |
$request = $context->getRequest(); |
| 372 |
$output = $context->getOutput(); |
| 373 |
|
| 374 |
if ( $request->getRawVal( 'printable' ) === 'yes' ) { |
| 375 |
$output->setPrintable(); |
| 376 |
} |
| 377 |
|
| 378 |
$user = $context->getUser(); |
| 379 |
$title = $context->getTitle(); |
| 380 |
$requestTitle = $title; |
| 381 |
|
| 382 |
$userOptionsLookup = $this->getServiceContainer()->getUserOptionsLookup(); |
| 383 |
if ( $userOptionsLookup->getBoolOption( $user, 'forcesafemode' ) ) { |
| 384 |
$request->setVal( 'safemode', '1' ); |
| 385 |
} |
| 386 |
|
| 387 |
$this->getHookRunner()->onBeforeInitialize( $title, null, $output, $user, $request, $this ); |
| 388 |
|
| 389 |
|
| 390 |
if ( $title === null || ( $title->getDBkey() == '' && !$title->isExternal() ) |
| 391 |
|| $title->isSpecial( 'Badtitle' ) |
| 392 |
) { |
| 393 |
$context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) ); |
| 394 |
try { |
| 395 |
$this->parseTitle( $request ); |
| 396 |
} catch ( MalformedTitleException $ex ) { |
| 397 |
throw new BadTitleError( $ex ); |
| 398 |
} |
| 399 |
throw new BadTitleError(); |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
$permissionStatus = PermissionStatus::newEmpty(); |
| 406 |
if ( !$context->getAuthority()->authorizeRead( 'read', $title, $permissionStatus ) ) { |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
$badTitle = SpecialPage::getTitleFor( 'Badtitle' ); |
| 417 |
$context->setTitle( $badTitle ); |
| 418 |
$wgTitle = $badTitle; |
| 419 |
|
| 420 |
throw new PermissionsError( 'read', $permissionStatus ); |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
if ( $title->isExternal() ) { |
| 425 |
$rdfrom = $request->getVal( 'rdfrom' ); |
| 426 |
if ( $rdfrom ) { |
| 427 |
$url = $title->getFullURL( [ 'rdfrom' => $rdfrom ] ); |
| 428 |
} else { |
| 429 |
$query = $request->getValues(); |
| 430 |
unset( $query['title'] ); |
| 431 |
$url = $title->getFullURL( $query ); |
| 432 |
} |
| 433 |
|
| 434 |
if ( $url !== $request->getFullRequestURL() && $title->isLocal() ) { |
| 435 |
|
| 436 |
$output->redirect( $url, 301 ); |
| 437 |
} else { |
| 438 |
$context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) ); |
| 439 |
try { |
| 440 |
$this->parseTitle( $request ); |
| 441 |
} catch ( MalformedTitleException $ex ) { |
| 442 |
throw new BadTitleError( $ex ); |
| 443 |
} |
| 444 |
throw new BadTitleError(); |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
} elseif ( !$this->tryNormaliseRedirect( $title ) ) { |
| 449 |
|
| 450 |
$spFactory = $this->getServiceContainer()->getSpecialPageFactory(); |
| 451 |
if ( $title->isSpecialPage() ) { |
| 452 |
$specialPage = $spFactory->getPage( $title->getDBkey() ); |
| 453 |
if ( $specialPage instanceof RedirectSpecialPage ) { |
| 454 |
$specialPage->setContext( $context ); |
| 455 |
if ( $this->getConfig( MainConfigNames::HideIdentifiableRedirects ) |
| 456 |
&& $specialPage->personallyIdentifiableTarget() |
| 457 |
) { |
| 458 |
[ , $subpage ] = $spFactory->resolveAlias( $title->getDBkey() ); |
| 459 |
$target = $specialPage->getRedirect( $subpage ); |
| 460 |
|
| 461 |
if ( $target instanceof Title ) { |
| 462 |
if ( $target->isExternal() ) { |
| 463 |
|
| 464 |
$target = SpecialPage::getTitleFor( |
| 465 |
'GoToInterwiki', |
| 466 |
'force/' . $target->getPrefixedDBkey() |
| 467 |
); |
| 468 |
} |
| 469 |
|
| 470 |
$query = $specialPage->getRedirectQuery( $subpage ) ?: []; |
| 471 |
$derivateRequest = new DerivativeRequest( $request, $query ); |
| 472 |
$derivateRequest->setRequestURL( $request->getRequestURL() ); |
| 473 |
$context->setRequest( $derivateRequest ); |
| 474 |
|
| 475 |
$output->lowerCdnMaxage( 0 ); |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
$context->setTitle( $target ); |
| 480 |
$wgTitle = $target; |
| 481 |
$title = $target; |
| 482 |
$output->addJsConfigVars( [ |
| 483 |
'wgInternalRedirectTargetUrl' => $target->getLinkURL( $query ), |
| 484 |
] ); |
| 485 |
$output->addModules( 'mediawiki.action.view.redirect' ); |
| 486 |
|
| 487 |
|
| 488 |
if ( !$target->isValid() ) { |
| 489 |
try { |
| 490 |
$this->getServiceContainer()->getTitleParser() |
| 491 |
->parseTitle( $target->getPrefixedText() ); |
| 492 |
} catch ( MalformedTitleException $ex ) { |
| 493 |
throw new BadTitleError( $ex ); |
| 494 |
} |
| 495 |
throw new BadTitleError(); |
| 496 |
} |
| 497 |
} |
| 498 |
} |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
if ( $title->isSpecialPage() ) { |
| 504 |
|
| 505 |
$spFactory->executePath( $title, $context ); |
| 506 |
} else { |
| 507 |
|
| 508 |
|
| 509 |
$article = $this->initializeArticle(); |
| 510 |
if ( is_object( $article ) ) { |
| 511 |
$this->performAction( $article, $requestTitle ); |
| 512 |
} elseif ( is_string( $article ) ) { |
| 513 |
$output->redirect( $article ); |
| 514 |
} else { |
| 515 |
throw new UnexpectedValueException( "Shouldn't happen: MediaWiki::initializeArticle()" |
| 516 |
. " returned neither an object nor a URL" ); |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
$contextRequest = $context->getRequest(); |
| 521 |
if ( $contextRequest instanceof FauxRequest ) { |
| 522 |
$fauxResponse = $contextRequest->response(); |
| 523 |
if ( $fauxResponse->getStatusCode() ) { |
| 524 |
$request->response()->statusHeader( $fauxResponse->getStatusCode() ); |
| 525 |
} |
| 526 |
|
| 527 |
foreach ( $fauxResponse->getHeaders() as $key => $value ) { |
| 528 |
$request->response()->header( "$key: $value" ); |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
$output->considerCacheSettingsFinal(); |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
protected function tryNormaliseRedirect( Title $title ): bool { |
| 559 |
$request = $this->getRequest(); |
| 560 |
$output = $this->getOutput(); |
| 561 |
|
| 562 |
if ( ( $request->getRawVal( 'action' ) ?? 'view' ) !== 'view' |
| 563 |
|| $request->wasPosted() |
| 564 |
|| ( $request->getCheck( 'title' ) |
| 565 |
&& $title->getPrefixedDBkey() == $request->getText( 'title' ) ) |
| 566 |
|| count( $request->getValueNames( [ 'action', 'title' ] ) ) |
| 567 |
|| !$this->getHookRunner()->onTestCanonicalRedirect( $request, $title, $output ) |
| 568 |
) { |
| 569 |
return false; |
| 570 |
} |
| 571 |
|
| 572 |
if ( $this->getConfig( MainConfigNames::MainPageIsDomainRoot ) && $request->getRequestURL() === '/' ) { |
| 573 |
return false; |
| 574 |
} |
| 575 |
|
| 576 |
$services = $this->getServiceContainer(); |
| 577 |
|
| 578 |
if ( $title->isSpecialPage() ) { |
| 579 |
[ $name, $subpage ] = $services->getSpecialPageFactory() |
| 580 |
->resolveAlias( $title->getDBkey() ); |
| 581 |
|
| 582 |
if ( $name ) { |
| 583 |
$title = SpecialPage::getTitleFor( $name, $subpage ); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
$targetUrl = (string)$services->getUrlUtils()->expand( $title->getFullURL(), PROTO_CURRENT ); |
| 588 |
if ( $targetUrl == $request->getFullRequestURL() ) { |
| 589 |
$message = "Redirect loop detected!\n\n" . |
| 590 |
"This means the wiki got confused about what page was " . |
| 591 |
"requested; this sometimes happens when moving a wiki " . |
| 592 |
"to a new server or changing the server configuration.\n\n"; |
| 593 |
|
| 594 |
if ( $this->getConfig( MainConfigNames::UsePathInfo ) ) { |
| 595 |
$message .= "The wiki is trying to interpret the page " . |
| 596 |
"title from the URL path portion (PATH_INFO), which " . |
| 597 |
"sometimes fails depending on the web server. Try " . |
| 598 |
"setting \"\$wgUsePathInfo = false;\" in your " . |
| 599 |
"LocalSettings.php, or check that \$wgArticlePath " . |
| 600 |
"is correct."; |
| 601 |
} else { |
| 602 |
$message .= "Your web server was detected as possibly not " . |
| 603 |
"supporting URL path components (PATH_INFO) correctly; " . |
| 604 |
"check your LocalSettings.php for a customized " . |
| 605 |
"\$wgArticlePath setting and/or toggle \$wgUsePathInfo " . |
| 606 |
"to true."; |
| 607 |
} |
| 608 |
throw new HttpError( 500, $message ); |
| 609 |
} |
| 610 |
$output->setCdnMaxage( 1200 ); |
| 611 |
$output->redirect( $targetUrl, '301' ); |
| 612 |
return true; |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
protected function initializeArticle() { |
| 622 |
$context = $this->getContext(); |
| 623 |
|
| 624 |
$title = $context->getTitle(); |
| 625 |
$services = $this->getServiceContainer(); |
| 626 |
if ( $context->canUseWikiPage() ) { |
| 627 |
|
| 628 |
|
| 629 |
$page = $context->getWikiPage(); |
| 630 |
} else { |
| 631 |
|
| 632 |
|
| 633 |
$page = $services->getWikiPageFactory()->newFromTitle( $title ); |
| 634 |
$context->setWikiPage( $page ); |
| 635 |
wfWarn( "RequestContext::canUseWikiPage() returned false" ); |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
$article = Article::newFromWikiPage( $page, $context ); |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
if ( !$page->getContentHandler()->supportsRedirects() ) { |
| 645 |
return $article; |
| 646 |
} |
| 647 |
|
| 648 |
$request = $context->getRequest(); |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
$action = $request->getRawVal( 'action' ) ?? 'view'; |
| 653 |
$file = ( $page instanceof WikiFilePage ) ? $page->getFile() : null; |
| 654 |
if ( ( $action == 'view' || $action == 'render' ) |
| 655 |
&& !$request->getCheck( 'oldid' ) |
| 656 |
&& !$request->getCheck( 'diff' ) |
| 657 |
&& $request->getRawVal( 'redirect' ) !== 'no' |
| 658 |
|
| 659 |
&& !( is_object( $file ) && $file->exists() && !$file->getRedirected() ) |
| 660 |
) { |
| 661 |
|
| 662 |
$ignoreRedirect = $target = false; |
| 663 |
|
| 664 |
$this->getHookRunner()->onInitializeArticleMaybeRedirect( $title, $request, |
| 665 |
|
| 666 |
$ignoreRedirect, $target, $article ); |
| 667 |
$page = $article->getPage(); |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
if ( !$ignoreRedirect && ( $target || $page->isRedirect() ) ) { |
| 672 |
|
| 673 |
$target = $target ?: $page->followRedirect(); |
| 674 |
if ( is_string( $target ) && !$this->getConfig( MainConfigNames::DisableHardRedirects ) ) { |
| 675 |
|
| 676 |
return $target; |
| 677 |
} |
| 678 |
if ( is_object( $target ) ) { |
| 679 |
|
| 680 |
$rpage = $services->getWikiPageFactory()->newFromTitle( $target ); |
| 681 |
$rpage->loadPageData(); |
| 682 |
if ( $rpage->exists() || ( is_object( $file ) && !$file->isLocal() ) ) { |
| 683 |
$rarticle = Article::newFromWikiPage( $rpage, $context ); |
| 684 |
$rarticle->setRedirectedFrom( $title ); |
| 685 |
|
| 686 |
$article = $rarticle; |
| 687 |
|
| 688 |
$context->setTitle( $target ); |
| 689 |
$context->setWikiPage( $article->getPage() ); |
| 690 |
} |
| 691 |
} |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
return $article; |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
protected function performAction( Article $article, Title $requestTitle ) { |
| 705 |
$request = $this->getRequest(); |
| 706 |
$output = $this->getOutput(); |
| 707 |
$title = $this->getTitle(); |
| 708 |
$user = $this->getUser(); |
| 709 |
|
| 710 |
if ( !$this->getHookRunner()->onMediaWikiPerformAction( |
| 711 |
$output, $article, $title, $user, $request, $this ) |
| 712 |
) { |
| 713 |
return; |
| 714 |
} |
| 715 |
|
| 716 |
$t = microtime( true ); |
| 717 |
$actionName = $this->getAction(); |
| 718 |
$services = $this->getServiceContainer(); |
| 719 |
|
| 720 |
$action = $services->getActionFactory()->getAction( $actionName, $article, $this->getContext() ); |
| 721 |
if ( $action instanceof Action ) { |
| 722 |
ProfilingContext::singleton()->init( MW_ENTRY_POINT, $actionName ); |
| 723 |
|
| 724 |
|
| 725 |
if ( $action->needsReadRights() && !$user->isAllowed( 'read' ) ) { |
| 726 |
throw new PermissionsError( 'read' ); |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
if ( $request->wasPosted() && !$action->doesWrites() ) { |
| 731 |
$trxProfiler = Profiler::instance()->getTransactionProfiler(); |
| 732 |
$trxLimits = $this->getConfig( MainConfigNames::TrxProfilerLimits ); |
| 733 |
$trxProfiler->setExpectations( $trxLimits['POST-nonwrite'], __METHOD__ ); |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
if ( $this->getConfig( MainConfigNames::UseCdn ) ) { |
| 739 |
$htmlCacheUpdater = $services->getHtmlCacheUpdater(); |
| 740 |
if ( $request->matchURLForCDN( $htmlCacheUpdater->getUrls( $requestTitle ) ) ) { |
| 741 |
$output->setCdnMaxage( $this->getConfig( MainConfigNames::CdnMaxAge ) ); |
| 742 |
} elseif ( $action instanceof ViewAction ) { |
| 743 |
$output->setCdnMaxage( 3600 ); |
| 744 |
} |
| 745 |
} |
| 746 |
|
| 747 |
$action->show(); |
| 748 |
|
| 749 |
$runTime = microtime( true ) - $t; |
| 750 |
|
| 751 |
$statAction = strtr( $actionName, '.', '_' ); |
| 752 |
$services->getStatsFactory()->getTiming( 'action_executeTiming_seconds' ) |
| 753 |
->setLabel( 'action', $statAction ) |
| 754 |
->copyToStatsdAt( 'action.' . $statAction . '.executeTiming' ) |
| 755 |
->observe( 1000 * $runTime ); |
| 756 |
|
| 757 |
return; |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
$output->setStatusCode( 404 ); |
| 762 |
$output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); |
| 763 |
} |
| 764 |
} |