]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/populateLogSearch.inc
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.git] / maintenance / populateLogSearch.inc
1 <?php
2 /**
3  * Makes the required database updates for log display in Special:RevisionDelete
4  *
5  * Run via update.php or directly through populateLogSearch.php
6  *
7  * @file
8  * @ingroup Maintenance
9  */
10
11 define( 'LOG_SEARCH_BATCH_SIZE', 300 );
12
13 function migrate_log_params( $db ) {
14         $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
15         if( !$start ) {
16                 echo "Nothing to do.\n";
17                 return true;
18         }
19         $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
20         
21         # Do remaining chunk
22         $end += LOG_SEARCH_BATCH_SIZE - 1;
23         $blockStart = $start;
24         $blockEnd = $start + LOG_SEARCH_BATCH_SIZE - 1;
25         while( $blockEnd <= $end ) {
26                 echo "...doing log_id from $blockStart to $blockEnd\n";
27                 $cond = array("log_id BETWEEN $blockStart AND $blockEnd");
28                 # Applicable log types
29                 $cond['log_type'] = array('delete','suppress');
30                 $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
31                 $batch = array();
32                 while( $row = $db->fetchObject( $res ) ) {
33                         // RevisionDelete logs - revisions
34                         if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
35                                 $params = LogPage::extractParams( $row->log_params );
36                                 // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
37                                 if( count($params) >= 2 ) {
38                                         $field = RevisionDeleter::getRelationType($params[0]);
39                                         // B/C, the params may start with a title key
40                                         if( $field == null ) {
41                                                 array_shift($params);
42                                                 $field = RevisionDeleter::getRelationType($params[0]);
43                                         }
44                                         if( $field == null ) {
45                                                 echo "Invalid param type for $row->log_id\n";
46                                                 continue; // skip this row
47                                         }
48                                         $items = explode(',',$params[1]);
49                                         $log = new LogPage( $row->log_type );
50                                         $log->addRelations( $field, $items, $row->log_id );
51                                 }
52                         // RevisionDelete logs - log events
53                         } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
54                                 $params = LogPage::extractParams( $row->log_params );
55                                 // Param format: <item CSV> [<ofield> <nfield>]
56                                 if( count($params) >= 1 ) {
57                                         $items = explode(',',$params[0]);
58                                         $log = new LogPage( $row->log_type );
59                                         $log->addRelations( 'log_id', $items, $row->log_id );
60                                 }
61                         }
62                 }
63                 $blockStart += LOG_SEARCH_BATCH_SIZE;
64                 $blockEnd += LOG_SEARCH_BATCH_SIZE;
65                 wfWaitForSlaves( 5 );
66         }
67         if( $db->insert(
68                         'updatelog',
69                         array( 'ul_key' => 'populate log_search' ),
70                         __FUNCTION__,
71                         'IGNORE'
72                 )
73         ) {
74                 wfOut( "log_search population complete.\n" );
75                 return true;
76         } else {
77                 wfOut( "Could not insert log_search population row.\n" );
78                 return false;
79         }
80 }