More unused variables, whitespace
[lhc/web/wiklou.git] / includes / specials / SpecialTags.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 if (!defined('MEDIAWIKI'))
21 die;
22
23 class SpecialTags extends SpecialPage {
24
25 function __construct() {
26 parent::__construct( 'Tags' );
27 }
28
29 function execute( $par ) {
30 global $wgOut, $wgMessageCache;
31
32 $wgMessageCache->loadAllMessages();
33
34 $wgOut->setPageTitle( wfMsg( 'tags-title' ) );
35 $wgOut->wrapWikiMsg( "<div class='mw-tags-intro'>\n$1\n</div>", 'tags-intro' );
36
37 // Write the headers
38 $html = '';
39 $html = Xml::tags( 'tr', null, Xml::tags( 'th', null, wfMsgExt( 'tags-tag', 'parseinline' ) ) .
40 Xml::tags( 'th', null, wfMsgExt( 'tags-display-header', 'parseinline' ) ) .
41 Xml::tags( 'th', null, wfMsgExt( 'tags-description-header', 'parseinline' ) ) .
42 Xml::tags( 'th', null, wfMsgExt( 'tags-hitcount-header', 'parseinline' ) )
43 );
44 $dbr = wfGetDB( DB_SLAVE );
45 $res = $dbr->select( 'change_tag', array( 'ct_tag', 'count(*) as hitcount' ), array(), __METHOD__, array( 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC' ) );
46
47 while ( $row = $res->fetchObject() ) {
48 $html .= $this->doTagRow( $row->ct_tag, $row->hitcount );
49 }
50
51 foreach( ChangeTags::listDefinedTags() as $tag ) {
52 $html .= $this->doTagRow( $tag, 0 );
53 }
54
55 $wgOut->addHTML( Xml::tags( 'table', array( 'class' => 'wikitable mw-tags-table' ), $html ) );
56 }
57
58 function doTagRow( $tag, $hitcount ) {
59 static $sk=null, $doneTags=array();
60 if (!$sk) {
61 global $wgUser;
62 $sk = $wgUser->getSkin();
63 }
64
65 if ( in_array( $tag, $doneTags ) ) {
66 return '';
67 }
68
69 global $wgLang;
70
71 $newRow = '';
72 $newRow .= Xml::tags( 'td', null, Xml::element( 'tt', null, $tag ) );
73
74 $disp = ChangeTags::tagDescription( $tag );
75 $disp .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag" ), wfMsgHtml( 'tags-edit' ) ) . ')';
76 $newRow .= Xml::tags( 'td', null, $disp );
77
78 $desc = wfMsgExt( "tag-$tag-description", 'parseinline' );
79 $desc = wfEmptyMsg( "tag-$tag-description", $desc ) ? '' : $desc;
80 $desc .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag-description" ), wfMsgHtml( 'tags-edit' ) ) . ')';
81 $newRow .= Xml::tags( 'td', null, $desc );
82
83 $hitcount = wfMsgExt( 'tags-hitcount', array( 'parsemag' ), $wgLang->formatNum( $hitcount ) );
84 $hitcount = $sk->link( SpecialPage::getTitleFor( 'Recentchanges' ), $hitcount, array(), array( 'tagfilter' => $tag ) );
85 $newRow .= Xml::tags( 'td', null, $hitcount );
86
87 $doneTags[] = $tag;
88
89 return Xml::tags( 'tr', null, $newRow ) . "\n";
90 }
91 }