r56312 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56311‎ | r56312 | r56313 >
Date:17:09, 14 September 2009
Author:aaron
Status:deferred
Tags:
Comment:
bug 18472 Suppression log filtered by "offender", as Oversight log can be
Modified paths:
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialLog.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRevisiondelete.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)
  • /trunk/phase3/maintenance/populateLogSearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -717,6 +717,7 @@
718718 'revdelete-otherreason',
719719 'revdelete-reasonotherlist',
720720 'revdelete-edit-reasonlist',
 721+ 'revdelete-offender',
721722 ),
722723 'suppression' => array(
723724 'suppressionlog',
Index: trunk/phase3/maintenance/populateLogSearch.php
@@ -27,6 +27,8 @@
2828
2929 const LOG_SEARCH_BATCH_SIZE = 100;
3030
 31+ static $tableMap = array('rev' => 'revision', 'fa' => 'filearchive', 'oi' => 'oldimage', 'ar' => 'archive');
 32+
3133 public function __construct() {
3234 parent::__construct();
3335 $this->mDescription = "Migrate log params to new table and index for searching";
@@ -48,6 +50,8 @@
4951 $end += self::LOG_SEARCH_BATCH_SIZE - 1;
5052 $blockStart = $start;
5153 $blockEnd = $start + self::LOG_SEARCH_BATCH_SIZE - 1;
 54+
 55+ $delTypes = array('delete','suppress'); // revisiondelete types
5256 while( $blockEnd <= $end ) {
5357 $this->output( "...doing log_id from $blockStart to $blockEnd\n" );
5458 $cond = "log_id BETWEEN $blockStart AND $blockEnd";
@@ -55,33 +59,74 @@
5660 $batch = array();
5761 foreach( $res as $row ) {
5862 // RevisionDelete logs - revisions
59 - if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
 63+ if( LogEventsList::typeAction( $row, $delTypes, 'revision' ) ) {
6064 $params = LogPage::extractParams( $row->log_params );
6165 // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
62 - if( count($params) >= 2 ) {
 66+ if( count($params) < 2 ) continue; // bad row?
 67+ $field = RevisionDeleter::getRelationType($params[0]);
 68+ // B/C, the params may start with a title key (<title> <urlparam> <CSV>)
 69+ if( $field == null ) {
 70+ array_shift($params); // remove title param
6371 $field = RevisionDeleter::getRelationType($params[0]);
64 - // B/C, the params may start with a title key
6572 if( $field == null ) {
66 - array_shift($params);
67 - $field = RevisionDeleter::getRelationType($params[0]);
68 - }
69 - if( $field == null ) {
70 - $this->output( "Invalid param type for $row->log_id\n" );
 73+ $this->output( "Invalid param type for {$row->log_id}\n" );
7174 continue; // skip this row
 75+ } else {
 76+ // Clean up the row...
 77+ $db->update( 'logging',
 78+ array('log_params' => implode(',',$params) ),
 79+ array('log_id' => $row->log_id ) );
7280 }
73 - $items = explode(',',$params[1]);
74 - $log = new LogPage( $row->log_type );
75 - $log->addRelations( $field, $items, $row->log_id );
7681 }
 82+ $items = explode(',',$params[1]);
 83+ $log = new LogPage( $row->log_type );
 84+ // Add item relations...
 85+ $log->addRelations( $field, $items, $row->log_id );
 86+ // Determine what table to query...
 87+ $prefix = substr( $field, 0, strpos($field,'_') ); // db prefix
 88+ if( !isset(self::$tableMap[$prefix]) )
 89+ continue; // bad row?
 90+ $table = self::$tableMap[$prefix];
 91+ $userField = $prefix.'_user';
 92+ $userTextField = $prefix.'_user_text';
 93+ // Add item author relations...
 94+ $userIds = $userIPs = array();
 95+ $sres = $db->select( $table,
 96+ array($userField,$userTextField),
 97+ array($field => $items)
 98+ );
 99+ foreach( $sres as $srow ) {
 100+ if( $srow->$userField > 0 )
 101+ $userIds[] = intval($srow->$userField);
 102+ else if( $srow->$userTextField != '' )
 103+ $userIPs[] = $srow->$userTextField;
 104+ }
 105+ // Add item author relations...
 106+ $log->addRelations( 'target_author_id', $userIds, $row->log_id );
 107+ $log->addRelations( 'target_author_ip', $userIPs, $row->log_id );
77108 // RevisionDelete logs - log events
78 - } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
 109+ } else if( LogEventsList::typeAction( $row, $delTypes, 'event' ) ) {
79110 $params = LogPage::extractParams( $row->log_params );
80111 // Param format: <item CSV> [<ofield> <nfield>]
81 - if( count($params) >= 1 ) {
82 - $items = explode(',',$params[0]);
83 - $log = new LogPage( $row->log_type );
84 - $log->addRelations( 'log_id', $items, $row->log_id );
 112+ if( count($params) < 1 ) continue; // bad row
 113+ $items = explode( ',', $params[0] );
 114+ $log = new LogPage( $row->log_type );
 115+ // Add item relations...
 116+ $log->addRelations( 'log_id', $items, $row->log_id );
 117+ // Add item author relations...
 118+ $userIds = $userIPs = array();
 119+ $sres = $db->select( 'logging',
 120+ array('log_user','log_user_text'),
 121+ array('log_id' => $items)
 122+ );
 123+ foreach( $sres as $srow ) {
 124+ if( $srow->log_user > 0 )
 125+ $userIds[] = intval($srow->log_user);
 126+ else if( IP::isIPAddress($srow->log_user_text) )
 127+ $userIPs[] = $srow->log_user_text;
85128 }
 129+ $log->addRelations( 'target_author_id', $userIds, $row->log_id );
 130+ $log->addRelations( 'target_author_ip', $userIPs, $row->log_id );
86131 }
87132 }
88133 $blockStart += self::LOG_SEARCH_BATCH_SIZE;
Index: trunk/phase3/includes/LogEventsList.php
@@ -94,6 +94,7 @@
9595 $html .= $this->getTypeMenu( $types ) . "\n";
9696 $html .= $this->getUserInput( $user ) . "\n";
9797 $html .= $this->getTitleInput( $page ) . "\n";
 98+ $html .= $this->getExtraInputs( $types ) . "\n";
9899
99100 // Title pattern, if allowed
100101 if (!$wgMiserMode) {
@@ -238,6 +239,15 @@
239240 Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
240241 '</span>';
241242 }
 243+
 244+ private function getExtraInputs( $types ) {
 245+ global $wgRequest;
 246+ if( count($types) == 1 && $types[0] == 'suppress' ) {
 247+ return Xml::inputLabel( wfMsg('revdelete-offender'), 'offender',
 248+ 'mw-log-offender', 20, $wgRequest->getVal('offender') );
 249+ }
 250+ return '';
 251+ }
242252
243253 public function beginLogEventsList() {
244254 return "<ul>\n";
Index: trunk/phase3/includes/specials/SpecialLog.php
@@ -52,9 +52,19 @@
5353 $y = '';
5454 $m = '';
5555 }
 56+ # Handle type-specific inputs
 57+ $qc = array();
 58+ if( $type == 'suppress' ) {
 59+ $offender = User::newFromName( $wgRequest->getVal('offender'), false );
 60+ if( $offender && $offender->getId() > 0 ) {
 61+ $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
 62+ } else if( $offender && IP::isIPAddress( $offender->getName() ) ) {
 63+ $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
 64+ }
 65+ }
5666 # Create a LogPager item to get the results and a LogEventsList item to format them...
5767 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
58 - $pager = new LogPager( $loglist, $type, $user, $title, $pattern, array(), $y, $m, $tagFilter );
 68+ $pager = new LogPager( $loglist, $type, $user, $title, $pattern, $qc, $y, $m, $tagFilter );
5969 # Set title and add header
6070 $loglist->showHeader( $pager->getType() );
6171 # Show form options
Index: trunk/phase3/includes/specials/SpecialRevisiondelete.php
@@ -201,9 +201,8 @@
202202 # Give a link to the logs/hist for this page
203203 if( $this->targetObj ) {
204204 $links = array();
205 - $logtitle = SpecialPage::getTitleFor( 'Log' );
206205 $links[] = $this->skin->linkKnown(
207 - $logtitle,
 206+ SpecialPage::getTitleFor( 'Log' ),
208207 wfMsgHtml( 'viewpagelogs' ),
209208 array(),
210209 array( 'page' => $this->targetObj->getPrefixedText() )
@@ -616,6 +615,7 @@
617616 // Get DB field name for URL param...
618617 // Future code for other things may also track
619618 // other types of revision-specific changes.
 619+ // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
620620 public static function getRelationType( $typeName ) {
621621 if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
622622 $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
@@ -638,6 +638,8 @@
639639 var $type = null; // override this
640640 var $idField = null; // override this
641641 var $dateField = false; // override this
 642+ var $authorIdField = false; // override this
 643+ var $authorNameField = false; // override this
642644
643645 /**
644646 * @param $special The parent SpecialPage
@@ -658,7 +660,7 @@
659661 }
660662
661663 /**
662 - * Get the DB field name associated with the ID list/
 664+ * Get the DB field name associated with the ID list
663665 */
664666 public function getIdField() {
665667 return $this->idField;
@@ -672,6 +674,19 @@
673675 }
674676
675677 /**
 678+ * Get the DB field name storing user ids
 679+ */
 680+ public function getAuthorIdField() {
 681+ return $this->authorIdField;
 682+ }
 683+
 684+ /**
 685+ * Get the DB field name storing user names
 686+ */
 687+ public function getAuthorNameField() {
 688+ return $this->authorNameField;
 689+ }
 690+ /**
676691 * Set the visibility for the revisions in this list. Logging and
677692 * transactions are done here.
678693 *
@@ -692,6 +707,7 @@
693708 $missing = array_flip( $this->ids );
694709 $this->clearFileOps();
695710 $idsForLog = array();
 711+ $authorIds = $authorIPs = array();
696712
697713 for ( $this->reset(); $this->current(); $this->next() ) {
698714 $item = $this->current();
@@ -731,6 +747,11 @@
732748 if ( $ok ) {
733749 $idsForLog[] = $item->getId();
734750 $status->successCount++;
 751+ if( $item->getAuthorId() > 0 ) {
 752+ $authorIds[] = $item->getAuthorId();
 753+ } else if( IP::isIPAddress( $item->getAuthorName() ) ) {
 754+ $authorIPs[] = $item->getAuthorName();
 755+ }
735756 } else {
736757 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
737758 $status->failCount++;
@@ -768,6 +789,8 @@
769790 'oldBits' => $oldBits,
770791 'comment' => $comment,
771792 'ids' => $idsForLog,
 793+ 'authorIds' => $authorIds,
 794+ 'authorIPs' => $authorIPs
772795 ) );
773796 $dbw->commit();
774797
@@ -793,6 +816,8 @@
794817 * title: The target title
795818 * ids: The ID list
796819 * comment: The log comment
 820+ * authorsIds: The array of the user IDs of the offenders
 821+ * authorsIPs: The array of the IP/anon user offenders
797822 */
798823 protected function updateLog( $params ) {
799824 // Get the URL param's corresponding DB field
@@ -814,6 +839,8 @@
815840 $params['comment'], $logParams );
816841 // Allow for easy searching of deletion log items for revision/log items
817842 $log->addRelations( $field, $params['ids'], $logid );
 843+ $log->addRelations( 'target_author_id', $params['authorIds'], $logid );
 844+ $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid );
818845 }
819846
820847 /**
@@ -976,7 +1003,23 @@
9771004 $field = $this->list->getTimestampField();
9781005 return wfTimestamp( TS_MW, $this->row->$field );
9791006 }
 1007+
 1008+ /**
 1009+ * Get the author user ID
 1010+ */
 1011+ public function getAuthorId() {
 1012+ $field = $this->list->getAuthorIdField();
 1013+ return intval( $this->row->$field );
 1014+ }
9801015
 1016+ /**
 1017+ * Get the author user name
 1018+ */
 1019+ public function getAuthorName() {
 1020+ $field = $this->list->getAuthorNameField();
 1021+ return strval( $this->row->$field );
 1022+ }
 1023+
9811024 /**
9821025 * Returns true if the item is "current", and the operation to set the given
9831026 * bits can't be executed for that reason
@@ -1023,6 +1066,8 @@
10241067 var $type = 'revision';
10251068 var $idField = 'rev_id';
10261069 var $dateField = 'rev_timestamp';
 1070+ var $authorIdField = 'rev_user';
 1071+ var $authorNameField = 'rev_user_text';
10271072
10281073 public function doQuery( $db ) {
10291074 $ids = array_map( 'intval', $this->ids );
@@ -1192,6 +1237,8 @@
11931238 var $type = 'archive';
11941239 var $idField = 'ar_timestamp';
11951240 var $dateField = 'ar_timestamp';
 1241+ var $authorIdField = 'ar_user';
 1242+ var $authorNameField = 'ar_user_text';
11961243
11971244 public function doQuery( $db ) {
11981245 $timestamps = array();
@@ -1286,6 +1333,8 @@
12871334 var $type = 'oldimage';
12881335 var $idField = 'oi_archive_name';
12891336 var $dateField = 'oi_timestamp';
 1337+ var $authorIdField = 'oi_user';
 1338+ var $authorNameField = 'oi_user_text';
12901339 var $storeBatch, $deleteBatch, $cleanupBatch;
12911340
12921341 public function doQuery( $db ) {
@@ -1501,6 +1550,8 @@
15021551 var $type = 'filearchive';
15031552 var $idField = 'fa_id';
15041553 var $dateField = 'fa_timestamp';
 1554+ var $authorIdField = 'fa_user';
 1555+ var $authorNameField = 'fa_user_text';
15051556
15061557 public function doQuery( $db ) {
15071558 $ids = array_map( 'intval', $this->ids );
@@ -1566,6 +1617,8 @@
15671618 var $type = 'logging';
15681619 var $idField = 'log_id';
15691620 var $dateField = 'log_timestamp';
 1621+ var $authorIdField = 'log_user';
 1622+ var $authorNameField = 'log_user_text';
15701623
15711624 public function doQuery( $db ) {
15721625 global $wgMessageCache;
@@ -1619,7 +1672,7 @@
16201673 ),
16211674 array(
16221675 'rc_logid' => $this->row->log_id,
1623 - 'rc_timestamp' => $this->row->log_timestamp
 1676+ 'rc_timestamp' => $this->row->log_timestamp // index
16241677 ),
16251678 __METHOD__
16261679 );
@@ -1641,9 +1694,9 @@
16421695 $paramArray = LogPage::extractParams( $this->row->log_params );
16431696 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
16441697
1645 - $logtitle = SpecialPage::getTitleFor( 'Log' );
 1698+ // Log link for this page
16461699 $loglink = $this->special->skin->link(
1647 - $logtitle,
 1700+ SpecialPage::getTitleFor( 'Log' ),
16481701 wfMsgHtml( 'log' ),
16491702 array(),
16501703 array( 'page' => $title->getPrefixedText() )
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1509,6 +1509,7 @@
15101510 'revdelete-otherreason' => 'Other/additional reason:',
15111511 'revdelete-reasonotherlist' => 'Other reason',
15121512 'revdelete-edit-reasonlist' => 'Edit delete reasons',
 1513+'revdelete-offender' => 'Offender:',
15131514
15141515 # Suppression log
15151516 'suppressionlog' => 'Suppression log',

Status & tagging log