MediaWiki  1.23.15
update.php
Go to the documentation of this file.
1 <?php
28 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.3.2' ) < 0 ) ) {
29  require dirname( __FILE__ ) . '/../includes/PHPVersionError.php';
30  wfPHPVersionError( 'cli' );
31 }
32 
34 require_once __DIR__ . '/Maintenance.php';
35 
42  function __construct() {
43  parent::__construct();
44  $this->mDescription = "MediaWiki database updater";
45  $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
46  $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
47  $this->addOption( 'doshared', 'Also update shared tables' );
48  $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
49  $this->addOption( 'noschema', 'Only do the updates that are not done during schema updates' );
50  $this->addOption( 'schema', 'Output SQL to do the schema updates instead of doing them. Works even when $wgAllowSchemaUpdates is false', false, true );
51  $this->addOption( 'force', 'Override when $wgAllowSchemaUpdates disables this script' );
52  }
53 
54  function getDbType() {
55  /* If we used the class constant PHP4 would give a parser error here */
56  return 2 /* Maintenance::DB_ADMIN */;
57  }
58 
59  function compatChecks() {
60  // Avoid syntax error in PHP4
61  $minimumPcreVersion = constant( 'Installer::MINIMUM_PCRE_VERSION' );
62 
63  list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 );
64  if ( version_compare( $pcreVersion, $minimumPcreVersion, '<' ) ) {
65  $this->error(
66  "PCRE $minimumPcreVersion or later is required.\n" .
67  "Your PHP binary is linked with PCRE $pcreVersion.\n\n" .
68  "More information:\n" .
69  "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" .
70  "ABORTING.\n",
71  true );
72  }
73 
74  $test = new PhpXmlBugTester();
75  if ( !$test->ok ) {
76  $this->error(
77  "Your system has a combination of PHP and libxml2 versions that is buggy\n" .
78  "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
79  "Upgrade to libxml2 2.7.3 or later.\n" .
80  "ABORTING (see https://bugs.php.net/bug.php?id=45996).\n",
81  true );
82  }
83  }
84 
85  function execute() {
86  global $wgVersion, $wgLang, $wgAllowSchemaUpdates;
87 
88  if ( !$wgAllowSchemaUpdates && !( $this->hasOption( 'force' ) || $this->hasOption( 'schema' ) || $this->hasOption( 'noschema' ) ) ) {
89  $this->error( "Do not run update.php on this wiki. If you're seeing this you should\n"
90  . "probably ask for some help in performing your schema updates or use\n"
91  . "the --noschema and --schema options to get an SQL file for someone\n"
92  . "else to inspect and run.\n\n"
93  . "If you know what you are doing, you can continue with --force\n", true );
94  }
95 
96  $this->fileHandle = null;
97  if ( substr( $this->getOption( 'schema' ), 0, 2 ) === "--" ) {
98  $this->error( "The --schema option requires a file as an argument.\n", true );
99  } elseif ( $this->hasOption( 'schema' ) ) {
100  $file = $this->getOption( 'schema' );
101  $this->fileHandle = fopen( $file, "w" );
102  if ( $this->fileHandle === false ) {
103  $err = error_get_last();
104  $this->error( "Problem opening the schema file for writing: $file\n\t{$err['message']}", true );
105  }
106  }
107 
108  $wgLang = Language::factory( 'en' );
109 
110  define( 'MW_UPDATER', true );
111 
112  $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
113 
114  wfWaitForSlaves( 5 ); // let's not kill databases, shall we? ;) --tor
115 
116  if ( !$this->hasOption( 'skip-compat-checks' ) ) {
117  $this->compatChecks();
118  } else {
119  $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
120  wfCountdown( 5 );
121  }
122 
123  # Attempt to connect to the database as a privileged user
124  # This will vomit up an error if there are permissions problems
125  $db = wfGetDB( DB_MASTER );
126 
127  $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
128  if ( $db->getType() === 'sqlite' ) {
129  $this->output( "Using SQLite file: '{$db->mDatabaseFile}'\n" );
130  }
131  $this->output( "Depending on the size of your database this may take a while!\n" );
132 
133  if ( !$this->hasOption( 'quick' ) ) {
134  $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
135  wfCountDown( 5 );
136  }
137 
138  $time1 = new MWTimestamp();
139 
140  $shared = $this->hasOption( 'doshared' );
141 
142  $updates = array( 'core', 'extensions' );
143  if ( !$this->hasOption( 'schema' ) ) {
144  if ( $this->hasOption( 'noschema' ) ) {
145  $updates[] = 'noschema';
146  }
147  $updates[] = 'stats';
148  }
149 
150  $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
151  $updater->doUpdates( $updates );
152 
153  foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
154  $child = $this->runChild( $maint );
155 
156  // LoggedUpdateMaintenance is checking the updatelog itself
157  $isLoggedUpdate = is_a( $child, 'LoggedUpdateMaintenance' );
158 
159  if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
160  continue;
161  }
162 
163  $child->execute();
164  if ( !$isLoggedUpdate ) {
165  $updater->insertUpdateRow( $maint );
166  }
167  }
168 
169  if ( !$this->hasOption( 'nopurge' ) ) {
170  $updater->purgeCache();
171  }
172  $time2 = new MWTimestamp();
173 
174  $timeDiff = $time2->diff( $time1 );
175  $this->output( "\nDone in " . $timeDiff->format( "%i:%S" ) . ".\n" );
176  }
177 
178  function afterFinalSetup() {
179  global $wgLocalisationCacheConf;
180 
181  # Don't try to access the database
182  # This needs to be disabled early since extensions will try to use the l10n
183  # cache from $wgExtensionFunctions (bug 20471)
184  $wgLocalisationCacheConf = array(
185  'class' => 'LocalisationCache',
186  'storeClass' => 'LCStoreNull',
187  'storeDirectory' => false,
188  'manualRecache' => false,
189  );
190  }
191 }
192 
193 $maintClass = 'UpdateMediaWiki';
194 require_once RUN_MAINTENANCE_IF_MAIN;
MWTimestamp
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:31
UpdateMediaWiki\getDbType
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: update.php:54
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
UpdateMediaWiki
Maintenance script to run database schema updates.
Definition: update.php:41
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3714
Maintenance\runChild
runChild( $maintClass, $classFile=null)
Run a child maintenance script.
Definition: Maintenance.php:444
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
wfPHPVersionError
wfPHPVersionError( $type)
Display something vaguely comprehensible in the event of a totally unrecoverable error.
Definition: PHPVersionError.php:40
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
$test
$test
Definition: Utf8Test.php:89
UpdateMediaWiki\__construct
__construct()
Default constructor.
Definition: update.php:42
$wgUseMasterForMaintenance
if(!function_exists( 'version_compare')||(version_compare(phpversion(), '5.3.2')< 0)) $wgUseMasterForMaintenance
Definition: update.php:33
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3859
list
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
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:3668
UpdateMediaWiki\afterFinalSetup
afterFinalSetup()
Execute a callback function at the end of initialisation.
Definition: update.php:178
UpdateMediaWiki\compatChecks
compatChecks()
Definition: update.php:59
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
$maintClass
$maintClass
Definition: update.php:193
PhpXmlBugTester
Test for PHP+libxml2 bug which breaks XML input subtly with certain versions.
Definition: PhpBugTests.php:30
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
UpdateMediaWiki\execute
execute()
Do the actual work.
Definition: update.php:85
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
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
wfCountDown
wfCountDown( $seconds)
Count down from $seconds to zero on the terminal, with a one-second pause between showing each number...
Definition: GlobalFunctions.php:3886