MediaWiki  1.23.12
deleteOldRevisions.php
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/Maintenance.php';
26 
33  public function __construct() {
34  parent::__construct();
35  $this->mDescription = "Delete old (non-current) revisions from the database";
36  $this->addOption( 'delete', 'Actually perform the deletion' );
37  $this->addOption( 'page_id', 'List of page ids to work on', false );
38  }
39 
40  public function execute() {
41  $this->output( "Delete old revisions\n\n" );
42  $this->doDelete( $this->hasOption( 'delete' ), $this->mArgs );
43  }
44 
45  function doDelete( $delete = false, $args = array() ) {
46 
47  # Data should come off the master, wrapped in a transaction
48  $dbw = wfGetDB( DB_MASTER );
49  $dbw->begin( __METHOD__ );
50 
51  $pageConds = array();
52  $revConds = array();
53 
54  # If a list of page_ids was provided, limit results to that set of page_ids
55  if ( count( $args ) > 0 ) {
56  $pageConds['page_id'] = $args;
57  $revConds['rev_page'] = $args;
58  $this->output( "Limiting to page IDs " . implode( ',', $args ) . "\n" );
59  }
60 
61  # Get "active" revisions from the page table
62  $this->output( "Searching for active revisions..." );
63  $res = $dbw->select( 'page', 'page_latest', $pageConds, __METHOD__ );
64  $latestRevs = array();
65  foreach ( $res as $row ) {
66  $latestRevs[] = $row->page_latest;
67  }
68  $this->output( "done.\n" );
69 
70  # Get all revisions that aren't in this set
71  $this->output( "Searching for inactive revisions..." );
72  if ( count( $latestRevs ) > 0 ) {
73  $revConds[] = 'rev_id NOT IN (' . $dbw->makeList( $latestRevs ) . ')';
74  }
75  $res = $dbw->select( 'revision', 'rev_id', $revConds, __METHOD__ );
76  $oldRevs = array();
77  foreach ( $res as $row ) {
78  $oldRevs[] = $row->rev_id;
79  }
80  $this->output( "done.\n" );
81 
82  # Inform the user of what we're going to do
83  $count = count( $oldRevs );
84  $this->output( "$count old revisions found.\n" );
85 
86  # Delete as appropriate
87  if ( $delete && $count ) {
88  $this->output( "Deleting..." );
89  $dbw->delete( 'revision', array( 'rev_id' => $oldRevs ), __METHOD__ );
90  $this->output( "done.\n" );
91  }
92 
93  # This bit's done
94  # Purge redundant text records
95  $dbw->commit( __METHOD__ );
96  if ( $delete ) {
97  $this->purgeRedundantText( true );
98  }
99  }
100 }
101 
102 $maintClass = "DeleteOldRevisions";
103 require_once RUN_MAINTENANCE_IF_MAIN;
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$maintClass
$maintClass
Definition: deleteOldRevisions.php:102
DeleteOldRevisions
Maintenance script that deletes old (non-current) revisions from the database.
Definition: deleteOldRevisions.php:32
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3706
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
DeleteOldRevisions\execute
execute()
Do the actual work.
Definition: deleteOldRevisions.php:40
DeleteOldRevisions\doDelete
doDelete( $delete=false, $args=array())
Definition: deleteOldRevisions.php:45
Maintenance\purgeRedundantText
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
Definition: Maintenance.php:943
$count
$count
Definition: UtfNormalTest2.php:96
$args
if( $line===false) $args
Definition: cdb.php:62
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
$res
$res
Definition: database.txt:21
DeleteOldRevisions\__construct
__construct()
Default constructor.
Definition: deleteOldRevisions.php:33