MediaWiki master
CategoryPage.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Page;
8
11
19class CategoryPage extends Article {
21 protected $mCategoryViewerClass = CategoryViewer::class;
22
27 protected function newPage( Title $title ) {
28 // Overload mPage with a category-specific page
29 return new WikiCategoryPage( $title );
30 }
31
32 public function view() {
33 $request = $this->getContext()->getRequest();
34 $diff = $request->getVal( 'diff' );
35
36 if ( $diff !== null && $this->isDiffOnlyView() ) {
37 parent::view();
38 return;
39 }
40
41 if ( !$this->getHookRunner()->onCategoryPageView( $this ) ) {
42 return;
43 }
44
45 $title = $this->getTitle();
46 if ( $title->inNamespace( NS_CATEGORY ) ) {
47 $this->openShowCategory();
48 }
49
50 parent::view();
51
52 if ( $title->inNamespace( NS_CATEGORY ) ) {
53 $this->closeShowCategory();
54 }
55
56 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often
57 $outputPage = $this->getContext()->getOutput();
58 $outputPage->adaptCdnTTL(
59 $this->getPage()->getTouched(),
60 60
61 );
62 }
63
64 public function openShowCategory() {
65 # For overloading
66 }
67
68 public function closeShowCategory() {
69 // Use these as defaults for back compat --catrope
70 $request = $this->getContext()->getRequest();
71 $oldFrom = $request->getVal( 'from' );
72 $oldUntil = $request->getVal( 'until' );
73
74 $reqArray = $request->getQueryValues();
75
76 $from = $until = [];
77 foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
78 $from[$type] = $request->getVal( "{$type}from", $oldFrom );
79 $until[$type] = $request->getVal( "{$type}until", $oldUntil );
80
81 // Do not want old-style from/until propagating in nav links.
82 if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
83 $reqArray["{$type}from"] = $reqArray["from"];
84 }
85 if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
86 $reqArray["{$type}to"] = $reqArray["to"];
87 }
88 }
89
90 unset( $reqArray["from"] );
91 unset( $reqArray["to"] );
92
93 $viewer = new $this->mCategoryViewerClass(
94 $this->getPage(),
95 $this->getContext(),
96 $from,
97 $until,
98 $reqArray
99 );
100 $out = $this->getContext()->getOutput();
101 $out->addHTML( $viewer->getHTML() );
102 $this->addHelpLink( 'Help:Categories' );
103 }
104}
105
107class_alias( CategoryPage::class, 'CategoryPage' );
const NS_CATEGORY
Definition Defines.php:65
Legacy class representing an editable page and handling UI for some page actions.
Definition Article.php:64
getPage()
Get the WikiPage object of this instance.
Definition Article.php:245
getTitle()
Get the title object of the article.
Definition Article.php:235
getContext()
Gets the context this Article is executed in.
Definition Article.php:2123
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition Article.php:1980
Special handling for category description pages.
view()
This is the default action of the index.php entry point: just view the page of the given title.
class string< CategoryViewer > $mCategoryViewerClass
Subclasses can change this to override the viewer class.
Special handling for representing category pages.
Represents a title within MediaWiki.
Definition Title.php:70