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