Merge "SpecialBlock [Vue]: add NamespacesField and PagesField components"
[mediawiki.git] / includes / actions / ViewAction.php
blob36ab69cf3d2b35eefa9319a8e43aece350114e73
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 * @file
18 * @ingroup Actions
21 use MediaWiki\MainConfigNames;
22 use MediaWiki\MediaWikiServices;
24 /**
25 * An action that views article content
27 * This is a wrapper that will call Article::view().
29 * @ingroup Actions
31 class ViewAction extends FormlessAction {
33 public function getName() {
34 return 'view';
37 public function onView() {
38 return null;
41 public function needsReadRights() {
42 // Pages in $wgWhitelistRead can be viewed without having the 'read'
43 // right. We rely on Article::view() to properly check read access.
44 return false;
47 public function show() {
48 $config = $this->context->getConfig();
50 // Emit deprecated hook warnings.
51 // We do this only in the view action so that it reliably shows up in
52 // the debug toolbar without unduly impacting the performance of API and
53 // ResourceLoader requests.
54 MediaWikiServices::getInstance()->getHookContainer()->emitDeprecationWarnings();
56 if (
57 !$config->get( MainConfigNames::DebugToolbar ) && // don't let this get stuck on pages
58 $this->getWikiPage()->checkTouched() // page exists and is not a redirect
59 ) {
60 // Include any redirect in the last-modified calculation
61 $redirFromTitle = $this->getArticle()->getRedirectedFrom();
62 if ( !$redirFromTitle ) {
63 $touched = $this->getWikiPage()->getTouched();
64 } else {
65 $touched = max(
66 $this->getWikiPage()->getTouched(),
67 $redirFromTitle->getTouched()
71 // Send HTTP 304 if the IMS matches or otherwise set expiry/last-modified headers
72 if ( $touched && $this->getOutput()->checkLastModified( $touched ) ) {
73 wfDebug( __METHOD__ . ": done 304" );
74 return;
78 $this->getArticle()->view();