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