MediaWiki  1.23.6
deleteOrphanedRevisions.php
Go to the documentation of this file.
1 <?php
27 require_once __DIR__ . '/Maintenance.php';
28 
35  public function __construct() {
36  parent::__construct();
37  $this->mDescription = "Maintenance script to delete revisions which refer to a nonexisting page";
38  $this->addOption( 'report', 'Prints out a count of affected revisions but doesn\'t delete them' );
39  }
40 
41  public function execute() {
42  $this->output( "Delete Orphaned Revisions\n" );
43 
44  $report = $this->hasOption( 'report' );
45 
46  $dbw = wfGetDB( DB_MASTER );
47  $dbw->begin( __METHOD__ );
48  list( $page, $revision ) = $dbw->tableNamesN( 'page', 'revision' );
49 
50  # Find all the orphaned revisions
51  $this->output( "Checking for orphaned revisions..." );
52  $sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id WHERE page_namespace IS NULL";
53  $res = $dbw->query( $sql, 'deleteOrphanedRevisions' );
54 
55  # Stash 'em all up for deletion (if needed)
56  $revisions = array();
57  foreach ( $res as $row ) {
58  $revisions[] = $row->rev_id;
59  }
60  $count = count( $revisions );
61  $this->output( "found {$count}.\n" );
62 
63  # Nothing to do?
64  if ( $report || $count == 0 ) {
65  $dbw->commit( __METHOD__ );
66  exit( 0 );
67  }
68 
69  # Delete each revision
70  $this->output( "Deleting..." );
71  $this->deleteRevs( $revisions, $dbw );
72  $this->output( "done.\n" );
73 
74  # Close the transaction and call the script to purge unused text records
75  $dbw->commit( __METHOD__ );
76  $this->purgeRedundantText( true );
77  }
78 
86  private function deleteRevs( $id, &$dbw ) {
87  if ( !is_array( $id ) ) {
88  $id = array( $id );
89  }
90  $dbw->delete( 'revision', array( 'rev_id' => $id ), __METHOD__ );
91  }
92 }
93 
94 $maintClass = "DeleteOrphanedRevisions";
95 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
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
$maintClass
$maintClass
Definition: deleteOrphanedRevisions.php:94
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
DeleteOrphanedRevisions\execute
execute()
Do the actual work.
Definition: deleteOrphanedRevisions.php:41
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.
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
DeleteOrphanedRevisions
Maintenance script that deletes revisions which refer to a nonexisting page.
Definition: deleteOrphanedRevisions.php:34
Maintenance\purgeRedundantText
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
Definition: Maintenance.php:943
DeleteOrphanedRevisions\__construct
__construct()
Default constructor.
Definition: deleteOrphanedRevisions.php:35
$count
$count
Definition: UtfNormalTest2.php:96
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
DeleteOrphanedRevisions\deleteRevs
deleteRevs( $id, &$dbw)
Delete one or more revisions from the database Do this inside a transaction.
Definition: deleteOrphanedRevisions.php:86
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