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