r50597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50596‎ | r50597 | r50598 >
Date:19:49, 14 May 2009
Author:aaron
Status:ok (Comments)
Tags:
Comment:
Tweaks to r50567:
* Improved exception handling
* Removed redundant ls_log_id cond
* Added log_type to getLogQueryCond()
* Don't show duplicate rows in log results
* populateLogSearch now handles an older log_param format
Modified paths:
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)
  • /trunk/phase3/includes/LogPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRevisiondelete.php (modified) (history)
  • /trunk/phase3/maintenance/populateLogSearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/populateLogSearch.php
@@ -44,6 +44,15 @@
4545 // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
4646 if( count($params) >= 2 ) {
4747 $field = RevisionDeleter::getRelationType($params[0]);
 48+ // B/C, the params may start with a title key
 49+ if( $field == null ) {
 50+ array_shift($params);
 51+ $field = RevisionDeleter::getRelationType($params[0]);
 52+ }
 53+ if( $field == null ) {
 54+ echo "Invalid param type for $row->log_id";
 55+ continue; // skip this row
 56+ }
4857 $items = explode(',',$params[1]);
4958 $log = new LogPage( $row->log_type );
5059 $log->addRelations( $field, $items, $row->log_id );
Index: trunk/phase3/includes/LogEventsList.php
@@ -653,11 +653,13 @@
654654 public function getQueryInfo() {
655655 $tables = array( 'logging', 'user' );
656656 $this->mConds[] = 'user_id = log_user';
 657+ $groupBy = false;
657658 $index = array();
658659 # Add log_search table if there are conditions on it
659660 if( array_key_exists('ls_field',$this->mConds) ) {
660661 $tables[] = 'log_search';
661662 $index = array( 'log_search' => 'PRIMARY', 'logging' => 'PRIMARY' );
 663+ $groupBy = 'ls_log_id';
662664 # Don't use the wrong logging index
663665 } else if( $this->title || $this->pattern || $this->user ) {
664666 $index = array( 'logging' => array('page_time','user_time') );
@@ -666,16 +668,22 @@
667669 } else {
668670 $index = array( 'logging' => 'times' );
669671 }
 672+ $options = array( 'USE INDEX' => $index );
 673+ # Don't show duplicate rows when using log_search
 674+ if( $groupBy ) $options['GROUP BY'] = $groupBy;
670675 $info = array(
671 - 'tables' => $tables,
672 - 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title', 'log_params',
673 - 'log_comment', 'log_id', 'log_deleted', 'log_timestamp', 'user_name', 'user_editcount' ),
674 - 'conds' => $this->mConds,
675 - 'options' => array( 'USE INDEX' => $index ),
676 - 'join_conds' => array( 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
677 - 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' ) ),
 676+ 'tables' => $tables,
 677+ 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace',
 678+ 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted',
 679+ 'log_timestamp', 'user_name', 'user_editcount' ),
 680+ 'conds' => $this->mConds,
 681+ 'options' => $options,
 682+ 'join_conds' => array(
 683+ 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
 684+ 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
 685+ )
678686 );
679 -
 687+ # Add ChangeTags filter query
680688 ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
681689 $info['join_conds'], $info['options'], $this->mTagFilter );
682690
Index: trunk/phase3/includes/specials/SpecialRevisiondelete.php
@@ -120,6 +120,7 @@
121121 }
122122
123123 private function getLogQueryCond() {
 124+ $conds = array();
124125 $logAction = 'revision';
125126 switch( $this->deleteKey ) {
126127 case 'oldid':
@@ -142,10 +143,10 @@
143144 return array();
144145 }
145146 // Revision delete logs for these item
146 - $conds = array( 'log_action' => $logAction );
 147+ $conds['log_type'] = array('delete','suppress');
 148+ $conds['log_action'] = $logAction;
147149 $conds['ls_field'] = RevisionDeleter::getRelationType( $this->deleteKey );
148150 $conds['ls_value'] = $ids;
149 - $conds[] = 'log_id = ls_log_id';
150151 return $conds;
151152 }
152153
@@ -1527,9 +1528,12 @@
15281529 * @param string $param, URL param
15291530 * @param Array $items
15301531 */
1531 - function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target,
 1532+ protected function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target,
15321533 $param, $items = array() )
15331534 {
 1535+ // Get the URL param's corresponding DB field
 1536+ if( !($field = self::getRelationType($param)) )
 1537+ throw new MWException( "Bad log URL param type!" );
15341538 // Put things hidden from sysops in the oversight log
15351539 $logType = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ?
15361540 'suppress' : 'delete';
@@ -1547,7 +1551,7 @@
15481552 $log = new LogPage( $logType );
15491553 $logid = $log->addEntry( $logAction, $title, $comment, $params );
15501554 // Allow for easy searching of deletion log items for revision/log items
1551 - $log->addRelations( self::getRelationType($param), $items, $logid );
 1555+ $log->addRelations( $field, $items, $logid );
15521556 }
15531557
15541558 // Get DB field name for URL param...
@@ -1566,6 +1570,6 @@
15671571 case 'logid':
15681572 return 'log_id';
15691573 }
1570 - throw new MWException( "Bad log URL param type!" );
 1574+ return null; // bad URL type
15711575 }
15721576 }
\ No newline at end of file
Index: trunk/phase3/includes/LogPage.php
@@ -379,7 +379,7 @@
380380 * @static
381381 */
382382 public function addRelations( $field, $values, $logid ) {
383 - if( empty($values) )
 383+ if( !strlen($field) || empty($values) )
384384 return false; // nothing
385385 $data = array();
386386 foreach( $values as $value ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r50567[schema change] Use new log_search table to replace ugly code from r48839. Ma...aaron22:03, 13 May 2009

Comments

#Comment by OverlordQ (talk | contribs)   05:15, 28 August 2009

Why is there a group by on ls_log_id? From what I can tell every modification through revision delete generates a new log_id so there should be no rows with the same ls_log_id in the table. So this is relatively pointless as I can tell and also against SQL spec.

see bug #20150

Status & tagging log