MediaWiki  master
ViewAction.php
Go to the documentation of this file.
1 <?php
22 
30 class ViewAction extends FormlessAction {
31 
32  public function getName() {
33  return 'view';
34  }
35 
36  public function onView() {
37  return null;
38  }
39 
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( 'DebugToolbar' ) == false && // 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  } elseif ( $config->get( 'MaxRedirects' ) <= 1 ) {
58  $touched = max(
59  $this->getWikiPage()->getTouched(),
60  $redirFromTitle->getTouched()
61  );
62  } else {
63  // Don't bother following the chain and getting the max mtime
64  $touched = null;
65  }
66 
67  // Send HTTP 304 if the IMS matches or otherwise set expiry/last-modified headers
68  if ( $touched && $this->getOutput()->checkLastModified( $touched ) ) {
69  wfDebug( __METHOD__ . ": done 304" );
70  return;
71  }
72  }
73 
74  $this->getArticle()->view();
75  }
76 }
FormlessAction
An action which just does something, without showing a form first.
Definition: FormlessAction.php:30
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
ViewAction\onView
onView()
Show something on GET request.
Definition: ViewAction.php:36
Action\getArticle
getArticle()
Get a Article object.
Definition: Action.php:289
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:909
Action\getWikiPage
getWikiPage()
Get a WikiPage object.
Definition: Action.php:278
ViewAction
An action that views article content.
Definition: ViewAction.php:30
Action\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:239
ViewAction\getName
getName()
Return the name of the action this object responds to.
Definition: ViewAction.php:32
ViewAction\show
show()
Stable to override.
Definition: ViewAction.php:40