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  $diffOnly = $request->getBool( 'diffonly',
45  $this->getContext()->getUser()->getOption( 'diffonly' ) );
46 
47  if ( $diff !== null && $diffOnly ) {
48  parent::view();
49  return;
50  }
51 
52  if ( !$this->getHookRunner()->onCategoryPageView( $this ) ) {
53  return;
54  }
55 
56  $title = $this->getTitle();
57  if ( $title->inNamespace( NS_CATEGORY ) ) {
58  $this->openShowCategory();
59  }
60 
61  parent::view();
62 
63  if ( $title->inNamespace( NS_CATEGORY ) ) {
64  $this->closeShowCategory();
65  }
66 
67  # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often
68  $outputPage = $this->getContext()->getOutput();
69  $outputPage->adaptCdnTTL(
70  $this->getPage()->getTouched(),
71  IExpiringStore::TTL_MINUTE
72  );
73  }
74 
75  public function openShowCategory() {
76  # For overloading
77  }
78 
79  public function closeShowCategory() {
80  // Use these as defaults for back compat --catrope
81  $request = $this->getContext()->getRequest();
82  $oldFrom = $request->getVal( 'from' );
83  $oldUntil = $request->getVal( 'until' );
84 
85  $reqArray = $request->getValues();
86 
87  $from = $until = [];
88  foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
89  $from[$type] = $request->getVal( "{$type}from", $oldFrom );
90  $until[$type] = $request->getVal( "{$type}until", $oldUntil );
91 
92  // Do not want old-style from/until propagating in nav links.
93  if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
94  $reqArray["{$type}from"] = $reqArray["from"];
95  }
96  if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
97  $reqArray["{$type}to"] = $reqArray["to"];
98  }
99  }
100 
101  unset( $reqArray["from"] );
102  unset( $reqArray["to"] );
103 
104  $viewer = new $this->mCategoryViewerClass(
105  $this->getPage(),
106  $this->getContext(),
107  $from,
108  $until,
109  $reqArray
110  );
111  $out = $this->getContext()->getOutput();
112  $out->addHTML( $viewer->getHTML() );
113  $this->addHelpLink( 'Help:Categories' );
114  }
115 
119  public function getCategoryViewerClass() {
120  wfDeprecated( __METHOD__, '1.35' );
122  }
123 
127  public function setCategoryViewerClass( $class ) {
128  wfDeprecated( __METHOD__, '1.35' );
129  $this->mCategoryViewerClass = $class;
130  }
131 }
getUser()
const NS_CATEGORY
Definition: Defines.php:78
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Legacy class representing an editable page and handling UI for some page actions.
Definition: Article.php:47
getContext()
Gets the context this Article is executed in.
Definition: Article.php:1992
getTitle()
Get the title object of the article.
Definition: Article.php:223
getPage()
Get the WikiPage object of this instance.
Definition: Article.php:233
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: Article.php:1786
Special handling for category description pages.
string $mCategoryViewerClass
Subclasses can change this to override the viewer class.
setCategoryViewerClass( $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:48
Special handling for representing category pages.