MediaWiki REL1_28
Go to the documentation of this file.
25require_once __DIR__ . '/Maintenance.php';
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription( '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 }
40 public function execute() {
41 $this->output( "Delete old revisions\n\n" );
42 $this->doDelete( $this->hasOption( 'delete' ), $this->mArgs );
43 }
45 function doDelete( $delete = false, $args = [] ) {
47 # Data should come off the master, wrapped in a transaction
48 $dbw = $this->getDB( DB_MASTER );
49 $this->beginTransaction( $dbw, __METHOD__ );
51 $pageConds = [];
52 $revConds = [];
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 }
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 = [];
65 foreach ( $res as $row ) {
66 $latestRevs[] = $row->page_latest;
67 }
68 $this->output( "done.\n" );
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 = [];
77 foreach ( $res as $row ) {
78 $oldRevs[] = $row->rev_id;
79 }
80 $this->output( "done.\n" );
82 # Inform the user of what we're going to do
83 $count = count( $oldRevs );
84 $this->output( "$count old revisions found.\n" );
86 # Delete as appropriate
87 if ( $delete && $count ) {
88 $this->output( "Deleting..." );
89 $dbw->delete( 'revision', [ 'rev_id' => $oldRevs ], __METHOD__ );
90 $this->output( "done.\n" );
91 }
93 # This bit's done
94 # Purge redundant text records
95 $this->commitTransaction( $dbw, __METHOD__ );
96 if ( $delete ) {
97 $this->purgeRedundantText( true );
98 }
99 }
102$maintClass = "DeleteOldRevisions";
103require_once RUN_MAINTENANCE_IF_MAIN;
if( $line===false) $args
Definition cdb.php:64
Maintenance script that deletes old (non-current) revisions from the database.
Do the actual work.
doDelete( $delete=false, $args=[])
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition database.txt:21
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
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
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:37
Definition defines.php:23