Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
10.53% |
2 / 19 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ViewAction | |
11.11% |
2 / 18 |
|
50.00% |
2 / 4 |
65.89 | |
0.00% |
0 / 1 |
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onView | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| needsReadRights | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| show | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | * @ingroup Actions |
| 6 | */ |
| 7 | |
| 8 | namespace MediaWiki\Actions; |
| 9 | |
| 10 | use MediaWiki\MainConfigNames; |
| 11 | use MediaWiki\MediaWikiServices; |
| 12 | |
| 13 | /** |
| 14 | * An action that views article content |
| 15 | * |
| 16 | * This is a wrapper that will call Article::view(). |
| 17 | * |
| 18 | * @ingroup Actions |
| 19 | */ |
| 20 | class ViewAction extends FormlessAction { |
| 21 | |
| 22 | /** @inheritDoc */ |
| 23 | public function getName() { |
| 24 | return 'view'; |
| 25 | } |
| 26 | |
| 27 | /** @inheritDoc */ |
| 28 | public function onView() { |
| 29 | return null; |
| 30 | } |
| 31 | |
| 32 | /** @inheritDoc */ |
| 33 | public function needsReadRights() { |
| 34 | // Pages in $wgWhitelistRead can be viewed without having the 'read' |
| 35 | // right. We rely on Article::view() to properly check read access. |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | /** @inheritDoc */ |
| 40 | public function show() { |
| 41 | $config = $this->context->getConfig(); |
| 42 | |
| 43 | // Emit deprecated hook warnings. |
| 44 | // We do this only in the view action so that it reliably shows up in |
| 45 | // the debug toolbar without unduly impacting the performance of API and |
| 46 | // ResourceLoader requests. |
| 47 | MediaWikiServices::getInstance()->getHookContainer()->emitDeprecationWarnings(); |
| 48 | |
| 49 | if ( |
| 50 | !$config->get( MainConfigNames::DebugToolbar ) && // don't let this get stuck on pages |
| 51 | $this->getWikiPage()->checkTouched() // page exists and is not a redirect |
| 52 | ) { |
| 53 | // Include any redirect in the last-modified calculation |
| 54 | $redirFromTitle = $this->getArticle()->getRedirectedFrom(); |
| 55 | if ( !$redirFromTitle ) { |
| 56 | $touched = $this->getWikiPage()->getTouched(); |
| 57 | } else { |
| 58 | $touched = max( |
| 59 | $this->getWikiPage()->getTouched(), |
| 60 | $redirFromTitle->getTouched() |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | // Send HTTP 304 if the IMS matches or otherwise set expiry/last-modified headers |
| 65 | if ( $touched && $this->getOutput()->checkLastModified( $touched ) ) { |
| 66 | wfDebug( __METHOD__ . ": done 304" ); |
| 67 | return; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | $this->getArticle()->view(); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** @deprecated class alias since 1.44 */ |
| 76 | class_alias( ViewAction::class, 'ViewAction' ); |