Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| CategoryPage | |
0.00% |
0 / 44 |
|
0.00% |
0 / 4 |
210 | |
0.00% |
0 / 1 |
| newPage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| view | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
42 | |||
| openShowCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| closeShowCategory | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Page; |
| 8 | |
| 9 | use MediaWiki\Category\CategoryViewer; |
| 10 | use MediaWiki\Title\Title; |
| 11 | |
| 12 | /** |
| 13 | * Special handling for category description pages. |
| 14 | * |
| 15 | * This displays category members: subcategories, pages, and files categorised here. |
| 16 | * |
| 17 | * @method WikiCategoryPage getPage() Set by overwritten newPage() in this class |
| 18 | */ |
| 19 | class CategoryPage extends Article { |
| 20 | /** @var class-string<CategoryViewer> Subclasses can change this to override the viewer class. */ |
| 21 | protected $mCategoryViewerClass = CategoryViewer::class; |
| 22 | |
| 23 | /** |
| 24 | * @param Title $title |
| 25 | * @return WikiCategoryPage |
| 26 | */ |
| 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 | |
| 106 | /** @deprecated class alias since 1.44 */ |
| 107 | class_alias( CategoryPage::class, 'CategoryPage' ); |