3 # Update already-installed software
6 include( "./install-utils.inc" );
7 install_version_checks();
9 if ( ! ( is_readable( "./LocalSettings.php" )
10 && is_readable( "./AdminSettings.php" ) ) ) {
11 print "A copy of your installation's LocalSettings.php\n" .
12 "and AdminSettings.php must exist in this source directory.\n";
17 include_once( "./LocalSettings.php" );
18 include_once( "./AdminSettings.php" );
20 include( "$IP/Version.php" );
22 if( $wgSitename == "MediaWiki" ) {
23 die( "You must set the site name in \$wgSitename before installation.\n\n" );
26 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
27 print "To use math functions, you must first compile texvc by\n" .
28 "running \"make\" in the math directory.\n";
33 # Copy files into installation directories
37 $wgDBuser = $wgDBadminuser;
38 $wgDBpassword = $wgDBadminpassword;
40 include_once( "{$IP}/Setup.php" );
41 include_once( "./maintenance/InitialiseMessages.inc" );
43 $wgTitle = Title
::newFromText( "Update script" );
46 # Check the database for things that need to be fixed...
48 print "Checking database for necessary updates...\n";
50 $wgDatabase = Database
::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname,
51 1, false, true, false);
52 if ( !$wgDatabase->isOpen() ) {
53 print "Unable to connect to database: " . $wgDatabase->lastError() . "\n";
57 do_revision_updates();
60 do_interwiki_update();
63 do_hitcounter_update();
64 do_recentchanges_update();
77 function do_update_files() {
78 global $IP, $wgStyleSheetDirectory, $wgUploadDirectory, $wgLanguageCode, $wgDebugLogFile;
79 print "Copying files... ";
81 copyfile( ".", "index.php", $IP );
82 copyfile( ".", "redirect.php", $IP );
83 # compatibility with older versions, can be removed in a year or so
84 # (written in Feb 2004)
85 copyfile( ".", "wiki.phtml", $IP );
86 copyfile( ".", "redirect.phtml", $IP );
88 copydirectory( "./includes", $IP );
89 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
91 copyfile( "./images", "wiki.png", $wgUploadDirectory );
92 copyfile( "./images", "button_bold.png", $wgUploadDirectory );
93 copyfile( "./images", "button_extlink.png", $wgUploadDirectory );
94 copyfile( "./images", "button_headline.png", $wgUploadDirectory );
95 copyfile( "./images", "button_hr.png", $wgUploadDirectory );
96 copyfile( "./images", "button_image.png", $wgUploadDirectory );
97 copyfile( "./images", "button_italic.png", $wgUploadDirectory );
98 copyfile( "./images", "button_link.png", $wgUploadDirectory );
99 copyfile( "./images", "button_math.png", $wgUploadDirectory );
100 copyfile( "./images", "button_media.png", $wgUploadDirectory );
101 copyfile( "./images", "button_nowiki.png", $wgUploadDirectory );
102 copyfile( "./images", "button_sig.png", $wgUploadDirectory );
103 copyfile( "./images", "button_template.png", $wgUploadDirectory );
105 copyfile( "./languages", "Language.php", $IP );
106 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
108 if( !empty( $wgDebugLogFile ) ) {
109 $fp = fopen( $wgDebugLogFile, "w" );
110 if ( false === $fp ) {
111 print "Could not create log file \"{$wgDebugLogFile}\".\n";
114 $d = date( "Y-m-d H:i:s" );
115 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
120 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
121 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
122 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
125 copyfile( ".", "Version.php", $IP );
130 function do_revision_updates() {
131 global $wgSoftwareRevision;
132 if ( $wgSoftwareRevision < 1001 ) {
137 function update_passwords() {
139 $fname = "Update script: update_passwords()";
140 print "\nIt appears that you need to update the user passwords in your\n" .
141 "database. If you have already done this (if you've run this update\n" .
142 "script once before, for example), doing so again will make all your\n" .
143 "user accounts inaccessible, so be sure you only do this once.\n" .
144 "Update user passwords? (yes/no)";
146 $resp = readconsole();
147 if ( ! ( "Y" == $resp{0} ||
"y" == $resp{0} ) ) { return; }
149 $sql = "SELECT user_id,user_password FROM user";
150 $source = $wgDatabase->query( $sql, $fname );
152 while ( $row = $wgDatabase->fetchObject( $source ) ) {
154 $oldpass = $row->user_password
;
155 $newpass = md5( "{$id}-{$oldpass}" );
157 $sql = "UPDATE user SET user_password='{$newpass}' " .
158 "WHERE user_id={$id}";
159 $wgDatabase->query( $sql, $fname );
163 function do_ipblocks_update() {
168 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_id" ) ) {
171 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_expiry" ) ) {
175 if ( $do1 ||
$do2 ) {
176 echo "Updating ipblocks table... ";
178 dbsource( "maintenance/archives/patch-ipblocks.sql", $wgDatabase );
181 dbsource( "maintenance/archives/patch-ipb_expiry.sql", $wgDatabase );
185 echo "...ipblocks is up to date.\n";
191 function do_interwiki_update() {
192 # Check that interwiki table exists; if it doesn't source it
194 if( $wgDatabase->tableExists( "interwiki" ) ) {
195 echo "...already have interwiki table\n";
198 echo "Creating interwiki table: ";
199 dbsource( "maintenance/archives/patch-interwiki.sql" );
201 echo "Adding default interwiki definitions: ";
202 dbsource( "maintenance/interwiki.sql" );
206 function do_index_update() {
207 # Check that proper indexes are in place
209 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
210 if( $meta->multiple_key
== 0 ) {
211 echo "Updating indexes to 20031107: ";
212 dbsource( "maintenance/archives/patch-indexes.sql" );
216 echo "...indexes seem up to 20031107 standards\n";
220 function do_linkscc_update() {
221 // Create linkscc if necessary
223 if( $wgDatabase->tableExists( "linkscc" ) ) {
224 echo "...have linkscc table.\n";
226 echo "Adding linkscc table... ";
227 dbsource( "maintenance/archives/patch-linkscc.sql", $wgDatabase );
232 function do_hitcounter_update() {
233 // Create hitcounter if necessary
235 if( $wgDatabase->tableExists( "hitcounter" ) ) {
236 echo "...have hitcounter table.\n";
238 echo "Adding hitcounter table... ";
239 dbsource( "maintenance/archives/patch-hitcounter.sql", $wgDatabase );
244 function do_recentchanges_update() {
246 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_type" ) ) {
247 echo "Adding rc_type, rc_moved_to_ns, rc_moved_to_title...";
248 dbsource( "maintenance/archives/patch-rc_type.sql" , $wgDatabase );