MediaWiki  1.28.3
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->addDescription( '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 = $this->getDB( DB_MASTER );
47 
48  $affected = 0;
49  foreach ( $this->mArgs as $revID ) {
50  $dbw->insertSelect( 'archive', [ 'page', 'revision' ],
51  [
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  ],
65  [
66  'rev_id' => $revID,
67  'page_id = rev_page'
68  ],
69  __METHOD__
70  );
71  if ( !$dbw->affectedRows() ) {
72  $this->output( "Revision $revID not found\n" );
73  } else {
74  $affected += $dbw->affectedRows();
75  $pageID = $dbw->selectField(
76  'revision',
77  'rev_page',
78  [ 'rev_id' => $revID ],
79  __METHOD__
80  );
81  $pageLatest = $dbw->selectField(
82  'page',
83  'page_latest',
84  [ 'page_id' => $pageID ],
85  __METHOD__
86  );
87  $dbw->delete( 'revision', [ 'rev_id' => $revID ] );
88  if ( $pageLatest == $revID ) {
89  // Database integrity
90  $newLatest = $dbw->selectField(
91  'revision',
92  'rev_id',
93  [ 'rev_page' => $pageID ],
94  __METHOD__,
95  [ 'ORDER BY' => 'rev_timestamp DESC' ]
96  );
97  $dbw->update(
98  'page',
99  [ 'page_latest' => $newLatest ],
100  [ 'page_id' => $pageID ],
101  __METHOD__
102  );
103  }
104  }
105  }
106  $this->output( "Deleted $affected revisions\n" );
107  }
108 }
109 
110 $maintClass = "DeleteRevision";
111 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that deletes one or more revisions by moving them to the archive table...
$maintClass
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
getDB($db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
const DB_MASTER
Definition: defines.php:23
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
addDescription($text)
Set the description text.
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
output($out, $channel=null)
Throw some output to the user.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
error($err, $die=0)
Throw an error to the user.