MediaWiki REL1_28
Go to the documentation of this file.
27require_once __DIR__ . '/Maintenance.php';
35 public function __construct() {
36 parent::__construct();
37 $this->addDescription(
38 'Maintenance script to delete revisions which refer to a nonexisting page' );
39 $this->addOption( 'report', 'Prints out a count of affected revisions but doesn\'t delete them' );
40 }
42 public function execute() {
43 $this->output( "Delete Orphaned Revisions\n" );
45 $report = $this->hasOption( 'report' );
47 $dbw = $this->getDB( DB_MASTER );
48 $this->beginTransaction( $dbw, __METHOD__ );
49 list( $page, $revision ) = $dbw->tableNamesN( 'page', 'revision' );
51 # Find all the orphaned revisions
52 $this->output( "Checking for orphaned revisions..." );
53 $sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id "
54 . "WHERE page_namespace IS NULL";
55 $res = $dbw->query( $sql, 'deleteOrphanedRevisions' );
57 # Stash 'em all up for deletion (if needed)
58 $revisions = [];
59 foreach ( $res as $row ) {
60 $revisions[] = $row->rev_id;
61 }
62 $count = count( $revisions );
63 $this->output( "found {$count}.\n" );
65 # Nothing to do?
66 if ( $report || $count == 0 ) {
67 $this->commitTransaction( $dbw, __METHOD__ );
68 exit( 0 );
69 }
71 # Delete each revision
72 $this->output( "Deleting..." );
73 $this->deleteRevs( $revisions, $dbw );
74 $this->output( "done.\n" );
76 # Close the transaction and call the script to purge unused text records
77 $this->commitTransaction( $dbw, __METHOD__ );
78 $this->purgeRedundantText( true );
79 }
88 private function deleteRevs( $id, &$dbw ) {
89 if ( !is_array( $id ) ) {
90 $id = [ $id ];
91 }
92 $dbw->delete( 'revision', [ 'rev_id' => $id ], __METHOD__ );
93 }
96$maintClass = "DeleteOrphanedRevisions";
Maintenance script that deletes revisions which refer to a nonexisting page.
deleteRevs( $id, &$dbw)
Delete one or more revisions from the database Do this inside a transaction.
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
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
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
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition hooks.txt:2534
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