ViewAction.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.
  7. *
  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.
  12. *
  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
  16. *
  17. * @file
  18. * @ingroup Actions
  19. */
  20. /**
  21. * An action that views article content
  22. *
  23. * This is a wrapper that will call Article::view().
  24. *
  25. * @ingroup Actions
  26. */
  27. class ViewAction extends FormlessAction {
  28. public function getName() {
  29. return 'view';
  30. }
  31. public function onView() {
  32. return null;
  33. }
  34. public function show() {
  35. $config = $this->context->getConfig();
  36. if (
  37. $config->get( 'DebugToolbar' ) == false && // don't let this get stuck on pages
  38. $this->page->checkTouched() // page exists and is not a redirect
  39. ) {
  40. // Include any redirect in the last-modified calculation
  41. $redirFromTitle = $this->page->getRedirectedFrom();
  42. if ( !$redirFromTitle ) {
  43. $touched = $this->page->getTouched();
  44. } elseif ( $config->get( 'MaxRedirects' ) <= 1 ) {
  45. $touched = max( $this->page->getTouched(), $redirFromTitle->getTouched() );
  46. } else {
  47. // Don't bother following the chain and getting the max mtime
  48. $touched = null;
  49. }
  50. // Send HTTP 304 if the IMS matches or otherwise set expiry/last-modified headers
  51. if ( $touched && $this->getOutput()->checkLastModified( $touched ) ) {
  52. wfDebug( __METHOD__ . ": done 304\n" );
  53. return;
  54. }
  55. }
  56. $this->page->view();
  57. }
  58. }