[FileRepo] Purging/transaction fixes.
[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 * @return CategoryPage|null
33 */
34 public static function newFromID( $id ) {
35 $t = Title::newFromID( $id );
36 # @todo FIXME: Doesn't inherit right
37 return $t == null ? null : new self( $t );
38 # return $t == null ? null : new static( $t ); // PHP 5.3
39 }
40
41 function view() {
42 $request = $this->getContext()->getRequest();
43 $diff = $request->getVal( 'diff' );
44 $diffOnly = $request->getBool( 'diffonly',
45 $this->getContext()->getUser()->getOption( 'diffonly' ) );
46
47 if ( isset( $diff ) && $diffOnly ) {
48 parent::view();
49 return;
50 }
51
52 if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) ) {
53 return;
54 }
55
56 $title = $this->getTitle();
57 if ( NS_CATEGORY == $title->getNamespace() ) {
58 $this->openShowCategory();
59 }
60
61 parent::view();
62
63 if ( NS_CATEGORY == $title->getNamespace() ) {
64 $this->closeShowCategory();
65 }
66 }
67
68 function openShowCategory() {
69 # For overloading
70 }
71
72 function closeShowCategory() {
73 // Use these as defaults for back compat --catrope
74 $request = $this->getContext()->getRequest();
75 $oldFrom = $request->getVal( 'from' );
76 $oldUntil = $request->getVal( 'until' );
77
78 $reqArray = $request->getValues();
79
80 $from = $until = array();
81 foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
82 $from[$type] = $request->getVal( "{$type}from", $oldFrom );
83 $until[$type] = $request->getVal( "{$type}until", $oldUntil );
84
85 // Do not want old-style from/until propagating in nav links.
86 if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
87 $reqArray["{$type}from"] = $reqArray["from"];
88 }
89 if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
90 $reqArray["{$type}to"] = $reqArray["to"];
91 }
92 }
93
94 unset( $reqArray["from"] );
95 unset( $reqArray["to"] );
96
97 $viewer = new $this->mCategoryViewerClass( $this->getContext()->getTitle(), $this->getContext(), $from, $until, $reqArray );
98 $this->getContext()->getOutput()->addHTML( $viewer->getHTML() );
99 }
100 }