de1ac3359911f1498eb17162b0b222c9f53495b7
[lhc/web/wiklou.git] / maintenance / updaters.inc
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 */
6
7 /** */
8
9 require_once 'convertLinks.inc';
10 require_once 'InitialiseMessages.inc';
11 require_once 'archives/moveCustomMessages.inc';
12
13 $wgNewTables = array(
14 # table patch file (in maintenance/archives)
15 array( 'linkscc', 'patch-linkscc.sql' ),
16 array( 'hitcounter', 'patch-hitcounter.sql' ),
17 array( 'querycache', 'patch-querycache.sql' ),
18 array( 'objectcache', 'patch-objectcache.sql' ),
19 array( 'categorylinks', 'patch-categorylinks.sql' ),
20 array( 'logging', 'patch-logging.sql' ),
21 array( 'user_rights', 'patch-user_rights.sql' ),
22 );
23
24 $wgNewFields = array(
25 # table field patch file (in maintenance/archives)
26 array( 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ),
27 array( 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ),
28 array( 'recentchanges', 'rc_type', 'patch-rc_type.sql' ),
29 array( 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ),
30 array( 'recentchanges', 'rc_id', 'patch-rc_id.sql' ),
31 array( 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ),
32 array( 'user', 'user_real_name', 'patch-user-realname.sql' ),
33 array( 'user', 'user_token', 'patch-user_token.sql' ),
34 array( 'user_rights', 'ur_uid', 'patch-rename-user_groups-and_rights.sql' ),
35 );
36
37 function add_table( $name, $patch ) {
38 global $wgDatabase;
39 if ( $wgDatabase->tableExists( $name ) ) {
40 echo "...$name table already exists.\n";
41 } else {
42 echo "Creating $name table...";
43 dbsource( "maintenance/archives/$patch", $wgDatabase );
44 echo "ok\n";
45 }
46 }
47
48 function add_field( $table, $field, $patch ) {
49 global $wgDatabase;
50 if ( $wgDatabase->fieldExists( $table, $field ) ) {
51 echo "...have $field field in $table table.\n";
52 } else {
53 echo "Adding $field field to table $table...";
54 dbsource( "maintenance/archives/$patch" , $wgDatabase );
55 echo "ok\n";
56 }
57 }
58
59 function do_revision_updates() {
60 global $wgSoftwareRevision;
61 if ( $wgSoftwareRevision < 1001 ) {
62 update_passwords();
63 }
64 }
65
66 function update_passwords() {
67 global $wgDatabase;
68 $fname = "Update script: update_passwords()";
69 print "\nIt appears that you need to update the user passwords in your\n" .
70 "database. If you have already done this (if you've run this update\n" .
71 "script once before, for example), doing so again will make all your\n" .
72 "user accounts inaccessible, so be sure you only do this once.\n" .
73 "Update user passwords? (yes/no)";
74
75 $resp = readconsole();
76 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
77
78 $sql = "SELECT user_id,user_password FROM user";
79 $source = $wgDatabase->query( $sql, $fname );
80
81 while ( $row = $wgDatabase->fetchObject( $source ) ) {
82 $id = $row->user_id;
83 $oldpass = $row->user_password;
84 $newpass = md5( "{$id}-{$oldpass}" );
85
86 $sql = "UPDATE user SET user_password='{$newpass}' " .
87 "WHERE user_id={$id}";
88 $wgDatabase->query( $sql, $fname );
89 }
90 }
91
92 function do_interwiki_update() {
93 # Check that interwiki table exists; if it doesn't source it
94 global $wgDatabase;
95 if( $wgDatabase->tableExists( "interwiki" ) ) {
96 echo "...already have interwiki table\n";
97 return true;
98 }
99 echo "Creating interwiki table: ";
100 dbsource( "maintenance/archives/patch-interwiki.sql" );
101 echo "ok\n";
102 echo "Adding default interwiki definitions: ";
103 dbsource( "maintenance/interwiki.sql" );
104 echo "ok\n";
105 }
106
107 function do_index_update() {
108 # Check that proper indexes are in place
109 global $wgDatabase;
110 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
111 if( $meta->multiple_key == 0 ) {
112 echo "Updating indexes to 20031107: ";
113 dbsource( "maintenance/archives/patch-indexes.sql" );
114 echo "ok\n";
115 return true;
116 }
117 echo "...indexes seem up to 20031107 standards\n";
118 return false;
119 }
120
121 function do_linkscc_1_3_update() {
122 // Update linkscc table to 1.3 schema if necessary
123 global $wgDatabase, $wgVersion;
124 if( ( strpos( "1.3", $wgVersion ) === 0 ) && $wgDatabase->tableExists( "linkscc" )
125 && $wgDatabase->fieldExists( "linkscc", "lcc_title" ) ) {
126 echo "Altering lcc_title field from linkscc table... ";
127 dbsource( "maintenance/archives/patch-linkscc-1.3.sql", $wgDatabase );
128 echo "ok\n";
129 } else {
130 echo "...linkscc is up to date, or does not exist. Good.\n";
131 }
132 }
133
134 function do_image_name_unique_update() {
135 global $wgDatabase;
136 if( $wgDatabase->indexExists( 'image', 'PRIMARY' ) ) {
137 echo "...image primary key already set.\n";
138 } else {
139 echo "Making img_name the primary key... ";
140 dbsource( "maintenance/archives/patch-image_name_primary.sql", $wgDatabase );
141 echo "ok\n";
142 }
143 }
144
145 function do_all_updates() {
146 global $wgNewTables, $wgNewFields;
147
148 # Add missing tables
149 foreach ( $wgNewTables as $tableRecord ) {
150 add_table( $tableRecord[0], $tableRecord[1] );
151 flush();
152 }
153
154 # Add missing fields
155 foreach ( $wgNewFields as $fieldRecord ) {
156 add_table( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2] );
157 flush();
158 }
159
160 # Do schema updates which require special handling
161 do_interwiki_update(); flush();
162 do_index_update(); flush();
163 do_linkscc_1_3_update(); flush();
164 convertLinks(); flush();
165 do_image_name_unique_update(); flush();
166
167 if ( isTemplateInitialised() ) {
168 print "Template namespace already initialised\n";
169 } else {
170 moveCustomMessages( 1 ); flush();
171 moveCustomMessages( 2 ); flush();
172 moveCustomMessages( 3 ); flush();
173 }
174
175 initialiseMessages(); flush();
176 }
177
178 ?>