Correct the address of the FSF in some of the GPL headers
[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, $wgUser, $wgMessageCache;
31
32 $wgMessageCache->loadAllMessages();
33
34 $sk = $wgUser->getSkin();
35 $wgOut->setPageTitle( wfMsg( 'tags-title' ) );
36 $wgOut->wrapWikiMsg( "<div class='mw-tags-intro'>\n$1\n</div>", 'tags-intro' );
37
38 // Write the headers
39 $html = '';
40 $html = Xml::tags( 'tr', null, Xml::tags( 'th', null, wfMsgExt( 'tags-tag', 'parseinline' ) ) .
41 Xml::tags( 'th', null, wfMsgExt( 'tags-display-header', 'parseinline' ) ) .
42 Xml::tags( 'th', null, wfMsgExt( 'tags-description-header', 'parseinline' ) ) .
43 Xml::tags( 'th', null, wfMsgExt( 'tags-hitcount-header', 'parseinline' ) )
44 );
45 $dbr = wfGetDB( DB_SLAVE );
46 $res = $dbr->select( 'change_tag', array( 'ct_tag', 'count(*) as hitcount' ), array(), __METHOD__, array( 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC' ) );
47
48 while ( $row = $res->fetchObject() ) {
49 $html .= $this->doTagRow( $row->ct_tag, $row->hitcount );
50 }
51
52 foreach( ChangeTags::listDefinedTags() as $tag ) {
53 $html .= $this->doTagRow( $tag, 0 );
54 }
55
56 $wgOut->addHTML( Xml::tags( 'table', array( 'class' => 'wikitable mw-tags-table' ), $html ) );
57 }
58
59 function doTagRow( $tag, $hitcount ) {
60 static $sk=null, $doneTags=array();
61 if (!$sk) {
62 global $wgUser;
63 $sk = $wgUser->getSkin();
64 }
65
66 if ( in_array( $tag, $doneTags ) ) {
67 return '';
68 }
69
70 global $wgLang;
71
72 $newRow = '';
73 $newRow .= Xml::tags( 'td', null, Xml::element( 'tt', null, $tag ) );
74
75 $disp = ChangeTags::tagDescription( $tag );
76 $disp .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag" ), wfMsgHtml( 'tags-edit' ) ) . ')';
77 $newRow .= Xml::tags( 'td', null, $disp );
78
79 $desc = wfMsgExt( "tag-$tag-description", 'parseinline' );
80 $desc = wfEmptyMsg( "tag-$tag-description", $desc ) ? '' : $desc;
81 $desc .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag-description" ), wfMsgHtml( 'tags-edit' ) ) . ')';
82 $newRow .= Xml::tags( 'td', null, $desc );
83
84 $hitcount = wfMsgExt( 'tags-hitcount', array( 'parsemag' ), $wgLang->formatNum( $hitcount ) );
85 $hitcount = $sk->link( SpecialPage::getTitleFor( 'Recentchanges' ), $hitcount, array(), array( 'tagfilter' => $tag ) );
86 $newRow .= Xml::tags( 'td', null, $hitcount );
87
88 $doneTags[] = $tag;
89
90 return Xml::tags( 'tr', null, $newRow ) . "\n";
91 }
92 }