blob: 0842018eac6152065395cd31c7b47822ffd6c8f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
/**
* Maintenance script to delete revisions which refer to a nonexisting page
* Sometimes manual deletion done in a rush leaves crap in the database
*
* @addtogroup Maintenance
* @author Rob Church <robchur@gmail.com>
* @todo More efficient cleanup of text records
*/
$options = array( 'report', 'help' );
require_once( 'commandLine.inc' );
require_once( 'deleteOrphanedRevisions.inc.php' );
echo( "Delete Orphaned Revisions\n" );
if( isset( $options['help'] ) )
showUsage();
$report = isset( $options['report'] );
$dbw = wfGetDB( DB_MASTER );
$dbw->immediateBegin();
extract( $dbw->tableNames( 'page', 'revision' ) );
# Find all the orphaned revisions
echo( "Checking for orphaned revisions..." );
$sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id WHERE page_namespace IS NULL";
$res = $dbw->query( $sql, 'deleteOrphanedRevisions' );
# Stash 'em all up for deletion (if needed)
while( $row = $dbw->fetchObject( $res ) )
$revisions[] = $row->rev_id;
$dbw->freeResult( $res );
$count = count( $revisions );
echo( "found {$count}.\n" );
# Nothing to do?
if( $report || $count == 0 ) {
$dbw->immediateCommit();
exit();
}
# Delete each revision
echo( "Deleting..." );
deleteRevisions( $revisions, $dbw );
echo( "done.\n" );
# Close the transaction and call the script to purge unused text records
$dbw->immediateCommit();
require_once( 'purgeOldText.inc' );
PurgeRedundantText( true );
|