Merge "Localisation updates from http://translatewiki.net."
[lhc/web/wiklou.git] / includes / CategoryPage.php
1 <?php
2 /**
3 * Special handling for category description pages.
4 * Modelled after ImagePage.php.
5 *
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.
10 *
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.
15 *
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
20 *
21 * @file
22 */
23
24 if ( !defined( 'MEDIAWIKI' ) )
25 die( 1 );
26
27 /**
28 * Special handling for category description pages, showing pages,
29 * subcategories and file that belong to the category
30 */
31 class CategoryPage extends Article {
32 # Subclasses can change this to override the viewer class.
33 protected $mCategoryViewerClass = 'CategoryViewer';
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 /**
45 * Constructor from a page id
46 * @param $id Int article ID to load
47 * @return CategoryPage|null
48 */
49 public static function newFromID( $id ) {
50 $t = Title::newFromID( $id );
51 # @todo FIXME: Doesn't inherit right
52 return $t == null ? null : new self( $t );
53 # return $t == null ? null : new static( $t ); // PHP 5.3
54 }
55
56 function view() {
57 $request = $this->getContext()->getRequest();
58 $diff = $request->getVal( 'diff' );
59 $diffOnly = $request->getBool( 'diffonly',
60 $this->getContext()->getUser()->getOption( 'diffonly' ) );
61
62 if ( isset( $diff ) && $diffOnly ) {
63 parent::view();
64 return;
65 }
66
67 if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) ) {
68 return;
69 }
70
71 $title = $this->getTitle();
72 if ( NS_CATEGORY == $title->getNamespace() ) {
73 $this->openShowCategory();
74 }
75
76 parent::view();
77
78 if ( NS_CATEGORY == $title->getNamespace() ) {
79 $this->closeShowCategory();
80 }
81 }
82
83 function openShowCategory() {
84 # For overloading
85 }
86
87 function closeShowCategory() {
88 // Use these as defaults for back compat --catrope
89 $request = $this->getContext()->getRequest();
90 $oldFrom = $request->getVal( 'from' );
91 $oldUntil = $request->getVal( 'until' );
92
93 $reqArray = $request->getValues();
94
95 $from = $until = array();
96 foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
97 $from[$type] = $request->getVal( "{$type}from", $oldFrom );
98 $until[$type] = $request->getVal( "{$type}until", $oldUntil );
99
100 // Do not want old-style from/until propagating in nav links.
101 if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
102 $reqArray["{$type}from"] = $reqArray["from"];
103 }
104 if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
105 $reqArray["{$type}to"] = $reqArray["to"];
106 }
107 }
108
109 unset( $reqArray["from"] );
110 unset( $reqArray["to"] );
111
112 $viewer = new $this->mCategoryViewerClass( $this->getContext()->getTitle(), $this->getContext(), $from, $until, $reqArray );
113 $this->getContext()->getOutput()->addHTML( $viewer->getHTML() );
114 }
115 }