Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
CategoryPage
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 4
210
0.00% covered (danger)
0.00%
0 / 1
 newPage
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 view
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
42
 openShowCategory
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 closeShowCategory
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
42
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 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
17 *
18 * @file
19 */
20
21use MediaWiki\Category\CategoryViewer;
22use MediaWiki\Title\Title;
23
24/**
25 * Special handling for category description pages.
26 *
27 * This displays category members: subcategories, pages, and files categorised here.
28 *
29 * @method WikiCategoryPage getPage() Set by overwritten newPage() in this class
30 */
31class CategoryPage extends Article {
32    /** @var string Subclasses can change this to override the viewer class. */
33    protected $mCategoryViewerClass = CategoryViewer::class;
34
35    /**
36     * @param Title $title
37     * @return WikiCategoryPage
38     */
39    protected function newPage( Title $title ) {
40        // Overload mPage with a category-specific page
41        return new WikiCategoryPage( $title );
42    }
43
44    public function view() {
45        $request = $this->getContext()->getRequest();
46        $diff = $request->getVal( 'diff' );
47
48        if ( $diff !== null && $this->isDiffOnlyView() ) {
49            parent::view();
50            return;
51        }
52
53        if ( !$this->getHookRunner()->onCategoryPageView( $this ) ) {
54            return;
55        }
56
57        $title = $this->getTitle();
58        if ( $title->inNamespace( NS_CATEGORY ) ) {
59            $this->openShowCategory();
60        }
61
62        parent::view();
63
64        if ( $title->inNamespace( NS_CATEGORY ) ) {
65            $this->closeShowCategory();
66        }
67
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(),
72            60
73        );
74    }
75
76    public function openShowCategory() {
77        # For overloading
78    }
79
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' );
85
86        $reqArray = $request->getQueryValues();
87
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 );
92
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"];
96            }
97            if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
98                $reqArray["{$type}to"] = $reqArray["to"];
99            }
100        }
101
102        unset( $reqArray["from"] );
103        unset( $reqArray["to"] );
104
105        $viewer = new $this->mCategoryViewerClass(
106            $this->getPage(),
107            $this->getContext(),
108            $from,
109            $until,
110            $reqArray
111        );
112        $out = $this->getContext()->getOutput();
113        $out->addHTML( $viewer->getHTML() );
114        $this->addHelpLink( 'Help:Categories' );
115    }
116}