MediaWiki master
ViewAction.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Actions;
22
25
34
35 public function getName() {
36 return 'view';
37 }
38
39 public function onView() {
40 return null;
41 }
42
43 public function needsReadRights() {
44 // Pages in $wgWhitelistRead can be viewed without having the 'read'
45 // right. We rely on Article::view() to properly check read access.
46 return false;
47 }
48
49 public function show() {
50 $config = $this->context->getConfig();
51
52 // Emit deprecated hook warnings.
53 // We do this only in the view action so that it reliably shows up in
54 // the debug toolbar without unduly impacting the performance of API and
55 // ResourceLoader requests.
56 MediaWikiServices::getInstance()->getHookContainer()->emitDeprecationWarnings();
57
58 if (
59 !$config->get( MainConfigNames::DebugToolbar ) && // don't let this get stuck on pages
60 $this->getWikiPage()->checkTouched() // page exists and is not a redirect
61 ) {
62 // Include any redirect in the last-modified calculation
63 $redirFromTitle = $this->getArticle()->getRedirectedFrom();
64 if ( !$redirFromTitle ) {
65 $touched = $this->getWikiPage()->getTouched();
66 } else {
67 $touched = max(
68 $this->getWikiPage()->getTouched(),
69 $redirFromTitle->getTouched()
70 );
71 }
72
73 // Send HTTP 304 if the IMS matches or otherwise set expiry/last-modified headers
74 if ( $touched && $this->getOutput()->checkLastModified( $touched ) ) {
75 wfDebug( __METHOD__ . ": done 304" );
76 return;
77 }
78 }
79
80 $this->getArticle()->view();
81 }
82}
83
85class_alias( ViewAction::class, 'ViewAction' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getWikiPage()
Get a WikiPage object.
Definition Action.php:205
getArticle()
Get a Article object.
Definition Action.php:216
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:156
An action which just does something, without showing a form first.
An action that views article content.
onView()
Show something on GET request.
getName()
Return the name of the action this object responds to.
needsReadRights()
Indicates whether this action requires read rights.
A class containing constants representing the names of configuration variables.
const DebugToolbar
Name constant for the DebugToolbar setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.