4 * @subpackage Maintenance
9 require_once 'convertLinks.inc';
10 require_once 'InitialiseMessages.inc';
11 require_once 'archives/moveCustomMessages.inc';
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' ),
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' ),
36 function add_table( $name, $patch ) {
38 if ( $wgDatabase->tableExists( $name ) ) {
39 echo "...$name table already exists.\n";
41 echo "Creating $name table...";
42 dbsource( "maintenance/archives/$patch", $wgDatabase );
47 function add_field( $table, $field, $patch ) {
49 if ( $wgDatabase->fieldExists( $table, $field ) ) {
50 echo "...have $field field in $table table.\n";
52 echo "Adding $field field to table $table...";
53 dbsource( "maintenance/archives/$patch" , $wgDatabase );
58 function do_revision_updates() {
59 global $wgSoftwareRevision;
60 if ( $wgSoftwareRevision < 1001 ) {
65 function update_passwords() {
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)";
74 $resp = readconsole();
75 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
77 $sql = "SELECT user_id,user_password FROM user";
78 $source = $wgDatabase->query( $sql, $fname );
80 while ( $row = $wgDatabase->fetchObject( $source ) ) {
82 $oldpass = $row->user_password;
83 $newpass = md5( "{$id}-{$oldpass}" );
85 $sql = "UPDATE user SET user_password='{$newpass}' " .
86 "WHERE user_id={$id}";
87 $wgDatabase->query( $sql, $fname );
91 function do_interwiki_update() {
92 # Check that interwiki table exists; if it doesn't source it
94 if( $wgDatabase->tableExists( "interwiki" ) ) {
95 echo "...already have interwiki table\n";
98 echo "Creating interwiki table: ";
99 dbsource( "maintenance/archives/patch-interwiki.sql" );
101 echo "Adding default interwiki definitions: ";
102 dbsource( "maintenance/interwiki.sql" );
106 function do_index_update() {
107 # Check that proper indexes are in place
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" );
116 echo "...indexes seem up to 20031107 standards\n";
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 );
129 echo "...linkscc is up to date, or does not exist. Good.\n";
133 function do_image_name_unique_update() {
135 if( $wgDatabase->indexExists( 'image', 'PRIMARY' ) ) {
136 echo "...image primary key already set.\n";
138 echo "Making img_name the primary key... ";
139 dbsource( "maintenance/archives/patch-image_name_primary.sql", $wgDatabase );
144 function do_all_updates() {
145 global $wgNewTables, $wgNewFields;
148 foreach ( $wgNewTables as $tableRecord ) {
149 add_table( $tableRecord[0], $tableRecord[1] );
154 foreach ( $wgNewFields as $fieldRecord ) {
155 add_table( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2] );
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();
166 if ( isTemplateInitialised() ) {
167 print "Template namespace already initialised\n";
169 moveCustomMessages( 1 ); flush();
170 moveCustomMessages( 2 ); flush();
171 moveCustomMessages( 3 ); flush();
174 initialiseMessages(); flush();