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