remove old_namespace and old_title from old table.
[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 array( 'old', 'old_articleid', 'patch-remove-old-title-namespace.sql' ),
31 );
32
33 function add_table( $name, $patch ) {
34 global $wgDatabase;
35 if ( $wgDatabase->tableExists( $name ) ) {
36 echo "...$name table already exists.\n";
37 } else {
38 echo "Creating $name table...";
39 dbsource( "maintenance/archives/$patch", $wgDatabase );
40 echo "ok\n";
41 }
42 }
43
44 function add_field( $table, $field, $patch ) {
45 global $wgDatabase;
46 if ( $wgDatabase->fieldExists( $table, $field ) ) {
47 echo "...have $field field in $table table.\n";
48 } else {
49 echo "Adding $field field to table $table...";
50 dbsource( "maintenance/archives/$patch" , $wgDatabase );
51 echo "ok\n";
52 }
53 }
54
55 function do_revision_updates() {
56 global $wgSoftwareRevision;
57 if ( $wgSoftwareRevision < 1001 ) {
58 update_passwords();
59 }
60 }
61
62 function update_passwords() {
63 global $wgDatabase;
64 $fname = "Update script: update_passwords()";
65 print "\nIt appears that you need to update the user passwords in your\n" .
66 "database. If you have already done this (if you've run this update\n" .
67 "script once before, for example), doing so again will make all your\n" .
68 "user accounts inaccessible, so be sure you only do this once.\n" .
69 "Update user passwords? (yes/no)";
70
71 $resp = readconsole();
72 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
73
74 $sql = "SELECT user_id,user_password FROM user";
75 $source = $wgDatabase->query( $sql, $fname );
76
77 while ( $row = $wgDatabase->fetchObject( $source ) ) {
78 $id = $row->user_id;
79 $oldpass = $row->user_password;
80 $newpass = md5( "{$id}-{$oldpass}" );
81
82 $sql = "UPDATE user SET user_password='{$newpass}' " .
83 "WHERE user_id={$id}";
84 $wgDatabase->query( $sql, $fname );
85 }
86 }
87
88 function do_interwiki_update() {
89 # Check that interwiki table exists; if it doesn't source it
90 global $wgDatabase;
91 if( $wgDatabase->tableExists( "interwiki" ) ) {
92 echo "...already have interwiki table\n";
93 return true;
94 }
95 echo "Creating interwiki table: ";
96 dbsource( "maintenance/archives/patch-interwiki.sql" );
97 echo "ok\n";
98 echo "Adding default interwiki definitions: ";
99 dbsource( "maintenance/interwiki.sql" );
100 echo "ok\n";
101 }
102
103 function do_index_update() {
104 # Check that proper indexes are in place
105 global $wgDatabase;
106 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
107 if( $meta->multiple_key == 0 ) {
108 echo "Updating indexes to 20031107: ";
109 dbsource( "maintenance/archives/patch-indexes.sql" );
110 echo "ok\n";
111 return true;
112 }
113 echo "...indexes seem up to 20031107 standards\n";
114 return false;
115 }
116
117 function do_linkscc_1_3_update() {
118 // Update linkscc table to 1.3 schema if necessary
119 global $wgDatabase, $wgVersion;
120 if( ( strpos( "1.3", $wgVersion ) === 0 ) && $wgDatabase->tableExists( "linkscc" )
121 && $wgDatabase->fieldExists( "linkscc", "lcc_title" ) ) {
122 echo "Altering lcc_title field from linkscc table... ";
123 dbsource( "maintenance/archives/patch-linkscc-1.3.sql", $wgDatabase );
124 echo "ok\n";
125 } else {
126 echo "...linkscc is up to date, or does not exist. Good.\n";
127 }
128 }
129
130 function do_image_name_unique_update() {
131 global $wgDatabase;
132 if ( $wgDatabase->indexUnique( 'image', 'img_name' ) ) {
133 echo "...img_name already unique.\n";
134 } else {
135 echo "Making the img_name index unique... ";
136 dbsource( "maintenance/archives/patch-image_name_unique.sql", $wgDatabase );
137 echo "ok\n";
138 }
139 }
140
141 ?>