r52616 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52615‎ | r52616 | r52617 >
Date:00:32, 1 July 2009
Author:demon
Status:deferred
Tags:
Comment:
* Missing globals in eval
* Port dumpLinks, deleteOldRevisions, deleteOrphanedRevisions
Modified paths:
  • /branches/maintenance-work/maintenance/deleteOldRevisions.inc (deleted) (history)
  • /branches/maintenance-work/maintenance/deleteOldRevisions.php (modified) (history)
  • /branches/maintenance-work/maintenance/deleteOrphanedRevisions.inc (deleted) (history)
  • /branches/maintenance-work/maintenance/deleteOrphanedRevisions.php (modified) (history)
  • /branches/maintenance-work/maintenance/dumpLinks.php (modified) (history)
  • /branches/maintenance-work/maintenance/eval.php (modified) (history)

Diff [purge]

Index: branches/maintenance-work/maintenance/deleteOldRevisions.inc
@@ -1,68 +0,0 @@
2 -<?php
3 -/**
4 - * Support functions for the deleteOldRevisions script
5 - *
6 - * @file
7 - * @ingroup Maintenance
8 - * @author Rob Church <robchur@gmail.com>
9 - */
10 -
11 -require_once( 'purgeOldText.inc' );
12 -
13 -function DeleteOldRevisions( $delete = false, $args = array() ) {
14 -
15 - # Data should come off the master, wrapped in a transaction
16 - $dbw = wfGetDB( DB_MASTER );
17 - $dbw->begin();
18 -
19 - $tbl_pag = $dbw->tableName( 'page' );
20 - $tbl_rev = $dbw->tableName( 'revision' );
21 -
22 - $pageIdClause = '';
23 - $revPageClause = '';
24 -
25 - # If a list of page_ids was provided, limit results to that set of page_ids
26 - if ( sizeof( $args ) > 0 ) {
27 - $pageIdList = implode( ',', $args );
28 - $pageIdClause = " WHERE page_id IN ({$pageIdList})";
29 - $revPageClause = " AND rev_page IN ({$pageIdList})";
30 - echo( "Limiting to {$tbl_pag}.page_id IN ({$pageIdList})\n" );
31 - }
32 -
33 - # Get "active" revisions from the page table
34 - echo( "Searching for active revisions..." );
35 - $res = $dbw->query( "SELECT page_latest FROM $tbl_pag{$pageIdClause}" );
36 - while( $row = $dbw->fetchObject( $res ) ) {
37 - $cur[] = $row->page_latest;
38 - }
39 - echo( "done.\n" );
40 -
41 - # Get all revisions that aren't in this set
42 - echo( "Searching for inactive revisions..." );
43 - $set = implode( ', ', $cur );
44 - $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_id NOT IN ( $set ){$revPageClause}" );
45 - while( $row = $dbw->fetchObject( $res ) ) {
46 - $old[] = $row->rev_id;
47 - }
48 - echo( "done.\n" );
49 -
50 - # Inform the user of what we're going to do
51 - $count = count( $old );
52 - echo( "$count old revisions found.\n" );
53 -
54 - # Delete as appropriate
55 - if( $delete && $count ) {
56 - echo( "Deleting..." );
57 - $set = implode( ', ', $old );
58 - $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
59 - echo( "done.\n" );
60 - }
61 -
62 - # This bit's done
63 - # Purge redundant text records
64 - $dbw->commit();
65 - if( $delete ) {
66 - PurgeRedundantText( true );
67 - }
68 -
69 -}
Index: branches/maintenance-work/maintenance/deleteOrphanedRevisions.inc
@@ -1,32 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Support functions for the deleteOrphanedRevisions maintenance script
6 - *
7 - * @file
8 - * @ingroup 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 -
Index: branches/maintenance-work/maintenance/dumpLinks.php
@@ -30,34 +30,45 @@
3131 * @ingroup Mainatenance
3232 */
3333
34 -require_once 'commandLine.inc';
 34+require_once( "Maintenance.php" );
3535
36 -$dbr = wfGetDB( DB_SLAVE );
37 -$result = $dbr->select( array( 'pagelinks', 'page' ),
38 - array(
39 - 'page_id',
40 - 'page_namespace',
41 - 'page_title',
42 - 'pl_namespace',
43 - 'pl_title' ),
44 - array( 'page_id=pl_from' ),
45 - 'dumpLinks',
46 - array( 'ORDER BY' => 'page_id' ) );
 36+class DumpLinks extends Maintenance {
 37+ public function __construct() {
 38+ parent::__construct();
 39+ $this->mDescription = "Quick demo hack to generate a plaintext link dump";
 40+ }
4741
48 -$lastPage = null;
49 -while( $row = $dbr->fetchObject( $result ) ) {
50 - if( $lastPage != $row->page_id ) {
51 - if( isset( $lastPage ) ) {
52 - print "\n";
 42+ public function execute() {
 43+ $dbr = wfGetDB( DB_SLAVE );
 44+ $result = $dbr->select( array( 'pagelinks', 'page' ),
 45+ array(
 46+ 'page_id',
 47+ 'page_namespace',
 48+ 'page_title',
 49+ 'pl_namespace',
 50+ 'pl_title' ),
 51+ array( 'page_id=pl_from' ),
 52+ __METHOD__,
 53+ array( 'ORDER BY' => 'page_id' ) );
 54+
 55+ $lastPage = null;
 56+ while( $row = $dbr->fetchObject( $result ) ) {
 57+ if( $lastPage != $row->page_id ) {
 58+ if( isset( $lastPage ) ) {
 59+ $this->output( "\n" );
 60+ }
 61+ $page = Title::makeTitle( $row->page_namespace, $row->page_title );
 62+ $this->output( $page->getPrefixedUrl() );
 63+ $lastPage = $row->page_id;
 64+ }
 65+ $link = Title::makeTitle( $row->pl_namespace, $row->pl_title );
 66+ $this-output( " " . $link->getPrefixedUrl() );
5367 }
54 - $page = Title::makeTitle( $row->page_namespace, $row->page_title );
55 - print $page->getPrefixedUrl();
56 - $lastPage = $row->page_id;
 68+ if( isset( $lastPage ) )
 69+ $this->output( "\n" );
5770 }
58 - $link = Title::makeTitle( $row->pl_namespace, $row->pl_title );
59 - print " " . $link->getPrefixedUrl();
6071 }
61 -if( isset( $lastPage ) )
62 - print "\n";
6372
 73+$maintClass = "DumpLinks";
 74+require_once( DO_MAINTENANCE );
6475
Index: branches/maintenance-work/maintenance/deleteOldRevisions.php
@@ -8,22 +8,81 @@
99 * @author Rob Church <robchur@gmail.com>
1010 */
1111
12 -$options = array( 'delete', 'help' );
13 -require_once( 'commandLine.inc' );
14 -require_once( 'deleteOldRevisions.inc' );
 12+require_once( "Maintenance.php" );
1513
16 -echo( "Delete Old Revisions\n\n" );
 14+class DeleteOldRevisions extends Maintenance {
 15+ public function __construct() {
 16+ parent::__construct();
 17+ $this->mDescription = "Delete old (non-current) revisions from the database";
 18+ $this->addOption( 'delete', 'Actually perform the deletion' );
 19+ }
 20+
 21+ public function execute() {
 22+ $this->output( "Delete old revisions\n\n" );
 23+ if( count( $this->mArgs ) < 1 ) {
 24+ $this->error( "Must pass at least 1 page_id", true );
 25+ }
 26+ $this->doDelete( $this->hasOption( 'delete' ), $this->mArgs );
 27+ }
 28+
 29+ function doDelete( $delete = false, $args = array() ) {
1730
18 -if( @$options['help'] ) {
19 - ShowUsage();
20 -} else {
21 - DeleteOldRevisions( @$options['delete'], $args );
 31+ # Data should come off the master, wrapped in a transaction
 32+ $dbw = wfGetDB( DB_MASTER );
 33+ $dbw->begin();
 34+
 35+ $tbl_pag = $dbw->tableName( 'page' );
 36+ $tbl_rev = $dbw->tableName( 'revision' );
 37+
 38+ $pageIdClause = '';
 39+ $revPageClause = '';
 40+
 41+ # If a list of page_ids was provided, limit results to that set of page_ids
 42+ if ( sizeof( $args ) > 0 ) {
 43+ $pageIdList = implode( ',', $args );
 44+ $pageIdClause = " WHERE page_id IN ({$pageIdList})";
 45+ $revPageClause = " AND rev_page IN ({$pageIdList})";
 46+ $this->output( "Limiting to {$tbl_pag}.page_id IN ({$pageIdList})\n" );
 47+ }
 48+
 49+ # Get "active" revisions from the page table
 50+ $this->output( "Searching for active revisions..." );
 51+ $res = $dbw->query( "SELECT page_latest FROM $tbl_pag{$pageIdClause}" );
 52+ while( $row = $dbw->fetchObject( $res ) ) {
 53+ $cur[] = $row->page_latest;
 54+ }
 55+ $this->output( "done.\n" );
 56+
 57+ # Get all revisions that aren't in this set
 58+ $this->output( "Searching for inactive revisions..." );
 59+ $set = implode( ', ', $cur );
 60+ $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_id NOT IN ( $set ){$revPageClause}" );
 61+ while( $row = $dbw->fetchObject( $res ) ) {
 62+ $old[] = $row->rev_id;
 63+ }
 64+ $this->output( "done.\n" );
 65+
 66+ # Inform the user of what we're going to do
 67+ $count = count( $old );
 68+ $this->output( "$count old revisions found.\n" );
 69+
 70+ # Delete as appropriate
 71+ if( $delete && $count ) {
 72+ $this->output( "Deleting..." );
 73+ $set = implode( ', ', $old );
 74+ $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
 75+ $this->output( "done.\n" );
 76+ }
 77+
 78+ # This bit's done
 79+ # Purge redundant text records
 80+ $dbw->commit();
 81+ if( $delete ) {
 82+ $this->purgeRedundantText( true );
 83+ }
 84+ }
2285 }
2386
24 -function ShowUsage() {
25 - echo( "Deletes non-current revisions from the database.\n\n" );
26 - echo( "Usage: php deleteOldRevisions.php [--delete|--help] [<page_id> ...]\n\n" );
27 - echo( "delete : Performs the deletion\n" );
28 - echo( " help : Show this usage information\n" );
29 -}
 87+$maintClass = "DeleteOldRevisions";
 88+require_once( DO_MAINTENANCE );
3089
Index: branches/maintenance-work/maintenance/deleteOrphanedRevisions.php
@@ -9,48 +9,67 @@
1010 * @author Rob Church <robchur@gmail.com>
1111 * @todo More efficient cleanup of text records
1212 */
13 -
14 -$options = array( 'report', 'help' );
15 -require_once( 'commandLine.inc' );
16 -require_once( 'deleteOrphanedRevisions.inc' );
17 -echo( "Delete Orphaned Revisions\n" );
1813
19 -if( isset( $options['help'] ) ) {
20 - showUsage();
21 - exit(1);
22 -}
 14+require_once( "Maintenance.php" );
2315
24 -$report = isset( $options['report'] );
 16+class DeleteOrphanedRevisions extends Maintenance {
 17+ public function __construct() {
 18+ parent::__construct();
 19+ $this->mDescription = "Maintenance script to delete revisions which refer to a nonexisting page";
 20+ $this->addOption( 'report', 'Prints out a count of affected revisions but doesn\'t delete them' );
 21+ }
2522
26 -$dbw = wfGetDB( DB_MASTER );
27 -$dbw->immediateBegin();
28 -extract( $dbw->tableNames( 'page', 'revision' ) );
 23+ public function execute() {
 24+ $this->output( "Delete Orphaned Revisions\n" );
2925
30 -# Find all the orphaned revisions
31 -echo( "Checking for orphaned revisions..." );
32 -$sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id WHERE page_namespace IS NULL";
33 -$res = $dbw->query( $sql, 'deleteOrphanedRevisions' );
 26+ $report = $this->hasOption('report');
3427
35 -# Stash 'em all up for deletion (if needed)
36 -while( $row = $dbw->fetchObject( $res ) )
37 - $revisions[] = $row->rev_id;
38 -$dbw->freeResult( $res );
39 -$count = count( $revisions );
40 -echo( "found {$count}.\n" );
 28+ $dbw = wfGetDB( DB_MASTER );
 29+ $dbw->immediateBegin();
 30+ list( $page, $revision ) = $dbw->tableNames( 'page', 'revision' );
4131
42 -# Nothing to do?
43 -if( $report || $count == 0 ) {
44 - $dbw->immediateCommit();
45 - exit(0);
 32+ # Find all the orphaned revisions
 33+ $this->output( "Checking for orphaned revisions..." );
 34+ $sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id WHERE page_namespace IS NULL";
 35+ $res = $dbw->query( $sql, 'deleteOrphanedRevisions' );
 36+
 37+ # Stash 'em all up for deletion (if needed)
 38+ while( $row = $dbw->fetchObject( $res ) )
 39+ $revisions[] = $row->rev_id;
 40+ $dbw->freeResult( $res );
 41+ $count = count( $revisions );
 42+ $this->output( "found {$count}.\n" );
 43+
 44+ # Nothing to do?
 45+ if( $report || $count == 0 ) {
 46+ $dbw->immediateCommit();
 47+ exit(0);
 48+ }
 49+
 50+ # Delete each revision
 51+ $this->output( "Deleting..." );
 52+ $this->deleteRevs( $revisions, $dbw );
 53+ $this->output( "done.\n" );
 54+
 55+ # Close the transaction and call the script to purge unused text records
 56+ $dbw->immediateCommit();
 57+ $this->purgeRedundantText( true );
 58+ }
 59+
 60+ /**
 61+ * Delete one or more revisions from the database
 62+ * Do this inside a transaction
 63+ *
 64+ * @param $id Array of revision id values
 65+ * @param $db Database class (needs to be a master)
 66+ */
 67+ private function deleteRevs( $id, &$dbw ) {
 68+ if( !is_array( $id ) )
 69+ $id = array( $id );
 70+ $dbw->delete( 'revision', array( 'rev_id' => $id ), __METHOD__ );
 71+ }
4672 }
4773
48 -# Delete each revision
49 -echo( "Deleting..." );
50 -deleteRevisions( $revisions, $dbw );
51 -echo( "done.\n" );
 74+$maintClass = "DeleteOrphanedRevisions";
 75+require_once( DO_MAINTENANCE );
5276
53 -# Close the transaction and call the script to purge unused text records
54 -$dbw->immediateCommit();
55 -require_once( 'purgeOldText.inc' );
56 -PurgeRedundantText( true );
57 -
Index: branches/maintenance-work/maintenance/eval.php
@@ -28,7 +28,7 @@
2929 }
3030
3131 public function execute() {
32 - global $wgUseNormalUser;
 32+ global $wgUseNormalUser, $wgDebugFunctionEntry, $wgDebugLogFile;
3333 $wgUseNormalUser = (bool)getenv('MW_WIKIUSER');
3434 if ( $this->hasOption('d') ) {
3535 $d = $this->getOption('d');

Status & tagging log