Followup cf5f641: pass $params by reference again
[lhc/web/wiklou.git] / includes / specials / SpecialTags.php
1 <?php
2 /**
3 * Implements Special:Tags
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that lists tags for edits
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialTags extends SpecialPage {
30 /**
31 * @var array List of defined tags
32 */
33 public $definedTags;
34
35 function __construct() {
36 parent::__construct( 'Tags' );
37 }
38
39 function execute( $par ) {
40 $this->setHeaders();
41 $this->outputHeader();
42
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' );
46
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() )
53 );
54
55 // Used in #doTagRow()
56 $this->definedTags = array_fill_keys( ChangeTags::listDefinedTags(), true );
57
58 foreach ( ChangeTags::tagUsageStatistics() as $tag => $hitcount ) {
59 $html .= $this->doTagRow( $tag, $hitcount );
60 }
61
62 $out->addHTML( Xml::tags(
63 'table',
64 array( 'class' => 'wikitable sortable mw-tags-table' ),
65 $html
66 ) );
67 }
68
69 function doTagRow( $tag, $hitcount ) {
70 $user = $this->getUser();
71 $newRow = '';
72 $newRow .= Xml::tags( 'td', null, Xml::element( 'code', null, $tag ) );
73
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()
80 );
81 $disp .= $this->msg( 'parentheses' )->rawParams( $editLink )->escaped();
82 }
83 $newRow .= Xml::tags( 'td', null, $disp );
84
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()
92 );
93 $desc .= $this->msg( 'parentheses' )->rawParams( $editDescLink )->escaped();
94 }
95 $newRow .= Xml::tags( 'td', null, $desc );
96
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 );
100
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 )
107 );
108
109 // add raw $hitcount for sorting, because tags-hitcount contains numbers and letters
110 $newRow .= Xml::tags( 'td', array( 'data-sort-value' => $hitcount ), $hitcountLink );
111
112 return Xml::tags( 'tr', null, $newRow ) . "\n";
113 }
114
115 protected function getGroupName() {
116 return 'changes';
117 }
118 }