MediaWiki REL1_27
PostgresUpdater.php
Go to the documentation of this file.
1<?php
31
35 protected $db;
36
42 protected function getCoreUpdateList() {
43 return [
44 # rename tables 1.7.3
45 # r15791 Change reserved word table names "user" and "text"
46 [ 'renameTable', 'user', 'mwuser' ],
47 [ 'renameTable', 'text', 'pagecontent' ],
48 [ 'renameIndex', 'mwuser', 'user_pkey', 'mwuser_pkey' ],
49 [ 'renameIndex', 'mwuser', 'user_user_name_key', 'mwuser_user_name_key' ],
50 [ 'renameIndex', 'pagecontent', 'text_pkey', 'pagecontent_pkey' ],
51
52 # renamed sequences
53 [ 'renameSequence', 'ipblocks_ipb_id_val', 'ipblocks_ipb_id_seq' ],
54 [ 'renameSequence', 'rev_rev_id_val', 'revision_rev_id_seq' ],
55 [ 'renameSequence', 'text_old_id_val', 'text_old_id_seq' ],
56 [ 'renameSequence', 'rc_rc_id_seq', 'recentchanges_rc_id_seq' ],
57 [ 'renameSequence', 'log_log_id_seq', 'logging_log_id_seq' ],
58 [ 'renameSequence', 'pr_id_val', 'page_restrictions_pr_id_seq' ],
59 [ 'renameSequence', 'us_id_seq', 'uploadstash_us_id_seq' ],
60
61 # since r58263
62 [ 'renameSequence', 'category_id_seq', 'category_cat_id_seq' ],
63
64 # new sequences if not renamed above
65 [ 'addSequence', 'logging', false, 'logging_log_id_seq' ],
66 [ 'addSequence', 'page_restrictions', false, 'page_restrictions_pr_id_seq' ],
67 [ 'addSequence', 'filearchive', 'fa_id', 'filearchive_fa_id_seq' ],
68 [ 'addSequence', 'archive', false, 'archive_ar_id_seq' ],
69 [ 'addSequence', 'externallinks', false, 'externallinks_el_id_seq' ],
70 [ 'addSequence', 'watchlist', false, 'watchlist_wl_id_seq' ],
71
72 # new tables
73 [ 'addTable', 'category', 'patch-category.sql' ],
74 [ 'addTable', 'page', 'patch-page.sql' ],
75 [ 'addTable', 'querycachetwo', 'patch-querycachetwo.sql' ],
76 [ 'addTable', 'page_props', 'patch-page_props.sql' ],
77 [ 'addTable', 'page_restrictions', 'patch-page_restrictions.sql' ],
78 [ 'addTable', 'profiling', 'patch-profiling.sql' ],
79 [ 'addTable', 'protected_titles', 'patch-protected_titles.sql' ],
80 [ 'addTable', 'redirect', 'patch-redirect.sql' ],
81 [ 'addTable', 'updatelog', 'patch-updatelog.sql' ],
82 [ 'addTable', 'change_tag', 'patch-change_tag.sql' ],
83 [ 'addTable', 'tag_summary', 'patch-tag_summary.sql' ],
84 [ 'addTable', 'valid_tag', 'patch-valid_tag.sql' ],
85 [ 'addTable', 'user_properties', 'patch-user_properties.sql' ],
86 [ 'addTable', 'log_search', 'patch-log_search.sql' ],
87 [ 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ],
88 [ 'addTable', 'iwlinks', 'patch-iwlinks.sql' ],
89 [ 'addTable', 'module_deps', 'patch-module_deps.sql' ],
90 [ 'addTable', 'uploadstash', 'patch-uploadstash.sql' ],
91 [ 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ],
92 [ 'addTable', 'sites', 'patch-sites.sql' ],
93 [ 'addTable', 'bot_passwords', 'patch-bot_passwords.sql' ],
94
95 # Needed before new field
96 [ 'convertArchive2' ],
97
98 # new fields
99 [ 'addPgField', 'updatelog', 'ul_value', 'TEXT' ],
100 [ 'addPgField', 'archive', 'ar_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
101 [ 'addPgField', 'archive', 'ar_len', 'INTEGER' ],
102 [ 'addPgField', 'archive', 'ar_page_id', 'INTEGER' ],
103 [ 'addPgField', 'archive', 'ar_parent_id', 'INTEGER' ],
104 [ 'addPgField', 'archive', 'ar_content_model', 'TEXT' ],
105 [ 'addPgField', 'archive', 'ar_content_format', 'TEXT' ],
106 [ 'addPgField', 'categorylinks', 'cl_sortkey_prefix', "TEXT NOT NULL DEFAULT ''" ],
107 [ 'addPgField', 'categorylinks', 'cl_collation', "TEXT NOT NULL DEFAULT 0" ],
108 [ 'addPgField', 'categorylinks', 'cl_type', "TEXT NOT NULL DEFAULT 'page'" ],
109 [ 'addPgField', 'image', 'img_sha1', "TEXT NOT NULL DEFAULT ''" ],
110 [ 'addPgField', 'ipblocks', 'ipb_allow_usertalk', 'SMALLINT NOT NULL DEFAULT 0' ],
111 [ 'addPgField', 'ipblocks', 'ipb_anon_only', 'SMALLINT NOT NULL DEFAULT 0' ],
112 [ 'addPgField', 'ipblocks', 'ipb_by_text', "TEXT NOT NULL DEFAULT ''" ],
113 [ 'addPgField', 'ipblocks', 'ipb_block_email', 'SMALLINT NOT NULL DEFAULT 0' ],
114 [ 'addPgField', 'ipblocks', 'ipb_create_account', 'SMALLINT NOT NULL DEFAULT 1' ],
115 [ 'addPgField', 'ipblocks', 'ipb_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
116 [ 'addPgField', 'ipblocks', 'ipb_enable_autoblock', 'SMALLINT NOT NULL DEFAULT 1' ],
117 [ 'addPgField', 'ipblocks', 'ipb_parent_block_id',
118 'INTEGER DEFAULT NULL REFERENCES ipblocks(ipb_id) ' .
119 'ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED' ],
120 [ 'addPgField', 'filearchive', 'fa_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
121 [ 'addPgField', 'filearchive', 'fa_sha1', "TEXT NOT NULL DEFAULT ''" ],
122 [ 'addPgField', 'logging', 'log_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
123 [ 'addPgField', 'logging', 'log_id',
124 "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('logging_log_id_seq')" ],
125 [ 'addPgField', 'logging', 'log_params', 'TEXT' ],
126 [ 'addPgField', 'mwuser', 'user_editcount', 'INTEGER' ],
127 [ 'addPgField', 'mwuser', 'user_newpass_time', 'TIMESTAMPTZ' ],
128 [ 'addPgField', 'oldimage', 'oi_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
129 [ 'addPgField', 'oldimage', 'oi_major_mime', "TEXT NOT NULL DEFAULT 'unknown'" ],
130 [ 'addPgField', 'oldimage', 'oi_media_type', 'TEXT' ],
131 [ 'addPgField', 'oldimage', 'oi_metadata', "BYTEA NOT NULL DEFAULT ''" ],
132 [ 'addPgField', 'oldimage', 'oi_minor_mime', "TEXT NOT NULL DEFAULT 'unknown'" ],
133 [ 'addPgField', 'oldimage', 'oi_sha1', "TEXT NOT NULL DEFAULT ''" ],
134 [ 'addPgField', 'page', 'page_content_model', 'TEXT' ],
135 [ 'addPgField', 'page_restrictions', 'pr_id',
136 "INTEGER NOT NULL UNIQUE DEFAULT nextval('page_restrictions_pr_id_seq')" ],
137 [ 'addPgField', 'profiling', 'pf_memory', 'NUMERIC(18,10) NOT NULL DEFAULT 0' ],
138 [ 'addPgField', 'recentchanges', 'rc_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
139 [ 'addPgField', 'recentchanges', 'rc_log_action', 'TEXT' ],
140 [ 'addPgField', 'recentchanges', 'rc_log_type', 'TEXT' ],
141 [ 'addPgField', 'recentchanges', 'rc_logid', 'INTEGER NOT NULL DEFAULT 0' ],
142 [ 'addPgField', 'recentchanges', 'rc_new_len', 'INTEGER' ],
143 [ 'addPgField', 'recentchanges', 'rc_old_len', 'INTEGER' ],
144 [ 'addPgField', 'recentchanges', 'rc_params', 'TEXT' ],
145 [ 'addPgField', 'redirect', 'rd_interwiki', 'TEXT NULL' ],
146 [ 'addPgField', 'redirect', 'rd_fragment', 'TEXT NULL' ],
147 [ 'addPgField', 'revision', 'rev_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
148 [ 'addPgField', 'revision', 'rev_len', 'INTEGER' ],
149 [ 'addPgField', 'revision', 'rev_parent_id', 'INTEGER DEFAULT NULL' ],
150 [ 'addPgField', 'revision', 'rev_content_model', 'TEXT' ],
151 [ 'addPgField', 'revision', 'rev_content_format', 'TEXT' ],
152 [ 'addPgField', 'site_stats', 'ss_active_users', "INTEGER DEFAULT '-1'" ],
153 [ 'addPgField', 'user_newtalk', 'user_last_timestamp', 'TIMESTAMPTZ' ],
154 [ 'addPgField', 'logging', 'log_user_text', "TEXT NOT NULL DEFAULT ''" ],
155 [ 'addPgField', 'logging', 'log_page', 'INTEGER' ],
156 [ 'addPgField', 'interwiki', 'iw_api', "TEXT NOT NULL DEFAULT ''" ],
157 [ 'addPgField', 'interwiki', 'iw_wikiid', "TEXT NOT NULL DEFAULT ''" ],
158 [ 'addPgField', 'revision', 'rev_sha1', "TEXT NOT NULL DEFAULT ''" ],
159 [ 'addPgField', 'archive', 'ar_sha1', "TEXT NOT NULL DEFAULT ''" ],
160 [ 'addPgField', 'uploadstash', 'us_chunk_inx', "INTEGER NULL" ],
161 [ 'addPgField', 'job', 'job_timestamp', "TIMESTAMPTZ" ],
162 [ 'addPgField', 'job', 'job_random', "INTEGER NOT NULL DEFAULT 0" ],
163 [ 'addPgField', 'job', 'job_attempts', "INTEGER NOT NULL DEFAULT 0" ],
164 [ 'addPgField', 'job', 'job_token', "TEXT NOT NULL DEFAULT ''" ],
165 [ 'addPgField', 'job', 'job_token_timestamp', "TIMESTAMPTZ" ],
166 [ 'addPgField', 'job', 'job_sha1', "TEXT NOT NULL DEFAULT ''" ],
167 [ 'addPgField', 'archive', 'ar_id',
168 "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('archive_ar_id_seq')" ],
169 [ 'addPgField', 'externallinks', 'el_id',
170 "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('externallinks_el_id_seq')" ],
171 [ 'addPgField', 'uploadstash', 'us_props', "BYTEA" ],
172
173 # type changes
174 [ 'changeField', 'archive', 'ar_deleted', 'smallint', '' ],
175 [ 'changeField', 'archive', 'ar_minor_edit', 'smallint',
176 'ar_minor_edit::smallint DEFAULT 0' ],
177 [ 'changeField', 'filearchive', 'fa_deleted', 'smallint', '' ],
178 [ 'changeField', 'filearchive', 'fa_height', 'integer', '' ],
179 [ 'changeField', 'filearchive', 'fa_metadata', 'bytea', "decode(fa_metadata,'escape')" ],
180 [ 'changeField', 'filearchive', 'fa_size', 'integer', '' ],
181 [ 'changeField', 'filearchive', 'fa_width', 'integer', '' ],
182 [ 'changeField', 'filearchive', 'fa_storage_group', 'text', '' ],
183 [ 'changeField', 'filearchive', 'fa_storage_key', 'text', '' ],
184 [ 'changeField', 'image', 'img_metadata', 'bytea', "decode(img_metadata,'escape')" ],
185 [ 'changeField', 'image', 'img_size', 'integer', '' ],
186 [ 'changeField', 'image', 'img_width', 'integer', '' ],
187 [ 'changeField', 'image', 'img_height', 'integer', '' ],
188 [ 'changeField', 'interwiki', 'iw_local', 'smallint', 'iw_local::smallint' ],
189 [ 'changeField', 'interwiki', 'iw_trans', 'smallint', 'iw_trans::smallint DEFAULT 0' ],
190 [ 'changeField', 'ipblocks', 'ipb_auto', 'smallint', 'ipb_auto::smallint DEFAULT 0' ],
191 [ 'changeField', 'ipblocks', 'ipb_anon_only', 'smallint',
192 "CASE WHEN ipb_anon_only=' ' THEN 0 ELSE ipb_anon_only::smallint END DEFAULT 0" ],
193 [ 'changeField', 'ipblocks', 'ipb_create_account', 'smallint',
194 "CASE WHEN ipb_create_account=' ' THEN 0 ELSE ipb_create_account::smallint END DEFAULT 1" ],
195 [ 'changeField', 'ipblocks', 'ipb_enable_autoblock', 'smallint',
196 "CASE WHEN ipb_enable_autoblock=' ' THEN 0 ELSE ipb_enable_autoblock::smallint END DEFAULT 1" ],
197 [ 'changeField', 'ipblocks', 'ipb_block_email', 'smallint',
198 "CASE WHEN ipb_block_email=' ' THEN 0 ELSE ipb_block_email::smallint END DEFAULT 0" ],
199 [ 'changeField', 'ipblocks', 'ipb_address', 'text', 'ipb_address::text' ],
200 [ 'changeField', 'ipblocks', 'ipb_deleted', 'smallint', 'ipb_deleted::smallint DEFAULT 0' ],
201 [ 'changeField', 'mwuser', 'user_token', 'text', '' ],
202 [ 'changeField', 'mwuser', 'user_email_token', 'text', '' ],
203 [ 'changeField', 'objectcache', 'keyname', 'text', '' ],
204 [ 'changeField', 'oldimage', 'oi_height', 'integer', '' ],
205 [ 'changeField', 'oldimage', 'oi_metadata', 'bytea', "decode(img_metadata,'escape')" ],
206 [ 'changeField', 'oldimage', 'oi_size', 'integer', '' ],
207 [ 'changeField', 'oldimage', 'oi_width', 'integer', '' ],
208 [ 'changeField', 'page', 'page_is_redirect', 'smallint',
209 'page_is_redirect::smallint DEFAULT 0' ],
210 [ 'changeField', 'page', 'page_is_new', 'smallint', 'page_is_new::smallint DEFAULT 0' ],
211 [ 'changeField', 'querycache', 'qc_value', 'integer', '' ],
212 [ 'changeField', 'querycachetwo', 'qcc_value', 'integer', '' ],
213 [ 'changeField', 'recentchanges', 'rc_bot', 'smallint', 'rc_bot::smallint DEFAULT 0' ],
214 [ 'changeField', 'recentchanges', 'rc_deleted', 'smallint', '' ],
215 [ 'changeField', 'recentchanges', 'rc_minor', 'smallint', 'rc_minor::smallint DEFAULT 0' ],
216 [ 'changeField', 'recentchanges', 'rc_new', 'smallint', 'rc_new::smallint DEFAULT 0' ],
217 [ 'changeField', 'recentchanges', 'rc_type', 'smallint', 'rc_type::smallint DEFAULT 0' ],
218 [ 'changeField', 'recentchanges', 'rc_patrolled', 'smallint',
219 'rc_patrolled::smallint DEFAULT 0' ],
220 [ 'changeField', 'revision', 'rev_deleted', 'smallint', 'rev_deleted::smallint DEFAULT 0' ],
221 [ 'changeField', 'revision', 'rev_minor_edit', 'smallint',
222 'rev_minor_edit::smallint DEFAULT 0' ],
223 [ 'changeField', 'templatelinks', 'tl_namespace', 'smallint', 'tl_namespace::smallint' ],
224 [ 'changeField', 'user_newtalk', 'user_ip', 'text', 'host(user_ip)' ],
225 [ 'changeField', 'uploadstash', 'us_image_bits', 'smallint', '' ],
226 [ 'changeField', 'profiling', 'pf_time', 'float', '' ],
227 [ 'changeField', 'profiling', 'pf_memory', 'float', '' ],
228
229 # null changes
230 [ 'changeNullableField', 'oldimage', 'oi_bits', 'NULL' ],
231 [ 'changeNullableField', 'oldimage', 'oi_timestamp', 'NULL' ],
232 [ 'changeNullableField', 'oldimage', 'oi_major_mime', 'NULL' ],
233 [ 'changeNullableField', 'oldimage', 'oi_minor_mime', 'NULL' ],
234 [ 'changeNullableField', 'image', 'img_metadata', 'NOT NULL' ],
235 [ 'changeNullableField', 'filearchive', 'fa_metadata', 'NOT NULL' ],
236 [ 'changeNullableField', 'recentchanges', 'rc_cur_id', 'NULL' ],
237 [ 'changeNullableField', 'recentchanges', 'rc_cur_time', 'NULL' ],
238
239 [ 'checkOiDeleted' ],
240
241 # New indexes
242 [ 'addPgIndex', 'archive', 'archive_user_text', '(ar_user_text)' ],
243 [ 'addPgIndex', 'image', 'img_sha1', '(img_sha1)' ],
244 [ 'addPgIndex', 'ipblocks', 'ipb_parent_block_id', '(ipb_parent_block_id)' ],
245 [ 'addPgIndex', 'oldimage', 'oi_sha1', '(oi_sha1)' ],
246 [ 'addPgIndex', 'page', 'page_mediawiki_title', '(page_title) WHERE page_namespace = 8' ],
247 [ 'addPgIndex', 'pagelinks', 'pagelinks_title', '(pl_title)' ],
248 [ 'addPgIndex', 'page_props', 'pp_propname_page', '(pp_propname, pp_page)' ],
249 [ 'addPgIndex', 'revision', 'rev_text_id_idx', '(rev_text_id)' ],
250 [ 'addPgIndex', 'recentchanges', 'rc_timestamp_bot', '(rc_timestamp) WHERE rc_bot = 0' ],
251 [ 'addPgIndex', 'templatelinks', 'templatelinks_from', '(tl_from)' ],
252 [ 'addPgIndex', 'watchlist', 'wl_user', '(wl_user)' ],
253 [ 'addPgIndex', 'watchlist', 'wl_user_notificationtimestamp',
254 '(wl_user, wl_notificationtimestamp)' ],
255 [ 'addPgIndex', 'logging', 'logging_user_type_time',
256 '(log_user, log_type, log_timestamp)' ],
257 [ 'addPgIndex', 'logging', 'logging_page_id_time', '(log_page,log_timestamp)' ],
258 [ 'addPgIndex', 'iwlinks', 'iwl_prefix_from_title', '(iwl_prefix, iwl_from, iwl_title)' ],
259 [ 'addPgIndex', 'iwlinks', 'iwl_prefix_title_from', '(iwl_prefix, iwl_title, iwl_from)' ],
260 [ 'addPgIndex', 'job', 'job_timestamp_idx', '(job_timestamp)' ],
261 [ 'addPgIndex', 'job', 'job_sha1', '(job_sha1)' ],
262 [ 'addPgIndex', 'job', 'job_cmd_token', '(job_cmd, job_token, job_random)' ],
263 [ 'addPgIndex', 'job', 'job_cmd_token_id', '(job_cmd, job_token, job_id)' ],
264 [ 'addPgIndex', 'filearchive', 'fa_sha1', '(fa_sha1)' ],
265 [ 'addPgIndex', 'logging', 'logging_user_text_type_time',
266 '(log_user_text, log_type, log_timestamp)' ],
267 [ 'addPgIndex', 'logging', 'logging_user_text_time', '(log_user_text, log_timestamp)' ],
268
269 [ 'checkIndex', 'pagelink_unique', [
270 [ 'pl_from', 'int4_ops', 'btree', 0 ],
271 [ 'pl_namespace', 'int2_ops', 'btree', 0 ],
272 [ 'pl_title', 'text_ops', 'btree', 0 ],
273 ],
274 'CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)' ],
275 [ 'checkIndex', 'cl_sortkey', [
276 [ 'cl_to', 'text_ops', 'btree', 0 ],
277 [ 'cl_sortkey', 'text_ops', 'btree', 0 ],
278 [ 'cl_from', 'int4_ops', 'btree', 0 ],
279 ],
280 'CREATE INDEX cl_sortkey ON "categorylinks" ' .
281 'USING "btree" ("cl_to", "cl_sortkey", "cl_from")' ],
282 [ 'checkIndex', 'iwl_prefix_title_from', [
283 [ 'iwl_prefix', 'text_ops', 'btree', 0 ],
284 [ 'iwl_title', 'text_ops', 'btree', 0 ],
285 [ 'iwl_from', 'int4_ops', 'btree', 0 ],
286 ],
287 'CREATE INDEX iwl_prefix_title_from ON "iwlinks" ' .
288 'USING "btree" ("iwl_prefix", "iwl_title", "iwl_from")' ],
289 [ 'checkIndex', 'logging_times', [
290 [ 'log_timestamp', 'timestamptz_ops', 'btree', 0 ],
291 ],
292 'CREATE INDEX "logging_times" ON "logging" USING "btree" ("log_timestamp")' ],
293 [ 'dropIndex', 'oldimage', 'oi_name' ],
294 [ 'checkIndex', 'oi_name_archive_name', [
295 [ 'oi_name', 'text_ops', 'btree', 0 ],
296 [ 'oi_archive_name', 'text_ops', 'btree', 0 ],
297 ],
298 'CREATE INDEX "oi_name_archive_name" ON "oldimage" ' .
299 'USING "btree" ("oi_name", "oi_archive_name")' ],
300 [ 'checkIndex', 'oi_name_timestamp', [
301 [ 'oi_name', 'text_ops', 'btree', 0 ],
302 [ 'oi_timestamp', 'timestamptz_ops', 'btree', 0 ],
303 ],
304 'CREATE INDEX "oi_name_timestamp" ON "oldimage" ' .
305 'USING "btree" ("oi_name", "oi_timestamp")' ],
306 [ 'checkIndex', 'page_main_title', [
307 [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
308 ],
309 'CREATE INDEX "page_main_title" ON "page" ' .
310 'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 0)' ],
311 [ 'checkIndex', 'page_mediawiki_title', [
312 [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
313 ],
314 'CREATE INDEX "page_mediawiki_title" ON "page" ' .
315 'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 8)' ],
316 [ 'checkIndex', 'page_project_title', [
317 [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
318 ],
319 'CREATE INDEX "page_project_title" ON "page" ' .
320 'USING "btree" ("page_title" "text_pattern_ops") ' .
321 'WHERE ("page_namespace" = 4)' ],
322 [ 'checkIndex', 'page_talk_title', [
323 [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
324 ],
325 'CREATE INDEX "page_talk_title" ON "page" ' .
326 'USING "btree" ("page_title" "text_pattern_ops") ' .
327 'WHERE ("page_namespace" = 1)' ],
328 [ 'checkIndex', 'page_user_title', [
329 [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
330 ],
331 'CREATE INDEX "page_user_title" ON "page" ' .
332 'USING "btree" ("page_title" "text_pattern_ops") WHERE ' .
333 '("page_namespace" = 2)' ],
334 [ 'checkIndex', 'page_utalk_title', [
335 [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
336 ],
337 'CREATE INDEX "page_utalk_title" ON "page" ' .
338 'USING "btree" ("page_title" "text_pattern_ops") ' .
339 'WHERE ("page_namespace" = 3)' ],
340 [ 'checkIndex', 'ts2_page_text', [
341 [ 'textvector', 'tsvector_ops', 'gist', 0 ],
342 ],
343 'CREATE INDEX "ts2_page_text" ON "pagecontent" USING "gist" ("textvector")' ],
344 [ 'checkIndex', 'ts2_page_title', [
345 [ 'titlevector', 'tsvector_ops', 'gist', 0 ],
346 ],
347 'CREATE INDEX "ts2_page_title" ON "page" USING "gist" ("titlevector")' ],
348
349 [ 'checkOiNameConstraint' ],
350 [ 'checkPageDeletedTrigger' ],
351 [ 'checkRevUserFkey' ],
352 [ 'dropIndex', 'ipblocks', 'ipb_address' ],
353 [ 'checkIndex', 'ipb_address_unique', [
354 [ 'ipb_address', 'text_ops', 'btree', 0 ],
355 [ 'ipb_user', 'int4_ops', 'btree', 0 ],
356 [ 'ipb_auto', 'int2_ops', 'btree', 0 ],
357 [ 'ipb_anon_only', 'int2_ops', 'btree', 0 ],
358 ],
359 'CREATE UNIQUE INDEX ipb_address_unique ' .
360 'ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only)' ],
361
362 [ 'checkIwlPrefix' ],
363
364 # All FK columns should be deferred
365 [ 'changeFkeyDeferrable', 'archive', 'ar_user', 'mwuser(user_id) ON DELETE SET NULL' ],
366 [ 'changeFkeyDeferrable', 'categorylinks', 'cl_from', 'page(page_id) ON DELETE CASCADE' ],
367 [ 'changeFkeyDeferrable', 'externallinks', 'el_from', 'page(page_id) ON DELETE CASCADE' ],
368 [ 'changeFkeyDeferrable', 'filearchive', 'fa_deleted_user',
369 'mwuser(user_id) ON DELETE SET NULL' ],
370 [ 'changeFkeyDeferrable', 'filearchive', 'fa_user', 'mwuser(user_id) ON DELETE SET NULL' ],
371 [ 'changeFkeyDeferrable', 'image', 'img_user', 'mwuser(user_id) ON DELETE SET NULL' ],
372 [ 'changeFkeyDeferrable', 'imagelinks', 'il_from', 'page(page_id) ON DELETE CASCADE' ],
373 [ 'changeFkeyDeferrable', 'ipblocks', 'ipb_by', 'mwuser(user_id) ON DELETE CASCADE' ],
374 [ 'changeFkeyDeferrable', 'ipblocks', 'ipb_user', 'mwuser(user_id) ON DELETE SET NULL' ],
375 [ 'changeFkeyDeferrable', 'ipblocks', 'ipb_parent_block_id',
376 'ipblocks(ipb_id) ON DELETE SET NULL' ],
377 [ 'changeFkeyDeferrable', 'langlinks', 'll_from', 'page(page_id) ON DELETE CASCADE' ],
378 [ 'changeFkeyDeferrable', 'logging', 'log_user', 'mwuser(user_id) ON DELETE SET NULL' ],
379 [ 'changeFkeyDeferrable', 'oldimage', 'oi_name',
380 'image(img_name) ON DELETE CASCADE ON UPDATE CASCADE' ],
381 [ 'changeFkeyDeferrable', 'oldimage', 'oi_user', 'mwuser(user_id) ON DELETE SET NULL' ],
382 [ 'changeFkeyDeferrable', 'pagelinks', 'pl_from', 'page(page_id) ON DELETE CASCADE' ],
383 [ 'changeFkeyDeferrable', 'page_props', 'pp_page', 'page (page_id) ON DELETE CASCADE' ],
384 [ 'changeFkeyDeferrable', 'page_restrictions', 'pr_page',
385 'page(page_id) ON DELETE CASCADE' ],
386 [ 'changeFkeyDeferrable', 'protected_titles', 'pt_user',
387 'mwuser(user_id) ON DELETE SET NULL' ],
388 [ 'changeFkeyDeferrable', 'recentchanges', 'rc_user',
389 'mwuser(user_id) ON DELETE SET NULL' ],
390 [ 'changeFkeyDeferrable', 'redirect', 'rd_from', 'page(page_id) ON DELETE CASCADE' ],
391 [ 'changeFkeyDeferrable', 'revision', 'rev_page', 'page (page_id) ON DELETE CASCADE' ],
392 [ 'changeFkeyDeferrable', 'revision', 'rev_user', 'mwuser(user_id) ON DELETE RESTRICT' ],
393 [ 'changeFkeyDeferrable', 'templatelinks', 'tl_from', 'page(page_id) ON DELETE CASCADE' ],
394 [ 'changeFkeyDeferrable', 'user_groups', 'ug_user', 'mwuser(user_id) ON DELETE CASCADE' ],
395 [ 'changeFkeyDeferrable', 'user_newtalk', 'user_id', 'mwuser(user_id) ON DELETE CASCADE' ],
396 [ 'changeFkeyDeferrable', 'user_properties', 'up_user',
397 'mwuser(user_id) ON DELETE CASCADE' ],
398 [ 'changeFkeyDeferrable', 'watchlist', 'wl_user', 'mwuser(user_id) ON DELETE CASCADE' ],
399
400 # r81574
401 [ 'addInterwikiType' ],
402 # end
403 [ 'tsearchFixes' ],
404
405 // 1.23
406 [ 'addPgField', 'recentchanges', 'rc_source', "TEXT NOT NULL DEFAULT ''" ],
407 [ 'addPgField', 'page', 'page_links_updated', "TIMESTAMPTZ NULL" ],
408 [ 'addPgField', 'mwuser', 'user_password_expires', 'TIMESTAMPTZ NULL' ],
409 [ 'changeFieldPurgeTable', 'l10n_cache', 'lc_value', 'bytea',
410 "replace(lc_value,'\','\\\\')::bytea" ],
411 // 1.23.9
412 [ 'rebuildTextSearch' ],
413
414 // 1.24
415 [ 'addPgField', 'page_props', 'pp_sortkey', 'float NULL' ],
416 [ 'addPgIndex', 'page_props', 'pp_propname_sortkey_page',
417 '( pp_propname, pp_sortkey, pp_page ) WHERE ( pp_sortkey IS NOT NULL )' ],
418 [ 'addPgField', 'page', 'page_lang', 'TEXT default NULL' ],
419 [ 'addPgField', 'pagelinks', 'pl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ],
420 [ 'addPgField', 'templatelinks', 'tl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ],
421 [ 'addPgField', 'imagelinks', 'il_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ],
422
423 // 1.25
424 [ 'dropTable', 'hitcounter' ],
425 [ 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ],
426 [ 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ],
427 [ 'dropFkey', 'recentchanges', 'rc_cur_id' ],
428
429 // 1.27
430 [ 'dropTable', 'msg_resource_links' ],
431 [ 'dropTable', 'msg_resource' ],
432 [
433 'addPgField', 'watchlist', 'wl_id',
434 "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('watchlist_wl_id_seq')"
435 ],
436 ];
437 }
438
439 protected function getOldGlobalUpdates() {
440 global $wgExtNewTables, $wgExtPGNewFields, $wgExtPGAlteredFields, $wgExtNewIndexes;
441
442 $updates = [];
443
444 # Add missing extension tables
445 foreach ( $wgExtNewTables as $tableRecord ) {
446 $updates[] = [
447 'addTable', $tableRecord[0], $tableRecord[1], true
448 ];
449 }
450
451 # Add missing extension fields
452 foreach ( $wgExtPGNewFields as $fieldRecord ) {
453 $updates[] = [
454 'addPgField', $fieldRecord[0], $fieldRecord[1],
455 $fieldRecord[2]
456 ];
457 }
458
459 # Change altered columns
460 foreach ( $wgExtPGAlteredFields as $fieldRecord ) {
461 $updates[] = [
462 'changeField', $fieldRecord[0], $fieldRecord[1],
463 $fieldRecord[2]
464 ];
465 }
466
467 # Add missing extension indexes
468 foreach ( $wgExtNewIndexes as $fieldRecord ) {
469 $updates[] = [
470 'addPgExtIndex', $fieldRecord[0], $fieldRecord[1],
471 $fieldRecord[2]
472 ];
473 }
474
475 return $updates;
476 }
477
478 protected function describeTable( $table ) {
479 $q = <<<END
480SELECT attname, attnum FROM pg_namespace, pg_class, pg_attribute
481 WHERE pg_class.relnamespace = pg_namespace.oid
482 AND attrelid=pg_class.oid AND attnum > 0
483 AND relname=%s AND nspname=%s
484END;
485 $res = $this->db->query( sprintf( $q,
486 $this->db->addQuotes( $table ),
487 $this->db->addQuotes( $this->db->getCoreSchema() ) ) );
488 if ( !$res ) {
489 return null;
490 }
491
492 $cols = [];
493 foreach ( $res as $r ) {
494 $cols[] = [
495 "name" => $r[0],
496 "ord" => $r[1],
497 ];
498 }
499
500 return $cols;
501 }
502
503 function describeIndex( $idx ) {
504 // first fetch the key (which is a list of columns ords) and
505 // the table the index applies to (an oid)
506 $q = <<<END
507SELECT indkey, indrelid FROM pg_namespace, pg_class, pg_index
508 WHERE nspname=%s
509 AND pg_class.relnamespace = pg_namespace.oid
510 AND relname=%s
511 AND indexrelid=pg_class.oid
512END;
513 $res = $this->db->query(
514 sprintf(
515 $q,
516 $this->db->addQuotes( $this->db->getCoreSchema() ),
517 $this->db->addQuotes( $idx )
518 )
519 );
520 if ( !$res ) {
521 return null;
522 }
523 $r = $this->db->fetchRow( $res );
524 if ( !$r ) {
525 return null;
526 }
527
528 $indkey = $r[0];
529 $relid = intval( $r[1] );
530 $indkeys = explode( ' ', $indkey );
531
532 $colnames = [];
533 foreach ( $indkeys as $rid ) {
534 $query = <<<END
535SELECT attname FROM pg_class, pg_attribute
536 WHERE attrelid=$relid
537 AND attnum=%d
538 AND attrelid=pg_class.oid
539END;
540 $r2 = $this->db->query( sprintf( $query, $rid ) );
541 if ( !$r2 ) {
542 return null;
543 }
544 $row2 = $this->db->fetchRow( $r2 );
545 if ( !$row2 ) {
546 return null;
547 }
548 $colnames[] = $row2[0];
549 }
550
551 return $colnames;
552 }
553
554 function fkeyDeltype( $fkey ) {
555 $q = <<<END
556SELECT confdeltype FROM pg_constraint, pg_namespace
557 WHERE connamespace=pg_namespace.oid
558 AND nspname=%s
559 AND conname=%s;
560END;
561 $r = $this->db->query(
562 sprintf(
563 $q,
564 $this->db->addQuotes( $this->db->getCoreSchema() ),
565 $this->db->addQuotes( $fkey )
566 )
567 );
568 $row = $this->db->fetchRow( $r );
569 if ( !$row ) {
570 return null;
571 }
572
573 return $row[0];
574 }
575
576 function ruleDef( $table, $rule ) {
577 $q = <<<END
578SELECT definition FROM pg_rules
579 WHERE schemaname = %s
580 AND tablename = %s
581 AND rulename = %s
582END;
583 $r = $this->db->query(
584 sprintf(
585 $q,
586 $this->db->addQuotes( $this->db->getCoreSchema() ),
587 $this->db->addQuotes( $table ),
588 $this->db->addQuotes( $rule )
589 )
590 );
591 $row = $this->db->fetchRow( $r );
592 if ( !$row ) {
593 return null;
594 }
595 $d = $row[0];
596
597 return $d;
598 }
599
600 protected function addSequence( $table, $pkey, $ns ) {
601 if ( !$this->db->sequenceExists( $ns ) ) {
602 $this->output( "Creating sequence $ns\n" );
603 $this->db->query( "CREATE SEQUENCE $ns" );
604 if ( $pkey !== false ) {
605 $this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' );
606 }
607 }
608 }
609
610 protected function renameSequence( $old, $new ) {
611 if ( $this->db->sequenceExists( $new ) ) {
612 $this->output( "...sequence $new already exists.\n" );
613
614 return;
615 }
616 if ( $this->db->sequenceExists( $old ) ) {
617 $this->output( "Renaming sequence $old to $new\n" );
618 $this->db->query( "ALTER SEQUENCE $old RENAME TO $new" );
619 }
620 }
621
622 protected function renameTable( $old, $new, $patch = false ) {
623 if ( $this->db->tableExists( $old ) ) {
624 $this->output( "Renaming table $old to $new\n" );
625 $old = $this->db->realTableName( $old, "quoted" );
626 $new = $this->db->realTableName( $new, "quoted" );
627 $this->db->query( "ALTER TABLE $old RENAME TO $new" );
628 if ( $patch !== false ) {
629 $this->applyPatch( $patch );
630 }
631 }
632 }
633
634 protected function renameIndex(
635 $table, $old, $new, $skipBothIndexExistWarning = false, $a = false, $b = false
636 ) {
637 // First requirement: the table must exist
638 if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
639 $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
640
641 return;
642 }
643
644 // Second requirement: the new index must be missing
645 if ( $this->db->indexExists( $table, $new, __METHOD__ ) ) {
646 $this->output( "...index $new already set on $table table.\n" );
647 if ( !$skipBothIndexExistWarning
648 && $this->db->indexExists( $table, $old, __METHOD__ )
649 ) {
650 $this->output( "...WARNING: $old still exists, despite it has been " .
651 "renamed into $new (which also exists).\n" .
652 " $old should be manually removed if not needed anymore.\n" );
653 }
654
655 return;
656 }
657
658 // Third requirement: the old index must exist
659 if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) {
660 $this->output( "...skipping: index $old doesn't exist.\n" );
661
662 return;
663 }
664
665 $this->db->query( "ALTER INDEX $old RENAME TO $new" );
666 }
667
668 protected function addPgField( $table, $field, $type ) {
669 $fi = $this->db->fieldInfo( $table, $field );
670 if ( !is_null( $fi ) ) {
671 $this->output( "...column '$table.$field' already exists\n" );
672
673 return;
674 } else {
675 $this->output( "Adding column '$table.$field'\n" );
676 $this->db->query( "ALTER TABLE $table ADD $field $type" );
677 }
678 }
679
680 protected function changeField( $table, $field, $newtype, $default ) {
681 $fi = $this->db->fieldInfo( $table, $field );
682 if ( is_null( $fi ) ) {
683 $this->output( "...ERROR: expected column $table.$field to exist\n" );
684 exit( 1 );
685 }
686
687 if ( $fi->type() === $newtype ) {
688 $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
689 } else {
690 $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
691 $sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
692 if ( strlen( $default ) ) {
693 $res = [];
694 if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) {
695 $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]";
696 $this->db->query( $sqldef );
697 $default = preg_replace( '/\s*DEFAULT .+/', '', $default );
698 }
699 $sql .= " USING $default";
700 }
701 $this->db->query( $sql );
702 }
703 }
704
705 protected function changeFieldPurgeTable( $table, $field, $newtype, $default ) {
706 # # For a cache table, empty it if the field needs to be changed, because the old contents
707 # # may be corrupted. If the column is already the desired type, refrain from purging.
708 $fi = $this->db->fieldInfo( $table, $field );
709 if ( is_null( $fi ) ) {
710 $this->output( "...ERROR: expected column $table.$field to exist\n" );
711 exit( 1 );
712 }
713
714 if ( $fi->type() === $newtype ) {
715 $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
716 } else {
717 $this->output( "Purging data from cache table '$table'\n" );
718 $this->db->query( "DELETE from $table" );
719 $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
720 $sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
721 if ( strlen( $default ) ) {
722 $res = [];
723 if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) {
724 $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]";
725 $this->db->query( $sqldef );
726 $default = preg_replace( '/\s*DEFAULT .+/', '', $default );
727 }
728 $sql .= " USING $default";
729 }
730 $this->db->query( $sql );
731 }
732 }
733
734 protected function setDefault( $table, $field, $default ) {
735
736 $info = $this->db->fieldInfo( $table, $field );
737 if ( $info->defaultValue() !== $default ) {
738 $this->output( "Changing '$table.$field' default value\n" );
739 $this->db->query( "ALTER TABLE $table ALTER $field SET DEFAULT "
740 . $this->db->addQuotes( $default ) );
741 }
742 }
743
744 protected function changeNullableField( $table, $field, $null ) {
745 $fi = $this->db->fieldInfo( $table, $field );
746 if ( is_null( $fi ) ) {
747 $this->output( "...ERROR: expected column $table.$field to exist\n" );
748 exit( 1 );
749 }
750 if ( $fi->isNullable() ) {
751 # # It's NULL - does it need to be NOT NULL?
752 if ( 'NOT NULL' === $null ) {
753 $this->output( "Changing '$table.$field' to not allow NULLs\n" );
754 $this->db->query( "ALTER TABLE $table ALTER $field SET NOT NULL" );
755 } else {
756 $this->output( "...column '$table.$field' is already set as NULL\n" );
757 }
758 } else {
759 # # It's NOT NULL - does it need to be NULL?
760 if ( 'NULL' === $null ) {
761 $this->output( "Changing '$table.$field' to allow NULLs\n" );
762 $this->db->query( "ALTER TABLE $table ALTER $field DROP NOT NULL" );
763 } else {
764 $this->output( "...column '$table.$field' is already set as NOT NULL\n" );
765 }
766 }
767 }
768
769 public function addPgIndex( $table, $index, $type ) {
770 if ( $this->db->indexExists( $table, $index ) ) {
771 $this->output( "...index '$index' on table '$table' already exists\n" );
772 } else {
773 $this->output( "Creating index '$index' on table '$table' $type\n" );
774 $this->db->query( "CREATE INDEX $index ON $table $type" );
775 }
776 }
777
778 public function addPgExtIndex( $table, $index, $type ) {
779 if ( $this->db->indexExists( $table, $index ) ) {
780 $this->output( "...index '$index' on table '$table' already exists\n" );
781 } else {
782 if ( preg_match( '/^\‍(/', $type ) ) {
783 $this->output( "Creating index '$index' on table '$table'\n" );
784 $this->db->query( "CREATE INDEX $index ON $table $type" );
785 } else {
786 $this->applyPatch( $type, true, "Creating index '$index' on table '$table'" );
787 }
788 }
789 }
790
791 protected function dropFkey( $table, $field ) {
792 $fi = $this->db->fieldInfo( $table, $field );
793 if ( is_null( $fi ) ) {
794 $this->output( "WARNING! Column '$table.$field' does not exist but it should! " .
795 "Please report this.\n" );
796 return;
797 }
798 $conname = $fi->conname();
799 if ( $fi->conname() ) {
800 $this->output( "Dropping foreign key constraint on '$table.$field'\n" );
801 $conclause = "CONSTRAINT \"$conname\"";
802 $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
803 $this->db->query( $command );
804 } else {
805 $this->output( "...foreign key constraint on '$table.$field' already does not exist\n" );
806 };
807 }
808
809 protected function changeFkeyDeferrable( $table, $field, $clause ) {
810 $fi = $this->db->fieldInfo( $table, $field );
811 if ( is_null( $fi ) ) {
812 $this->output( "WARNING! Column '$table.$field' does not exist but it should! " .
813 "Please report this.\n" );
814
815 return;
816 }
817 if ( $fi->is_deferred() && $fi->is_deferrable() ) {
818 return;
819 }
820 $this->output( "Altering column '$table.$field' to be DEFERRABLE INITIALLY DEFERRED\n" );
821 $conname = $fi->conname();
822 if ( $fi->conname() ) {
823 $conclause = "CONSTRAINT \"$conname\"";
824 $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
825 $this->db->query( $command );
826 } else {
827 $this->output( "Column '$table.$field' does not have a foreign key " .
828 "constraint, will be added\n" );
829 $conclause = "";
830 }
831 $command =
832 "ALTER TABLE $table ADD $conclause " .
833 "FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED";
834 $this->db->query( $command );
835 }
836
837 protected function convertArchive2() {
838 if ( $this->db->tableExists( "archive2" ) ) {
839 if ( $this->db->ruleExists( 'archive', 'archive_insert' ) ) {
840 $this->output( "Dropping rule 'archive_insert'\n" );
841 $this->db->query( 'DROP RULE archive_insert ON archive' );
842 }
843 if ( $this->db->ruleExists( 'archive', 'archive_delete' ) ) {
844 $this->output( "Dropping rule 'archive_delete'\n" );
845 $this->db->query( 'DROP RULE archive_delete ON archive' );
846 }
847 $this->applyPatch(
848 'patch-remove-archive2.sql',
849 false,
850 "Converting 'archive2' back to normal archive table"
851 );
852 } else {
853 $this->output( "...obsolete table 'archive2' does not exist\n" );
854 }
855 }
856
857 protected function checkOiDeleted() {
858 if ( $this->db->fieldInfo( 'oldimage', 'oi_deleted' )->type() !== 'smallint' ) {
859 $this->output( "Changing 'oldimage.oi_deleted' to type 'smallint'\n" );
860 $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT" );
861 $this->db->query(
862 "ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)" );
863 $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0" );
864 } else {
865 $this->output( "...column 'oldimage.oi_deleted' is already of type 'smallint'\n" );
866 }
867 }
868
869 protected function checkOiNameConstraint() {
870 if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascaded" ) ) {
871 $this->output( "...table 'oldimage' has correct cascading delete/update " .
872 "foreign key to image\n" );
873 } else {
874 if ( $this->db->hasConstraint( "oldimage_oi_name_fkey" ) ) {
875 $this->db->query(
876 "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" );
877 }
878 if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascade" ) ) {
879 $this->db->query(
880 "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey_cascade" );
881 }
882 $this->output( "Making foreign key on table 'oldimage' (to image) a cascade delete/update\n" );
883 $this->db->query(
884 "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascaded " .
885 "FOREIGN KEY (oi_name) REFERENCES image(img_name) " .
886 "ON DELETE CASCADE ON UPDATE CASCADE" );
887 }
888 }
889
890 protected function checkPageDeletedTrigger() {
891 if ( !$this->db->triggerExists( 'page', 'page_deleted' ) ) {
892 $this->applyPatch(
893 'patch-page_deleted.sql',
894 false,
895 "Adding function and trigger 'page_deleted' to table 'page'"
896 );
897 } else {
898 $this->output( "...table 'page' has 'page_deleted' trigger\n" );
899 }
900 }
901
902 protected function dropIndex( $table, $index, $patch = '', $fullpath = false ) {
903 if ( $this->db->indexExists( $table, $index ) ) {
904 $this->output( "Dropping obsolete index '$index'\n" );
905 $this->db->query( "DROP INDEX \"" . $index . "\"" );
906 }
907 }
908
909 protected function checkIndex( $index, $should_be, $good_def ) {
910 $pu = $this->db->indexAttributes( $index );
911 if ( !empty( $pu ) && $pu != $should_be ) {
912 $this->output( "Dropping obsolete version of index '$index'\n" );
913 $this->db->query( "DROP INDEX \"" . $index . "\"" );
914 $pu = [];
915 } else {
916 $this->output( "...no need to drop index '$index'\n" );
917 }
918
919 if ( empty( $pu ) ) {
920 $this->output( "Creating index '$index'\n" );
921 $this->db->query( $good_def );
922 } else {
923 $this->output( "...index '$index' exists\n" );
924 }
925 }
926
927 protected function checkRevUserFkey() {
928 if ( $this->fkeyDeltype( 'revision_rev_user_fkey' ) == 'r' ) {
929 $this->output( "...constraint 'revision_rev_user_fkey' is ON DELETE RESTRICT\n" );
930 } else {
931 $this->applyPatch(
932 'patch-revision_rev_user_fkey.sql',
933 false,
934 "Changing constraint 'revision_rev_user_fkey' to ON DELETE RESTRICT"
935 );
936 }
937 }
938
939 protected function checkIwlPrefix() {
940 if ( $this->db->indexExists( 'iwlinks', 'iwl_prefix' ) ) {
941 $this->applyPatch(
942 'patch-rename-iwl_prefix.sql',
943 false,
944 "Replacing index 'iwl_prefix' with 'iwl_prefix_title_from'"
945 );
946 }
947 }
948
949 protected function addInterwikiType() {
950 $this->applyPatch( 'patch-add_interwiki.sql', false, "Refreshing add_interwiki()" );
951 }
952
953 protected function tsearchFixes() {
954 # Tweak the page_title tsearch2 trigger to filter out slashes
955 # This is create or replace, so harmless to call if not needed
956 $this->applyPatch( 'patch-ts2pagetitle.sql', false, "Refreshing ts2_page_title()" );
957
958 # If the server is 8.3 or higher, rewrite the tsearch2 triggers
959 # in case they have the old 'default' versions
960 # Gather version numbers in case we need them
961 if ( $this->db->getServerVersion() >= 8.3 ) {
962 $this->applyPatch( 'patch-tsearch2funcs.sql', false, "Rewriting tsearch2 triggers" );
963 }
964 }
965
966 protected function rebuildTextSearch() {
967 if ( $this->updateRowExists( 'patch-textsearch_bug66650.sql' ) ) {
968 $this->output( "...bug 66650 already fixed or not applicable.\n" );
969 return true;
970 };
971 $this->applyPatch( 'patch-textsearch_bug66650.sql', false,
972 'Rebuilding text search for bug 66650' );
973 }
974}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this definition
$command
Definition cdb.php:65
Class for handling database updates.
array $updates
Array of updates to perform on the database.
updateRowExists( $key)
Helper function: check if the given key is present in the updatelog table.
applyPatch( $path, $isFullPath=false, $msg=null)
Applies a SQL patch.
Class for handling updates to Postgres databases.
changeNullableField( $table, $field, $null)
changeField( $table, $field, $newtype, $default)
renameTable( $old, $new, $patch=false)
renameIndex( $table, $old, $new, $skipBothIndexExistWarning=false, $a=false, $b=false)
Rename an index from an existing table.
ruleDef( $table, $rule)
addPgExtIndex( $table, $index, $type)
addSequence( $table, $pkey, $ns)
getOldGlobalUpdates()
Before 1.17, we used to handle updates via stuff like $wgExtNewTables/Fields/Indexes.
renameSequence( $old, $new)
setDefault( $table, $field, $default)
DatabasePostgres $db
addPgField( $table, $field, $type)
dropIndex( $table, $index, $patch='', $fullpath=false)
Drop an index from an existing table.
dropFkey( $table, $field)
changeFkeyDeferrable( $table, $field, $clause)
checkIndex( $index, $should_be, $good_def)
changeFieldPurgeTable( $table, $field, $newtype, $default)
addPgIndex( $table, $index, $type)
$res
Definition database.txt:21
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition hooks.txt:2413
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:1811
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1458
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR ARISING FROM
Definition LICENSE.txt:24
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37