MediaWiki master
ViewAction.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Actions;
9
12
21
23 public function getName() {
24 return 'view';
25 }
26
28 public function onView() {
29 return null;
30 }
31
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
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
76class_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:192
getArticle()
Get a Article object.
Definition Action.php:203
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:143
An action which just does something, without showing a form first.
An action that views article content.
onView()
Show something on GET request.string|null Will be added to the HTMLForm if present,...
getName()
Return the name of the action this object responds to.1.17string Lowercase name
needsReadRights()
Indicates whether this action requires read rights.Implementations of this methods must always return...
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.