(bug 19004) Added support for tags to the API. Patch by Matthew Britton.
[lhc/web/wiklou.git] / includes / specials / SpecialTags.php
1 <?php
2
3 if (!defined('MEDIAWIKI'))
4 die;
5
6 class SpecialTags extends SpecialPage {
7
8 function __construct() {
9 parent::__construct( 'Tags' );
10 }
11
12 function execute( $par ) {
13 global $wgOut, $wgUser, $wgMessageCache;
14
15 $wgMessageCache->loadAllMessages();
16
17 $sk = $wgUser->getSkin();
18 $wgOut->setPageTitle( wfMsg( 'tags-title' ) );
19 $wgOut->wrapWikiMsg( "<div class='mw-tags-intro'>\n$1</div>", 'tags-intro' );
20
21 // Write the headers
22 $html = '';
23 $html = Xml::tags( 'tr', null, Xml::tags( 'th', null, wfMsgExt( 'tags-tag', 'parseinline' ) ) .
24 Xml::tags( 'th', null, wfMsgExt( 'tags-display-header', 'parseinline' ) ) .
25 Xml::tags( 'th', null, wfMsgExt( 'tags-description-header', 'parseinline' ) ) .
26 Xml::tags( 'th', null, wfMsgExt( 'tags-hitcount-header', 'parseinline' ) )
27 );
28
29 foreach( ChangeTags::getHitCounts() as $tag => $hitcount ) {
30 $html .= $this->doTagRow( $tag, $hitcount );
31 }
32
33 $wgOut->addHTML( Xml::tags( 'table', array( 'class' => 'wikitable mw-tags-table' ), $html ) );
34 }
35
36 function doTagRow( $tag, $hitcount ) {
37 static $sk=null, $doneTags=array();
38 if (!$sk) {
39 global $wgUser;
40 $sk = $wgUser->getSkin();
41 }
42
43 if ( in_array( $tag, $doneTags ) ) {
44 return '';
45 }
46
47 global $wgLang;
48
49 $newRow = '';
50 $newRow .= Xml::tags( 'td', null, Xml::element( 'tt', null, $tag ) );
51
52 $disp = ChangeTags::tagDescription( $tag );
53 $disp .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag" ), wfMsgHtml( 'tags-edit' ) ) . ')';
54 $newRow .= Xml::tags( 'td', null, $disp );
55
56 $desc = wfMsgExt( "tag-$tag-description", 'parseinline' );
57 $desc = wfEmptyMsg( "tag-$tag-description", $desc ) ? '' : $desc;
58 $desc .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag-description" ), wfMsgHtml( 'tags-edit' ) ) . ')';
59 $newRow .= Xml::tags( 'td', null, $desc );
60
61 $hitcount = wfMsgExt( 'tags-hitcount', array( 'parsemag' ), $wgLang->formatNum( $hitcount ) );
62 $hitcount = $sk->link( SpecialPage::getTitleFor( 'Recentchanges' ), $hitcount, array(), array( 'tagfilter' => $tag ) );
63 $newRow .= Xml::tags( 'td', null, $hitcount );
64
65 $doneTags[] = $tag;
66
67 return Xml::tags( 'tr', null, $newRow ) . "\n";
68 }
69 }