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=175 --memory-limit=2048M --procs=8 --nothrottle --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=55 --type=enotifNotify --memory-limit=2048M --procs=4 --nothrottle --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.hcaptcha_public_key,
301 :private_key => new_resource.hcaptcha_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 "CategoryTree" do
390 site new_resource.site
394 mediawiki_extension "cldr" do
395 site new_resource.site
396 template "mw-ext-cldr.inc.php.erb"
400 mediawiki_extension "CleanChanges" do
401 site new_resource.site
402 template "mw-ext-CleanChanges.inc.php.erb"
406 mediawiki_extension "LocalisationUpdate" do
407 site new_resource.site
408 template "mw-ext-LocalisationUpdate.inc.php.erb"
412 # mediawiki_extension "Translate" do
413 # site new_resource.site
414 # template "mw-ext-Translate.inc.php.erb"
418 mediawiki_extension "UniversalLanguageSelector" do
419 site new_resource.site
420 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
424 mediawiki_extension "AntiSpoof" do
425 site new_resource.site
426 template "mw-ext-AntiSpoof.inc.php.erb"
430 mediawiki_extension "AbuseFilter" do
431 site new_resource.site
432 template "mw-ext-AbuseFilter.inc.php.erb"
436 mediawiki_extension "CheckUser" do
437 site new_resource.site
438 template "mw-ext-CheckUser.inc.php.erb"
442 mediawiki_extension "DismissableSiteNotice" do
443 site new_resource.site
447 mediawiki_extension "Elastica" do
448 site new_resource.site
452 mediawiki_extension "CirrusSearch" do
453 site new_resource.site
454 template "mw-ext-CirrusSearch.inc.php.erb"
458 mediawiki_extension "osmtaginfo" do
459 site new_resource.site
460 repository "https://github.com/openstreetmap/osmtaginfo.git"
465 mediawiki_extension "OSMCALWikiWidget" do
466 site new_resource.site
467 repository "https://github.com/thomersch/OSMCALWikiWidget.git"
472 mediawiki_extension "DisableAccount" do
473 site new_resource.site
474 template "mw-ext-DisableAccount.inc.php.erb"
478 mediawiki_extension "VisualEditor" do
479 site new_resource.site
480 template "mw-ext-VisualEditor.inc.php.erb"
481 variables :version => new_resource.version
485 mediawiki_extension "TemplateData" do
486 site new_resource.site
490 if new_resource.commons
491 mediawiki_extension "QuickInstantCommons" do
492 site new_resource.site
496 mediawiki_extension "QuickInstantCommons" do
497 site new_resource.site
503 cookbook_file "#{site_directory}/cc-wiki.png" do
505 owner node[:mediawiki][:user]
506 group node[:mediawiki][:group]
511 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
513 owner node[:mediawiki][:user]
514 group node[:mediawiki][:group]
519 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
521 owner node[:mediawiki][:user]
522 group node[:mediawiki][:group]
527 ssl_certificate new_resource.site do
528 domains [new_resource.site] + Array(new_resource.aliases)
531 php_fpm new_resource.site do
532 pm_max_children new_resource.fpm_max_children
533 pm_start_servers new_resource.fpm_start_servers
534 pm_min_spare_servers new_resource.fpm_min_spare_servers
535 pm_max_spare_servers new_resource.fpm_max_spare_servers
536 request_terminate_timeout new_resource.fpm_request_terminate_timeout
537 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
538 php_values "memory_limit" => "500M",
539 "max_execution_time" => "240",
540 "upload_max_filesize" => "70M",
541 "post_max_size" => "100M"
542 prometheus_port new_resource.fpm_prometheus_port
545 apache_site new_resource.site do
547 template "apache.erb"
548 directory site_directory
549 variables :aliases => Array(new_resource.aliases),
550 :private_site => new_resource.private_site
554 # FIXME: needs to run one
555 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
557 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
558 cwd mediawiki_directory
559 user node[:mediawiki][:user]
560 group node[:mediawiki][:group]
565 mediawiki_directory = "#{site_directory}/w"
567 template "#{mediawiki_directory}/LocalSettings.php" do
569 source "LocalSettings.php.erb"
570 owner node[:mediawiki][:user]
571 group node[:mediawiki][:group]
573 variables :name => new_resource.site,
574 :directory => mediawiki_directory,
575 :database_params => database_params,
576 :mediawiki => mediawiki_params
577 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
580 execute "#{mediawiki_directory}/maintenance/update.php" do
582 command "php maintenance/update.php --quick"
583 cwd mediawiki_directory
584 user node[:mediawiki][:user]
585 group node[:mediawiki][:group]
590 apache_site new_resource.site do
595 declare_resource :directory, site_directory do
600 mysql_database new_resource.database_name do
604 mysql_user "#{new_resource.database_user}@localhost" do
610 include Chef::Mixin::PersistentToken
613 new_resource.directory || "/srv/#{new_resource.site}"
616 def mediawiki_reference
617 shell_out!("git", "ls-remote", "--refs", "--sort=-version:refname",
618 "https://gerrit.wikimedia.org/r/mediawiki/core.git",
619 "refs/tags/#{new_resource.version}.*")
628 new_resource.site.tr(".", "_")
633 :host => "localhost",
634 :name => new_resource.database_name,
635 :username => new_resource.database_user,
636 :password => new_resource.database_password
642 :sitename => new_resource.sitename,
643 :metanamespace => new_resource.metanamespace,
644 :logo => new_resource.logo,
645 :email_contact => new_resource.email_contact,
646 :email_sender => new_resource.email_sender,
647 :email_sender_name => new_resource.email_sender_name,
648 :commons => new_resource.commons,
649 :skin => new_resource.skin,
650 :site_notice => new_resource.site_notice,
651 :site_readonly => new_resource.site_readonly,
652 :extra_file_extensions => new_resource.extra_file_extensions,
653 :private_accounts => new_resource.private_accounts,
654 :private_site => new_resource.private_site
660 notifies :reload, "service[apache2]" if reload_apache