MediaWiki master
CategoryPage.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Page;
8
10
16class CategoryPage extends Article {
18 protected $mCategoryViewerClass = CategoryViewer::class;
19
20 public function view() {
21 $request = $this->getContext()->getRequest();
22 $diff = $request->getVal( 'diff' );
23
24 if ( $diff !== null && $this->isDiffOnlyView() ) {
25 parent::view();
26 return;
27 }
28
29 if ( !$this->getHookRunner()->onCategoryPageView( $this ) ) {
30 return;
31 }
32
33 $title = $this->getTitle();
34 if ( $title->inNamespace( NS_CATEGORY ) ) {
35 $this->openShowCategory();
36 }
37
38 parent::view();
39
40 if ( $title->inNamespace( NS_CATEGORY ) ) {
41 $this->closeShowCategory();
42 }
43
44 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often
45 $outputPage = $this->getContext()->getOutput();
46 $outputPage->adaptCdnTTL(
47 $this->getPage()->getTouched(),
48 60
49 );
50 }
51
52 public function openShowCategory() {
53 # For overloading
54 }
55
56 public function closeShowCategory() {
57 // Use these as defaults for back compat --catrope
58 $request = $this->getContext()->getRequest();
59 $oldFrom = $request->getVal( 'from' );
60 $oldUntil = $request->getVal( 'until' );
61
62 $reqArray = $request->getQueryValues();
63
64 $from = $until = [];
65 foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
66 $from[$type] = $request->getVal( "{$type}from", $oldFrom );
67 $until[$type] = $request->getVal( "{$type}until", $oldUntil );
68
69 // Do not want old-style from/until propagating in nav links.
70 if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
71 $reqArray["{$type}from"] = $reqArray["from"];
72 }
73 if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
74 $reqArray["{$type}to"] = $reqArray["to"];
75 }
76 }
77
78 unset( $reqArray["from"] );
79 unset( $reqArray["to"] );
80
81 $viewer = new $this->mCategoryViewerClass(
82 $this->getPage(),
83 $this->getContext(),
84 $from,
85 $until,
86 $reqArray
87 );
88 $out = $this->getContext()->getOutput();
89 $out->addHTML( $viewer->getHTML() );
90 $this->addHelpLink( 'Help:Categories' );
91 }
92}
93
95class_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:67
getPage()
Get the WikiPage object of this instance.
Definition Article.php:264
getTitle()
Get the title object of the article.
Definition Article.php:254
getContext()
Gets the context this Article is executed in.
Definition Article.php:2188
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition Article.php:2043
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.