FU r106770: fixed the other getTransform() call
[lhc/web/wiklou.git] / includes / CategoryPage.php
1 <?php
2 /**
3 * Class for viewing MediaWiki category description pages.
4 * Modelled after ImagePage.php.
5 *
6 * @file
7 */
8
9 if ( !defined( 'MEDIAWIKI' ) )
10 die( 1 );
11
12 /**
13 * Special handling for category description pages, showing pages,
14 * subcategories and file that belong to the category
15 */
16 class CategoryPage extends Article {
17 # Subclasses can change this to override the viewer class.
18 protected $mCategoryViewerClass = 'CategoryViewer';
19
20 /**
21 * @param $title Title
22 * @return WikiCategoryPage
23 */
24 protected function newPage( Title $title ) {
25 // Overload mPage with a category-specific page
26 return new WikiCategoryPage( $title );
27 }
28
29 /**
30 * Constructor from a page id
31 * @param $id Int article ID to load
32 */
33 public static function newFromID( $id ) {
34 $t = Title::newFromID( $id );
35 # @todo FIXME: Doesn't inherit right
36 return $t == null ? null : new self( $t );
37 # return $t == null ? null : new static( $t ); // PHP 5.3
38 }
39
40 function view() {
41 $request = $this->getContext()->getRequest();
42 $diff = $request->getVal( 'diff' );
43 $diffOnly = $request->getBool( 'diffonly',
44 $this->getContext()->getUser()->getOption( 'diffonly' ) );
45
46 if ( isset( $diff ) && $diffOnly ) {
47 parent::view();
48 return;
49 }
50
51 if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) ) {
52 return;
53 }
54
55 $title = $this->getTitle();
56 if ( NS_CATEGORY == $title->getNamespace() ) {
57 $this->openShowCategory();
58 }
59
60 parent::view();
61
62 if ( NS_CATEGORY == $title->getNamespace() ) {
63 $this->closeShowCategory();
64 }
65 }
66
67 function openShowCategory() {
68 # For overloading
69 }
70
71 function closeShowCategory() {
72 // Use these as defaults for back compat --catrope
73 $request = $this->getContext()->getRequest();
74 $oldFrom = $request->getVal( 'from' );
75 $oldUntil = $request->getVal( 'until' );
76
77 $reqArray = $request->getValues();
78
79 $from = $until = array();
80 foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
81 $from[$type] = $request->getVal( "{$type}from", $oldFrom );
82 $until[$type] = $request->getVal( "{$type}until", $oldUntil );
83
84 // Do not want old-style from/until propagating in nav links.
85 if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
86 $reqArray["{$type}from"] = $reqArray["from"];
87 }
88 if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
89 $reqArray["{$type}to"] = $reqArray["to"];
90 }
91 }
92
93 unset( $reqArray["from"] );
94 unset( $reqArray["to"] );
95
96 $viewer = new $this->mCategoryViewerClass( $this->getContext()->getTitle(), $this->getContext(), $from, $until, $reqArray );
97 $this->getContext()->getOutput()->addHTML( $viewer->getHTML() );
98 }
99 }