MediaWiki  1.23.8
deleteRevision.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
32 class DeleteRevision extends Maintenance {
33 
34  public function __construct() {
35  parent::__construct();
36  $this->mDescription = "Delete one or more revisions by moving them to the archive table";
37  }
38 
39  public function execute() {
40  if ( count( $this->mArgs ) == 0 ) {
41  $this->error( "No revisions specified", true );
42  }
43 
44  $this->output( "Deleting revision(s) " . implode( ',', $this->mArgs ) .
45  " from " . wfWikiID() . "...\n" );
46  $dbw = wfGetDB( DB_MASTER );
47 
48  $affected = 0;
49  foreach ( $this->mArgs as $revID ) {
50  $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
51  array(
52  'ar_namespace' => 'page_namespace',
53  'ar_title' => 'page_title',
54  'ar_page_id' => 'page_id',
55  'ar_comment' => 'rev_comment',
56  'ar_user' => 'rev_user',
57  'ar_user_text' => 'rev_user_text',
58  'ar_timestamp' => 'rev_timestamp',
59  'ar_minor_edit' => 'rev_minor_edit',
60  'ar_rev_id' => 'rev_id',
61  'ar_text_id' => 'rev_text_id',
62  'ar_deleted' => 'rev_deleted',
63  'ar_len' => 'rev_len',
64  ), array(
65  'rev_id' => $revID,
66  'page_id = rev_page'
67  ), __METHOD__
68  );
69  if ( !$dbw->affectedRows() ) {
70  $this->output( "Revision $revID not found\n" );
71  } else {
72  $affected += $dbw->affectedRows();
73  $pageID = $dbw->selectField( 'revision', 'rev_page', array( 'rev_id' => $revID ), __METHOD__ );
74  $pageLatest = $dbw->selectField( 'page', 'page_latest', array( 'page_id' => $pageID ), __METHOD__ );
75  $dbw->delete( 'revision', array( 'rev_id' => $revID ) );
76  if ( $pageLatest == $revID ) {
77  // Database integrity
78  $newLatest = $dbw->selectField( 'revision', 'rev_id', array( 'rev_page' => $pageID ), __METHOD__, array( 'ORDER BY' => 'rev_timestamp DESC' ) );
79  $dbw->update( 'page', array( 'page_latest' => $newLatest ), array( 'page_id' => $pageID ), __METHOD__ );
80  }
81  }
82  }
83  $this->output( "Deleted $affected revisions\n" );
84  }
85 }
86 
87 $maintClass = "DeleteRevision";
88 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
DeleteRevision\__construct
__construct()
Default constructor.
Definition: deleteRevision.php:34
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.
DeleteRevision
Maintenance script that deletes one or more revisions by moving them to the archive table.
Definition: deleteRevision.php:32
DeleteRevision\execute
execute()
Do the actual work.
Definition: deleteRevision.php:39
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:3613
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\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
$maintClass
$maintClass
Definition: deleteRevision.php:87