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 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 daily"
211 user node[:mediawiki][:user]
212 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"
215 cron_d "mediawiki-#{cron_name}-cleanup-gs" do
216 comment "Clean up imagemagick garbage"
219 user node[:mediawiki][:user]
220 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'gs_*' -delete"
223 cron_d "mediawiki-#{cron_name}-cleanup-magick" do
224 comment "Clean up imagemagick garbage"
227 user node[:mediawiki][:user]
228 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'magick-*' -delete"
231 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
233 source "mediawiki-backup.cron.erb"
237 variables :name => new_resource.site,
238 :directory => site_directory,
239 :database_params => database_params
242 # MobileFrontend extension is required by MinervaNeue skin
243 mediawiki_extension "MobileFrontend" do
244 site new_resource.site
245 template "mw-ext-MobileFrontend.inc.php.erb"
248 # MobileFrontend extension is required by MinervaNeue skin
249 mediawiki_skin "MinervaNeue" do
250 site new_resource.site
255 mediawiki_skin "CologneBlue" do
256 site new_resource.site
261 mediawiki_skin "Modern" do
262 site new_resource.site
267 mediawiki_skin "MonoBook" do
268 site new_resource.site
273 mediawiki_skin "Vector" do
274 site new_resource.site
279 mediawiki_extension "Cite" do
280 site new_resource.site
284 mediawiki_extension "CiteThisPage" do
285 site new_resource.site
289 if new_resource.private_accounts || new_resource.private_site
290 mediawiki_extension "ConfirmEdit" do
291 site new_resource.site
296 mediawiki_extension "ConfirmEdit" do
297 site new_resource.site
298 template "mw-ext-ConfirmEdit.inc.php.erb"
299 variables :public_key => new_resource.hcaptcha_public_key,
300 :private_key => new_resource.hcaptcha_private_key
305 mediawiki_extension "Gadgets" do
306 site new_resource.site
310 mediawiki_extension "ImageMap" do
311 site new_resource.site
315 mediawiki_extension "InputBox" do
316 site new_resource.site
320 mediawiki_extension "Interwiki" do
321 site new_resource.site
322 template "mw-ext-Interwiki.inc.php.erb"
326 mediawiki_extension "Nuke" do
327 site new_resource.site
331 mediawiki_extension "ParserFunctions" do
332 site new_resource.site
333 template "mw-ext-ParserFunctions.inc.php.erb"
337 mediawiki_extension "PdfHandler" do
338 site new_resource.site
339 template "mw-ext-PdfHandler.inc.php.erb"
343 mediawiki_extension "Poem" do
344 site new_resource.site
348 mediawiki_extension "Renameuser" do
349 site new_resource.site
353 mediawiki_extension "SimpleAntiSpam" do
354 site new_resource.site
359 mediawiki_extension "SpamBlacklist" do
360 site new_resource.site
361 template "mw-ext-SpamBlacklist.inc.php.erb"
365 mediawiki_extension "SyntaxHighlight_GeSHi" do
366 site new_resource.site
367 template "mw-ext-SyntaxHighlight.inc.php.erb"
371 mediawiki_extension "TitleBlacklist" do
372 site new_resource.site
373 template "mw-ext-TitleBlacklist.inc.php.erb"
377 mediawiki_extension "WikiEditor" do
378 site new_resource.site
382 mediawiki_extension "Babel" do
383 site new_resource.site
384 template "mw-ext-Babel.inc.php.erb"
388 mediawiki_extension "CategoryTree" do
389 site new_resource.site
393 mediawiki_extension "cldr" do
394 site new_resource.site
395 template "mw-ext-cldr.inc.php.erb"
399 mediawiki_extension "CleanChanges" do
400 site new_resource.site
401 template "mw-ext-CleanChanges.inc.php.erb"
405 mediawiki_extension "LocalisationUpdate" do
406 site new_resource.site
407 template "mw-ext-LocalisationUpdate.inc.php.erb"
411 # mediawiki_extension "Translate" do
412 # site new_resource.site
413 # template "mw-ext-Translate.inc.php.erb"
417 mediawiki_extension "UniversalLanguageSelector" do
418 site new_resource.site
419 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
423 mediawiki_extension "AntiSpoof" do
424 site new_resource.site
425 template "mw-ext-AntiSpoof.inc.php.erb"
429 mediawiki_extension "AbuseFilter" do
430 site new_resource.site
431 template "mw-ext-AbuseFilter.inc.php.erb"
435 mediawiki_extension "CheckUser" do
436 site new_resource.site
437 template "mw-ext-CheckUser.inc.php.erb"
441 mediawiki_extension "DismissableSiteNotice" do
442 site new_resource.site
446 mediawiki_extension "Elastica" do
447 site new_resource.site
451 mediawiki_extension "CirrusSearch" do
452 site new_resource.site
453 template "mw-ext-CirrusSearch.inc.php.erb"
457 mediawiki_extension "osmtaginfo" do
458 site new_resource.site
459 repository "https://github.com/Firefishy/osmtaginfo.git"
464 mediawiki_extension "OSMCALWikiWidget" do
465 site new_resource.site
466 repository "https://github.com/thomersch/OSMCALWikiWidget.git"
471 mediawiki_extension "SimpleMap" do
472 site new_resource.site
473 template "mw-ext-SimpleMap.inc.php.erb"
474 repository "https://github.com/Firefishy/SimpleMap.git"
480 mediawiki_extension "SlippyMap" do
481 site new_resource.site
486 mediawiki_extension "Mantle" do
487 site new_resource.site
492 mediawiki_extension "DisableAccount" do
493 site new_resource.site
494 template "mw-ext-DisableAccount.inc.php.erb"
498 mediawiki_extension "VisualEditor" do
499 site new_resource.site
500 template "mw-ext-VisualEditor.inc.php.erb"
501 variables :version => new_resource.version
505 mediawiki_extension "TemplateData" do
506 site new_resource.site
510 if new_resource.commons
511 mediawiki_extension "QuickInstantCommons" do
512 site new_resource.site
516 mediawiki_extension "QuickInstantCommons" do
517 site new_resource.site
523 cookbook_file "#{site_directory}/cc-wiki.png" do
525 owner node[:mediawiki][:user]
526 group node[:mediawiki][:group]
531 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
533 owner node[:mediawiki][:user]
534 group node[:mediawiki][:group]
539 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
541 owner node[:mediawiki][:user]
542 group node[:mediawiki][:group]
547 ssl_certificate new_resource.site do
548 domains [new_resource.site] + Array(new_resource.aliases)
551 php_fpm new_resource.site do
552 pm_max_children new_resource.fpm_max_children
553 pm_start_servers new_resource.fpm_start_servers
554 pm_min_spare_servers new_resource.fpm_min_spare_servers
555 pm_max_spare_servers new_resource.fpm_max_spare_servers
556 request_terminate_timeout new_resource.fpm_request_terminate_timeout
557 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
558 php_values "memory_limit" => "500M",
559 "max_execution_time" => "240",
560 "upload_max_filesize" => "70M",
561 "post_max_size" => "100M"
562 prometheus_port new_resource.fpm_prometheus_port
565 apache_site new_resource.site do
567 template "apache.erb"
568 directory site_directory
569 variables :aliases => Array(new_resource.aliases),
570 :private_site => new_resource.private_site
574 # FIXME: needs to run one
575 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
577 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
578 cwd mediawiki_directory
579 user node[:mediawiki][:user]
580 group node[:mediawiki][:group]
585 mediawiki_directory = "#{site_directory}/w"
587 template "#{mediawiki_directory}/LocalSettings.php" do
589 source "LocalSettings.php.erb"
590 owner node[:mediawiki][:user]
591 group node[:mediawiki][:group]
593 variables :name => new_resource.site,
594 :directory => mediawiki_directory,
595 :database_params => database_params,
596 :mediawiki => mediawiki_params
597 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
600 execute "#{mediawiki_directory}/maintenance/update.php" do
602 command "php maintenance/update.php --quick"
603 cwd mediawiki_directory
604 user node[:mediawiki][:user]
605 group node[:mediawiki][:group]
610 apache_site new_resource.site do
615 declare_resource :directory, site_directory do
620 mysql_database new_resource.database_name do
624 mysql_user "#{new_resource.database_user}@localhost" do
630 include Chef::Mixin::PersistentToken
633 new_resource.directory || "/srv/#{new_resource.site}"
636 def mediawiki_reference
637 shell_out!("git", "ls-remote", "--refs", "--sort=-version:refname",
638 "https://gerrit.wikimedia.org/r/mediawiki/core.git",
639 "refs/tags/#{new_resource.version}.*")
648 new_resource.site.tr(".", "_")
653 :host => "localhost",
654 :name => new_resource.database_name,
655 :username => new_resource.database_user,
656 :password => new_resource.database_password
662 :sitename => new_resource.sitename,
663 :metanamespace => new_resource.metanamespace,
664 :logo => new_resource.logo,
665 :email_contact => new_resource.email_contact,
666 :email_sender => new_resource.email_sender,
667 :email_sender_name => new_resource.email_sender_name,
668 :commons => new_resource.commons,
669 :skin => new_resource.skin,
670 :site_notice => new_resource.site_notice,
671 :site_readonly => new_resource.site_readonly,
672 :extra_file_extensions => new_resource.extra_file_extensions,
673 :private_accounts => new_resource.private_accounts,
674 :private_site => new_resource.private_site
680 notifies :reload, "service[apache2]" if reload_apache