| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use MediaWiki\Cache\LinkBatchFactory; |
| 24 |
use MediaWiki\Category\TrackingCategories; |
| 25 |
use MediaWiki\Html\Html; |
| 26 |
use MediaWiki\SpecialPage\SpecialPage; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
class SpecialTrackingCategories extends SpecialPage { |
| 39 |
|
| 40 |
private LinkBatchFactory $linkBatchFactory; |
| 41 |
private TrackingCategories $trackingCategories; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function __construct( |
| 48 |
LinkBatchFactory $linkBatchFactory, |
| 49 |
TrackingCategories $trackingCategories |
| 50 |
) { |
| 51 |
parent::__construct( 'TrackingCategories' ); |
| 52 |
$this->linkBatchFactory = $linkBatchFactory; |
| 53 |
$this->trackingCategories = $trackingCategories; |
| 54 |
} |
| 55 |
|
| 56 |
public function execute( $par ) { |
| 57 |
$this->setHeaders(); |
| 58 |
$this->outputHeader(); |
| 59 |
$this->addHelpLink( 'Help:Tracking categories' ); |
| 60 |
$this->getOutput()->getMetadata()->setPreventClickjacking( false ); |
| 61 |
$this->getOutput()->addModuleStyles( [ |
| 62 |
'jquery.tablesorter.styles', |
| 63 |
'mediawiki.pager.styles' |
| 64 |
] ); |
| 65 |
$this->getOutput()->addModules( 'jquery.tablesorter' ); |
| 66 |
$this->getOutput()->addHTML( |
| 67 |
Html::openElement( 'table', [ 'class' => 'mw-datatable sortable', |
| 68 |
'id' => 'mw-trackingcategories-table' ] ) . "\n" . |
| 69 |
'<thead><tr>' . |
| 70 |
Html::element( 'th', [], $this->msg( 'trackingcategories-msg' )->text() ) . |
| 71 |
Html::element( 'th', [], $this->msg( 'trackingcategories-name' )->text() ) . |
| 72 |
Html::element( 'th', [], $this->msg( 'trackingcategories-desc' )->text() ) . |
| 73 |
'</tr></thead>' |
| 74 |
); |
| 75 |
|
| 76 |
$categoryList = $this->trackingCategories->getTrackingCategories(); |
| 77 |
|
| 78 |
$batch = $this->linkBatchFactory->newLinkBatch(); |
| 79 |
foreach ( $categoryList as $data ) { |
| 80 |
$batch->addObj( $data['msg'] ); |
| 81 |
foreach ( $data['cats'] as $catTitle ) { |
| 82 |
$batch->addObj( $catTitle ); |
| 83 |
} |
| 84 |
} |
| 85 |
$batch->execute(); |
| 86 |
|
| 87 |
$this->getHookRunner()->onSpecialTrackingCategories__preprocess( $this, $categoryList ); |
| 88 |
|
| 89 |
$linkRenderer = $this->getLinkRenderer(); |
| 90 |
|
| 91 |
foreach ( $categoryList as $catMsg => $data ) { |
| 92 |
$allMsgs = []; |
| 93 |
$catDesc = $catMsg . '-desc'; |
| 94 |
|
| 95 |
$catMsgTitleText = $linkRenderer->makeLink( |
| 96 |
$data['msg'], |
| 97 |
$catMsg |
| 98 |
); |
| 99 |
|
| 100 |
foreach ( $data['cats'] as $catTitle ) { |
| 101 |
$html = Html::rawElement( 'bdi', [ 'dir' => $this->getContentLanguage()->getDir() ], |
| 102 |
$linkRenderer->makeLink( |
| 103 |
$catTitle, |
| 104 |
$catTitle->getText() |
| 105 |
) ); |
| 106 |
|
| 107 |
$this->getHookRunner()->onSpecialTrackingCategories__generateCatLink( |
| 108 |
$this, $catTitle, $html ); |
| 109 |
|
| 110 |
$allMsgs[] = $html; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
if ( $allMsgs === [] ) { |
| 115 |
$allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse(); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
$descMsg = $this->msg( $catDesc ); |
| 123 |
if ( $descMsg->isBlank() ) { |
| 124 |
$descMsg = $this->msg( 'trackingcategories-nodesc' ); |
| 125 |
} |
| 126 |
|
| 127 |
$this->getOutput()->addHTML( |
| 128 |
Html::openElement( 'tr' ) . |
| 129 |
Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) . |
| 130 |
$this->getLanguage()->commaList( array_unique( $allMsgs ) ) . |
| 131 |
Html::closeElement( 'td' ) . |
| 132 |
Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) . |
| 133 |
$catMsgTitleText . |
| 134 |
Html::closeElement( 'td' ) . |
| 135 |
Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) . |
| 136 |
$descMsg->parse() . |
| 137 |
Html::closeElement( 'td' ) . |
| 138 |
Html::closeElement( 'tr' ) |
| 139 |
); |
| 140 |
} |
| 141 |
$this->getOutput()->addHTML( Html::closeElement( 'table' ) ); |
| 142 |
} |
| 143 |
|
| 144 |
protected function getGroupName() { |
| 145 |
return 'pages'; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
class_alias( SpecialTrackingCategories::class, 'SpecialTrackingCategories' ); |