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.
20 default_action :create
22 property :site, :kind_of => String, :name_property => true
23 property :aliases, :kind_of => [String, Array]
24 property :directory, :kind_of => String
25 property :version, :kind_of => String, :default => "1.35"
26 property :database_name, :kind_of => String, :required => true
27 property :database_user, :kind_of => String, :required => [:create, :update]
28 property :database_password, :kind_of => String, :required => [:create, :update]
29 property :sitename, :kind_of => String, :default => "OpenStreetMap Wiki"
30 property :metanamespace, :kind_of => String, :default => "OpenStreetMap"
31 property :logo, :kind_of => String, :default => "$wgStylePath/common/images/wiki.png"
32 property :email_contact, :kind_of => String, :default => ""
33 property :email_sender, :kind_of => String, :default => ""
34 property :email_sender_name, :kind_of => String, :default => "MediaWiki Mail"
35 property :commons, :kind_of => [TrueClass, FalseClass], :default => true
36 property :skin, :kind_of => String, :default => "vector"
37 property :site_notice, :kind_of => [String, TrueClass, FalseClass], :default => false
38 property :site_readonly, :kind_of => [String, TrueClass, FalseClass], :default => false
39 property :admin_user, :kind_of => String, :default => "Admin"
40 property :admin_password, :kind_of => String, :required => [:create]
41 property :private_accounts, :kind_of => [TrueClass, FalseClass], :default => false
42 property :private_site, :kind_of => [TrueClass, FalseClass], :default => false
43 property :recaptcha_public_key, :kind_of => String
44 property :recaptcha_private_key, :kind_of => String
45 property :extra_file_extensions, :kind_of => [String, Array], :default => []
46 property :fpm_max_children, :kind_of => Integer, :default => 5
47 property :fpm_start_servers, :kind_of => Integer, :default => 2
48 property :fpm_min_spare_servers, :kind_of => Integer, :default => 1
49 property :fpm_max_spare_servers, :kind_of => Integer, :default => 3
50 property :fpm_request_terminate_timeout, :kind_of => Integer, :default => 300
51 property :fpm_prometheus_port, :kind_of => Integer
52 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
55 node.default[:mediawiki][:sites][new_resource.site] = {
56 :directory => site_directory,
57 :version => new_resource.version
60 secret_key = persistent_token("mediawiki", new_resource.site, "wgSecretKey")
62 mysql_user "#{new_resource.database_user}@localhost" do
63 password new_resource.database_password
66 mysql_database new_resource.database_name do
67 permissions "#{new_resource.database_user}@localhost" => :all
70 mediawiki_directory = "#{site_directory}/w"
72 ruby_block "rename-installer-localsettings" do
75 ::File.rename("#{mediawiki_directory}/LocalSettings.php", "#{mediawiki_directory}/LocalSettings-install.php")
79 execute "#{mediawiki_directory}/maintenance/install.php" do
81 # Use metanamespace as Site Name to ensure correct set namespace
82 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}'"
83 cwd mediawiki_directory
84 user node[:mediawiki][:user]
85 group node[:mediawiki][:group]
87 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
89 notifies :run, "ruby_block[rename-installer-localsettings]", :immediately
92 execute "#{mediawiki_directory}/maintenance/update.php" do
94 command "php maintenance/update.php --quick"
95 cwd mediawiki_directory
96 user node[:mediawiki][:user]
97 group node[:mediawiki][:group]
100 declare_resource :directory, site_directory do
101 owner node[:mediawiki][:user]
102 group node[:mediawiki][:group]
106 declare_resource :directory, mediawiki_directory do
107 owner node[:mediawiki][:user]
108 group node[:mediawiki][:group]
112 mediawiki_reference = "REL#{new_resource.version}".tr(".", "_")
114 git mediawiki_directory do
116 repository "https://gerrit.wikimedia.org/r/mediawiki/core.git"
117 revision mediawiki_reference
119 user node[:mediawiki][:user]
120 group node[:mediawiki][:group]
121 notifies :run, "execute[#{mediawiki_directory}/composer.json]", :immediately
122 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
123 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
126 execute "#{mediawiki_directory}/composer.json" do
128 command "composer update --no-dev"
129 cwd mediawiki_directory
130 user node[:mediawiki][:user]
131 group node[:mediawiki][:group]
132 environment "COMPOSER_HOME" => site_directory
135 template "#{mediawiki_directory}/composer.local.json" do
137 source "composer.local.json.erb"
138 owner node[:mediawiki][:user]
139 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 cron_d "mediawiki-#{cron_name}-sitemap" do
187 comment "Generate sitemap.xml daily"
190 user node[:mediawiki][:user]
191 command "/usr/bin/nice /usr/bin/php -d memory_limit=2048M -d error_reporting=22517 #{site_directory}/w/maintenance/generateSitemap.php --server=https://#{new_resource.site} --urlpath=https://#{new_resource.site}/ --fspath=#{site_directory} --quiet --skip-redirects"
194 cron_d "mediawiki-#{cron_name}-jobs" do
195 comment "Run mediawiki jobs"
197 user node[:mediawiki][:user]
198 command "/usr/bin/nice /usr/bin/php -d memory_limit=2048M -d error_reporting=22517 #{site_directory}/w/maintenance/runJobs.php --server=https://#{new_resource.site} --maxtime=160 --memory-limit=2048M --procs=8 --quiet"
201 cron_d "mediawiki-#{cron_name}-email-jobs" do
202 comment "Run mediawiki email jobs"
203 user node[:mediawiki][:user]
204 command "/usr/bin/nice /usr/bin/php -d memory_limit=2048M -d error_reporting=22517 #{site_directory}/w/maintenance/runJobs.php --server=https://#{new_resource.site} --maxtime=30 --type=enotifNotify --memory-limit=2048M --procs=4 --quiet"
207 cron_d "mediawiki-#{cron_name}-refresh-links" do
208 comment "Run mediawiki refresh links table weekly"
212 user node[:mediawiki][:user]
213 command "/usr/bin/nice /usr/bin/php -d memory_limit=2048M -d error_reporting=22517 #{site_directory}/w/maintenance/refreshLinks.php --server=https://#{new_resource.site} --memory-limit=2048M --quiet"
216 cron_d "mediawiki-#{cron_name}-cleanup-gs" do
217 comment "Clean up imagemagick garbage"
220 user node[:mediawiki][:user]
221 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'gs_*' -delete"
224 cron_d "mediawiki-#{cron_name}-cleanup-magick" do
225 comment "Clean up imagemagick garbage"
228 user node[:mediawiki][:user]
229 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'magick-*' -delete"
232 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
234 source "mediawiki-backup.cron.erb"
238 variables :name => new_resource.site,
239 :directory => site_directory,
240 :database_params => database_params
243 # MobileFrontend extension is required by MinervaNeue skin
244 mediawiki_extension "MobileFrontend" do
245 site new_resource.site
246 template "mw-ext-MobileFrontend.inc.php.erb"
249 # MobileFrontend extension is required by MinervaNeue skin
250 mediawiki_skin "MinervaNeue" do
251 site new_resource.site
256 mediawiki_skin "CologneBlue" do
257 site new_resource.site
262 mediawiki_skin "Modern" do
263 site new_resource.site
268 mediawiki_skin "MonoBook" do
269 site new_resource.site
274 mediawiki_skin "Vector" do
275 site new_resource.site
280 mediawiki_extension "Cite" do
281 site new_resource.site
285 mediawiki_extension "CiteThisPage" do
286 site new_resource.site
290 if new_resource.private_accounts || new_resource.private_site
291 mediawiki_extension "ConfirmEdit" do
292 site new_resource.site
297 mediawiki_extension "ConfirmEdit" do
298 site new_resource.site
299 template "mw-ext-ConfirmEdit.inc.php.erb"
300 variables :public_key => new_resource.recaptcha_public_key,
301 :private_key => new_resource.recaptcha_private_key
306 mediawiki_extension "Gadgets" do
307 site new_resource.site
311 mediawiki_extension "ImageMap" do
312 site new_resource.site
316 mediawiki_extension "InputBox" do
317 site new_resource.site
321 mediawiki_extension "Interwiki" do
322 site new_resource.site
323 template "mw-ext-Interwiki.inc.php.erb"
327 mediawiki_extension "Nuke" do
328 site new_resource.site
332 mediawiki_extension "ParserFunctions" do
333 site new_resource.site
334 template "mw-ext-ParserFunctions.inc.php.erb"
338 mediawiki_extension "PdfHandler" do
339 site new_resource.site
340 template "mw-ext-PdfHandler.inc.php.erb"
344 mediawiki_extension "Poem" do
345 site new_resource.site
349 mediawiki_extension "Renameuser" do
350 site new_resource.site
354 mediawiki_extension "SimpleAntiSpam" do
355 site new_resource.site
360 mediawiki_extension "SpamBlacklist" do
361 site new_resource.site
362 template "mw-ext-SpamBlacklist.inc.php.erb"
366 mediawiki_extension "SyntaxHighlight_GeSHi" do
367 site new_resource.site
368 template "mw-ext-SyntaxHighlight.inc.php.erb"
372 mediawiki_extension "TitleBlacklist" do
373 site new_resource.site
374 template "mw-ext-TitleBlacklist.inc.php.erb"
378 mediawiki_extension "WikiEditor" do
379 site new_resource.site
383 mediawiki_extension "Babel" do
384 site new_resource.site
385 template "mw-ext-Babel.inc.php.erb"
389 mediawiki_extension "cldr" do
390 site new_resource.site
391 template "mw-ext-cldr.inc.php.erb"
395 mediawiki_extension "CleanChanges" do
396 site new_resource.site
397 template "mw-ext-CleanChanges.inc.php.erb"
401 mediawiki_extension "LocalisationUpdate" do
402 site new_resource.site
403 template "mw-ext-LocalisationUpdate.inc.php.erb"
407 # mediawiki_extension "Translate" do
408 # site new_resource.site
409 # template "mw-ext-Translate.inc.php.erb"
413 mediawiki_extension "UniversalLanguageSelector" do
414 site new_resource.site
415 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
419 mediawiki_extension "AntiSpoof" do
420 site new_resource.site
421 template "mw-ext-AntiSpoof.inc.php.erb"
425 mediawiki_extension "AbuseFilter" do
426 site new_resource.site
427 template "mw-ext-AbuseFilter.inc.php.erb"
431 mediawiki_extension "CheckUser" do
432 site new_resource.site
433 template "mw-ext-CheckUser.inc.php.erb"
437 mediawiki_extension "DismissableSiteNotice" do
438 site new_resource.site
442 mediawiki_extension "Elastica" do
443 site new_resource.site
447 mediawiki_extension "CirrusSearch" do
448 site new_resource.site
449 template "mw-ext-CirrusSearch.inc.php.erb"
453 mediawiki_extension "osmtaginfo" do
454 site new_resource.site
455 template "mw-ext-osmtaginfo.inc.php.erb"
456 repository "https://github.com/Firefishy/osmtaginfo.git"
461 mediawiki_extension "OSMCALWikiWidget" do
462 site new_resource.site
463 repository "https://github.com/thomersch/OSMCALWikiWidget.git"
468 mediawiki_extension "SimpleMap" do
469 site new_resource.site
470 template "mw-ext-SimpleMap.inc.php.erb"
471 repository "https://github.com/Firefishy/SimpleMap.git"
476 mediawiki_extension "SlippyMap" do
477 site new_resource.site
482 mediawiki_extension "Mantle" do
483 site new_resource.site
488 mediawiki_extension "DisableAccount" do
489 site new_resource.site
490 template "mw-ext-DisableAccount.inc.php.erb"
494 mediawiki_extension "VisualEditor" do
495 site new_resource.site
496 template "mw-ext-VisualEditor.inc.php.erb"
500 mediawiki_extension "TemplateData" do
501 site new_resource.site
505 cookbook_file "#{site_directory}/cc-wiki.png" do
507 owner node[:mediawiki][:user]
508 group node[:mediawiki][:group]
513 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
515 owner node[:mediawiki][:user]
516 group node[:mediawiki][:group]
521 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
523 owner node[:mediawiki][:user]
524 group node[:mediawiki][:group]
529 ssl_certificate new_resource.site do
530 domains [new_resource.site] + Array(new_resource.aliases)
533 php_fpm new_resource.site do
534 pm_max_children new_resource.fpm_max_children
535 pm_start_servers new_resource.fpm_start_servers
536 pm_min_spare_servers new_resource.fpm_min_spare_servers
537 pm_max_spare_servers new_resource.fpm_max_spare_servers
538 request_terminate_timeout new_resource.fpm_request_terminate_timeout
539 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
540 php_values "memory_limit" => "500M",
541 "max_execution_time" => "240",
542 "upload_max_filesize" => "70M",
543 "post_max_size" => "100M"
544 prometheus_port new_resource.fpm_prometheus_port
547 apache_site new_resource.site do
549 template "apache.erb"
550 directory site_directory
551 variables :aliases => Array(new_resource.aliases),
552 :private_site => new_resource.private_site
556 # FIXME: needs to run one
557 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
559 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
560 cwd mediawiki_directory
561 user node[:mediawiki][:user]
562 group node[:mediawiki][:group]
567 mediawiki_directory = "#{site_directory}/w"
569 template "#{mediawiki_directory}/LocalSettings.php" do
571 source "LocalSettings.php.erb"
572 owner node[:mediawiki][:user]
573 group node[:mediawiki][:group]
575 variables :name => new_resource.site,
576 :directory => mediawiki_directory,
577 :database_params => database_params,
578 :mediawiki => mediawiki_params
579 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
582 execute "#{mediawiki_directory}/maintenance/update.php" do
584 command "php maintenance/update.php --quick"
585 cwd mediawiki_directory
586 user node[:mediawiki][:user]
587 group node[:mediawiki][:group]
592 apache_site new_resource.site do
597 declare_resource :directory, site_directory do
602 mysql_database new_resource.database_name do
606 mysql_user "#{new_resource.database_user}@localhost" do
612 include Chef::Mixin::PersistentToken
615 new_resource.directory || "/srv/#{new_resource.site}"
619 new_resource.site.tr(".", "_")
624 :host => "localhost",
625 :name => new_resource.database_name,
626 :username => new_resource.database_user,
627 :password => new_resource.database_password
633 :sitename => new_resource.sitename,
634 :metanamespace => new_resource.metanamespace,
635 :logo => new_resource.logo,
636 :email_contact => new_resource.email_contact,
637 :email_sender => new_resource.email_sender,
638 :email_sender_name => new_resource.email_sender_name,
639 :commons => new_resource.commons,
640 :skin => new_resource.skin,
641 :site_notice => new_resource.site_notice,
642 :site_readonly => new_resource.site_readonly,
643 :extra_file_extensions => new_resource.extra_file_extensions,
644 :private_accounts => new_resource.private_accounts,
645 :private_site => new_resource.private_site
651 notifies :reload, "service[apache2]" if reload_apache