3 # Resource:: mediawiki_site
5 # Copyright:: 2015, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
22 default_action :create
24 property :site, :kind_of => String, :name_property => true
25 property :aliases, :kind_of => [String, Array]
26 property :directory, :kind_of => String
27 property :version, :kind_of => String, :default => "1.37"
28 property :database_name, :kind_of => String, :required => true
29 property :database_user, :kind_of => String, :required => [:create, :update]
30 property :database_password, :kind_of => String, :required => [:create, :update]
31 property :sitename, :kind_of => String, :default => "OpenStreetMap Wiki"
32 property :metanamespace, :kind_of => String, :default => "OpenStreetMap"
33 property :logo, :kind_of => String, :default => "$wgStylePath/common/images/wiki.png"
34 property :email_contact, :kind_of => String, :default => ""
35 property :email_sender, :kind_of => String, :default => ""
36 property :email_sender_name, :kind_of => String, :default => "MediaWiki Mail"
37 property :commons, :kind_of => [TrueClass, FalseClass], :default => true
38 property :skin, :kind_of => String, :default => "vector"
39 property :site_notice, :kind_of => [String, TrueClass, FalseClass], :default => false
40 property :site_readonly, :kind_of => [String, TrueClass, FalseClass], :default => false
41 property :admin_user, :kind_of => String, :default => "Admin"
42 property :admin_password, :kind_of => String, :required => [:create]
43 property :private_accounts, :kind_of => [TrueClass, FalseClass], :default => false
44 property :private_site, :kind_of => [TrueClass, FalseClass], :default => false
45 property :hcaptcha_public_key, :kind_of => String, :default => ""
46 property :hcaptcha_private_key, :kind_of => String, :default => ""
47 property :extra_file_extensions, :kind_of => [String, Array], :default => []
48 property :fpm_max_children, :kind_of => Integer, :default => 5
49 property :fpm_start_servers, :kind_of => Integer, :default => 2
50 property :fpm_min_spare_servers, :kind_of => Integer, :default => 1
51 property :fpm_max_spare_servers, :kind_of => Integer, :default => 3
52 property :fpm_request_terminate_timeout, :kind_of => Integer, :default => 300
53 property :fpm_prometheus_port, :kind_of => Integer
54 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
57 node.default[:mediawiki][:sites][new_resource.site] = {
58 :directory => site_directory,
59 :version => new_resource.version
62 secret_key = persistent_token("mediawiki", new_resource.site, "wgSecretKey")
64 mysql_user "#{new_resource.database_user}@localhost" do
65 password new_resource.database_password
68 mysql_database new_resource.database_name do
69 permissions "#{new_resource.database_user}@localhost" => :all
72 mediawiki_directory = "#{site_directory}/w"
74 ruby_block "rename-installer-localsettings" do
77 ::File.rename("#{mediawiki_directory}/LocalSettings.php", "#{mediawiki_directory}/LocalSettings-install.php")
81 declare_resource :directory, site_directory do
82 owner node[:mediawiki][:user]
83 group node[:mediawiki][:group]
87 declare_resource :directory, mediawiki_directory do
88 owner node[:mediawiki][:user]
89 group node[:mediawiki][:group]
93 git mediawiki_directory do
95 repository "https://gerrit.wikimedia.org/r/mediawiki/core.git"
96 revision mediawiki_reference
98 user node[:mediawiki][:user]
99 group node[:mediawiki][:group]
100 notifies :run, "execute[#{mediawiki_directory}/composer.json]", :immediately
101 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
102 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
105 template "#{mediawiki_directory}/composer.local.json" do
107 source "composer.local.json.erb"
108 owner node[:mediawiki][:user]
109 group node[:mediawiki][:group]
113 execute "#{mediawiki_directory}/composer.json" do
115 command "composer update --no-dev"
116 cwd mediawiki_directory
117 user node[:mediawiki][:user]
118 group node[:mediawiki][:group]
119 environment "COMPOSER_HOME" => site_directory
122 execute "#{mediawiki_directory}/maintenance/install.php" do
124 # Use metanamespace as Site Name to ensure correct set namespace
125 command "php maintenance/install.php --server '#{name}' --dbtype 'mysql' --dbname '#{new_resource.database_name}' --dbuser '#{new_resource.database_user}' --dbpass '#{new_resource.database_password}' --dbserver 'localhost' --scriptpath /w --pass '#{new_resource.admin_password}' '#{new_resource.metanamespace}' '#{new_resource.admin_user}'"
126 cwd mediawiki_directory
127 user node[:mediawiki][:user]
128 group node[:mediawiki][:group]
130 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
132 notifies :run, "ruby_block[rename-installer-localsettings]", :immediately
135 execute "#{mediawiki_directory}/maintenance/update.php" do
137 command "php maintenance/update.php --quick"
138 cwd mediawiki_directory
139 user node[:mediawiki][:user]
140 group node[:mediawiki][:group]
143 # Safety catch if git doesn't update but install.php hasn't run
144 ruby_block "catch-installer-localsettings-run" do
149 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
151 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
154 declare_resource :directory, "#{mediawiki_directory}/images" do
156 group node[:mediawiki][:group]
160 declare_resource :directory, "#{mediawiki_directory}/cache" do
162 group node[:mediawiki][:group]
166 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
167 user node[:mediawiki][:user]
168 group node[:mediawiki][:group]
172 template "#{mediawiki_directory}/LocalSettings.php" do
174 source "LocalSettings.php.erb"
175 owner node[:mediawiki][:user]
176 group node[:mediawiki][:group]
178 variables :name => new_resource.site,
179 :directory => mediawiki_directory,
180 :database_params => database_params,
181 :mediawiki => mediawiki_params,
182 :secret_key => secret_key
183 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
186 service "mediawiki-sitemap@#{new_resource.site}.timer" do
187 action [:enable, :start]
190 service "mediawiki-jobs@#{new_resource.site}.timer" do
191 action [:enable, :start]
194 service "mediawiki-email-jobs@#{new_resource.site}.timer" do
195 action [:enable, :start]
198 service "mediawiki-refresh-links@#{new_resource.site}.timer" do
199 action [:enable, :start]
202 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
204 source "mediawiki-backup.cron.erb"
208 variables :name => new_resource.site,
209 :directory => site_directory,
210 :database_params => database_params
213 # MobileFrontend extension is required by MinervaNeue skin
214 mediawiki_extension "MobileFrontend" do
215 site new_resource.site
216 template "mw-ext-MobileFrontend.inc.php.erb"
219 # MobileFrontend extension is required by MinervaNeue skin
220 mediawiki_skin "MinervaNeue" do
221 site new_resource.site
226 mediawiki_skin "CologneBlue" do
227 site new_resource.site
232 mediawiki_skin "Modern" do
233 site new_resource.site
238 mediawiki_skin "MonoBook" do
239 site new_resource.site
244 mediawiki_skin "Vector" do
245 site new_resource.site
250 mediawiki_extension "Cite" do
251 site new_resource.site
255 mediawiki_extension "CiteThisPage" do
256 site new_resource.site
260 if new_resource.private_accounts || new_resource.private_site
261 mediawiki_extension "ConfirmEdit" do
262 site new_resource.site
267 mediawiki_extension "ConfirmEdit" do
268 site new_resource.site
269 template "mw-ext-ConfirmEdit.inc.php.erb"
270 variables :public_key => new_resource.hcaptcha_public_key,
271 :private_key => new_resource.hcaptcha_private_key
276 mediawiki_extension "Gadgets" do
277 site new_resource.site
281 mediawiki_extension "ImageMap" do
282 site new_resource.site
286 mediawiki_extension "InputBox" do
287 site new_resource.site
291 mediawiki_extension "Interwiki" do
292 site new_resource.site
293 template "mw-ext-Interwiki.inc.php.erb"
297 mediawiki_extension "Nuke" do
298 site new_resource.site
302 mediawiki_extension "ParserFunctions" do
303 site new_resource.site
304 template "mw-ext-ParserFunctions.inc.php.erb"
308 mediawiki_extension "PdfHandler" do
309 site new_resource.site
310 template "mw-ext-PdfHandler.inc.php.erb"
314 mediawiki_extension "Poem" do
315 site new_resource.site
319 mediawiki_extension "Renameuser" do
320 site new_resource.site
324 mediawiki_extension "SimpleAntiSpam" do
325 site new_resource.site
330 mediawiki_extension "SpamBlacklist" do
331 site new_resource.site
332 template "mw-ext-SpamBlacklist.inc.php.erb"
336 mediawiki_extension "SyntaxHighlight_GeSHi" do
337 site new_resource.site
338 template "mw-ext-SyntaxHighlight.inc.php.erb"
342 mediawiki_extension "TitleBlacklist" do
343 site new_resource.site
344 template "mw-ext-TitleBlacklist.inc.php.erb"
348 mediawiki_extension "WikiEditor" do
349 site new_resource.site
353 mediawiki_extension "Babel" do
354 site new_resource.site
355 template "mw-ext-Babel.inc.php.erb"
359 mediawiki_extension "CategoryTree" do
360 site new_resource.site
364 mediawiki_extension "cldr" do
365 site new_resource.site
366 template "mw-ext-cldr.inc.php.erb"
370 mediawiki_extension "CleanChanges" do
371 site new_resource.site
372 template "mw-ext-CleanChanges.inc.php.erb"
376 mediawiki_extension "LocalisationUpdate" do
377 site new_resource.site
378 template "mw-ext-LocalisationUpdate.inc.php.erb"
382 # mediawiki_extension "Translate" do
383 # site new_resource.site
384 # template "mw-ext-Translate.inc.php.erb"
388 mediawiki_extension "UniversalLanguageSelector" do
389 site new_resource.site
390 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
394 mediawiki_extension "AntiSpoof" do
395 site new_resource.site
396 template "mw-ext-AntiSpoof.inc.php.erb"
400 mediawiki_extension "AbuseFilter" do
401 site new_resource.site
402 template "mw-ext-AbuseFilter.inc.php.erb"
406 mediawiki_extension "CheckUser" do
407 site new_resource.site
408 template "mw-ext-CheckUser.inc.php.erb"
412 mediawiki_extension "DismissableSiteNotice" do
413 site new_resource.site
417 mediawiki_extension "Elastica" do
418 site new_resource.site
422 mediawiki_extension "CirrusSearch" do
423 site new_resource.site
424 template "mw-ext-CirrusSearch.inc.php.erb"
428 mediawiki_extension "osmtaginfo" do
429 site new_resource.site
430 repository "https://github.com/openstreetmap/osmtaginfo.git"
435 mediawiki_extension "OSMCALWikiWidget" do
436 site new_resource.site
437 repository "https://github.com/thomersch/OSMCALWikiWidget.git"
442 mediawiki_extension "DisableAccount" do
443 site new_resource.site
444 template "mw-ext-DisableAccount.inc.php.erb"
448 mediawiki_extension "VisualEditor" do
449 site new_resource.site
450 template "mw-ext-VisualEditor.inc.php.erb"
451 variables :version => new_resource.version
455 mediawiki_extension "TemplateData" do
456 site new_resource.site
460 if new_resource.commons
461 mediawiki_extension "QuickInstantCommons" do
462 site new_resource.site
466 mediawiki_extension "QuickInstantCommons" do
467 site new_resource.site
473 cookbook_file "#{site_directory}/cc-wiki.png" do
475 owner node[:mediawiki][:user]
476 group node[:mediawiki][:group]
481 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
483 owner node[:mediawiki][:user]
484 group node[:mediawiki][:group]
489 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
491 owner node[:mediawiki][:user]
492 group node[:mediawiki][:group]
497 ssl_certificate new_resource.site do
498 domains [new_resource.site] + Array(new_resource.aliases)
501 php_fpm new_resource.site do
502 pm_max_children new_resource.fpm_max_children
503 pm_start_servers new_resource.fpm_start_servers
504 pm_min_spare_servers new_resource.fpm_min_spare_servers
505 pm_max_spare_servers new_resource.fpm_max_spare_servers
506 request_terminate_timeout new_resource.fpm_request_terminate_timeout
507 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
508 php_values "memory_limit" => "500M",
509 "max_execution_time" => "240",
510 "upload_max_filesize" => "70M",
511 "post_max_size" => "100M"
512 prometheus_port new_resource.fpm_prometheus_port
515 apache_site new_resource.site do
517 template "apache.erb"
518 directory site_directory
519 variables :aliases => Array(new_resource.aliases),
520 :private_site => new_resource.private_site
524 # FIXME: needs to run one
525 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
527 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
528 cwd mediawiki_directory
529 user node[:mediawiki][:user]
530 group node[:mediawiki][:group]
535 mediawiki_directory = "#{site_directory}/w"
537 template "#{mediawiki_directory}/LocalSettings.php" do
539 source "LocalSettings.php.erb"
540 owner node[:mediawiki][:user]
541 group node[:mediawiki][:group]
543 variables :name => new_resource.site,
544 :directory => mediawiki_directory,
545 :database_params => database_params,
546 :mediawiki => mediawiki_params
547 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
550 execute "#{mediawiki_directory}/maintenance/update.php" do
552 command "php maintenance/update.php --quick"
553 cwd mediawiki_directory
554 user node[:mediawiki][:user]
555 group node[:mediawiki][:group]
560 apache_site new_resource.site do
565 declare_resource :directory, site_directory do
570 mysql_database new_resource.database_name do
574 mysql_user "#{new_resource.database_user}@localhost" do
580 include OpenStreetMap::Mixin::PersistentToken
583 new_resource.directory || "/srv/#{new_resource.site}"
586 def mediawiki_reference
587 shell_out!("git", "ls-remote", "--refs", "--sort=-version:refname",
588 "https://gerrit.wikimedia.org/r/mediawiki/core.git",
589 "refs/tags/#{new_resource.version}.*")
598 new_resource.site.tr(".", "_")
603 :host => "localhost",
604 :name => new_resource.database_name,
605 :username => new_resource.database_user,
606 :password => new_resource.database_password
612 :sitename => new_resource.sitename,
613 :metanamespace => new_resource.metanamespace,
614 :logo => new_resource.logo,
615 :email_contact => new_resource.email_contact,
616 :email_sender => new_resource.email_sender,
617 :email_sender_name => new_resource.email_sender_name,
618 :commons => new_resource.commons,
619 :skin => new_resource.skin,
620 :site_notice => new_resource.site_notice,
621 :site_readonly => new_resource.site_readonly,
622 :extra_file_extensions => new_resource.extra_file_extensions,
623 :private_accounts => new_resource.private_accounts,
624 :private_site => new_resource.private_site
630 notifies :reload, "service[apache2]" if reload_apache