r14262 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14261‎ | r14262 | r14263 >
Date:07:37, 17 May 2006
Author:robchurch
Status:old
Tags:
Comment:
Maintenance script to remove orphaned revisions from the database
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/maintenance/deleteOrphanedRevisions.inc.php (added) (history)
  • /trunk/phase3/maintenance/deleteOrphanedRevisions.php (added) (history)

Diff [purge]

Index: trunk/phase3/maintenance/deleteOrphanedRevisions.inc.php
@@ -0,0 +1,33 @@
 2+<?php
 3+
 4+/**
 5+ * Support functions for the deleteOrphanedRevisions maintenance script
 6+ *
 7+ * @package MediaWiki
 8+ * @subpackage Maintenance
 9+ * @author Rob Church <robchur@gmail.com>
 10+ */
 11+
 12+/**
 13+ * Delete one or more revisions from the database
 14+ * Do this inside a transaction
 15+ *
 16+ * @param $id Array of revision id values
 17+ * @param $db Database class (needs to be a master)
 18+ */
 19+function deleteRevisions( $id, &$dbw ) {
 20+ if( !is_array( $id ) )
 21+ $id = array( $id );
 22+ $dbw->delete( 'revision', array( 'rev_id' => $id ), 'deleteRevision' );
 23+}
 24+
 25+/**
 26+ * Spit out script usage information and exit
 27+ */
 28+function showUsage() {
 29+ echo( "Finds revisions which refer to nonexisting pages and deletes them from the database\n" );
 30+ echo( "USAGE: php deleteOrphanedRevisions.php [--report]\n\n" );
 31+ echo( " --report : Prints out a count of affected revisions but doesn't delete them\n\n" );
 32+}
 33+
 34+?>
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/deleteOrphanedRevisions.inc.php
___________________________________________________________________
Added: svn:eol-style
135 + native
Index: trunk/phase3/maintenance/deleteOrphanedRevisions.php
@@ -0,0 +1,55 @@
 2+<?php
 3+
 4+/**
 5+ * Maintenance script to delete revisions which refer to a nonexisting page
 6+ * Sometimes manual deletion done in a rush leaves crap in the database
 7+ *
 8+ * @package MediaWiki
 9+ * @subpackage Maintenance
 10+ * @author Rob Church <robchur@gmail.com>
 11+ * @todo More efficient cleanup of text records
 12+ */
 13+
 14+$options = array( 'report', 'help' );
 15+require_once( 'commandLine.inc' );
 16+require_once( 'deleteOrphanedRevisions.inc.php' );
 17+echo( "Delete Orphaned Revisions\n" );
 18+
 19+if( isset( $options['help'] ) )
 20+ showUsage();
 21+
 22+$report = isset( $options['report'] );
 23+
 24+$dbw =& wfGetDB( DB_MASTER );
 25+$dbw->immediateBegin();
 26+extract( $dbw->tableNames( 'page', 'revision' ) );
 27+
 28+# Find all the orphaned revisions
 29+echo( "Checking for orphaned revisions..." );
 30+$sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id WHERE page_namespace IS NULL";
 31+$res = $dbw->query( $sql, 'deleteOrphanedRevisions' );
 32+
 33+# Stash 'em all up for deletion (if needed)
 34+while( $row = $dbw->fetchObject( $res ) )
 35+ $revisions[] = $row->rev_id;
 36+$dbw->freeResult( $res );
 37+$count = count( $revisions );
 38+echo( "found {$count}.\n" );
 39+
 40+# Nothing to do?
 41+if( $report || $count == 0 ) {
 42+ $dbw->immediateCommit();
 43+ exit();
 44+}
 45+
 46+# Delete each revision
 47+echo( "Deleting..." );
 48+deleteRevisions( $revisions, $dbw );
 49+echo( "done.\n" );
 50+
 51+# Close the transaction and call the script to purge unused text records
 52+$dbw->immediateCommit();
 53+require_once( 'purgeOldText.inc' );
 54+PurgeRedundantText( true );
 55+
 56+?>
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/deleteOrphanedRevisions.php
___________________________________________________________________
Added: svn:eol-style
157 + native
Index: trunk/phase3/RELEASE-NOTES
@@ -281,6 +281,7 @@
282282 * (bug 5962) Update for Italian language (it)
283283 * Suppress images in galleries which appear on the bad image list (when rendering
284284 for a wiki page; galleries in special pages and categories are unaffected)
 285+* Maintenance script to remove orphaned revisions from the database
285286
286287 == Compatibility ==
287288

Status & tagging log