MediaWiki REL1_32
cleanupAncientTables.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
33
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Cleanup ancient tables and indexes' );
37 $this->addOption( 'force', 'Actually run this script' );
38 }
39
40 public function execute() {
41 if ( !$this->hasOption( 'force' ) ) {
42 $this->error( "This maintenance script will remove old columns and indexes.\n"
43 . "It is recommended to backup your database first, and ensure all your data has\n"
44 . "been migrated to newer tables. If you want to continue, run this script again\n"
45 . "with --force.\n"
46 );
47 }
48
49 $db = $this->getDB( DB_MASTER );
50 $ancientTables = [
51 'blobs', // 1.4
52 'brokenlinks', // 1.4
53 'cur', // 1.4
54 'ip_blocks_old', // Temporary in 1.6
55 'links', // 1.4
56 'linkscc', // 1.4
57 // 'math', // 1.18, but don't want to drop if math extension is enabled...
58 'old', // 1.4
59 'oldwatchlist', // pre 1.1?
60 'trackback', // 1.19
61 'user_rights', // 1.5
62 'validate', // 1.6
63 ];
64
65 foreach ( $ancientTables as $table ) {
66 if ( $db->tableExists( $table, __METHOD__ ) ) {
67 $this->output( "Dropping table $table..." );
68 $db->dropTable( $table, __METHOD__ );
69 $this->output( "done.\n" );
70 }
71 }
72
73 $this->output( "Cleaning up text table\n" );
74
75 $oldIndexes = [
76 'old_namespace',
77 'old_timestamp',
78 'name_title_timestamp',
79 'user_timestamp',
80 'usertext_timestamp',
81 ];
82 foreach ( $oldIndexes as $index ) {
83 if ( $db->indexExists( 'text', $index, __METHOD__ ) ) {
84 $this->output( "Dropping index $index from the text table..." );
85 $db->query( "DROP INDEX " . $db->addIdentifierQuotes( $index )
86 . " ON " . $db->tableName( 'text' ) );
87 $this->output( "done.\n" );
88 }
89 }
90
91 $oldFields = [
92 'old_namespace',
93 'old_title',
94 'old_comment',
95 'old_user',
96 'old_user_text',
97 'old_timestamp',
98 'old_minor_edit',
99 'inverse_timestamp',
100 ];
101 foreach ( $oldFields as $field ) {
102 if ( $db->fieldExists( 'text', $field, __METHOD__ ) ) {
103 $this->output( "Dropping the $field field from the text table..." );
104 $db->query( "ALTER TABLE " . $db->tableName( 'text' )
105 . " DROP COLUMN " . $db->addIdentifierQuotes( $field ) );
106 $this->output( "done.\n" );
107 }
108 }
109 $this->output( "Done!\n" );
110 }
111}
112
113$maintClass = CleanupAncientTables::class;
114require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to cleans up old database tables, dropping old indexes and fields.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
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
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:26