Revision: 45986
Author:   werdna
Date:     2009-01-21 23:45:10 +0000 (Wed, 21 Jan 2009)

Log Message:
-----------
Introduce a special page which lists tags, and their meanings, and all that 
jazz.

Modified Paths:
--------------
    branches/change-tagging/extensions/AbuseFilter/AbuseFilter.hooks.php
    branches/change-tagging/extensions/AbuseFilter/AbuseFilter.php
    branches/change-tagging/extensions/TorBlock/TorBlock.class.php
    branches/change-tagging/extensions/TorBlock/TorBlock.i18n.php
    branches/change-tagging/extensions/TorBlock/TorBlock.php
    branches/change-tagging/phase3/docs/hooks.txt
    branches/change-tagging/phase3/includes/AutoLoader.php
    branches/change-tagging/phase3/includes/ChangeTags.php
    branches/change-tagging/phase3/includes/SpecialPage.php
    branches/change-tagging/phase3/languages/messages/MessagesEn.php
    branches/change-tagging/phase3/maintenance/archives/patch-change_tag.sql
    branches/change-tagging/phase3/maintenance/tables.sql

Added Paths:
-----------
    branches/change-tagging/phase3/includes/specials/SpecialTags.php

Modified: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.hooks.php
===================================================================
--- branches/change-tagging/extensions/AbuseFilter/AbuseFilter.hooks.php        
2009-01-21 23:12:59 UTC (rev 45985)
+++ branches/change-tagging/extensions/AbuseFilter/AbuseFilter.hooks.php        
2009-01-21 23:45:10 UTC (rev 45986)
@@ -175,4 +175,17 @@
 
                return true;
        }
+
+       public static function onListDefinedTags( &$emptyTags ) {
+               ## This is a pretty awful hack.
+               $dbr = wfGetDB( DB_SLAVE );
+
+               $res = $dbr->select( 'abuse_filter_action', 'afa_parameters', 
array( 'afa_consequence' => 'tag' ), __METHOD__ );
+
+               while( $row = $res->fetchObject() ) {
+                       $emptyTags = array_filter( array_merge( explode( "\n", 
$row->afa_parameters ), $emptyTags ) );
+               }
+
+               return true;
+       }
 }

Modified: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.php
===================================================================
--- branches/change-tagging/extensions/AbuseFilter/AbuseFilter.php      
2009-01-21 23:12:59 UTC (rev 45985)
+++ branches/change-tagging/extensions/AbuseFilter/AbuseFilter.php      
2009-01-21 23:45:10 UTC (rev 45986)
@@ -45,6 +45,7 @@
 $wgHooks['LoadExtensionSchemaUpdates'][] = 'AbuseFilterHooks::onSchemaUpdate';
 $wgHooks['AbortDeleteQueueNominate'][] = 
'AbuseFilterHooks::onAbortDeleteQueueNominate';
 $wgHooks['RecentChange_save'][] = 'AbuseFilterHooks::onRecentChangeSave';
+$wgHooks['ListDefinedTags'][] = 'AbuseFilterHooks::onListDefinedTags';
 
 $wgAvailableRights[] = 'abusefilter-modify';
 $wgAvailableRights[] = 'abusefilter-log-detail';

Modified: branches/change-tagging/extensions/TorBlock/TorBlock.class.php
===================================================================
--- branches/change-tagging/extensions/TorBlock/TorBlock.class.php      
2009-01-21 23:12:59 UTC (rev 45985)
+++ branches/change-tagging/extensions/TorBlock/TorBlock.class.php      
2009-01-21 23:45:10 UTC (rev 45986)
@@ -175,4 +175,9 @@
                }
                return true;
        }
+
+       public static function onListDefinedTags( &$emptyTags ) {
+               $emptyTags[] = 'tor';
+               return true;
+       }
 }

Modified: branches/change-tagging/extensions/TorBlock/TorBlock.i18n.php
===================================================================
--- branches/change-tagging/extensions/TorBlock/TorBlock.i18n.php       
2009-01-21 23:12:59 UTC (rev 45985)
+++ branches/change-tagging/extensions/TorBlock/TorBlock.i18n.php       
2009-01-21 23:45:10 UTC (rev 45986)
@@ -15,6 +15,8 @@
        'torblock-blocked' => 'Your IP address, <tt>$1</tt>, has been 
automatically identified as a tor exit node.
 Editing through tor is blocked to prevent abuse.',
        'right-torunblocked' => 'Bypass automatic blocks of tor exit nodes',
+       'tag-tor-description' => 'If this tag is set, an edit was made from a 
Tor exit node.',
+       'tag-tor' => 'Made through tor',
 );
 
 /** Message documentation (Message documentation)

Modified: branches/change-tagging/extensions/TorBlock/TorBlock.php
===================================================================
--- branches/change-tagging/extensions/TorBlock/TorBlock.php    2009-01-21 
23:12:59 UTC (rev 45985)
+++ branches/change-tagging/extensions/TorBlock/TorBlock.php    2009-01-21 
23:45:10 UTC (rev 45986)
@@ -34,6 +34,7 @@
 $wgHooks['GetBlockedStatus'][] = 'TorBlock::onGetBlockedStatus';
 $wgHooks['AutopromoteCondition'][] = 'TorBlock::onAutopromoteCondition';
 $wgHooks['RecentChange_save'][] = 'TorBlock::onRecentChangeSave';
+$wgHooks['ListDefinedTags'][] = 'TorBlock::onListDefinedTags';
 
 // Define new autopromote condition
 define('APCOND_TOR', 'tor'); // Numbers won't work, we'll get collisions

Modified: branches/change-tagging/phase3/docs/hooks.txt
===================================================================
--- branches/change-tagging/phase3/docs/hooks.txt       2009-01-21 23:12:59 UTC 
(rev 45985)
+++ branches/change-tagging/phase3/docs/hooks.txt       2009-01-21 23:45:10 UTC 
(rev 45986)
@@ -850,6 +850,9 @@
 'LinksUpdateConstructed': At the end of LinksUpdate() is contruction.
 &$linksUpdate: the LinkUpdate object
 
+'ListDefinedTags': When trying to find all defined tags.
+&$tags: The list of tags.
+
 'LoadAllMessages': called by MessageCache::loadAllMessages() to load 
extensions messages
 
 'LoadExtensionSchemaUpdates': called by maintenance/updaters.inc when 
upgrading database schema

Modified: branches/change-tagging/phase3/includes/AutoLoader.php
===================================================================
--- branches/change-tagging/phase3/includes/AutoLoader.php      2009-01-21 
23:12:59 UTC (rev 45985)
+++ branches/change-tagging/phase3/includes/AutoLoader.php      2009-01-21 
23:45:10 UTC (rev 45986)
@@ -495,6 +495,7 @@
        'SpecialSearch' => 'includes/specials/SpecialSearch.php',
        'SpecialSearchOld' => 'includes/specials/SpecialSearch.php',
        'SpecialStatistics' => 'includes/specials/SpecialStatistics.php',
+       'SpecialTags' => 'includes/specials/SpecialTags.php',
        'SpecialVersion' => 'includes/specials/SpecialVersion.php',
        'UncategorizedCategoriesPage' => 
'includes/specials/SpecialUncategorizedcategories.php',
        'UncategorizedPagesPage' => 
'includes/specials/SpecialUncategorizedpages.php',

Modified: branches/change-tagging/phase3/includes/ChangeTags.php
===================================================================
--- branches/change-tagging/phase3/includes/ChangeTags.php      2009-01-21 
23:12:59 UTC (rev 45985)
+++ branches/change-tagging/phase3/includes/ChangeTags.php      2009-01-21 
23:45:10 UTC (rev 45986)
@@ -13,17 +13,21 @@
                $tags = explode( ',', $tags );
                $displayTags = array();
                foreach( $tags as $tag ) {
-                       if (!wfEmptyMsg( "tag-$tag" , wfMsg( "tag-$tag" ) ) ) {
-                               $displayTags[] = wfMsgExt( "tag-$tag", 
'parseinline' );
-                       } else {
-                               $displayTags[] = $tag;
-                       }
+                       $displayTags[] = self::tagDescription( $tag );
                        $classes[] = "mw-tag-$tag";
                }
 
                return array( '(' . implode( ', ', $displayTags ) . ')', 
$classes );
        }
 
+       static function tagDescription( $tag ) {
+               $msg = wfMsgExt( "tag-$tag", 'parseinline' );
+               if ( wfEmptyMsg( "tag-$tag", $msg ) ) {
+                       return htmlspecialchars($tag);
+               }
+               return $msg;
+       }
+
        ## Basic utility method to add tags to a particular change, given its 
rc_id, rev_id and/or log_id.
        static function addTags( $tags, $rc_id=null, $rev_id=null, 
$log_id=null, $params = null ) {
                if ( !is_array($tags) ) {
@@ -74,7 +78,7 @@
                        $tagsRows[] = array_filter( array( 'ct_tag' => $tag, 
'ct_rc_id' => $rc_id, 'ct_log_id' => $log_id, 'ct_rev_id' => $rev_id, 
'ct_params' => $params ) );
                }
 
-               $dbw->insert( 'change_tag', array( array( 'ct_tag', 'ct_rc_id', 
'ct_rev_id', 'ct_log_id' ) ), $tagsRows, __METHOD__, array('IGNORE') );
+               $dbw->insert( 'change_tag', $tagsRows, __METHOD__, 
array('IGNORE') );
 
                return true;
        }
@@ -138,4 +142,20 @@
 
                return $html;
        }
+
+       /** Basically lists defined tags which count even if they aren't 
applied to anything */
+       static function listDefinedTags() {
+               $emptyTags = array();
+
+               // Some DB stuff
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( 'valid_tag', 'vt_tag', array(), __METHOD__ 
);
+               while( $row = $res->fetchObject() ) {
+                       $emptyTags[] = $row->vt_tag;
+               }
+               
+               wfRunHooks( 'ListDefinedTags', array(&$emptyTags) );
+
+               return array_filter( array_unique( $emptyTags ) );
+       }
 }
\ No newline at end of file

Modified: branches/change-tagging/phase3/includes/SpecialPage.php
===================================================================
--- branches/change-tagging/phase3/includes/SpecialPage.php     2009-01-21 
23:12:59 UTC (rev 45985)
+++ branches/change-tagging/phase3/includes/SpecialPage.php     2009-01-21 
23:45:10 UTC (rev 45986)
@@ -159,6 +159,7 @@
                'Randomredirect'            => 'SpecialRandomredirect',
                'Withoutinterwiki'          => array( 'SpecialPage', 
'Withoutinterwiki' ),
                'Filepath'                  => array( 'SpecialPage', 'Filepath' 
),
+               'Tags'                      => 'SpecialTags',
 
                'Mypage'                    => array( 'SpecialMypage' ),
                'Mytalk'                    => array( 'SpecialMytalk' ),

Added: branches/change-tagging/phase3/includes/specials/SpecialTags.php
===================================================================
--- branches/change-tagging/phase3/includes/specials/SpecialTags.php            
                (rev 0)
+++ branches/change-tagging/phase3/includes/specials/SpecialTags.php    
2009-01-21 23:45:10 UTC (rev 45986)
@@ -0,0 +1,75 @@
+<?php
+
+if (!defined('MEDIAWIKI'))
+       die;
+
+class SpecialTags extends SpecialPage {
+
+       function __construct() {
+               parent::__construct( 'Tags' );
+       }
+
+       function execute() {
+               global $wgOut, $wgUser, $wgMessageCache;
+
+               $wgMessageCache->loadAllMessages();
+               
+               $sk = $wgUser->getSkin();
+               $wgOut->setPageTitle( wfMsg( 'tags-title' ) );
+               $wgOut->addWikiMsg( 'tags-intro' );
+
+               // Write the headers
+               $html = '';
+               $html = Xml::tags( 'tr', null, Xml::tags( 'th', null, wfMsgExt( 
'tags-tag', 'parseinline' ) ) .
+                               Xml::tags( 'th', null, wfMsgExt( 
'tags-display-header', 'parseinline' ) ) .
+                               Xml::tags( 'th', null, wfMsgExt( 
'tags-description-header', 'parseinline' ) ) .
+                               Xml::tags( 'th', null, wfMsgExt( 
'tags-hitcount-header', 'parseinline' ) )
+                       );
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( 'change_tag', array( 'ct_tag', 'count(*) 
as hitcount' ), array(), __METHOD__, array( 'GROUP BY' => 'ct_tag', 'ORDER BY' 
=> 'hitcount DESC' ) );
+
+               while ( $row = $res->fetchObject() ) {
+                       $html .= $this->doTagRow( $row->ct_tag, $row->hitcount 
);
+               }
+
+               foreach( ChangeTags::listDefinedTags() as $tag ) {
+                       $html .= $this->doTagRow( $tag, 0 );
+               }
+
+               $html = "<table style='width: 
80%'><tbody>$html</tbody></table>";
+
+               $wgOut->addHTML( $html );
+       }
+
+       function doTagRow( $tag, $hitcount ) {
+               static $sk=null, $doneTags=array();
+               if (!$sk) {
+                       global $wgUser;
+                       $sk = $wgUser->getSkin();
+               }
+
+               if ( in_array( $tag, $doneTags ) ) {
+                       return '';
+               }
+               
+               $newRow = '';
+               $newRow .= Xml::tags( 'td', null, Xml::element( 'tt', null, 
$tag ) );
+
+               $disp = ChangeTags::tagDescription( $tag );
+               $disp .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, 
"Tag-$tag" ), wfMsg( 'tag-edit' ) ) . ')';
+               $newRow .= Xml::tags( 'td', null, $disp );
+
+               $desc = wfMsgExt( "tag-$tag-description", 'parseinline' );
+               $desc = wfEmptyMsg( "tag-$tag-description", $desc ) ? '' : 
$desc;
+               $desc .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, 
"Tag-$tag-description" ), wfMsg( 'tag-edit' ) ) . ')';
+               $newRow .= Xml::tags( 'td', null, $desc );
+
+               $hitcount = wfMsg( 'tags-hitcount', $hitcount );
+               $hitcount = $sk->link( SpecialPage::getTitleFor( 
'RecentChanges' ), $hitcount, array(), array( 'tagfilter' => $tag ) );
+               $newRow .= Xml::tags( 'td', null, $hitcount );
+
+               $doneTags[] = $tag;
+
+               return Xml::tags( 'tr', null, $newRow ) . "\n";
+       }
+}
\ No newline at end of file

Modified: branches/change-tagging/phase3/languages/messages/MessagesEn.php
===================================================================
--- branches/change-tagging/phase3/languages/messages/MessagesEn.php    
2009-01-21 23:12:59 UTC (rev 45985)
+++ branches/change-tagging/phase3/languages/messages/MessagesEn.php    
2009-01-21 23:45:10 UTC (rev 45986)
@@ -3785,5 +3785,12 @@
 ## Taggng-related stuff
 'tag-filter' => 'Tag filter:',
 'tag-filter-submit' => 'Filter',
-
+'tags-title' => 'Tags',
+'tags-intro' => 'This page lists the tags that the software may mark an edit 
with, and their meaning.',
+'tags-tag' => 'Internal tag name',
+'tags-display-header' => 'Appearance on change lists',
+'tags-description-header' => 'Full description of meaning',
+'tags-hitcount-header' => 'Tagged edits',
+'tags-edit' => 'edit',
+'tags-hitcount' => '$1 changes',
 );

Modified: 
branches/change-tagging/phase3/maintenance/archives/patch-change_tag.sql
===================================================================
--- branches/change-tagging/phase3/maintenance/archives/patch-change_tag.sql    
2009-01-21 23:12:59 UTC (rev 45985)
+++ branches/change-tagging/phase3/maintenance/archives/patch-change_tag.sql    
2009-01-21 23:45:10 UTC (rev 45986)
@@ -23,4 +23,9 @@
        UNIQUE KEY (ts_rc_id),
        UNIQUE KEY (ts_log_id),
        UNIQUE KEY (ts_rev_id)
+) /*$wgDBTableOptions*/;
+
+CREATE TABLE /*_*/valid_tag (
+       vt_tag varchar(255) NOT NULL,
+       PRIMARY KEY (vt_tag)
 ) /*$wgDBTableOptions*/;
\ No newline at end of file

Modified: branches/change-tagging/phase3/maintenance/tables.sql
===================================================================
--- branches/change-tagging/phase3/maintenance/tables.sql       2009-01-21 
23:12:59 UTC (rev 45985)
+++ branches/change-tagging/phase3/maintenance/tables.sql       2009-01-21 
23:45:10 UTC (rev 45986)
@@ -1260,4 +1260,9 @@
        UNIQUE KEY (ts_rev_id),
 ) /*$wgDBTableOptions*/;
 
+CREATE TABLE /*_*/valid_tag (
+       vt_tag varchar(255) NOT NULL,
+       PRIMARY KEY (vt_tag)
+) /*$wgDBTableOptions*/;
+
 -- vim: sw=2 sts=2 et



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to