Replace some of the deprecated wfGetLBFactory() calls
[lhc/web/wiklou.git] / includes / installer / MysqlUpdater.php
1 <?php
2 /**
3 * MySQL-specific updater.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Deployment
22 */
23 use MediaWiki\MediaWikiServices;
24
25 /**
26 * Mysql update list and mysql-specific update functions.
27 *
28 * @ingroup Deployment
29 * @since 1.17
30 */
31 class MysqlUpdater extends DatabaseUpdater {
32 protected function getCoreUpdateList() {
33 return [
34 [ 'disableContentHandlerUseDB' ],
35
36 // 1.2
37 [ 'addField', 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ],
38 [ 'addField', 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ],
39 [ 'doInterwikiUpdate' ],
40 [ 'doIndexUpdate' ],
41 [ 'addField', 'recentchanges', 'rc_type', 'patch-rc_type.sql' ],
42 [ 'addIndex', 'recentchanges', 'new_name_timestamp', 'patch-rc-newindex.sql' ],
43
44 // 1.3
45 [ 'addField', 'user', 'user_real_name', 'patch-user-realname.sql' ],
46 [ 'addTable', 'querycache', 'patch-querycache.sql' ],
47 [ 'addTable', 'objectcache', 'patch-objectcache.sql' ],
48 [ 'addTable', 'categorylinks', 'patch-categorylinks.sql' ],
49 [ 'doOldLinksUpdate' ],
50 [ 'doFixAncientImagelinks' ],
51 [ 'addField', 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ],
52
53 // 1.4
54 [ 'addIndex', 'image', 'PRIMARY', 'patch-image_name_primary.sql' ],
55 [ 'addField', 'recentchanges', 'rc_id', 'patch-rc_id.sql' ],
56 [ 'addField', 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ],
57 [ 'addTable', 'logging', 'patch-logging.sql' ],
58 [ 'addField', 'user', 'user_token', 'patch-user_token.sql' ],
59 [ 'addField', 'watchlist', 'wl_notificationtimestamp', 'patch-email-notification.sql' ],
60 [ 'doWatchlistUpdate' ],
61 [ 'dropField', 'user', 'user_emailauthenticationtimestamp',
62 'patch-email-authentication.sql' ],
63
64 // 1.5
65 [ 'doSchemaRestructuring' ],
66 [ 'addField', 'logging', 'log_params', 'patch-log_params.sql' ],
67 [ 'checkBin', 'logging', 'log_title', 'patch-logging-title.sql', ],
68 [ 'addField', 'archive', 'ar_rev_id', 'patch-archive-rev_id.sql' ],
69 [ 'addField', 'page', 'page_len', 'patch-page_len.sql' ],
70 [ 'dropField', 'revision', 'inverse_timestamp', 'patch-inverse_timestamp.sql' ],
71 [ 'addField', 'revision', 'rev_text_id', 'patch-rev_text_id.sql' ],
72 [ 'addField', 'revision', 'rev_deleted', 'patch-rev_deleted.sql' ],
73 [ 'addField', 'image', 'img_width', 'patch-img_width.sql' ],
74 [ 'addField', 'image', 'img_metadata', 'patch-img_metadata.sql' ],
75 [ 'addField', 'user', 'user_email_token', 'patch-user_email_token.sql' ],
76 [ 'addField', 'archive', 'ar_text_id', 'patch-archive-text_id.sql' ],
77 [ 'doNamespaceSize' ],
78 [ 'addField', 'image', 'img_media_type', 'patch-img_media_type.sql' ],
79 [ 'doPagelinksUpdate' ],
80 [ 'dropField', 'image', 'img_type', 'patch-drop_img_type.sql' ],
81 [ 'doUserUniqueUpdate' ],
82 [ 'doUserGroupsUpdate' ],
83 [ 'addField', 'site_stats', 'ss_total_pages', 'patch-ss_total_articles.sql' ],
84 [ 'addTable', 'user_newtalk', 'patch-usernewtalk2.sql' ],
85 [ 'addTable', 'transcache', 'patch-transcache.sql' ],
86 [ 'addField', 'interwiki', 'iw_trans', 'patch-interwiki-trans.sql' ],
87
88 // 1.6
89 [ 'doWatchlistNull' ],
90 [ 'addIndex', 'logging', 'times', 'patch-logging-times-index.sql' ],
91 [ 'addField', 'ipblocks', 'ipb_range_start', 'patch-ipb_range_start.sql' ],
92 [ 'doPageRandomUpdate' ],
93 [ 'addField', 'user', 'user_registration', 'patch-user_registration.sql' ],
94 [ 'doTemplatelinksUpdate' ],
95 [ 'addTable', 'externallinks', 'patch-externallinks.sql' ],
96 [ 'addTable', 'job', 'patch-job.sql' ],
97 [ 'addField', 'site_stats', 'ss_images', 'patch-ss_images.sql' ],
98 [ 'addTable', 'langlinks', 'patch-langlinks.sql' ],
99 [ 'addTable', 'querycache_info', 'patch-querycacheinfo.sql' ],
100 [ 'addTable', 'filearchive', 'patch-filearchive.sql' ],
101 [ 'addField', 'ipblocks', 'ipb_anon_only', 'patch-ipb_anon_only.sql' ],
102 [ 'addIndex', 'recentchanges', 'rc_ns_usertext', 'patch-recentchanges-utindex.sql' ],
103 [ 'addIndex', 'recentchanges', 'rc_user_text', 'patch-rc_user_text-index.sql' ],
104
105 // 1.9
106 [ 'addField', 'user', 'user_newpass_time', 'patch-user_newpass_time.sql' ],
107 [ 'addTable', 'redirect', 'patch-redirect.sql' ],
108 [ 'addTable', 'querycachetwo', 'patch-querycachetwo.sql' ],
109 [ 'addField', 'ipblocks', 'ipb_enable_autoblock', 'patch-ipb_optional_autoblock.sql' ],
110 [ 'doBacklinkingIndicesUpdate' ],
111 [ 'addField', 'recentchanges', 'rc_old_len', 'patch-rc_len.sql' ],
112 [ 'addField', 'user', 'user_editcount', 'patch-user_editcount.sql' ],
113
114 // 1.10
115 [ 'doRestrictionsUpdate' ],
116 [ 'addField', 'logging', 'log_id', 'patch-log_id.sql' ],
117 [ 'addField', 'revision', 'rev_parent_id', 'patch-rev_parent_id.sql' ],
118 [ 'addField', 'page_restrictions', 'pr_id', 'patch-page_restrictions_sortkey.sql' ],
119 [ 'addField', 'revision', 'rev_len', 'patch-rev_len.sql' ],
120 [ 'addField', 'recentchanges', 'rc_deleted', 'patch-rc_deleted.sql' ],
121 [ 'addField', 'logging', 'log_deleted', 'patch-log_deleted.sql' ],
122 [ 'addField', 'archive', 'ar_deleted', 'patch-ar_deleted.sql' ],
123 [ 'addField', 'ipblocks', 'ipb_deleted', 'patch-ipb_deleted.sql' ],
124 [ 'addField', 'filearchive', 'fa_deleted', 'patch-fa_deleted.sql' ],
125 [ 'addField', 'archive', 'ar_len', 'patch-ar_len.sql' ],
126
127 // 1.11
128 [ 'addField', 'ipblocks', 'ipb_block_email', 'patch-ipb_emailban.sql' ],
129 [ 'doCategorylinksIndicesUpdate' ],
130 [ 'addField', 'oldimage', 'oi_metadata', 'patch-oi_metadata.sql' ],
131 [ 'addIndex', 'archive', 'usertext_timestamp', 'patch-archive-user-index.sql' ],
132 [ 'addIndex', 'image', 'img_usertext_timestamp', 'patch-image-user-index.sql' ],
133 [ 'addIndex', 'oldimage', 'oi_usertext_timestamp', 'patch-oldimage-user-index.sql' ],
134 [ 'addField', 'archive', 'ar_page_id', 'patch-archive-page_id.sql' ],
135 [ 'addField', 'image', 'img_sha1', 'patch-img_sha1.sql' ],
136
137 // 1.12
138 [ 'addTable', 'protected_titles', 'patch-protected_titles.sql' ],
139
140 // 1.13
141 [ 'addField', 'ipblocks', 'ipb_by_text', 'patch-ipb_by_text.sql' ],
142 [ 'addTable', 'page_props', 'patch-page_props.sql' ],
143 [ 'addTable', 'updatelog', 'patch-updatelog.sql' ],
144 [ 'addTable', 'category', 'patch-category.sql' ],
145 [ 'doCategoryPopulation' ],
146 [ 'addField', 'archive', 'ar_parent_id', 'patch-ar_parent_id.sql' ],
147 [ 'addField', 'user_newtalk', 'user_last_timestamp', 'patch-user_last_timestamp.sql' ],
148 [ 'doPopulateParentId' ],
149 [ 'checkBin', 'protected_titles', 'pt_title', 'patch-pt_title-encoding.sql', ],
150 [ 'doMaybeProfilingMemoryUpdate' ],
151 [ 'doFilearchiveIndicesUpdate' ],
152
153 // 1.14
154 [ 'addField', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ],
155 [ 'doActiveUsersInit' ],
156 [ 'addField', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ],
157
158 // 1.15
159 [ 'addTable', 'change_tag', 'patch-change_tag.sql' ],
160 [ 'addTable', 'tag_summary', 'patch-tag_summary.sql' ],
161 [ 'addTable', 'valid_tag', 'patch-valid_tag.sql' ],
162
163 // 1.16
164 [ 'addTable', 'user_properties', 'patch-user_properties.sql' ],
165 [ 'addTable', 'log_search', 'patch-log_search.sql' ],
166 [ 'addField', 'logging', 'log_user_text', 'patch-log_user_text.sql' ],
167 # listed separately from the previous update because 1.16 was released without this update
168 [ 'doLogUsertextPopulation' ],
169 [ 'doLogSearchPopulation' ],
170 [ 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ],
171 [ 'addIndex', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ],
172 [ 'addIndex', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ],
173 [ 'addField', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ],
174 [ 'doUpdateTranscacheField' ],
175 [ 'doUpdateMimeMinorField' ],
176
177 // 1.17
178 [ 'addTable', 'iwlinks', 'patch-iwlinks.sql' ],
179 [ 'addIndex', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ],
180 [ 'addField', 'updatelog', 'ul_value', 'patch-ul_value.sql' ],
181 [ 'addField', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ],
182 [ 'dropIndex', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ],
183 [ 'addField', 'categorylinks', 'cl_collation', 'patch-categorylinks-better-collation.sql' ],
184 [ 'doClFieldsUpdate' ],
185 [ 'addTable', 'module_deps', 'patch-module_deps.sql' ],
186 [ 'dropIndex', 'archive', 'ar_page_revid', 'patch-archive_kill_ar_page_revid.sql' ],
187 [ 'addIndex', 'archive', 'ar_revid', 'patch-archive_ar_revid.sql' ],
188 [ 'doLangLinksLengthUpdate' ],
189
190 // 1.18
191 [ 'doUserNewTalkTimestampNotNull' ],
192 [ 'addIndex', 'user', 'user_email', 'patch-user_email_index.sql' ],
193 [ 'modifyField', 'user_properties', 'up_property', 'patch-up_property.sql' ],
194 [ 'addTable', 'uploadstash', 'patch-uploadstash.sql' ],
195 [ 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ],
196
197 // 1.19
198 [ 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql' ],
199 [ 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ],
200 [ 'doMigrateUserOptions' ],
201 [ 'dropField', 'user', 'user_options', 'patch-drop-user_options.sql' ],
202 [ 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' ],
203 [ 'addIndex', 'page', 'page_redirect_namespace_len',
204 'patch-page_redirect_namespace_len.sql' ],
205 [ 'addField', 'uploadstash', 'us_chunk_inx', 'patch-uploadstash_chunk.sql' ],
206 [ 'addfield', 'job', 'job_timestamp', 'patch-jobs-add-timestamp.sql' ],
207
208 // 1.20
209 [ 'addIndex', 'revision', 'page_user_timestamp', 'patch-revision-user-page-index.sql' ],
210 [ 'addField', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id.sql' ],
211 [ 'addIndex', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id-index.sql' ],
212 [ 'dropField', 'category', 'cat_hidden', 'patch-cat_hidden.sql' ],
213
214 // 1.21
215 [ 'addField', 'revision', 'rev_content_format', 'patch-revision-rev_content_format.sql' ],
216 [ 'addField', 'revision', 'rev_content_model', 'patch-revision-rev_content_model.sql' ],
217 [ 'addField', 'archive', 'ar_content_format', 'patch-archive-ar_content_format.sql' ],
218 [ 'addField', 'archive', 'ar_content_model', 'patch-archive-ar_content_model.sql' ],
219 [ 'addField', 'page', 'page_content_model', 'patch-page-page_content_model.sql' ],
220 [ 'enableContentHandlerUseDB' ],
221 [ 'dropField', 'site_stats', 'ss_admins', 'patch-drop-ss_admins.sql' ],
222 [ 'dropField', 'recentchanges', 'rc_moved_to_title', 'patch-rc_moved.sql' ],
223 [ 'addTable', 'sites', 'patch-sites.sql' ],
224 [ 'addField', 'filearchive', 'fa_sha1', 'patch-fa_sha1.sql' ],
225 [ 'addField', 'job', 'job_token', 'patch-job_token.sql' ],
226 [ 'addField', 'job', 'job_attempts', 'patch-job_attempts.sql' ],
227 [ 'doEnableProfiling' ],
228 [ 'addField', 'uploadstash', 'us_props', 'patch-uploadstash-us_props.sql' ],
229 [ 'modifyField', 'user_groups', 'ug_group', 'patch-ug_group-length-increase-255.sql' ],
230 [ 'modifyField', 'user_former_groups', 'ufg_group',
231 'patch-ufg_group-length-increase-255.sql' ],
232 [ 'addIndex', 'page_props', 'pp_propname_page',
233 'patch-page_props-propname-page-index.sql' ],
234 [ 'addIndex', 'image', 'img_media_mime', 'patch-img_media_mime-index.sql' ],
235
236 // 1.22
237 [ 'doIwlinksIndexNonUnique' ],
238 [ 'addIndex', 'iwlinks', 'iwl_prefix_from_title',
239 'patch-iwlinks-from-title-index.sql' ],
240 [ 'addField', 'archive', 'ar_id', 'patch-archive-ar_id.sql' ],
241 [ 'addField', 'externallinks', 'el_id', 'patch-externallinks-el_id.sql' ],
242
243 // 1.23
244 [ 'addField', 'recentchanges', 'rc_source', 'patch-rc_source.sql' ],
245 [ 'addIndex', 'logging', 'log_user_text_type_time',
246 'patch-logging_user_text_type_time_index.sql' ],
247 [ 'addIndex', 'logging', 'log_user_text_time', 'patch-logging_user_text_time_index.sql' ],
248 [ 'addField', 'page', 'page_links_updated', 'patch-page_links_updated.sql' ],
249 [ 'addField', 'user', 'user_password_expires', 'patch-user_password_expire.sql' ],
250
251 // 1.24
252 [ 'addField', 'page_props', 'pp_sortkey', 'patch-pp_sortkey.sql' ],
253 [ 'dropField', 'recentchanges', 'rc_cur_time', 'patch-drop-rc_cur_time.sql' ],
254 [ 'addIndex', 'watchlist', 'wl_user_notificationtimestamp',
255 'patch-watchlist-user-notificationtimestamp-index.sql' ],
256 [ 'addField', 'page', 'page_lang', 'patch-page_lang.sql' ],
257 [ 'addField', 'pagelinks', 'pl_from_namespace', 'patch-pl_from_namespace.sql' ],
258 [ 'addField', 'templatelinks', 'tl_from_namespace', 'patch-tl_from_namespace.sql' ],
259 [ 'addField', 'imagelinks', 'il_from_namespace', 'patch-il_from_namespace.sql' ],
260 [ 'modifyField', 'image', 'img_major_mime',
261 'patch-img_major_mime-chemical.sql' ],
262 [ 'modifyField', 'oldimage', 'oi_major_mime',
263 'patch-oi_major_mime-chemical.sql' ],
264 [ 'modifyField', 'filearchive', 'fa_major_mime',
265 'patch-fa_major_mime-chemical.sql' ],
266
267 // 1.25
268 [ 'doUserNewTalkUseridUnsigned' ],
269 // note this patch covers other _comment and _description fields too
270 [ 'modifyField', 'recentchanges', 'rc_comment', 'patch-editsummary-length.sql' ],
271
272 // 1.26
273 [ 'dropTable', 'hitcounter' ],
274 [ 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ],
275 [ 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ],
276
277 // 1.27
278 [ 'dropTable', 'msg_resource_links' ],
279 [ 'dropTable', 'msg_resource' ],
280 [ 'addTable', 'bot_passwords', 'patch-bot_passwords.sql' ],
281 [ 'addField', 'watchlist', 'wl_id', 'patch-watchlist-wl_id.sql' ],
282 [ 'dropIndex', 'categorylinks', 'cl_collation', 'patch-kill-cl_collation_index.sql' ],
283 [ 'addIndex', 'categorylinks', 'cl_collation_ext',
284 'patch-add-cl_collation_ext_index.sql' ],
285 [ 'doCollationUpdate' ],
286
287 // 1.28
288 [ 'addIndex', 'recentchanges', 'rc_name_type_patrolled_timestamp',
289 'patch-add-rc_name_type_patrolled_timestamp_index.sql' ],
290 [ 'doRevisionPageRevIndexNonUnique' ],
291 [ 'doNonUniquePlTlIl' ],
292 [ 'addField', 'change_tag', 'ct_id', 'patch-change_tag-ct_id.sql' ],
293 [ 'addField', 'tag_summary', 'ts_id', 'patch-tag_summary-ts_id.sql' ],
294 [ 'modifyField', 'recentchanges', 'rc_ip', 'patch-rc_ip_modify.sql' ],
295
296 // 1.29
297 [ 'addField', 'externallinks', 'el_index_60', 'patch-externallinks-el_index_60.sql' ],
298 [ 'dropIndex', 'user_groups', 'ug_user_group', 'patch-user_groups-primary-key.sql' ],
299 [ 'addField', 'user_groups', 'ug_expiry', 'patch-user_groups-ug_expiry.sql' ],
300 ];
301 }
302
303 /**
304 * 1.4 betas were missing the 'binary' marker from logging.log_title,
305 * which causes a collation mismatch error on joins in MySQL 4.1.
306 *
307 * @param string $table Table name
308 * @param string $field Field name to check
309 * @param string $patchFile Path to the patch to correct the field
310 * @return bool
311 */
312 protected function checkBin( $table, $field, $patchFile ) {
313 if ( !$this->doTable( $table ) ) {
314 return true;
315 }
316
317 /** @var MySQLField $fieldInfo */
318 $fieldInfo = $this->db->fieldInfo( $table, $field );
319 if ( $fieldInfo->isBinary() ) {
320 $this->output( "...$table table has correct $field encoding.\n" );
321 } else {
322 $this->applyPatch( $patchFile, false, "Fixing $field encoding on $table table" );
323 }
324 }
325
326 /**
327 * Check whether an index contain a field
328 *
329 * @param string $table Table name
330 * @param string $index Index name to check
331 * @param string $field Field that should be in the index
332 * @return bool
333 */
334 protected function indexHasField( $table, $index, $field ) {
335 if ( !$this->doTable( $table ) ) {
336 return true;
337 }
338
339 $info = $this->db->indexInfo( $table, $index, __METHOD__ );
340 if ( $info ) {
341 foreach ( $info as $row ) {
342 if ( $row->Column_name == $field ) {
343 $this->output( "...index $index on table $table includes field $field.\n" );
344
345 return true;
346 }
347 }
348 }
349 $this->output( "...index $index on table $table has no field $field; added.\n" );
350
351 return false;
352 }
353
354 /**
355 * Check that interwiki table exists; if it doesn't source it
356 */
357 protected function doInterwikiUpdate() {
358 global $IP;
359
360 if ( !$this->doTable( 'interwiki' ) ) {
361 return true;
362 }
363
364 if ( $this->db->tableExists( "interwiki", __METHOD__ ) ) {
365 $this->output( "...already have interwiki table\n" );
366
367 return;
368 }
369
370 $this->applyPatch( 'patch-interwiki.sql', false, 'Creating interwiki table' );
371 $this->applyPatch(
372 "$IP/maintenance/interwiki.sql",
373 true,
374 'Adding default interwiki definitions'
375 );
376 }
377
378 /**
379 * Check that proper indexes are in place
380 */
381 protected function doIndexUpdate() {
382 $meta = $this->db->fieldInfo( 'recentchanges', 'rc_timestamp' );
383 if ( $meta === false ) {
384 throw new MWException( 'Missing rc_timestamp field of recentchanges table. Should not happen.' );
385 }
386 if ( $meta->isMultipleKey() ) {
387 $this->output( "...indexes seem up to 20031107 standards.\n" );
388
389 return;
390 }
391
392 $this->applyPatch( 'patch-indexes.sql', true, "Updating indexes to 20031107" );
393 }
394
395 protected function doOldLinksUpdate() {
396 $cl = $this->maintenance->runChild( 'ConvertLinks' );
397 $cl->execute();
398 }
399
400 protected function doFixAncientImagelinks() {
401 $info = $this->db->fieldInfo( 'imagelinks', 'il_from' );
402 if ( !$info || $info->type() !== 'string' ) {
403 $this->output( "...il_from OK\n" );
404
405 return;
406 }
407
408 $applied = $this->applyPatch(
409 'patch-fix-il_from.sql',
410 false,
411 'Fixing ancient broken imagelinks table.'
412 );
413
414 if ( $applied ) {
415 $this->output( "NOTE: you will have to run maintenance/refreshLinks.php after this." );
416 }
417 }
418
419 /**
420 * Check if we need to add talk page rows to the watchlist
421 */
422 function doWatchlistUpdate() {
423 $talk = $this->db->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', __METHOD__ );
424 $nontalk = $this->db->selectField(
425 'watchlist',
426 'count(*)',
427 'NOT (wl_namespace & 1)',
428 __METHOD__
429 );
430 if ( $talk == $nontalk ) {
431 $this->output( "...watchlist talk page rows already present.\n" );
432
433 return;
434 }
435
436 $this->output( "Adding missing watchlist talk page rows... " );
437 $this->db->insertSelect( 'watchlist', 'watchlist',
438 [
439 'wl_user' => 'wl_user',
440 'wl_namespace' => 'wl_namespace | 1',
441 'wl_title' => 'wl_title',
442 'wl_notificationtimestamp' => 'wl_notificationtimestamp'
443 ], [ 'NOT (wl_namespace & 1)' ], __METHOD__, 'IGNORE' );
444 $this->output( "done.\n" );
445
446 $this->output( "Adding missing watchlist subject page rows... " );
447 $this->db->insertSelect( 'watchlist', 'watchlist',
448 [
449 'wl_user' => 'wl_user',
450 'wl_namespace' => 'wl_namespace & ~1',
451 'wl_title' => 'wl_title',
452 'wl_notificationtimestamp' => 'wl_notificationtimestamp'
453 ], [ 'wl_namespace & 1' ], __METHOD__, 'IGNORE' );
454 $this->output( "done.\n" );
455 }
456
457 function doSchemaRestructuring() {
458 if ( $this->db->tableExists( 'page', __METHOD__ ) ) {
459 $this->output( "...page table already exists.\n" );
460
461 return;
462 }
463
464 $this->output( "...converting from cur/old to page/revision/text DB structure.\n" );
465 $this->output( wfTimestamp( TS_DB ) );
466 $this->output( "......checking for duplicate entries.\n" );
467
468 list( $cur, $old, $page, $revision, $text ) = $this->db->tableNamesN(
469 'cur',
470 'old',
471 'page',
472 'revision',
473 'text'
474 );
475
476 $rows = $this->db->query( "
477 SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
478 FROM $cur
479 GROUP BY cur_title, cur_namespace
480 HAVING c>1",
481 __METHOD__
482 );
483
484 if ( $rows->numRows() > 0 ) {
485 $this->output( wfTimestamp( TS_DB ) );
486 $this->output( "......<b>Found duplicate entries</b>\n" );
487 $this->output( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
488 $duplicate = [];
489 foreach ( $rows as $row ) {
490 if ( !isset( $duplicate[$row->cur_namespace] ) ) {
491 $duplicate[$row->cur_namespace] = [];
492 }
493
494 $duplicate[$row->cur_namespace][] = $row->cur_title;
495 $this->output( sprintf(
496 " %-60s %3s %5s\n",
497 $row->cur_title, $row->cur_namespace,
498 $row->c
499 ) );
500 }
501 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE ";
502 $firstCond = true;
503 foreach ( $duplicate as $ns => $titles ) {
504 if ( $firstCond ) {
505 $firstCond = false;
506 } else {
507 $sql .= ' OR ';
508 }
509 $sql .= "( cur_namespace = {$ns} AND cur_title in (";
510 $first = true;
511 foreach ( $titles as $t ) {
512 if ( $first ) {
513 $sql .= $this->db->addQuotes( $t );
514 $first = false;
515 } else {
516 $sql .= ', ' . $this->db->addQuotes( $t );
517 }
518 }
519 $sql .= ") ) \n";
520 }
521 # By sorting descending, the most recent entry will be the first in the list.
522 # All following entries will be deleted by the next while-loop.
523 $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC';
524
525 $rows = $this->db->query( $sql, __METHOD__ );
526
527 $prev_title = $prev_namespace = false;
528 $deleteId = [];
529
530 foreach ( $rows as $row ) {
531 if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) {
532 $deleteId[] = $row->cur_id;
533 }
534 $prev_title = $row->cur_title;
535 $prev_namespace = $row->cur_namespace;
536 }
537 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . implode( ',', $deleteId ) . ')';
538 $this->db->query( $sql, __METHOD__ );
539 $this->output( wfTimestamp( TS_DB ) );
540 $this->output( "......<b>Deleted</b> " . $this->db->affectedRows() . " records.\n" );
541 }
542
543 $this->output( wfTimestamp( TS_DB ) );
544 $this->output( "......Creating tables.\n" );
545 $this->db->query( "CREATE TABLE $page (
546 page_id int(8) unsigned NOT NULL auto_increment,
547 page_namespace int NOT NULL,
548 page_title varchar(255) binary NOT NULL,
549 page_restrictions tinyblob NOT NULL,
550 page_is_redirect tinyint(1) unsigned NOT NULL default '0',
551 page_is_new tinyint(1) unsigned NOT NULL default '0',
552 page_random real unsigned NOT NULL,
553 page_touched char(14) binary NOT NULL default '',
554 page_latest int(8) unsigned NOT NULL,
555 page_len int(8) unsigned NOT NULL,
556
557 PRIMARY KEY page_id (page_id),
558 UNIQUE INDEX name_title (page_namespace,page_title),
559 INDEX (page_random),
560 INDEX (page_len)
561 ) ENGINE=InnoDB", __METHOD__ );
562 $this->db->query( "CREATE TABLE $revision (
563 rev_id int(8) unsigned NOT NULL auto_increment,
564 rev_page int(8) unsigned NOT NULL,
565 rev_comment tinyblob NOT NULL,
566 rev_user int(5) unsigned NOT NULL default '0',
567 rev_user_text varchar(255) binary NOT NULL default '',
568 rev_timestamp char(14) binary NOT NULL default '',
569 rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
570 rev_deleted tinyint(1) unsigned NOT NULL default '0',
571 rev_len int(8) unsigned,
572 rev_parent_id int(8) unsigned default NULL,
573 PRIMARY KEY rev_page_id (rev_page, rev_id),
574 UNIQUE INDEX rev_id (rev_id),
575 INDEX rev_timestamp (rev_timestamp),
576 INDEX page_timestamp (rev_page,rev_timestamp),
577 INDEX user_timestamp (rev_user,rev_timestamp),
578 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
579 ) ENGINE=InnoDB", __METHOD__ );
580
581 $this->output( wfTimestamp( TS_DB ) );
582 $this->output( "......Locking tables.\n" );
583 $this->db->query(
584 "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE",
585 __METHOD__
586 );
587
588 $maxold = intval( $this->db->selectField( 'old', 'max(old_id)', '', __METHOD__ ) );
589 $this->output( wfTimestamp( TS_DB ) );
590 $this->output( "......maxold is {$maxold}\n" );
591
592 $this->output( wfTimestamp( TS_DB ) );
593 global $wgLegacySchemaConversion;
594 if ( $wgLegacySchemaConversion ) {
595 // Create HistoryBlobCurStub entries.
596 // Text will be pulled from the leftover 'cur' table at runtime.
597 $this->output( "......Moving metadata from cur; using blob references to text in cur table.\n" );
598 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')";
599 $cur_flags = "'object'";
600 } else {
601 // Copy all cur text in immediately: this may take longer but avoids
602 // having to keep an extra table around.
603 $this->output( "......Moving text from cur.\n" );
604 $cur_text = 'cur_text';
605 $cur_flags = "''";
606 }
607 $this->db->query(
608 "INSERT INTO $old (old_namespace, old_title, old_text, old_comment, old_user,
609 old_user_text, old_timestamp, old_minor_edit, old_flags)
610 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text,
611 cur_timestamp, cur_minor_edit, $cur_flags
612 FROM $cur",
613 __METHOD__
614 );
615
616 $this->output( wfTimestamp( TS_DB ) );
617 $this->output( "......Setting up revision table.\n" );
618 $this->db->query(
619 "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user,
620 rev_user_text, rev_timestamp, rev_minor_edit)
621 SELECT old_id, cur_id, old_comment, old_user, old_user_text,
622 old_timestamp, old_minor_edit
623 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title",
624 __METHOD__
625 );
626
627 $this->output( wfTimestamp( TS_DB ) );
628 $this->output( "......Setting up page table.\n" );
629 $this->db->query(
630 "INSERT INTO $page (page_id, page_namespace, page_title,
631 page_restrictions, page_is_redirect, page_is_new, page_random,
632 page_touched, page_latest, page_len)
633 SELECT cur_id, cur_namespace, cur_title, cur_restrictions,
634 cur_is_redirect, cur_is_new, cur_random, cur_touched, rev_id, LENGTH(cur_text)
635 FROM $cur,$revision
636 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}",
637 __METHOD__
638 );
639
640 $this->output( wfTimestamp( TS_DB ) );
641 $this->output( "......Unlocking tables.\n" );
642 $this->db->query( "UNLOCK TABLES", __METHOD__ );
643
644 $this->output( wfTimestamp( TS_DB ) );
645 $this->output( "......Renaming old.\n" );
646 $this->db->query( "ALTER TABLE $old RENAME TO $text", __METHOD__ );
647
648 $this->output( wfTimestamp( TS_DB ) );
649 $this->output( "...done.\n" );
650 }
651
652 protected function doNamespaceSize() {
653 $tables = [
654 'page' => 'page',
655 'archive' => 'ar',
656 'recentchanges' => 'rc',
657 'watchlist' => 'wl',
658 'querycache' => 'qc',
659 'logging' => 'log',
660 ];
661 foreach ( $tables as $table => $prefix ) {
662 $field = $prefix . '_namespace';
663
664 $tablename = $this->db->tableName( $table );
665 $result = $this->db->query( "SHOW COLUMNS FROM $tablename LIKE '$field'", __METHOD__ );
666 $info = $this->db->fetchObject( $result );
667
668 if ( substr( $info->Type, 0, 3 ) == 'int' ) {
669 $this->output( "...$field is already a full int ($info->Type).\n" );
670 } else {
671 $this->output( "Promoting $field from $info->Type to int... " );
672 $this->db->query( "ALTER TABLE $tablename MODIFY $field int NOT NULL", __METHOD__ );
673 $this->output( "done.\n" );
674 }
675 }
676 }
677
678 protected function doPagelinksUpdate() {
679 if ( $this->db->tableExists( 'pagelinks', __METHOD__ ) ) {
680 $this->output( "...already have pagelinks table.\n" );
681
682 return;
683 }
684
685 $this->applyPatch(
686 'patch-pagelinks.sql',
687 false,
688 'Converting links and brokenlinks tables to pagelinks'
689 );
690
691 global $wgContLang;
692 foreach ( $wgContLang->getNamespaces() as $ns => $name ) {
693 if ( $ns == 0 ) {
694 continue;
695 }
696
697 $this->output( "Cleaning up broken links for namespace $ns... " );
698 $this->db->update( 'pagelinks',
699 [
700 'pl_namespace' => $ns,
701 "pl_title = TRIM(LEADING {$this->db->addQuotes( "$name:" )} FROM pl_title)",
702 ],
703 [
704 'pl_namespace' => 0,
705 'pl_title' . $this->db->buildLike( "$name:", $this->db->anyString() ),
706 ],
707 __METHOD__
708 );
709 $this->output( "done.\n" );
710 }
711 }
712
713 protected function doUserUniqueUpdate() {
714 if ( !$this->doTable( 'user' ) ) {
715 return true;
716 }
717
718 $duper = new UserDupes( $this->db, [ $this, 'output' ] );
719 if ( $duper->hasUniqueIndex() ) {
720 $this->output( "...already have unique user_name index.\n" );
721
722 return;
723 }
724
725 if ( !$duper->clearDupes() ) {
726 $this->output( "WARNING: This next step will probably fail due to unfixed duplicates...\n" );
727 }
728 $this->applyPatch( 'patch-user_nameindex.sql', false, "Adding unique index on user_name" );
729 }
730
731 protected function doUserGroupsUpdate() {
732 if ( !$this->doTable( 'user_groups' ) ) {
733 return true;
734 }
735
736 if ( $this->db->tableExists( 'user_groups', __METHOD__ ) ) {
737 $info = $this->db->fieldInfo( 'user_groups', 'ug_group' );
738 if ( $info->type() == 'int' ) {
739 $oldug = $this->db->tableName( 'user_groups' );
740 $newug = $this->db->tableName( 'user_groups_bogus' );
741 $this->output( "user_groups table exists but is in bogus intermediate " .
742 "format. Renaming to $newug... " );
743 $this->db->query( "ALTER TABLE $oldug RENAME TO $newug", __METHOD__ );
744 $this->output( "done.\n" );
745
746 $this->applyPatch( 'patch-user_groups.sql', false, "Re-adding fresh user_groups table" );
747
748 $this->output( "***\n" );
749 $this->output( "*** WARNING: You will need to manually fix up user " .
750 "permissions in the user_groups\n" );
751 $this->output( "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n" );
752 $this->output( "***\n" );
753 } else {
754 $this->output( "...user_groups table exists and is in current format.\n" );
755 }
756
757 return;
758 }
759
760 $this->applyPatch( 'patch-user_groups.sql', false, "Adding user_groups table" );
761
762 if ( !$this->db->tableExists( 'user_rights', __METHOD__ ) ) {
763 if ( $this->db->fieldExists( 'user', 'user_rights', __METHOD__ ) ) {
764 $this->applyPatch(
765 'patch-user_rights.sql',
766 false,
767 'Upgrading from a 1.3 or older database? Breaking out user_rights for conversion'
768 );
769 } else {
770 $this->output( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" );
771 $this->output( "*** You may need to manually configure some sysops by manipulating\n" );
772 $this->output( "*** the user_groups table.\n" );
773
774 return;
775 }
776 }
777
778 $this->output( "Converting user_rights table to user_groups... " );
779 $result = $this->db->select( 'user_rights',
780 [ 'ur_user', 'ur_rights' ],
781 [ "ur_rights != ''" ],
782 __METHOD__ );
783
784 foreach ( $result as $row ) {
785 $groups = array_unique(
786 array_map( 'trim',
787 explode( ',', $row->ur_rights ) ) );
788
789 foreach ( $groups as $group ) {
790 $this->db->insert( 'user_groups',
791 [
792 'ug_user' => $row->ur_user,
793 'ug_group' => $group ],
794 __METHOD__ );
795 }
796 }
797 $this->output( "done.\n" );
798 }
799
800 /**
801 * Make sure wl_notificationtimestamp can be NULL,
802 * and update old broken items.
803 */
804 protected function doWatchlistNull() {
805 $info = $this->db->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
806 if ( !$info ) {
807 return;
808 }
809 if ( $info->isNullable() ) {
810 $this->output( "...wl_notificationtimestamp is already nullable.\n" );
811
812 return;
813 }
814
815 $this->applyPatch(
816 'patch-watchlist-null.sql',
817 false,
818 'Making wl_notificationtimestamp nullable'
819 );
820 }
821
822 /**
823 * Set page_random field to a random value where it is equals to 0.
824 *
825 * @see bug 3946
826 */
827 protected function doPageRandomUpdate() {
828 $page = $this->db->tableName( 'page' );
829 $this->db->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", __METHOD__ );
830 $rows = $this->db->affectedRows();
831
832 if ( $rows ) {
833 $this->output( "Set page_random to a random value on $rows rows where it was set to 0\n" );
834 } else {
835 $this->output( "...no page_random rows needed to be set\n" );
836 }
837 }
838
839 protected function doTemplatelinksUpdate() {
840 if ( $this->db->tableExists( 'templatelinks', __METHOD__ ) ) {
841 $this->output( "...templatelinks table already exists\n" );
842
843 return;
844 }
845
846 $this->applyPatch( 'patch-templatelinks.sql', false, "Creating templatelinks table" );
847
848 $this->output( "Populating...\n" );
849 if ( wfGetLB()->getServerCount() > 1 ) {
850 // Slow, replication-friendly update
851 $res = $this->db->select( 'pagelinks', [ 'pl_from', 'pl_namespace', 'pl_title' ],
852 [ 'pl_namespace' => NS_TEMPLATE ], __METHOD__ );
853 $count = 0;
854 foreach ( $res as $row ) {
855 $count = ( $count + 1 ) % 100;
856 if ( $count == 0 ) {
857 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
858 $lbFactory->waitForReplication( [ 'wiki' => wfWikiID() ] );
859 }
860 $this->db->insert( 'templatelinks',
861 [
862 'tl_from' => $row->pl_from,
863 'tl_namespace' => $row->pl_namespace,
864 'tl_title' => $row->pl_title,
865 ], __METHOD__
866 );
867 }
868 } else {
869 // Fast update
870 $this->db->insertSelect( 'templatelinks', 'pagelinks',
871 [
872 'tl_from' => 'pl_from',
873 'tl_namespace' => 'pl_namespace',
874 'tl_title' => 'pl_title'
875 ], [
876 'pl_namespace' => 10
877 ], __METHOD__
878 );
879 }
880 $this->output( "Done. Please run maintenance/refreshLinks.php for a more " .
881 "thorough templatelinks update.\n" );
882 }
883
884 protected function doBacklinkingIndicesUpdate() {
885 if ( !$this->indexHasField( 'pagelinks', 'pl_namespace', 'pl_from' ) ||
886 !$this->indexHasField( 'templatelinks', 'tl_namespace', 'tl_from' ) ||
887 !$this->indexHasField( 'imagelinks', 'il_to', 'il_from' )
888 ) {
889 $this->applyPatch( 'patch-backlinkindexes.sql', false, "Updating backlinking indices" );
890 }
891 }
892
893 /**
894 * Adding page_restrictions table, obsoleting page.page_restrictions.
895 * Migrating old restrictions to new table
896 * -- Andrew Garrett, January 2007.
897 */
898 protected function doRestrictionsUpdate() {
899 if ( $this->db->tableExists( 'page_restrictions', __METHOD__ ) ) {
900 $this->output( "...page_restrictions table already exists.\n" );
901
902 return;
903 }
904
905 $this->applyPatch(
906 'patch-page_restrictions.sql',
907 false,
908 'Creating page_restrictions table (1/2)'
909 );
910 $this->applyPatch(
911 'patch-page_restrictions_sortkey.sql',
912 false,
913 'Creating page_restrictions table (2/2)'
914 );
915 $this->output( "done.\n" );
916
917 $this->output( "Migrating old restrictions to new table...\n" );
918 $task = $this->maintenance->runChild( 'UpdateRestrictions' );
919 $task->execute();
920 }
921
922 protected function doCategorylinksIndicesUpdate() {
923 if ( !$this->indexHasField( 'categorylinks', 'cl_sortkey', 'cl_from' ) ) {
924 $this->applyPatch( 'patch-categorylinksindex.sql', false, "Updating categorylinks Indices" );
925 }
926 }
927
928 protected function doCategoryPopulation() {
929 if ( $this->updateRowExists( 'populate category' ) ) {
930 $this->output( "...category table already populated.\n" );
931
932 return;
933 }
934
935 $this->output(
936 "Populating category table, printing progress markers. " .
937 "For large databases, you\n" .
938 "may want to hit Ctrl-C and do this manually with maintenance/\n" .
939 "populateCategory.php.\n"
940 );
941 $task = $this->maintenance->runChild( 'PopulateCategory' );
942 $task->execute();
943 $this->output( "Done populating category table.\n" );
944 }
945
946 protected function doPopulateParentId() {
947 if ( !$this->updateRowExists( 'populate rev_parent_id' ) ) {
948 $this->output(
949 "Populating rev_parent_id fields, printing progress markers. For large\n" .
950 "databases, you may want to hit Ctrl-C and do this manually with\n" .
951 "maintenance/populateParentId.php.\n" );
952
953 $task = $this->maintenance->runChild( 'PopulateParentId' );
954 $task->execute();
955 }
956 }
957
958 protected function doMaybeProfilingMemoryUpdate() {
959 if ( !$this->doTable( 'profiling' ) ) {
960 return true;
961 }
962
963 if ( !$this->db->tableExists( 'profiling', __METHOD__ ) ) {
964 return true;
965 } elseif ( $this->db->fieldExists( 'profiling', 'pf_memory', __METHOD__ ) ) {
966 $this->output( "...profiling table has pf_memory field.\n" );
967
968 return true;
969 }
970
971 return $this->applyPatch(
972 'patch-profiling-memory.sql',
973 false,
974 'Adding pf_memory field to table profiling'
975 );
976 }
977
978 protected function doFilearchiveIndicesUpdate() {
979 $info = $this->db->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ );
980 if ( !$info ) {
981 $this->applyPatch( 'patch-filearchive-user-index.sql', false, "Updating filearchive indices" );
982 }
983
984 return true;
985 }
986
987 protected function doNonUniquePlTlIl() {
988 $info = $this->db->indexInfo( 'pagelinks', 'pl_namespace' );
989 if ( is_array( $info ) && $info[0]->Non_unique ) {
990 $this->output( "...pl_namespace, tl_namespace, il_to indices are already non-UNIQUE.\n" );
991
992 return true;
993 }
994 if ( $this->skipSchema ) {
995 $this->output( "...skipping schema change (making pl_namespace, tl_namespace " .
996 "and il_to indices non-UNIQUE).\n" );
997
998 return false;
999 }
1000
1001 return $this->applyPatch(
1002 'patch-pl-tl-il-nonunique.sql',
1003 false,
1004 'Making pl_namespace, tl_namespace and il_to indices non-UNIQUE'
1005 );
1006 }
1007
1008 protected function doUpdateMimeMinorField() {
1009 if ( $this->updateRowExists( 'mime_minor_length' ) ) {
1010 $this->output( "...*_mime_minor fields are already long enough.\n" );
1011
1012 return;
1013 }
1014
1015 $this->applyPatch(
1016 'patch-mime_minor_length.sql',
1017 false,
1018 'Altering all *_mime_minor fields to 100 bytes in size'
1019 );
1020 }
1021
1022 protected function doClFieldsUpdate() {
1023 if ( $this->updateRowExists( 'cl_fields_update' ) ) {
1024 $this->output( "...categorylinks up-to-date.\n" );
1025
1026 return;
1027 }
1028
1029 $this->applyPatch(
1030 'patch-categorylinks-better-collation2.sql',
1031 false,
1032 'Updating categorylinks (again)'
1033 );
1034 }
1035
1036 protected function doLangLinksLengthUpdate() {
1037 $langlinks = $this->db->tableName( 'langlinks' );
1038 $res = $this->db->query( "SHOW COLUMNS FROM $langlinks LIKE 'll_lang'" );
1039 $row = $this->db->fetchObject( $res );
1040
1041 if ( $row && $row->Type == "varbinary(10)" ) {
1042 $this->applyPatch(
1043 'patch-langlinks-ll_lang-20.sql',
1044 false,
1045 'Updating length of ll_lang in langlinks'
1046 );
1047 } else {
1048 $this->output( "...ll_lang is up-to-date.\n" );
1049 }
1050 }
1051
1052 protected function doUserNewTalkTimestampNotNull() {
1053 if ( !$this->doTable( 'user_newtalk' ) ) {
1054 return true;
1055 }
1056
1057 $info = $this->db->fieldInfo( 'user_newtalk', 'user_last_timestamp' );
1058 if ( $info === false ) {
1059 return;
1060 }
1061 if ( $info->isNullable() ) {
1062 $this->output( "...user_last_timestamp is already nullable.\n" );
1063
1064 return;
1065 }
1066
1067 $this->applyPatch(
1068 'patch-user-newtalk-timestamp-null.sql',
1069 false,
1070 'Making user_last_timestamp nullable'
1071 );
1072 }
1073
1074 protected function doIwlinksIndexNonUnique() {
1075 $info = $this->db->indexInfo( 'iwlinks', 'iwl_prefix_title_from' );
1076 if ( is_array( $info ) && $info[0]->Non_unique ) {
1077 $this->output( "...iwl_prefix_title_from index is already non-UNIQUE.\n" );
1078
1079 return true;
1080 }
1081 if ( $this->skipSchema ) {
1082 $this->output( "...skipping schema change (making iwl_prefix_title_from index non-UNIQUE).\n" );
1083
1084 return false;
1085 }
1086
1087 return $this->applyPatch(
1088 'patch-iwl_prefix_title_from-non-unique.sql',
1089 false,
1090 'Making iwl_prefix_title_from index non-UNIQUE'
1091 );
1092 }
1093
1094 protected function doUserNewTalkUseridUnsigned() {
1095 if ( !$this->doTable( 'user_newtalk' ) ) {
1096 return true;
1097 }
1098
1099 $info = $this->db->fieldInfo( 'user_newtalk', 'user_id' );
1100 if ( $info === false ) {
1101 return true;
1102 }
1103 if ( $info->isUnsigned() ) {
1104 $this->output( "...user_id is already unsigned int.\n" );
1105
1106 return true;
1107 }
1108
1109 return $this->applyPatch(
1110 'patch-user-newtalk-userid-unsigned.sql',
1111 false,
1112 'Making user_id unsigned int'
1113 );
1114 }
1115
1116 protected function doRevisionPageRevIndexNonUnique() {
1117 if ( !$this->doTable( 'revision' ) ) {
1118 return true;
1119 } elseif ( !$this->db->indexExists( 'revision', 'rev_page_id' ) ) {
1120 $this->output( "...rev_page_id index not found on revision.\n" );
1121 return true;
1122 }
1123
1124 if ( !$this->db->indexUnique( 'revision', 'rev_page_id' ) ) {
1125 $this->output( "...rev_page_id index already non-unique.\n" );
1126 return true;
1127 }
1128
1129 return $this->applyPatch(
1130 'patch-revision-page-rev-index-nonunique.sql',
1131 false,
1132 'Making rev_page_id index non-unique'
1133 );
1134 }
1135
1136 public function getSchemaVars() {
1137 global $wgDBTableOptions;
1138
1139 $vars = [];
1140 $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions );
1141 $vars['wgDBTableOptions'] = str_replace(
1142 'CHARSET=mysql4',
1143 'CHARSET=binary',
1144 $vars['wgDBTableOptions']
1145 );
1146
1147 return $vars;
1148 }
1149 }