Refactored updaters.inc. With all those functions doing virtually the same thing...
[lhc/web/wiklou.git] / maintenance / updaters.inc
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 */
6
7 /** */
8
9 $wgNewTables = array(
10 # table patch file (in maintenance/archives)
11 array( 'linkscc', 'patch-linkscc.sql' ),
12 array( 'hitcounter', 'patch-hitcounter.sql' ),
13 array( 'querycache', 'patch-querycache.sql' ),
14 array( 'objectcache', 'patch-objectcache.sql' ),
15 array( 'categorylinks', 'patch-categorylinks.sql' ),
16 array( 'logging', 'patch-logging.sql' ),
17 array( 'user_rights', 'patch-user_rights.sql' ),
18 );
19
20 $wgNewFields = array(
21 # table field patch file (in maintenance/archives)
22 array( 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ),
23 array( 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ),
24 array( 'recentchanges', 'rc_type', 'patch-rc_type.sql' ),
25 array( 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ),
26 array( 'recentchanges', 'rc_id', 'patch-rc_id.sql' ),
27 array( 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ),
28 array( 'user', 'user_real_name', 'patch-user-realname.sql' ),
29 array( 'user', 'user_token', 'patch-user_token.sql' ),
30 );
31
32 function add_table( $name, $patch ) {
33 global $wgDatabase;
34 if ( $wgDatabase->tableExists( $name ) ) {
35 echo "...$name table already exists.\n";
36 } else {
37 echo "Creating $name table...";
38 dbsource( "maintenance/archives/$patch", $wgDatabase );
39 echo "ok\n";
40 }
41 }
42
43 function add_field( $table, $field, $patch ) {
44 global $wgDatabase;
45 if ( $wgDatabase->fieldExists( $table, $field ) ) {
46 echo "...have $field field in $table table.\n";
47 } else {
48 echo "Adding $field field to table $table...";
49 dbsource( "maintenance/archives/$patch" , $wgDatabase );
50 echo "ok\n";
51 }
52 }
53
54 function do_revision_updates() {
55 global $wgSoftwareRevision;
56 if ( $wgSoftwareRevision < 1001 ) {
57 update_passwords();
58 }
59 }
60
61 function update_passwords() {
62 global $wgDatabase;
63 $fname = "Update script: update_passwords()";
64 print "\nIt appears that you need to update the user passwords in your\n" .
65 "database. If you have already done this (if you've run this update\n" .
66 "script once before, for example), doing so again will make all your\n" .
67 "user accounts inaccessible, so be sure you only do this once.\n" .
68 "Update user passwords? (yes/no)";
69
70 $resp = readconsole();
71 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
72
73 $sql = "SELECT user_id,user_password FROM user";
74 $source = $wgDatabase->query( $sql, $fname );
75
76 while ( $row = $wgDatabase->fetchObject( $source ) ) {
77 $id = $row->user_id;
78 $oldpass = $row->user_password;
79 $newpass = md5( "{$id}-{$oldpass}" );
80
81 $sql = "UPDATE user SET user_password='{$newpass}' " .
82 "WHERE user_id={$id}";
83 $wgDatabase->query( $sql, $fname );
84 }
85 }
86
87 function do_interwiki_update() {
88 # Check that interwiki table exists; if it doesn't source it
89 global $wgDatabase;
90 if( $wgDatabase->tableExists( "interwiki" ) ) {
91 echo "...already have interwiki table\n";
92 return true;
93 }
94 echo "Creating interwiki table: ";
95 dbsource( "maintenance/archives/patch-interwiki.sql" );
96 echo "ok\n";
97 echo "Adding default interwiki definitions: ";
98 dbsource( "maintenance/interwiki.sql" );
99 echo "ok\n";
100 }
101
102 function do_index_update() {
103 # Check that proper indexes are in place
104 global $wgDatabase;
105 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
106 if( $meta->multiple_key == 0 ) {
107 echo "Updating indexes to 20031107: ";
108 dbsource( "maintenance/archives/patch-indexes.sql" );
109 echo "ok\n";
110 return true;
111 }
112 echo "...indexes seem up to 20031107 standards\n";
113 return false;
114 }
115
116 function do_linkscc_1_3_update() {
117 // Update linkscc table to 1.3 schema if necessary
118 global $wgDatabase, $wgVersion;
119 if( ( strpos( "1.3", $wgVersion ) === 0 ) && $wgDatabase->tableExists( "linkscc" )
120 && $wgDatabase->fieldExists( "linkscc", "lcc_title" ) ) {
121 echo "Altering lcc_title field from linkscc table... ";
122 dbsource( "maintenance/archives/patch-linkscc-1.3.sql", $wgDatabase );
123 echo "ok\n";
124 } else {
125 echo "...linkscc is up to date, or does not exist. Good.\n";
126 }
127 }
128
129 function do_image_name_unique_update() {
130 global $wgDatabase;
131 if ( $wgDatabase->indexUnique( 'image', 'img_name' ) ) {
132 echo "...img_name already unique.\n";
133 } else {
134 echo "Making the img_name index unique... ";
135 dbsource( "maintenance/archives/patch-image_name_unique.sql", $wgDatabase );
136 echo "ok\n";
137 }
138 }
139
140 ?>