Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / page / CategoryPage.php
blob03a5b89a0d44d75eeb35fbc7996b9810b1f90572
1 <?php
2 /**
3 * Special handling for category description pages.
4 * Modelled after ImagePage.php.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @file
24 /**
25 * Special handling for category description pages, showing pages,
26 * subcategories and file that belong to the category
28 class CategoryPage extends Article {
29 # Subclasses can change this to override the viewer class.
30 protected $mCategoryViewerClass = 'CategoryViewer';
32 /**
33 * @param Title $title
34 * @return WikiCategoryPage
36 protected function newPage( Title $title ) {
37 // Overload mPage with a category-specific page
38 return new WikiCategoryPage( $title );
41 /**
42 * Constructor from a page id
43 * @param int $id Article ID to load
44 * @return CategoryPage|null
46 public static function newFromID( $id ) {
47 $t = Title::newFromID( $id );
48 # @todo FIXME: Doesn't inherit right
49 return $t == null ? null : new self( $t );
50 # return $t == null ? null : new static( $t ); // PHP 5.3
53 function view() {
54 $request = $this->getContext()->getRequest();
55 $diff = $request->getVal( 'diff' );
56 $diffOnly = $request->getBool( 'diffonly',
57 $this->getContext()->getUser()->getOption( 'diffonly' ) );
59 if ( $diff !== null && $diffOnly ) {
60 parent::view();
61 return;
64 if ( !Hooks::run( 'CategoryPageView', array( &$this ) ) ) {
65 return;
68 $title = $this->getTitle();
69 if ( NS_CATEGORY == $title->getNamespace() ) {
70 $this->openShowCategory();
73 parent::view();
75 if ( NS_CATEGORY == $title->getNamespace() ) {
76 $this->closeShowCategory();
80 function openShowCategory() {
81 # For overloading
84 function closeShowCategory() {
85 // Use these as defaults for back compat --catrope
86 $request = $this->getContext()->getRequest();
87 $oldFrom = $request->getVal( 'from' );
88 $oldUntil = $request->getVal( 'until' );
90 $reqArray = $request->getValues();
92 $from = $until = array();
93 foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
94 $from[$type] = $request->getVal( "{$type}from", $oldFrom );
95 $until[$type] = $request->getVal( "{$type}until", $oldUntil );
97 // Do not want old-style from/until propagating in nav links.
98 if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
99 $reqArray["{$type}from"] = $reqArray["from"];
101 if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
102 $reqArray["{$type}to"] = $reqArray["to"];
106 unset( $reqArray["from"] );
107 unset( $reqArray["to"] );
109 $viewer = new $this->mCategoryViewerClass(
110 $this->getContext()->getTitle(),
111 $this->getContext(),
112 $from,
113 $until,
114 $reqArray
116 $this->getContext()->getOutput()->addHTML( $viewer->getHTML() );