Split user table into two parts: user and user_rights, for single login. BUG#57
[lhc/web/wiklou.git] / maintenance / updaters.inc
1 <?php
2
3 function do_revision_updates() {
4 global $wgSoftwareRevision;
5 if ( $wgSoftwareRevision < 1001 ) {
6 update_passwords();
7 }
8 }
9
10 function update_passwords() {
11 global $wgDatabase;
12 $fname = "Update script: update_passwords()";
13 print "\nIt appears that you need to update the user passwords in your\n" .
14 "database. If you have already done this (if you've run this update\n" .
15 "script once before, for example), doing so again will make all your\n" .
16 "user accounts inaccessible, so be sure you only do this once.\n" .
17 "Update user passwords? (yes/no)";
18
19 $resp = readconsole();
20 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
21
22 $sql = "SELECT user_id,user_password FROM user";
23 $source = $wgDatabase->query( $sql, $fname );
24
25 while ( $row = $wgDatabase->fetchObject( $source ) ) {
26 $id = $row->user_id;
27 $oldpass = $row->user_password;
28 $newpass = md5( "{$id}-{$oldpass}" );
29
30 $sql = "UPDATE user SET user_password='{$newpass}' " .
31 "WHERE user_id={$id}";
32 $wgDatabase->query( $sql, $fname );
33 }
34 }
35
36 function do_ipblocks_update() {
37 global $wgDatabase;
38
39 $do1 = $do2 = false;
40
41 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_id" ) ) {
42 $do1 = true;
43 }
44 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_expiry" ) ) {
45 $do2 = true;
46 }
47
48 if ( $do1 || $do2 ) {
49 echo "Updating ipblocks table... ";
50 if ( $do1 ) {
51 dbsource( "maintenance/archives/patch-ipblocks.sql", $wgDatabase );
52 }
53 if ( $do2 ) {
54 dbsource( "maintenance/archives/patch-ipb_expiry.sql", $wgDatabase );
55 }
56 echo "ok\n";
57 } else {
58 echo "...ipblocks is up to date.\n";
59 }
60
61 }
62
63
64 function do_interwiki_update() {
65 # Check that interwiki table exists; if it doesn't source it
66 global $wgDatabase;
67 if( $wgDatabase->tableExists( "interwiki" ) ) {
68 echo "...already have interwiki table\n";
69 return true;
70 }
71 echo "Creating interwiki table: ";
72 dbsource( "maintenance/archives/patch-interwiki.sql" );
73 echo "ok\n";
74 echo "Adding default interwiki definitions: ";
75 dbsource( "maintenance/interwiki.sql" );
76 echo "ok\n";
77 }
78
79 function do_index_update() {
80 # Check that proper indexes are in place
81 global $wgDatabase;
82 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
83 if( $meta->multiple_key == 0 ) {
84 echo "Updating indexes to 20031107: ";
85 dbsource( "maintenance/archives/patch-indexes.sql" );
86 echo "ok\n";
87 return true;
88 }
89 echo "...indexes seem up to 20031107 standards\n";
90 return false;
91 }
92
93 function do_linkscc_update() {
94 // Create linkscc if necessary
95 global $wgDatabase;
96 if( $wgDatabase->tableExists( "linkscc" ) ) {
97 echo "...have linkscc table.\n";
98 } else {
99 echo "Adding linkscc table... ";
100 dbsource( "maintenance/archives/patch-linkscc.sql", $wgDatabase );
101 echo "ok\n";
102 }
103 }
104
105 function do_linkscc_1_3_update() {
106 // Update linkscc table to 1.3 schema if necessary
107 global $wgDatabase, $wgVersion;
108 if( ( strpos( "1.3", $wgVersion ) === 0 ) && $wgDatabase->tableExists( "linkscc" )
109 && $wgDatabase->fieldExists( "linkscc", "lcc_title" ) ) {
110 echo "Altering lcc_title field from linkscc table... ";
111 dbsource( "maintenance/archives/patch-linkscc-1.3.sql", $wgDatabase );
112 echo "ok\n";
113 } else {
114 echo "...linkscc is up to date, or does not exist. Good.\n";
115 }
116 }
117
118 function do_hitcounter_update() {
119 // Create hitcounter if necessary
120 global $wgDatabase;
121 if( $wgDatabase->tableExists( "hitcounter" ) ) {
122 echo "...have hitcounter table.\n";
123 } else {
124 echo "Adding hitcounter table... ";
125 dbsource( "maintenance/archives/patch-hitcounter.sql", $wgDatabase );
126 echo "ok\n";
127 }
128 }
129
130 function do_recentchanges_update() {
131 global $wgDatabase;
132 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_type" ) ) {
133 echo "Adding rc_type, rc_moved_to_ns, rc_moved_to_title...";
134 dbsource( "maintenance/archives/patch-rc_type.sql" , $wgDatabase );
135 echo "ok\n";
136 }
137 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_ip" ) ) {
138 echo "Adding rc_ip...";
139 dbsource( "maintenance/archives/patch-rc_ip.sql", $wgDatabase );
140 echo "ok\n";
141 }
142 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_id" ) ) {
143 echo "Adding rc_id...";
144 dbsource( "maintenance/archives/patch-rc_id.sql", $wgDatabase );
145 echo "ok\n";
146 }
147 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_patrolled" ) ) {
148 echo "Adding rc_patrolled...";
149 dbsource( "maintenance/archives/patch-rc-patrol.sql", $wgDatabase );
150 echo "ok\n";
151 }
152 }
153
154 function do_user_real_name_update() {
155 global $wgDatabase;
156 if ( $wgDatabase->fieldExists( "user", "user_real_name" ) ) {
157 echo "...have user_real_name field in user table.\n";
158 } else {
159 echo "Adding user_real_name field to table user...";
160 dbsource( "maintenance/archives/patch-user-realname.sql" , $wgDatabase );
161 echo "ok\n";
162 }
163 }
164
165 function do_querycache_update() {
166 global $wgDatabase;
167 if( $wgDatabase->tableExists( "querycache" ) ) {
168 echo "...have special page querycache table.\n";
169 } else {
170 echo "Adding querycache table for slow special pages... ";
171 dbsource( "maintenance/archives/patch-querycache.sql", $wgDatabase );
172 echo "ok\n";
173 }
174 }
175
176 function do_objectcache_update() {
177 global $wgDatabase;
178 if( $wgDatabase->tableExists( "objectcache" ) ) {
179 echo "...have objectcache table.\n";
180 } else {
181 echo "Adding objectcache table for message caching... ";
182 dbsource( "maintenance/archives/patch-objectcache.sql", $wgDatabase );
183 echo "ok\n";
184 }
185 }
186
187 function do_categorylinks_update() {
188 global $wgDatabase;
189 if( $wgDatabase->tableExists( "categorylinks" ) ) {
190 echo "...have categorylinks table.\n";
191 } else {
192 echo "Adding categorylinks table for category management... ";
193 dbsource( "maintenance/archives/patch-categorylinks.sql", $wgDatabase );
194 echo "ok\n";
195 }
196 }
197
198 function do_image_name_unique_update() {
199 global $wgDatabase;
200 if ( $wgDatabase->indexUnique( 'image', 'img_name' ) ) {
201 echo "...img_name already unique.\n";
202 } else {
203 echo "Making the img_name index unique... ";
204 dbsource( "maintenance/archives/patch-image_name_unique.sql", $wgDatabase );
205 echo "ok\n";
206 }
207 }
208
209 function do_logging_update() {
210 global $wgDatabase;
211 if ( $wgDatabase->tableExists( 'logging' ) ) {
212 echo "...logging table already unique.\n";
213 } else {
214 echo "Creating logging table and adjusting recentchanges... ";
215 dbsource( "maintenance/archives/patch-logging.sql", $wgDatabase );
216 echo "ok\n";
217 }
218 }
219
220 function do_user_rights_update() {
221 global $wgDatabase;
222 if ( $wgDatabase->tableExists( 'user_rights' ) ) {
223 echo "...user_rights table already exists.\n";
224 } else {
225 echo 'Creating user rights table...';
226 dbsource( 'maintenance/archives/patch-user_rights.sql', $wgDatabase );
227 echo "ok\n";
228 }
229 }
230
231 ?>