MediaWiki
REL1_21
|
00001 <?php 00030 class MysqlUpdater extends DatabaseUpdater { 00031 00032 protected function getCoreUpdateList() { 00033 return array( 00034 array( 'disableContentHandlerUseDB' ), 00035 00036 // 1.2 00037 array( 'addField', 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ), 00038 array( 'addField', 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ), 00039 array( 'doInterwikiUpdate' ), 00040 array( 'doIndexUpdate' ), 00041 array( 'addTable', 'hitcounter', 'patch-hitcounter.sql' ), 00042 array( 'addField', 'recentchanges', 'rc_type', 'patch-rc_type.sql' ), 00043 00044 // 1.3 00045 array( 'addField', 'user', 'user_real_name', 'patch-user-realname.sql' ), 00046 array( 'addTable', 'querycache', 'patch-querycache.sql' ), 00047 array( 'addTable', 'objectcache', 'patch-objectcache.sql' ), 00048 array( 'addTable', 'categorylinks', 'patch-categorylinks.sql' ), 00049 array( 'doOldLinksUpdate' ), 00050 array( 'doFixAncientImagelinks' ), 00051 array( 'addField', 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ), 00052 00053 // 1.4 00054 array( 'addIndex', 'image', 'PRIMARY', 'patch-image_name_primary.sql' ), 00055 array( 'addField', 'recentchanges', 'rc_id', 'patch-rc_id.sql' ), 00056 array( 'addField', 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ), 00057 array( 'addTable', 'logging', 'patch-logging.sql' ), 00058 array( 'addField', 'user', 'user_token', 'patch-user_token.sql' ), 00059 array( 'addField', 'watchlist', 'wl_notificationtimestamp', 'patch-email-notification.sql' ), 00060 array( 'doWatchlistUpdate' ), 00061 array( 'dropField', 'user', 'user_emailauthenticationtimestamp', 'patch-email-authentication.sql' ), 00062 00063 // 1.5 00064 array( 'doSchemaRestructuring' ), 00065 array( 'addField', 'logging', 'log_params', 'patch-log_params.sql' ), 00066 array( 'checkBin', 'logging', 'log_title', 'patch-logging-title.sql', ), 00067 array( 'addField', 'archive', 'ar_rev_id', 'patch-archive-rev_id.sql' ), 00068 array( 'addField', 'page', 'page_len', 'patch-page_len.sql' ), 00069 array( 'dropField', 'revision', 'inverse_timestamp', 'patch-inverse_timestamp.sql' ), 00070 array( 'addField', 'revision', 'rev_text_id', 'patch-rev_text_id.sql' ), 00071 array( 'addField', 'revision', 'rev_deleted', 'patch-rev_deleted.sql' ), 00072 array( 'addField', 'image', 'img_width', 'patch-img_width.sql' ), 00073 array( 'addField', 'image', 'img_metadata', 'patch-img_metadata.sql' ), 00074 array( 'addField', 'user', 'user_email_token', 'patch-user_email_token.sql' ), 00075 array( 'addField', 'archive', 'ar_text_id', 'patch-archive-text_id.sql' ), 00076 array( 'doNamespaceSize' ), 00077 array( 'addField', 'image', 'img_media_type', 'patch-img_media_type.sql' ), 00078 array( 'doPagelinksUpdate' ), 00079 array( 'dropField', 'image', 'img_type', 'patch-drop_img_type.sql' ), 00080 array( 'doUserUniqueUpdate' ), 00081 array( 'doUserGroupsUpdate' ), 00082 array( 'addField', 'site_stats', 'ss_total_pages', 'patch-ss_total_articles.sql' ), 00083 array( 'addTable', 'user_newtalk', 'patch-usernewtalk2.sql' ), 00084 array( 'addTable', 'transcache', 'patch-transcache.sql' ), 00085 array( 'addField', 'interwiki', 'iw_trans', 'patch-interwiki-trans.sql' ), 00086 00087 // 1.6 00088 array( 'doWatchlistNull' ), 00089 array( 'addIndex', 'logging', 'times', 'patch-logging-times-index.sql' ), 00090 array( 'addField', 'ipblocks', 'ipb_range_start', 'patch-ipb_range_start.sql' ), 00091 array( 'doPageRandomUpdate' ), 00092 array( 'addField', 'user', 'user_registration', 'patch-user_registration.sql' ), 00093 array( 'doTemplatelinksUpdate' ), 00094 array( 'addTable', 'externallinks', 'patch-externallinks.sql' ), 00095 array( 'addTable', 'job', 'patch-job.sql' ), 00096 array( 'addField', 'site_stats', 'ss_images', 'patch-ss_images.sql' ), 00097 array( 'addTable', 'langlinks', 'patch-langlinks.sql' ), 00098 array( 'addTable', 'querycache_info', 'patch-querycacheinfo.sql' ), 00099 array( 'addTable', 'filearchive', 'patch-filearchive.sql' ), 00100 array( 'addField', 'ipblocks', 'ipb_anon_only', 'patch-ipb_anon_only.sql' ), 00101 array( 'addIndex', 'recentchanges', 'rc_ns_usertext', 'patch-recentchanges-utindex.sql' ), 00102 array( 'addIndex', 'recentchanges', 'rc_user_text', 'patch-rc_user_text-index.sql' ), 00103 00104 // 1.9 00105 array( 'addField', 'user', 'user_newpass_time', 'patch-user_newpass_time.sql' ), 00106 array( 'addTable', 'redirect', 'patch-redirect.sql' ), 00107 array( 'addTable', 'querycachetwo', 'patch-querycachetwo.sql' ), 00108 array( 'addField', 'ipblocks', 'ipb_enable_autoblock', 'patch-ipb_optional_autoblock.sql' ), 00109 array( 'doBacklinkingIndicesUpdate' ), 00110 array( 'addField', 'recentchanges', 'rc_old_len', 'patch-rc_len.sql' ), 00111 array( 'addField', 'user', 'user_editcount', 'patch-user_editcount.sql' ), 00112 00113 // 1.10 00114 array( 'doRestrictionsUpdate' ), 00115 array( 'addField', 'logging', 'log_id', 'patch-log_id.sql' ), 00116 array( 'addField', 'revision', 'rev_parent_id', 'patch-rev_parent_id.sql' ), 00117 array( 'addField', 'page_restrictions', 'pr_id', 'patch-page_restrictions_sortkey.sql' ), 00118 array( 'addField', 'revision', 'rev_len', 'patch-rev_len.sql' ), 00119 array( 'addField', 'recentchanges', 'rc_deleted', 'patch-rc_deleted.sql' ), 00120 array( 'addField', 'logging', 'log_deleted', 'patch-log_deleted.sql' ), 00121 array( 'addField', 'archive', 'ar_deleted', 'patch-ar_deleted.sql' ), 00122 array( 'addField', 'ipblocks', 'ipb_deleted', 'patch-ipb_deleted.sql' ), 00123 array( 'addField', 'filearchive', 'fa_deleted', 'patch-fa_deleted.sql' ), 00124 array( 'addField', 'archive', 'ar_len', 'patch-ar_len.sql' ), 00125 00126 // 1.11 00127 array( 'addField', 'ipblocks', 'ipb_block_email', 'patch-ipb_emailban.sql' ), 00128 array( 'doCategorylinksIndicesUpdate' ), 00129 array( 'addField', 'oldimage', 'oi_metadata', 'patch-oi_metadata.sql' ), 00130 array( 'addIndex', 'archive', 'usertext_timestamp', 'patch-archive-user-index.sql' ), 00131 array( 'addIndex', 'image', 'img_usertext_timestamp', 'patch-image-user-index.sql' ), 00132 array( 'addIndex', 'oldimage', 'oi_usertext_timestamp', 'patch-oldimage-user-index.sql' ), 00133 array( 'addField', 'archive', 'ar_page_id', 'patch-archive-page_id.sql' ), 00134 array( 'addField', 'image', 'img_sha1', 'patch-img_sha1.sql' ), 00135 00136 // 1.12 00137 array( 'addTable', 'protected_titles', 'patch-protected_titles.sql' ), 00138 00139 // 1.13 00140 array( 'addField', 'ipblocks', 'ipb_by_text', 'patch-ipb_by_text.sql' ), 00141 array( 'addTable', 'page_props', 'patch-page_props.sql' ), 00142 array( 'addTable', 'updatelog', 'patch-updatelog.sql' ), 00143 array( 'addTable', 'category', 'patch-category.sql' ), 00144 array( 'doCategoryPopulation' ), 00145 array( 'addField', 'archive', 'ar_parent_id', 'patch-ar_parent_id.sql' ), 00146 array( 'addField', 'user_newtalk', 'user_last_timestamp', 'patch-user_last_timestamp.sql' ), 00147 array( 'doPopulateParentId' ), 00148 array( 'checkBin', 'protected_titles', 'pt_title', 'patch-pt_title-encoding.sql', ), 00149 array( 'doMaybeProfilingMemoryUpdate' ), 00150 array( 'doFilearchiveIndicesUpdate' ), 00151 00152 // 1.14 00153 array( 'addField', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ), 00154 array( 'doActiveUsersInit' ), 00155 array( 'addField', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ), 00156 00157 // 1.15 00158 array( 'doUniquePlTlIl' ), 00159 array( 'addTable', 'change_tag', 'patch-change_tag.sql' ), 00160 /* array( 'addTable', 'tag_summary', 'patch-change_tag.sql' ), */ 00161 /* array( 'addTable', 'valid_tag', 'patch-change_tag.sql' ), */ 00162 00163 // 1.16 00164 array( 'addTable', 'user_properties', 'patch-user_properties.sql' ), 00165 array( 'addTable', 'log_search', 'patch-log_search.sql' ), 00166 array( 'addField', 'logging', 'log_user_text', 'patch-log_user_text.sql' ), 00167 array( 'doLogUsertextPopulation' ), # listed separately from the previous update because 1.16 was released without this update 00168 array( 'doLogSearchPopulation' ), 00169 array( 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ), 00170 array( 'addTable', 'external_user', 'patch-external_user.sql' ), 00171 array( 'addIndex', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ), 00172 array( 'addIndex', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ), 00173 array( 'addField', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ), 00174 array( 'doUpdateTranscacheField' ), 00175 array( 'renameEuWikiId' ), 00176 array( 'doUpdateMimeMinorField' ), 00177 00178 // 1.17 00179 array( 'addTable', 'iwlinks', 'patch-iwlinks.sql' ), 00180 array( 'addIndex', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ), 00181 array( 'addField', 'updatelog', 'ul_value', 'patch-ul_value.sql' ), 00182 array( 'addField', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ), 00183 array( 'dropIndex', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ), 00184 array( 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ), 00185 array( 'addField', 'categorylinks', 'cl_collation', 'patch-categorylinks-better-collation.sql' ), 00186 array( 'doClFieldsUpdate' ), 00187 array( 'doCollationUpdate' ), 00188 array( 'addTable', 'msg_resource', 'patch-msg_resource.sql' ), 00189 array( 'addTable', 'module_deps', 'patch-module_deps.sql' ), 00190 array( 'dropIndex', 'archive', 'ar_page_revid', 'patch-archive_kill_ar_page_revid.sql' ), 00191 array( 'addIndex', 'archive', 'ar_revid', 'patch-archive_ar_revid.sql' ), 00192 array( 'doLangLinksLengthUpdate' ), 00193 00194 // 1.18 00195 array( 'doUserNewTalkTimestampNotNull' ), 00196 array( 'addIndex', 'user', 'user_email', 'patch-user_email_index.sql' ), 00197 array( 'modifyField', 'user_properties', 'up_property', 'patch-up_property.sql' ), 00198 array( 'addTable', 'uploadstash', 'patch-uploadstash.sql' ), 00199 array( 'addTable', 'user_former_groups', 'patch-user_former_groups.sql'), 00200 00201 // 1.19 00202 array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql'), 00203 array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ), 00204 array( 'doMigrateUserOptions' ), 00205 array( 'dropField', 'user', 'user_options', 'patch-drop-user_options.sql' ), 00206 array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' ), 00207 array( 'addIndex', 'page', 'page_redirect_namespace_len', 'patch-page_redirect_namespace_len.sql' ), 00208 array( 'addField', 'uploadstash', 'us_chunk_inx', 'patch-uploadstash_chunk.sql' ), 00209 array( 'addfield', 'job', 'job_timestamp', 'patch-jobs-add-timestamp.sql' ), 00210 00211 // 1.20 00212 array( 'addIndex', 'revision', 'page_user_timestamp', 'patch-revision-user-page-index.sql' ), 00213 array( 'addField', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id.sql' ), 00214 array( 'addIndex', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id-index.sql' ), 00215 array( 'dropField', 'category', 'cat_hidden', 'patch-cat_hidden.sql' ), 00216 00217 // 1.21 00218 array( 'addField', 'revision', 'rev_content_format', 'patch-revision-rev_content_format.sql' ), 00219 array( 'addField', 'revision', 'rev_content_model', 'patch-revision-rev_content_model.sql' ), 00220 array( 'addField', 'archive', 'ar_content_format', 'patch-archive-ar_content_format.sql' ), 00221 array( 'addField', 'archive', 'ar_content_model', 'patch-archive-ar_content_model.sql' ), 00222 array( 'addField', 'page', 'page_content_model', 'patch-page-page_content_model.sql' ), 00223 array( 'enableContentHandlerUseDB' ), 00224 00225 array( 'dropField', 'site_stats', 'ss_admins', 'patch-drop-ss_admins.sql' ), 00226 array( 'dropField', 'recentchanges', 'rc_moved_to_title', 'patch-rc_moved.sql' ), 00227 array( 'addTable', 'sites', 'patch-sites.sql' ), 00228 array( 'addField', 'filearchive', 'fa_sha1', 'patch-fa_sha1.sql' ), 00229 array( 'addField', 'job', 'job_token', 'patch-job_token.sql' ), 00230 array( 'addField', 'job', 'job_attempts', 'patch-job_attempts.sql' ), 00231 array( 'doEnableProfiling' ), 00232 array( 'addField', 'uploadstash', 'us_props', 'patch-uploadstash-us_props.sql' ), 00233 array( 'modifyField', 'user_groups', 'ug_group', 'patch-ug_group-length-increase-255.sql' ), 00234 array( 'modifyField', 'user_former_groups', 'ufg_group', 'patch-ufg_group-length-increase-255.sql' ), 00235 array( 'addIndex', 'page_props', 'pp_propname_page', 'patch-page_props-propname-page-index.sql' ), 00236 array( 'addIndex', 'image', 'img_media_mime', 'patch-img_media_mime-index.sql' ), 00237 ); 00238 } 00239 00248 protected function checkBin( $table, $field, $patchFile ) { 00249 if ( !$this->doTable( $table ) ) { 00250 return true; 00251 } 00252 00253 $tableName = $this->db->tableName( $table ); 00254 $res = $this->db->query( "SELECT $field FROM $tableName LIMIT 0", __METHOD__ ); 00255 $flags = explode( ' ', mysql_field_flags( $res->result, 0 ) ); 00256 00257 if ( in_array( 'binary', $flags ) ) { 00258 $this->output( "...$table table has correct $field encoding.\n" ); 00259 } else { 00260 $this->applyPatch( $patchFile, false, "Fixing $field encoding on $table table" ); 00261 } 00262 } 00263 00272 protected function indexHasField( $table, $index, $field ) { 00273 if ( !$this->doTable( $table ) ) { 00274 return true; 00275 } 00276 00277 $info = $this->db->indexInfo( $table, $index, __METHOD__ ); 00278 if ( $info ) { 00279 foreach ( $info as $row ) { 00280 if ( $row->Column_name == $field ) { 00281 $this->output( "...index $index on table $table includes field $field.\n" ); 00282 return true; 00283 } 00284 } 00285 } 00286 $this->output( "...index $index on table $table has no field $field; added.\n" ); 00287 return false; 00288 } 00289 00293 protected function doInterwikiUpdate() { 00294 global $IP; 00295 00296 if ( !$this->doTable( 'interwiki' ) ) { 00297 return true; 00298 } 00299 00300 if ( $this->db->tableExists( "interwiki", __METHOD__ ) ) { 00301 $this->output( "...already have interwiki table\n" ); 00302 return; 00303 } 00304 00305 $this->applyPatch( 'patch-interwiki.sql', false, 'Creating interwiki table' ); 00306 $this->applyPatch( "$IP/maintenance/interwiki.sql", true, 'Adding default interwiki definitions' ); 00307 } 00308 00312 protected function doIndexUpdate() { 00313 $meta = $this->db->fieldInfo( 'recentchanges', 'rc_timestamp' ); 00314 if ( $meta === false ) { 00315 throw new MWException( 'Missing rc_timestamp field of recentchanges table. Should not happen.' ); 00316 } 00317 if ( $meta->isMultipleKey() ) { 00318 $this->output( "...indexes seem up to 20031107 standards.\n" ); 00319 return; 00320 } 00321 00322 $this->applyPatch( 'patch-indexes.sql', true, "Updating indexes to 20031107" ); 00323 } 00324 00325 protected function doOldLinksUpdate() { 00326 $cl = $this->maintenance->runChild( 'ConvertLinks' ); 00327 $cl->execute(); 00328 } 00329 00330 protected function doFixAncientImagelinks() { 00331 $info = $this->db->fieldInfo( 'imagelinks', 'il_from' ); 00332 if ( !$info || $info->type() !== 'string' ) { 00333 $this->output( "...il_from OK\n" ); 00334 return; 00335 } 00336 00337 if( $this->applyPatch( 'patch-fix-il_from.sql', false, "Fixing ancient broken imagelinks table." ) ) { 00338 $this->output( "NOTE: you will have to run maintenance/refreshLinks.php after this." ); 00339 } 00340 } 00341 00345 function doWatchlistUpdate() { 00346 $talk = $this->db->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', __METHOD__ ); 00347 $nontalk = $this->db->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', __METHOD__ ); 00348 if ( $talk == $nontalk ) { 00349 $this->output( "...watchlist talk page rows already present.\n" ); 00350 return; 00351 } 00352 00353 $this->output( "Adding missing watchlist talk page rows... " ); 00354 $this->db->insertSelect( 'watchlist', 'watchlist', 00355 array( 00356 'wl_user' => 'wl_user', 00357 'wl_namespace' => 'wl_namespace | 1', 00358 'wl_title' => 'wl_title', 00359 'wl_notificationtimestamp' => 'wl_notificationtimestamp' 00360 ), array( 'NOT (wl_namespace & 1)' ), __METHOD__, 'IGNORE' ); 00361 $this->output( "done.\n" ); 00362 } 00363 00364 function doSchemaRestructuring() { 00365 if ( $this->db->tableExists( 'page', __METHOD__ ) ) { 00366 $this->output( "...page table already exists.\n" ); 00367 return; 00368 } 00369 00370 $this->output( "...converting from cur/old to page/revision/text DB structure.\n" ); 00371 $this->output( wfTimestamp( TS_DB ) ); 00372 $this->output( "......checking for duplicate entries.\n" ); 00373 00374 list ( $cur, $old, $page, $revision, $text ) = $this->db->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' ); 00375 00376 $rows = $this->db->query( "SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c 00377 FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", __METHOD__ ); 00378 00379 if ( $rows->numRows() > 0 ) { 00380 $this->output( wfTimestamp( TS_DB ) ); 00381 $this->output( "......<b>Found duplicate entries</b>\n" ); 00382 $this->output( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) ); 00383 $duplicate = array(); 00384 foreach ( $rows as $row ) { 00385 if ( ! isset( $duplicate[$row->cur_namespace] ) ) { 00386 $duplicate[$row->cur_namespace] = array(); 00387 } 00388 $duplicate[$row->cur_namespace][] = $row->cur_title; 00389 $this->output( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) ); 00390 } 00391 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE "; 00392 $firstCond = true; 00393 foreach ( $duplicate as $ns => $titles ) { 00394 if ( $firstCond ) { 00395 $firstCond = false; 00396 } else { 00397 $sql .= ' OR '; 00398 } 00399 $sql .= "( cur_namespace = {$ns} AND cur_title in ("; 00400 $first = true; 00401 foreach ( $titles as $t ) { 00402 if ( $first ) { 00403 $sql .= $this->db->addQuotes( $t ); 00404 $first = false; 00405 } else { 00406 $sql .= ', ' . $this->db->addQuotes( $t ); 00407 } 00408 } 00409 $sql .= ") ) \n"; 00410 } 00411 # By sorting descending, the most recent entry will be the first in the list. 00412 # All following entries will be deleted by the next while-loop. 00413 $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC'; 00414 00415 $rows = $this->db->query( $sql, __METHOD__ ); 00416 00417 $prev_title = $prev_namespace = false; 00418 $deleteId = array(); 00419 00420 foreach ( $rows as $row ) { 00421 if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) { 00422 $deleteId[] = $row->cur_id; 00423 } 00424 $prev_title = $row->cur_title; 00425 $prev_namespace = $row->cur_namespace; 00426 } 00427 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')'; 00428 $this->db->query( $sql, __METHOD__ ); 00429 $this->output( wfTimestamp( TS_DB ) ); 00430 $this->output( "......<b>Deleted</b> " . $this->db->affectedRows() . " records.\n" ); 00431 } 00432 00433 $this->output( wfTimestamp( TS_DB ) ); 00434 $this->output( "......Creating tables.\n" ); 00435 $this->db->query( "CREATE TABLE $page ( 00436 page_id int(8) unsigned NOT NULL auto_increment, 00437 page_namespace int NOT NULL, 00438 page_title varchar(255) binary NOT NULL, 00439 page_restrictions tinyblob NOT NULL, 00440 page_counter bigint(20) unsigned NOT NULL default '0', 00441 page_is_redirect tinyint(1) unsigned NOT NULL default '0', 00442 page_is_new tinyint(1) unsigned NOT NULL default '0', 00443 page_random real unsigned NOT NULL, 00444 page_touched char(14) binary NOT NULL default '', 00445 page_latest int(8) unsigned NOT NULL, 00446 page_len int(8) unsigned NOT NULL, 00447 00448 PRIMARY KEY page_id (page_id), 00449 UNIQUE INDEX name_title (page_namespace,page_title), 00450 INDEX (page_random), 00451 INDEX (page_len) 00452 ) ENGINE=InnoDB", __METHOD__ ); 00453 $this->db->query( "CREATE TABLE $revision ( 00454 rev_id int(8) unsigned NOT NULL auto_increment, 00455 rev_page int(8) unsigned NOT NULL, 00456 rev_comment tinyblob NOT NULL, 00457 rev_user int(5) unsigned NOT NULL default '0', 00458 rev_user_text varchar(255) binary NOT NULL default '', 00459 rev_timestamp char(14) binary NOT NULL default '', 00460 rev_minor_edit tinyint(1) unsigned NOT NULL default '0', 00461 rev_deleted tinyint(1) unsigned NOT NULL default '0', 00462 rev_len int(8) unsigned, 00463 rev_parent_id int(8) unsigned default NULL, 00464 PRIMARY KEY rev_page_id (rev_page, rev_id), 00465 UNIQUE INDEX rev_id (rev_id), 00466 INDEX rev_timestamp (rev_timestamp), 00467 INDEX page_timestamp (rev_page,rev_timestamp), 00468 INDEX user_timestamp (rev_user,rev_timestamp), 00469 INDEX usertext_timestamp (rev_user_text,rev_timestamp) 00470 ) ENGINE=InnoDB", __METHOD__ ); 00471 00472 $this->output( wfTimestamp( TS_DB ) ); 00473 $this->output( "......Locking tables.\n" ); 00474 $this->db->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", __METHOD__ ); 00475 00476 $maxold = intval( $this->db->selectField( 'old', 'max(old_id)', '', __METHOD__ ) ); 00477 $this->output( wfTimestamp( TS_DB ) ); 00478 $this->output( "......maxold is {$maxold}\n" ); 00479 00480 $this->output( wfTimestamp( TS_DB ) ); 00481 global $wgLegacySchemaConversion; 00482 if ( $wgLegacySchemaConversion ) { 00483 // Create HistoryBlobCurStub entries. 00484 // Text will be pulled from the leftover 'cur' table at runtime. 00485 $this->output( "......Moving metadata from cur; using blob references to text in cur table.\n" ); 00486 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')"; 00487 $cur_flags = "'object'"; 00488 } else { 00489 // Copy all cur text in immediately: this may take longer but avoids 00490 // having to keep an extra table around. 00491 $this->output( "......Moving text from cur.\n" ); 00492 $cur_text = 'cur_text'; 00493 $cur_flags = "''"; 00494 } 00495 $this->db->query( "INSERT INTO $old (old_namespace, old_title, old_text, old_comment, old_user, old_user_text, 00496 old_timestamp, old_minor_edit, old_flags) 00497 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags 00498 FROM $cur", __METHOD__ ); 00499 00500 $this->output( wfTimestamp( TS_DB ) ); 00501 $this->output( "......Setting up revision table.\n" ); 00502 $this->db->query( "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp, 00503 rev_minor_edit) 00504 SELECT old_id, cur_id, old_comment, old_user, old_user_text, 00505 old_timestamp, old_minor_edit 00506 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", __METHOD__ ); 00507 00508 $this->output( wfTimestamp( TS_DB ) ); 00509 $this->output( "......Setting up page table.\n" ); 00510 $this->db->query( "INSERT INTO $page (page_id, page_namespace, page_title, page_restrictions, page_counter, 00511 page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len) 00512 SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new, 00513 cur_random, cur_touched, rev_id, LENGTH(cur_text) 00514 FROM $cur,$revision 00515 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", __METHOD__ ); 00516 00517 $this->output( wfTimestamp( TS_DB ) ); 00518 $this->output( "......Unlocking tables.\n" ); 00519 $this->db->query( "UNLOCK TABLES", __METHOD__ ); 00520 00521 $this->output( wfTimestamp( TS_DB ) ); 00522 $this->output( "......Renaming old.\n" ); 00523 $this->db->query( "ALTER TABLE $old RENAME TO $text", __METHOD__ ); 00524 00525 $this->output( wfTimestamp( TS_DB ) ); 00526 $this->output( "...done.\n" ); 00527 } 00528 00529 protected function doNamespaceSize() { 00530 $tables = array( 00531 'page' => 'page', 00532 'archive' => 'ar', 00533 'recentchanges' => 'rc', 00534 'watchlist' => 'wl', 00535 'querycache' => 'qc', 00536 'logging' => 'log', 00537 ); 00538 foreach ( $tables as $table => $prefix ) { 00539 $field = $prefix . '_namespace'; 00540 00541 $tablename = $this->db->tableName( $table ); 00542 $result = $this->db->query( "SHOW COLUMNS FROM $tablename LIKE '$field'", __METHOD__ ); 00543 $info = $this->db->fetchObject( $result ); 00544 00545 if ( substr( $info->Type, 0, 3 ) == 'int' ) { 00546 $this->output( "...$field is already a full int ($info->Type).\n" ); 00547 } else { 00548 $this->output( "Promoting $field from $info->Type to int... " ); 00549 $this->db->query( "ALTER TABLE $tablename MODIFY $field int NOT NULL", __METHOD__ ); 00550 $this->output( "done.\n" ); 00551 } 00552 } 00553 } 00554 00555 protected function doPagelinksUpdate() { 00556 if ( $this->db->tableExists( 'pagelinks', __METHOD__ ) ) { 00557 $this->output( "...already have pagelinks table.\n" ); 00558 return; 00559 } 00560 00561 $this->applyPatch( 'patch-pagelinks.sql', false, "Converting links and brokenlinks tables to pagelinks" ); 00562 00563 global $wgContLang; 00564 foreach ( MWNamespace::getCanonicalNamespaces() as $ns => $name ) { 00565 if ( $ns == 0 ) { 00566 continue; 00567 } 00568 00569 $this->output( "Cleaning up broken links for namespace $ns... " ); 00570 00571 $pagelinks = $this->db->tableName( 'pagelinks' ); 00572 $name = $wgContLang->getNsText( $ns ); 00573 $prefix = $this->db->strencode( $name ); 00574 $likeprefix = str_replace( '_', '\\_', $prefix ); 00575 00576 $sql = "UPDATE $pagelinks 00577 SET pl_namespace=$ns, 00578 pl_title=TRIM(LEADING '$prefix:' FROM pl_title) 00579 WHERE pl_namespace=0 00580 AND pl_title LIKE '$likeprefix:%'"; 00581 00582 $this->db->query( $sql, __METHOD__ ); 00583 $this->output( "done.\n" ); 00584 } 00585 } 00586 00587 protected function doUserUniqueUpdate() { 00588 if ( !$this->doTable( 'user' ) ) { 00589 return true; 00590 } 00591 00592 $duper = new UserDupes( $this->db, array( $this, 'output' ) ); 00593 if ( $duper->hasUniqueIndex() ) { 00594 $this->output( "...already have unique user_name index.\n" ); 00595 return; 00596 } 00597 00598 if ( !$duper->clearDupes() ) { 00599 $this->output( "WARNING: This next step will probably fail due to unfixed duplicates...\n" ); 00600 } 00601 $this->applyPatch( 'patch-user_nameindex.sql', false, "Adding unique index on user_name" ); 00602 } 00603 00604 protected function doUserGroupsUpdate() { 00605 if ( !$this->doTable( 'user_groups' ) ) { 00606 return true; 00607 } 00608 00609 if ( $this->db->tableExists( 'user_groups', __METHOD__ ) ) { 00610 $info = $this->db->fieldInfo( 'user_groups', 'ug_group' ); 00611 if ( $info->type() == 'int' ) { 00612 $oldug = $this->db->tableName( 'user_groups' ); 00613 $newug = $this->db->tableName( 'user_groups_bogus' ); 00614 $this->output( "user_groups table exists but is in bogus intermediate format. Renaming to $newug... " ); 00615 $this->db->query( "ALTER TABLE $oldug RENAME TO $newug", __METHOD__ ); 00616 $this->output( "done.\n" ); 00617 00618 $this->applyPatch( 'patch-user_groups.sql', false, "Re-adding fresh user_groups table" ); 00619 00620 $this->output( "***\n" ); 00621 $this->output( "*** WARNING: You will need to manually fix up user permissions in the user_groups\n" ); 00622 $this->output( "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n" ); 00623 $this->output( "***\n" ); 00624 } else { 00625 $this->output( "...user_groups table exists and is in current format.\n" ); 00626 } 00627 return; 00628 } 00629 00630 $this->applyPatch( 'patch-user_groups.sql', false, "Adding user_groups table" ); 00631 00632 if ( !$this->db->tableExists( 'user_rights', __METHOD__ ) ) { 00633 if ( $this->db->fieldExists( 'user', 'user_rights', __METHOD__ ) ) { 00634 $this->db->applyPatch( 'patch-user_rights.sql', false, "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion" ); 00635 } else { 00636 $this->output( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" ); 00637 $this->output( "*** You may need to manually configure some sysops by manipulating\n" ); 00638 $this->output( "*** the user_groups table.\n" ); 00639 return; 00640 } 00641 } 00642 00643 $this->output( "Converting user_rights table to user_groups... " ); 00644 $result = $this->db->select( 'user_rights', 00645 array( 'ur_user', 'ur_rights' ), 00646 array( "ur_rights != ''" ), 00647 __METHOD__ ); 00648 00649 foreach ( $result as $row ) { 00650 $groups = array_unique( 00651 array_map( 'trim', 00652 explode( ',', $row->ur_rights ) ) ); 00653 00654 foreach ( $groups as $group ) { 00655 $this->db->insert( 'user_groups', 00656 array( 00657 'ug_user' => $row->ur_user, 00658 'ug_group' => $group ), 00659 __METHOD__ ); 00660 } 00661 } 00662 $this->output( "done.\n" ); 00663 } 00664 00669 protected function doWatchlistNull() { 00670 $info = $this->db->fieldInfo( 'watchlist', 'wl_notificationtimestamp' ); 00671 if ( !$info ) { 00672 return; 00673 } 00674 if ( $info->isNullable() ) { 00675 $this->output( "...wl_notificationtimestamp is already nullable.\n" ); 00676 return; 00677 } 00678 00679 $this->applyPatch( 'patch-watchlist-null.sql', false, "Making wl_notificationtimestamp nullable" ); 00680 } 00681 00687 protected function doPageRandomUpdate() { 00688 $page = $this->db->tableName( 'page' ); 00689 $this->db->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", __METHOD__ ); 00690 $rows = $this->db->affectedRows(); 00691 00692 if( $rows ) { 00693 $this->output( "Set page_random to a random value on $rows rows where it was set to 0\n" ); 00694 } else { 00695 $this->output( "...no page_random rows needed to be set\n" ); 00696 } 00697 } 00698 00699 protected function doTemplatelinksUpdate() { 00700 if ( $this->db->tableExists( 'templatelinks', __METHOD__ ) ) { 00701 $this->output( "...templatelinks table already exists\n" ); 00702 return; 00703 } 00704 00705 $this->applyPatch( 'patch-templatelinks.sql', false, "Creating templatelinks table" ); 00706 00707 $this->output( "Populating...\n" ); 00708 if ( wfGetLB()->getServerCount() > 1 ) { 00709 // Slow, replication-friendly update 00710 $res = $this->db->select( 'pagelinks', array( 'pl_from', 'pl_namespace', 'pl_title' ), 00711 array( 'pl_namespace' => NS_TEMPLATE ), __METHOD__ ); 00712 $count = 0; 00713 foreach ( $res as $row ) { 00714 $count = ( $count + 1 ) % 100; 00715 if ( $count == 0 ) { 00716 wfWaitForSlaves(); 00717 } 00718 $this->db->insert( 'templatelinks', 00719 array( 00720 'tl_from' => $row->pl_from, 00721 'tl_namespace' => $row->pl_namespace, 00722 'tl_title' => $row->pl_title, 00723 ), __METHOD__ 00724 ); 00725 00726 } 00727 } else { 00728 // Fast update 00729 $this->db->insertSelect( 'templatelinks', 'pagelinks', 00730 array( 00731 'tl_from' => 'pl_from', 00732 'tl_namespace' => 'pl_namespace', 00733 'tl_title' => 'pl_title' 00734 ), array( 00735 'pl_namespace' => 10 00736 ), __METHOD__ 00737 ); 00738 } 00739 $this->output( "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n" ); 00740 } 00741 00742 protected function doBacklinkingIndicesUpdate() { 00743 if ( !$this->indexHasField( 'pagelinks', 'pl_namespace', 'pl_from' ) || 00744 !$this->indexHasField( 'templatelinks', 'tl_namespace', 'tl_from' ) || 00745 !$this->indexHasField( 'imagelinks', 'il_to', 'il_from' ) ) 00746 { 00747 $this->applyPatch( 'patch-backlinkindexes.sql', false, "Updating backlinking indices" ); 00748 } 00749 } 00750 00756 protected function doRestrictionsUpdate() { 00757 if ( $this->db->tableExists( 'page_restrictions', __METHOD__ ) ) { 00758 $this->output( "...page_restrictions table already exists.\n" ); 00759 return; 00760 } 00761 00762 $this->applyPatch( 'patch-page_restrictions.sql', false, "Creating page_restrictions table (1/2)" ); 00763 $this->applyPatch( 'patch-page_restrictions_sortkey.sql', false, "Creating page_restrictions table (2/2)" ); 00764 $this->output( "done.\n" ); 00765 00766 $this->output( "Migrating old restrictions to new table...\n" ); 00767 $task = $this->maintenance->runChild( 'UpdateRestrictions' ); 00768 $task->execute(); 00769 } 00770 00771 protected function doCategorylinksIndicesUpdate() { 00772 if ( !$this->indexHasField( 'categorylinks', 'cl_sortkey', 'cl_from' ) ) { 00773 $this->applyPatch( 'patch-categorylinksindex.sql', false, "Updating categorylinks Indices" ); 00774 } 00775 } 00776 00777 protected function doCategoryPopulation() { 00778 if ( $this->updateRowExists( 'populate category' ) ) { 00779 $this->output( "...category table already populated.\n" ); 00780 return; 00781 } 00782 00783 $this->output( 00784 "Populating category table, printing progress markers. " . 00785 "For large databases, you\n" . 00786 "may want to hit Ctrl-C and do this manually with maintenance/\n" . 00787 "populateCategory.php.\n" 00788 ); 00789 $task = $this->maintenance->runChild( 'PopulateCategory' ); 00790 $task->execute(); 00791 $this->output( "Done populating category table.\n" ); 00792 } 00793 00794 protected function doPopulateParentId() { 00795 if ( !$this->updateRowExists( 'populate rev_parent_id' ) ) { 00796 $this->output( 00797 "Populating rev_parent_id fields, printing progress markers. For large\n" . 00798 "databases, you may want to hit Ctrl-C and do this manually with\n" . 00799 "maintenance/populateParentId.php.\n" ); 00800 00801 $task = $this->maintenance->runChild( 'PopulateParentId' ); 00802 $task->execute(); 00803 } 00804 } 00805 00806 protected function doEnableProfiling() { 00807 global $wgProfileToDatabase; 00808 00809 if ( !$this->doTable( 'profiling' ) ) { 00810 return true; 00811 } 00812 00813 if ( $wgProfileToDatabase === true && ! $this->db->tableExists( 'profiling', __METHOD__ ) ) { 00814 $this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' ); 00815 } 00816 } 00817 00818 protected function doMaybeProfilingMemoryUpdate() { 00819 if ( !$this->doTable( 'profiling' ) ) { 00820 return true; 00821 } 00822 00823 if ( !$this->db->tableExists( 'profiling', __METHOD__ ) ) { 00824 return true; 00825 } elseif ( $this->db->fieldExists( 'profiling', 'pf_memory', __METHOD__ ) ) { 00826 $this->output( "...profiling table has pf_memory field.\n" ); 00827 return true; 00828 } 00829 return $this->applyPatch( 'patch-profiling-memory.sql', false, "Adding pf_memory field to table profiling" ); 00830 } 00831 00832 protected function doFilearchiveIndicesUpdate() { 00833 $info = $this->db->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ ); 00834 if ( !$info ) { 00835 $this->applyPatch( 'patch-filearchive-user-index.sql', false, "Updating filearchive indices" ); 00836 } 00837 return true; 00838 } 00839 00840 protected function doUniquePlTlIl() { 00841 $info = $this->db->indexInfo( 'pagelinks', 'pl_namespace' ); 00842 if ( is_array( $info ) && !$info[0]->Non_unique ) { 00843 $this->output( "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n" ); 00844 return true; 00845 } 00846 if ( $this->skipSchema ) { 00847 $this->output( "...skipping schema change (making pl_namespace, tl_namespace and il_to indices UNIQUE).\n" ); 00848 return false; 00849 } 00850 00851 return $this->applyPatch( 'patch-pl-tl-il-unique.sql', false, "Making pl_namespace, tl_namespace and il_to indices UNIQUE" ); 00852 } 00853 00854 protected function renameEuWikiId() { 00855 if ( $this->db->fieldExists( 'external_user', 'eu_local_id', __METHOD__ ) ) { 00856 $this->output( "...eu_wiki_id already renamed to eu_local_id.\n" ); 00857 return; 00858 } 00859 00860 $this->applyPatch( 'patch-eu_local_id.sql', false, "Renaming eu_wiki_id -> eu_local_id" ); 00861 } 00862 00863 protected function doUpdateMimeMinorField() { 00864 if ( $this->updateRowExists( 'mime_minor_length' ) ) { 00865 $this->output( "...*_mime_minor fields are already long enough.\n" ); 00866 return; 00867 } 00868 00869 $this->applyPatch( 'patch-mime_minor_length.sql', false, "Altering all *_mime_minor fields to 100 bytes in size" ); 00870 } 00871 00872 protected function doClFieldsUpdate() { 00873 if ( $this->updateRowExists( 'cl_fields_update' ) ) { 00874 $this->output( "...categorylinks up-to-date.\n" ); 00875 return; 00876 } 00877 00878 $this->applyPatch( 'patch-categorylinks-better-collation2.sql', false, 'Updating categorylinks (again)' ); 00879 } 00880 00881 protected function doLangLinksLengthUpdate() { 00882 $langlinks = $this->db->tableName( 'langlinks' ); 00883 $res = $this->db->query( "SHOW COLUMNS FROM $langlinks LIKE 'll_lang'" ); 00884 $row = $this->db->fetchObject( $res ); 00885 00886 if ( $row && $row->Type == "varbinary(10)" ) { 00887 $this->applyPatch( 'patch-langlinks-ll_lang-20.sql', false, 'Updating length of ll_lang in langlinks' ); 00888 } else { 00889 $this->output( "...ll_lang is up-to-date.\n" ); 00890 } 00891 } 00892 00893 protected function doUserNewTalkTimestampNotNull() { 00894 if ( !$this->doTable( 'user_newtalk' ) ) { 00895 return true; 00896 } 00897 00898 $info = $this->db->fieldInfo( 'user_newtalk', 'user_last_timestamp' ); 00899 if ( $info === false ) { 00900 return; 00901 } 00902 if ( $info->isNullable() ) { 00903 $this->output( "...user_last_timestamp is already nullable.\n" ); 00904 return; 00905 } 00906 00907 $this->applyPatch( 'patch-user-newtalk-timestamp-null.sql', false, "Making user_last_timestamp nullable" ); 00908 } 00909 }