Merge "Capitalized bullet points and updated last sentence to say MediaWiki instead...
[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 function __construct() {
32 parent::__construct( 'Tags' );
33 }
34
35 function execute( $par ) {
36 $this->setHeaders();
37 $this->outputHeader();
38
39 $out = $this->getOutput();
40 $out->setPageTitle( $this->msg( 'tags-title' ) );
41 $out->wrapWikiMsg( "<div class='mw-tags-intro'>\n$1\n</div>", 'tags-intro' );
42
43 // Write the headers
44 $html = Xml::tags( 'tr', null, Xml::tags( 'th', null, $this->msg( 'tags-tag' )->parse() ) .
45 Xml::tags( 'th', null, $this->msg( 'tags-display-header' )->parse() ) .
46 Xml::tags( 'th', null, $this->msg( 'tags-description-header' )->parse() ) .
47 Xml::tags( 'th', null, $this->msg( 'tags-hitcount-header' )->parse() )
48 );
49
50 foreach ( ChangeTags::tagUsageStatistics() as $tag => $hitcount ) {
51 $html .= $this->doTagRow( $tag, $hitcount );
52 }
53
54 $out->addHTML( Xml::tags( 'table', array( 'class' => 'wikitable sortable mw-tags-table' ), $html ) );
55 }
56
57 function doTagRow( $tag, $hitcount ) {
58 $user = $this->getUser();
59 $newRow = '';
60 $newRow .= Xml::tags( 'td', null, Xml::element( 'code', null, $tag ) );
61
62 $disp = ChangeTags::tagDescription( $tag );
63 if ( $user->isAllowed( 'editinterface' ) ) {
64 $disp .= ' ';
65 $editLink = Linker::link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag" ), $this->msg( 'tags-edit' )->escaped() );
66 $disp .= $this->msg( 'parentheses' )->rawParams( $editLink )->escaped();
67 }
68 $newRow .= Xml::tags( 'td', null, $disp );
69
70 $msg = $this->msg( "tag-$tag-description" );
71 $desc = !$msg->exists() ? '' : $msg->parse();
72 if ( $user->isAllowed( 'editinterface' ) ) {
73 $desc .= ' ';
74 $editDescLink = Linker::link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag-description" ), $this->msg( 'tags-edit' )->escaped() );
75 $desc .= $this->msg( 'parentheses' )->rawParams( $editDescLink )->escaped();
76 }
77 $newRow .= Xml::tags( 'td', null, $desc );
78
79 $hitcountLabel = $this->msg( 'tags-hitcount' )->numParams( $hitcount )->escaped();
80 $hitcountLink = Linker::link( SpecialPage::getTitleFor( 'Recentchanges' ), $hitcountLabel, array(), array( 'tagfilter' => $tag ) );
81 // add raw $hitcount for sorting, because tags-hitcount contains numbers and letters
82 $newRow .= Xml::tags( 'td', array( 'data-sort-value' => $hitcount ), $hitcountLink );
83
84 return Xml::tags( 'tr', null, $newRow ) . "\n";
85 }
86
87 protected function getGroupName() {
88 return 'changes';
89 }
90 }