From: Tom Hughes Date: Mon, 24 Mar 2025 19:14:14 +0000 (+0000) Subject: Fix wiki.openstreetmap.org hard coding in mediawiki cookbook X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/147f32c46259a3ff5995c8b5caa9c31d2e604b53?ds=inline Fix wiki.openstreetmap.org hard coding in mediawiki cookbook --- diff --git a/cookbooks/mediawiki/resources/site.rb b/cookbooks/mediawiki/resources/site.rb index 11e9446fe..840016fa4 100644 --- a/cookbooks/mediawiki/resources/site.rb +++ b/cookbooks/mediawiki/resources/site.rb @@ -44,6 +44,9 @@ property :private_site, :kind_of => [TrueClass, FalseClass], :default => false property :hcaptcha_public_key, :kind_of => String, :default => "" property :hcaptcha_private_key, :kind_of => String, :default => "" property :extra_file_extensions, :kind_of => [String, Array], :default => [] +property :namespaces, :kind_of => Hash, :default => {} +property :force_ui_messages, :kind_of => Array, :default => [] +property :watch_category_membership, :kind_of => [TrueClass, FalseClass], :default => false property :fpm_max_children, :kind_of => Integer, :default => 5 property :fpm_start_servers, :kind_of => Integer, :default => 2 property :fpm_min_spare_servers, :kind_of => Integer, :default => 1 @@ -598,7 +601,10 @@ action_class do :site_readonly => new_resource.site_readonly, :extra_file_extensions => new_resource.extra_file_extensions, :private_accounts => new_resource.private_accounts, - :private_site => new_resource.private_site + :private_site => new_resource.private_site, + :namespaces => new_resource.namespaces, + :force_ui_messages => new_resource.force_ui_messages, + :watch_category_membership => new_resource.watch_category_membership } end diff --git a/cookbooks/mediawiki/templates/default/LocalSettings.php.erb b/cookbooks/mediawiki/templates/default/LocalSettings.php.erb index 93aab016d..d70119627 100644 --- a/cookbooks/mediawiki/templates/default/LocalSettings.php.erb +++ b/cookbooks/mediawiki/templates/default/LocalSettings.php.erb @@ -296,92 +296,22 @@ $wgSiteNotice = "<%= @mediawiki[:site_notice] %>"; $wgReadOnly = "<%= @mediawiki[:site_readonly] %>"; <% end -%> -<% if @name == "wiki.openstreetmap.org" -%> -# DE -define('NS_LANG_DE', 200); -$wgExtraNamespaces[NS_LANG_DE] = 'DE'; -$wgNamespacesWithSubpages[NS_LANG_DE] = TRUE; -$wgContentNamespaces[] = NS_LANG_DE; -define('NS_LANG_DE_TALK', 201); -$wgExtraNamespaces[NS_LANG_DE_TALK] = 'DE_talk'; -$wgNamespacesWithSubpages[NS_LANG_DE_TALK] = TRUE; - -# FR -define('NS_LANG_FR', 202); -$wgExtraNamespaces[NS_LANG_FR] = 'FR'; -$wgNamespacesWithSubpages[NS_LANG_FR] = TRUE; -$wgContentNamespaces[] = NS_LANG_FR; -define('NS_LANG_FR_TALK', 203); -$wgExtraNamespaces[NS_LANG_FR_TALK] = 'FR_talk'; -$wgNamespacesWithSubpages[NS_LANG_FR_TALK] = TRUE; - -# ES -define('NS_LANG_ES', 204); -$wgExtraNamespaces[NS_LANG_ES] = 'ES'; -$wgNamespacesWithSubpages[NS_LANG_ES] = TRUE; -$wgContentNamespaces[] = NS_LANG_ES; -define('NS_LANG_ES_TALK', 205); -$wgExtraNamespaces[NS_LANG_ES_TALK] = 'ES_talk'; -$wgNamespacesWithSubpages[NS_LANG_ES_TALK] = TRUE; - -# IT -define('NS_LANG_IT', 206); -$wgExtraNamespaces[NS_LANG_IT] = 'IT'; -$wgNamespacesWithSubpages[NS_LANG_IT] = TRUE; -$wgContentNamespaces[] = NS_LANG_IT; -define('NS_LANG_IT_TALK', 207); -$wgExtraNamespaces[NS_LANG_IT_TALK] = 'IT_talk'; -$wgNamespacesWithSubpages[NS_LANG_IT_TALK] = TRUE; - -# NL -define('NS_LANG_NL', 208); -$wgExtraNamespaces[NS_LANG_NL] = 'NL'; -$wgNamespacesWithSubpages[NS_LANG_NL] = TRUE; -$wgContentNamespaces[] = NS_LANG_NL; -define('NS_LANG_NL_TALK', 209); -$wgExtraNamespaces[NS_LANG_NL_TALK] = 'NL_talk'; -$wgNamespacesWithSubpages[NS_LANG_NL_TALK] = TRUE; - -# RU -define('NS_LANG_RU', 210); -$wgExtraNamespaces[NS_LANG_RU] = 'RU'; -$wgNamespacesWithSubpages[NS_LANG_RU] = TRUE; -$wgContentNamespaces[] = NS_LANG_RU; -define('NS_LANG_RU_TALK', 211); -$wgExtraNamespaces[NS_LANG_RU_TALK] = 'RU_talk'; -$wgNamespacesWithSubpages[NS_LANG_RU_TALK] = TRUE; - -# JA -define('NS_LANG_JA', 212); -$wgExtraNamespaces[NS_LANG_JA] = 'JA'; -$wgNamespacesWithSubpages[NS_LANG_JA] = TRUE; -$wgContentNamespaces[] = NS_LANG_JA; -define('NS_LANG_JA_TALK', 213); -$wgExtraNamespaces[NS_LANG_JA_TALK] = 'JA_talk'; -$wgNamespacesWithSubpages[NS_LANG_JA_TALK] = TRUE; - -# Proposal -# namespace features a specific search weight defined at -# cookbooks/mediawiki/templates/default/mw-ext-CirrusSearch.inc.php.erb -define('NS_PROPOSAL', 3000); -$wgExtraNamespaces[NS_PROPOSAL] = 'Proposal'; -$wgNamespacesWithSubpages[NS_PROPOSAL] = TRUE; -$wgContentNamespaces[] = NS_PROPOSAL; -define('NS_PROPOSAL_TALK', 3001); -$wgExtraNamespaces[NS_PROPOSAL_TALK] = 'Proposal_talk'; -$wgNamespacesWithSubpages[NS_PROPOSAL_TALK] = TRUE; - -$wgNamespacesToBeSearchedDefault[NS_LANG_DE] = TRUE; -$wgNamespacesToBeSearchedDefault[NS_LANG_FR] = TRUE; -$wgNamespacesToBeSearchedDefault[NS_LANG_ES] = TRUE; -$wgNamespacesToBeSearchedDefault[NS_LANG_IT] = TRUE; -$wgNamespacesToBeSearchedDefault[NS_LANG_NL] = TRUE; -$wgNamespacesToBeSearchedDefault[NS_LANG_RU] = TRUE; -$wgNamespacesToBeSearchedDefault[NS_LANG_JA] = TRUE; -$wgNamespacesToBeSearchedDefault[NS_PROPOSAL] = TRUE; +<% @mediawiki[:namespaces].each do |name, details| -%> +# <%= name %> +define('NS_<%= name.upcase %>', <%= details[:id] %>); +$wgExtraNamespaces[NS_<%= name.upcase %>] = '<%= name %>'; +$wgNamespacesWithSubpages[NS_<%= name.upcase %>] = TRUE; +$wgContentNamespaces[] = NS_<%= name.upcase %>; +$wgNamespacesToBeSearchedDefault[NS_<%= name.upcase %>] = TRUE; +define('NS_<%= name.upcase %>_TALK', <%= details[:talk_id] %>); +$wgExtraNamespaces[NS_<%= name.upcase %>_TALK] = '<%= name %>_talk'; +$wgNamespacesWithSubpages[NS_<%= name.upcase %>_TALK] = TRUE; +<% end -%> + +<% unless @mediawiki[:force_ui_messages].empty? -%> # defines which links of the sidebar are translatable -$wgForceUIMsgAsContentMsg = array( 'mainpage-url', 'mapfeatures-url', 'contributors-url', 'helppage', 'blogs-url', 'shop-url', 'sitesupport-url' ); +$wgForceUIMsgAsContentMsg = array( '<%= @mediawiki[:force_ui_messages].join("', '") %>' ); <% end -%> # load extensions @@ -389,8 +319,8 @@ $wgForceUIMsgAsContentMsg = array( 'mainpage-url', 'mapfeatures-url', 'contribut <%= "require_once('#{file}');" %> <% end -%> -<% if @name == "wiki.openstreetmap.org" -%> -# wiki.openstreetmap.org specific config loaded after extensions +<% if @mediawiki[:watch_category_membership] -%> +# must be after extensions are loaded $wgRCWatchCategoryMembership = true; <% end -%> diff --git a/cookbooks/wiki/recipes/default.rb b/cookbooks/wiki/recipes/default.rb index f2bdcbb6d..4daec683c 100644 --- a/cookbooks/wiki/recipes/default.rb +++ b/cookbooks/wiki/recipes/default.rb @@ -57,6 +57,19 @@ mediawiki_site site_name do hcaptcha_public_key "b67a410b-955e-4049-b432-f9c00e0202c0" hcaptcha_private_key passwords["hcaptcha"] + namespaces "DE" => { :id => 200, :talk_id => 201 }, + "FR" => { :id => 202, :talk_id => 203 }, + "ES" => { :id => 204, :talk_id => 205 }, + "IT" => { :id => 206, :talk_id => 207 }, + "NL" => { :id => 208, :talk_id => 209 }, + "RU" => { :id => 210, :talk_id => 211 }, + "JA" => { :id => 212, :talk_id => 213 }, + "Proposal" => { :id => 3000, :talk_id => 3001 } + + force_ui_messages %w[mainpage-url mapfeatures-url contributors-url helppage blogs-url shop-url sitesupport-url] + + watch_category_membership true + site_notice node[:wiki][:site_notice] site_readonly node[:wiki][:site_readonly] end