Merge "docs: Fix typo"
[mediawiki.git] / includes / page / CategoryPage.php
blob2345a66e918751b23290b5c7d8476c315522d235
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 along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 use MediaWiki\Category\CategoryViewer;
22 use MediaWiki\Title\Title;
24 /**
25 * Special handling for category description pages.
27 * This displays category members: subcategories, pages, and files categorised here.
29 * @method WikiCategoryPage getPage() Set by overwritten newPage() in this class
31 class CategoryPage extends Article {
32 /** @var string Subclasses can change this to override the viewer class. */
33 protected $mCategoryViewerClass = CategoryViewer::class;
35 /**
36 * @param Title $title
37 * @return WikiCategoryPage
39 protected function newPage( Title $title ) {
40 // Overload mPage with a category-specific page
41 return new WikiCategoryPage( $title );
44 public function view() {
45 $request = $this->getContext()->getRequest();
46 $diff = $request->getVal( 'diff' );
48 if ( $diff !== null && $this->isDiffOnlyView() ) {
49 parent::view();
50 return;
53 if ( !$this->getHookRunner()->onCategoryPageView( $this ) ) {
54 return;
57 $title = $this->getTitle();
58 if ( $title->inNamespace( NS_CATEGORY ) ) {
59 $this->openShowCategory();
62 parent::view();
64 if ( $title->inNamespace( NS_CATEGORY ) ) {
65 $this->closeShowCategory();
68 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often
69 $outputPage = $this->getContext()->getOutput();
70 $outputPage->adaptCdnTTL(
71 $this->getPage()->getTouched(),
76 public function openShowCategory() {
77 # For overloading
80 public function closeShowCategory() {
81 // Use these as defaults for back compat --catrope
82 $request = $this->getContext()->getRequest();
83 $oldFrom = $request->getVal( 'from' );
84 $oldUntil = $request->getVal( 'until' );
86 $reqArray = $request->getQueryValues();
88 $from = $until = [];
89 foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
90 $from[$type] = $request->getVal( "{$type}from", $oldFrom );
91 $until[$type] = $request->getVal( "{$type}until", $oldUntil );
93 // Do not want old-style from/until propagating in nav links.
94 if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
95 $reqArray["{$type}from"] = $reqArray["from"];
97 if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
98 $reqArray["{$type}to"] = $reqArray["to"];
102 unset( $reqArray["from"] );
103 unset( $reqArray["to"] );
105 $viewer = new $this->mCategoryViewerClass(
106 $this->getPage(),
107 $this->getContext(),
108 $from,
109 $until,
110 $reqArray
112 $out = $this->getContext()->getOutput();
113 $out->addHTML( $viewer->getHTML() );
114 $this->addHelpLink( 'Help:Categories' );