Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 63 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SpecialTrackingCategories | |
0.00% |
0 / 62 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 60 |
|
0.00% |
0 / 1 |
56 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Specials; |
| 8 | |
| 9 | use MediaWiki\Category\TrackingCategories; |
| 10 | use MediaWiki\Html\Html; |
| 11 | use MediaWiki\Page\LinkBatchFactory; |
| 12 | use MediaWiki\SpecialPage\SpecialPage; |
| 13 | |
| 14 | /** |
| 15 | * A special page that displays list of tracking categories. |
| 16 | * |
| 17 | * Tracking categories allow pages with certain characteristics to be tracked. |
| 18 | * It works by adding any such page to a category automatically. |
| 19 | * Category is specified by the tracking category's system message. |
| 20 | * |
| 21 | * @ingroup SpecialPage |
| 22 | * @since 1.23 |
| 23 | */ |
| 24 | class SpecialTrackingCategories extends SpecialPage { |
| 25 | |
| 26 | public function __construct( |
| 27 | private readonly LinkBatchFactory $linkBatchFactory, |
| 28 | private readonly TrackingCategories $trackingCategories |
| 29 | ) { |
| 30 | parent::__construct( 'TrackingCategories' ); |
| 31 | } |
| 32 | |
| 33 | /** @inheritDoc */ |
| 34 | public function execute( $par ) { |
| 35 | $this->setHeaders(); |
| 36 | $this->outputHeader(); |
| 37 | $this->addHelpLink( 'Help:Tracking categories' ); |
| 38 | $this->getOutput()->getMetadata()->setPreventClickjacking( false ); |
| 39 | $this->getOutput()->addModuleStyles( [ |
| 40 | 'jquery.tablesorter.styles', |
| 41 | 'mediawiki.pager.styles' |
| 42 | ] ); |
| 43 | $this->getOutput()->addModules( 'jquery.tablesorter' ); |
| 44 | $this->getOutput()->addHTML( |
| 45 | Html::openElement( 'table', [ 'class' => [ 'mw-datatable', 'sortable' ], |
| 46 | 'id' => 'mw-trackingcategories-table' ] ) . "\n" . |
| 47 | '<thead><tr>' . |
| 48 | Html::element( 'th', [], $this->msg( 'trackingcategories-msg' )->text() ) . |
| 49 | Html::element( 'th', [], $this->msg( 'trackingcategories-name' )->text() ) . |
| 50 | Html::element( 'th', [], $this->msg( 'trackingcategories-desc' )->text() ) . |
| 51 | '</tr></thead>' |
| 52 | ); |
| 53 | |
| 54 | $categoryList = $this->trackingCategories->getTrackingCategories(); |
| 55 | |
| 56 | $batch = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ ); |
| 57 | foreach ( $categoryList as $data ) { |
| 58 | $batch->addObj( $data['msg'] ); |
| 59 | foreach ( $data['cats'] as $catTitle ) { |
| 60 | $batch->addObj( $catTitle ); |
| 61 | } |
| 62 | } |
| 63 | $batch->execute(); |
| 64 | |
| 65 | $this->getHookRunner()->onSpecialTrackingCategories__preprocess( $this, $categoryList ); |
| 66 | |
| 67 | $linkRenderer = $this->getLinkRenderer(); |
| 68 | |
| 69 | foreach ( $categoryList as $catMsg => $data ) { |
| 70 | $allMsgs = []; |
| 71 | $catDesc = $catMsg . '-desc'; |
| 72 | |
| 73 | $catMsgTitleText = $linkRenderer->makeLink( |
| 74 | $data['msg'], |
| 75 | $catMsg |
| 76 | ); |
| 77 | |
| 78 | foreach ( $data['cats'] as $catTitle ) { |
| 79 | $html = Html::rawElement( 'bdi', [ 'dir' => $this->getContentLanguage()->getDir() ], |
| 80 | $linkRenderer->makeLink( |
| 81 | $catTitle, |
| 82 | $catTitle->getText() |
| 83 | ) ); |
| 84 | |
| 85 | $this->getHookRunner()->onSpecialTrackingCategories__generateCatLink( |
| 86 | $this, $catTitle, $html ); |
| 87 | |
| 88 | $allMsgs[] = $html; |
| 89 | } |
| 90 | |
| 91 | # Extra message, when no category was found |
| 92 | if ( $allMsgs === [] ) { |
| 93 | $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse(); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Show category description if it exists as a system message |
| 98 | * as category-name-desc |
| 99 | */ |
| 100 | $descMsg = $this->msg( $catDesc ); |
| 101 | if ( $descMsg->isBlank() ) { |
| 102 | $descMsg = $this->msg( 'trackingcategories-nodesc' ); |
| 103 | } |
| 104 | |
| 105 | $this->getOutput()->addHTML( Html::rawElement( 'tr', [], |
| 106 | Html::rawElement( 'td', [ 'class' => 'mw-trackingcategories-name' ], |
| 107 | $this->getLanguage()->commaList( array_unique( $allMsgs ) ) |
| 108 | ) . |
| 109 | Html::rawElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ], |
| 110 | $catMsgTitleText |
| 111 | ) . |
| 112 | Html::rawElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ], |
| 113 | $descMsg->parse() |
| 114 | ) |
| 115 | ) ); |
| 116 | } |
| 117 | $this->getOutput()->addHTML( Html::closeElement( 'table' ) ); |
| 118 | } |
| 119 | |
| 120 | /** @inheritDoc */ |
| 121 | protected function getGroupName() { |
| 122 | return 'pages'; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Retain the old class name for backwards compatibility. |
| 128 | * @deprecated since 1.41 |
| 129 | */ |
| 130 | class_alias( SpecialTrackingCategories::class, 'SpecialTrackingCategories' ); |