3 if( !function_exists( "version_compare" ) ) {
4 # version_compare was introduced in 4.1.0
5 die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
7 if( version_compare( phpversion(), "4.3.2" ) < 0 ) {
8 echo "WARNING: PHP 4.3.2 or higher is recommended. Older versions from 4.1.x up may work but are not actively supported.\n\n";
10 if( !ini_get( "register_globals" ) ) {
11 echo "WARNING: register_globals is not on; MediaWiki currently relies on this option.\n\n";
16 TODO: Links cache will be very unhappy without a table like this //e23
18 CREATE TABLE linkscc (lcc_pageid INT UNSIGNED NOT NULL UNIQUE KEY,
19 lcc_title VARCHAR(255) NOT NULL UNIQUE KEY,
20 lcc_cacheobj MEDIUMBLOB NOT NULL);
26 # Update already-installed software
29 if ( ! ( is_readable( "./LocalSettings.php" )
30 && is_readable( "./AdminSettings.php" ) ) ) {
31 print "A copy of your installation's LocalSettings.php\n" .
32 "and AdminSettings.php must exist in this source directory.\n";
37 include_once( "./LocalSettings.php" );
38 include_once( "./AdminSettings.php" );
40 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
41 print "To use math functions, you must first compile texvc by\n" .
42 "running \"make\" in the math directory.\n";
49 include_once( "Version.php" );
50 include_once( "{$IP}/Setup.php" );
51 include_once( "./maintenance/InitialiseMessages.inc" );
53 $wgTitle = Title
::newFromText( "Update script" );
54 $wgCommandLineMode = true;
55 $wgAlterSpecs = array();
57 do_revision_updates();
62 # Run ALTER TABLE queries.
64 if ( count( $wgAlterSpecs ) ) {
65 $rconn = mysql_connect( $wgDBserver, $wgDBadminuser, $wgDBadminpassword );
66 mysql_select_db( $wgDBname );
68 foreach ( $wgAlterSpecs as $table => $specs ) {
69 $sql = "ALTER TABLE $table $specs";
71 $res = mysql_query( $sql, $rconn );
72 if ( $res === false ) {
73 print "MySQL error: " . mysql_error( $rconn ) . "\n";
76 mysql_close( $rconn );
81 # Copy files into installation directories
83 print "Copying files...\n";
85 copyfile( ".", "wiki.phtml", $IP );
86 copyfile( ".", "redirect.phtml", $IP );
87 copyfile( ".", "texvc.phtml", $IP );
89 copydirectory( "./includes", $IP );
90 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
92 copyfile( "./images", "wiki.png", $wgUploadDirectory );
93 copyfile( "./languages", "Language.php", $IP );
94 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
96 $fp = fopen( $wgDebugLogFile, "w" );
97 if ( false === $fp ) {
98 print "Could not create log file \"{$wgDebugLogFile}\".\n";
101 $d = date( "Y-m-d H:i:s" );
102 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
106 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
107 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
108 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
111 copyfile( ".", "Version.php", $IP );
120 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
121 global $wgInstallOwner, $wgInstallGroup;
123 $d = "{$ddir}/{$name}";
124 if ( copy( "{$sdir}/{$name}", $d ) ) {
125 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
126 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
128 # print "Copied \"{$name}\" to \"{$ddir}\".\n";
130 print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
135 function copydirectory( $source, $dest ) {
136 $handle = opendir( $source );
137 while ( false !== ( $f = readdir( $handle ) ) ) {
138 if ( "." == $f{0} ) continue;
139 # Windows turned all my CVS->cvs :(
140 if ( !strcasecmp ( "CVS", $f ) ) continue;
141 copyfile( $source, $f, $dest );
145 function readconsole() {
146 $fp = fopen( "php://stdin", "r" );
147 $resp = trim( fgets( $fp, 1024 ) );
152 function do_revision_updates() {
153 global $wgSoftwareRevision;
154 if ( $wgSoftwareRevision < 1001 ) { update_passwords(); }
157 function update_passwords() {
158 $fname = "Update script: update_passwords()";
159 print "\nIt appears that you need to update the user passwords in your\n" .
160 "database. If you have already done this (if you've run this update\n" .
161 "script once before, for example), doing so again will make all your\n" .
162 "user accounts inaccessible, so be sure you only do this once.\n" .
163 "Update user passwords? (yes/no)";
165 $resp = readconsole();
166 if ( ! ( "Y" == $resp{0} ||
"y" == $resp{0} ) ) { return; }
168 $sql = "SELECT user_id,user_password FROM user";
169 $source = wfQuery( $sql, DB_READ
, fname
);
171 while ( $row = mysql_fetch_object( $source ) ) {
173 $oldpass = $row->user_password
;
174 $newpass = md5( "{$id}-{$oldpass}" );
176 $sql = "UPDATE user SET user_password='{$newpass}' " .
177 "WHERE user_id={$id}";
178 wfQuery( $sql, DB_WRITE
, $fname );
182 function alter_ipblocks() {
183 global $wgAlterSpecs;
185 if ( wfFieldExists( "ipblocks", "ipb_id" ) ) {
189 if ( array_key_exists( "ipblocks", $wgAlterSpecs ) ) {
190 $wgAlterSpecs["ipblocks"] .= ",";
193 $wgAlterSpecs["ipblocks"] .=
194 "ADD ipb_auto tinyint(1) NOT NULL default '0', ".
195 "ADD ipb_id int(8) NOT NULL auto_increment,".
196 "ADD PRIMARY KEY (ipb_id)";