Implement extension registration from an extension.json file
[mediawiki.git] / includes / specials / SpecialTags.php
blobb76272851131cab80efca471d45cb33517910793
1 <?php
2 /**
3 * Implements Special:Tags
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * A special page that lists tags for edits
27 * @ingroup SpecialPage
29 class SpecialTags extends SpecialPage {
30 /**
31 * @var array List of defined tags
33 public $definedTags;
35 function __construct() {
36 parent::__construct( 'Tags' );
39 function execute( $par ) {
40 $this->setHeaders();
41 $this->outputHeader();
43 $out = $this->getOutput();
44 $out->setPageTitle( $this->msg( 'tags-title' ) );
45 $out->wrapWikiMsg( "<div class='mw-tags-intro'>\n$1\n</div>", 'tags-intro' );
47 // Write the headers
48 $html = Xml::tags( 'tr', null, Xml::tags( 'th', null, $this->msg( 'tags-tag' )->parse() ) .
49 Xml::tags( 'th', null, $this->msg( 'tags-display-header' )->parse() ) .
50 Xml::tags( 'th', null, $this->msg( 'tags-description-header' )->parse() ) .
51 Xml::tags( 'th', null, $this->msg( 'tags-active-header' )->parse() ) .
52 Xml::tags( 'th', null, $this->msg( 'tags-hitcount-header' )->parse() )
55 // Used in #doTagRow()
56 $this->definedTags = array_fill_keys( ChangeTags::listDefinedTags(), true );
58 foreach ( ChangeTags::tagUsageStatistics() as $tag => $hitcount ) {
59 $html .= $this->doTagRow( $tag, $hitcount );
62 $out->addHTML( Xml::tags(
63 'table',
64 array( 'class' => 'wikitable sortable mw-tags-table' ),
65 $html
66 ) );
69 function doTagRow( $tag, $hitcount ) {
70 $user = $this->getUser();
71 $newRow = '';
72 $newRow .= Xml::tags( 'td', null, Xml::element( 'code', null, $tag ) );
74 $disp = ChangeTags::tagDescription( $tag );
75 if ( $user->isAllowed( 'editinterface' ) ) {
76 $disp .= ' ';
77 $editLink = Linker::link(
78 Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag" ),
79 $this->msg( 'tags-edit' )->escaped()
81 $disp .= $this->msg( 'parentheses' )->rawParams( $editLink )->escaped();
83 $newRow .= Xml::tags( 'td', null, $disp );
85 $msg = $this->msg( "tag-$tag-description" );
86 $desc = !$msg->exists() ? '' : $msg->parse();
87 if ( $user->isAllowed( 'editinterface' ) ) {
88 $desc .= ' ';
89 $editDescLink = Linker::link(
90 Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag-description" ),
91 $this->msg( 'tags-edit' )->escaped()
93 $desc .= $this->msg( 'parentheses' )->rawParams( $editDescLink )->escaped();
95 $newRow .= Xml::tags( 'td', null, $desc );
97 $active = isset( $this->definedTags[$tag] ) ? 'tags-active-yes' : 'tags-active-no';
98 $active = $this->msg( $active )->escaped();
99 $newRow .= Xml::tags( 'td', null, $active );
101 $hitcountLabel = $this->msg( 'tags-hitcount' )->numParams( $hitcount )->escaped();
102 $hitcountLink = Linker::link(
103 SpecialPage::getTitleFor( 'Recentchanges' ),
104 $hitcountLabel,
105 array(),
106 array( 'tagfilter' => $tag )
109 // add raw $hitcount for sorting, because tags-hitcount contains numbers and letters
110 $newRow .= Xml::tags( 'td', array( 'data-sort-value' => $hitcount ), $hitcountLink );
112 return Xml::tags( 'tr', null, $newRow ) . "\n";
115 protected function getGroupName() {
116 return 'changes';