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 git mediawiki_directory do
114 repository "https://gerrit.wikimedia.org/r/mediawiki/core.git"
115 revision mediawiki_reference
117 user node[:mediawiki][:user]
118 group node[:mediawiki][:group]
119 notifies :run, "execute[#{mediawiki_directory}/composer.json]", :immediately
120 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
121 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
124 execute "#{mediawiki_directory}/composer.json" do
126 command "composer update --no-dev"
127 cwd mediawiki_directory
128 user node[:mediawiki][:user]
129 group node[:mediawiki][:group]
130 environment "COMPOSER_HOME" => site_directory
133 template "#{mediawiki_directory}/composer.local.json" do
135 source "composer.local.json.erb"
136 owner node[:mediawiki][:user]
137 group node[:mediawiki][:group]
141 # Safety catch if git doesn't update but install.php hasn't run
142 ruby_block "catch-installer-localsettings-run" do
147 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
149 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
152 declare_resource :directory, "#{mediawiki_directory}/images" do
154 group node[:mediawiki][:group]
158 declare_resource :directory, "#{mediawiki_directory}/cache" do
160 group node[:mediawiki][:group]
164 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
165 user node[:mediawiki][:user]
166 group node[:mediawiki][:group]
170 template "#{mediawiki_directory}/LocalSettings.php" do
172 source "LocalSettings.php.erb"
173 owner node[:mediawiki][:user]
174 group node[:mediawiki][:group]
176 variables :name => new_resource.site,
177 :directory => mediawiki_directory,
178 :database_params => database_params,
179 :mediawiki => mediawiki_params,
180 :secret_key => secret_key
181 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
184 cron_d "mediawiki-#{cron_name}-sitemap" do
185 comment "Generate sitemap.xml daily"
188 user node[:mediawiki][:user]
189 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"
192 cron_d "mediawiki-#{cron_name}-jobs" do
193 comment "Run mediawiki jobs"
195 user node[:mediawiki][:user]
196 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"
199 cron_d "mediawiki-#{cron_name}-email-jobs" do
200 comment "Run mediawiki email jobs"
201 user node[:mediawiki][:user]
202 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"
205 cron_d "mediawiki-#{cron_name}-refresh-links" do
206 comment "Run mediawiki refresh links table weekly"
210 user node[:mediawiki][:user]
211 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"
214 cron_d "mediawiki-#{cron_name}-cleanup-gs" do
215 comment "Clean up imagemagick garbage"
218 user node[:mediawiki][:user]
219 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'gs_*' -delete"
222 cron_d "mediawiki-#{cron_name}-cleanup-magick" do
223 comment "Clean up imagemagick garbage"
226 user node[:mediawiki][:user]
227 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'magick-*' -delete"
230 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
232 source "mediawiki-backup.cron.erb"
236 variables :name => new_resource.site,
237 :directory => site_directory,
238 :database_params => database_params
241 # MobileFrontend extension is required by MinervaNeue skin
242 mediawiki_extension "MobileFrontend" do
243 site new_resource.site
244 template "mw-ext-MobileFrontend.inc.php.erb"
247 # MobileFrontend extension is required by MinervaNeue skin
248 mediawiki_skin "MinervaNeue" do
249 site new_resource.site
254 mediawiki_skin "CologneBlue" do
255 site new_resource.site
260 mediawiki_skin "Modern" do
261 site new_resource.site
266 mediawiki_skin "MonoBook" do
267 site new_resource.site
272 mediawiki_skin "Vector" do
273 site new_resource.site
278 mediawiki_extension "Cite" do
279 site new_resource.site
283 mediawiki_extension "CiteThisPage" do
284 site new_resource.site
288 if new_resource.private_accounts || new_resource.private_site
289 mediawiki_extension "ConfirmEdit" do
290 site new_resource.site
295 mediawiki_extension "ConfirmEdit" do
296 site new_resource.site
297 template "mw-ext-ConfirmEdit.inc.php.erb"
298 variables :public_key => new_resource.recaptcha_public_key,
299 :private_key => new_resource.recaptcha_private_key
304 mediawiki_extension "Gadgets" do
305 site new_resource.site
309 mediawiki_extension "ImageMap" do
310 site new_resource.site
314 mediawiki_extension "InputBox" do
315 site new_resource.site
319 mediawiki_extension "Interwiki" do
320 site new_resource.site
321 template "mw-ext-Interwiki.inc.php.erb"
325 mediawiki_extension "Nuke" do
326 site new_resource.site
330 mediawiki_extension "ParserFunctions" do
331 site new_resource.site
332 template "mw-ext-ParserFunctions.inc.php.erb"
336 mediawiki_extension "PdfHandler" do
337 site new_resource.site
338 template "mw-ext-PdfHandler.inc.php.erb"
342 mediawiki_extension "Poem" do
343 site new_resource.site
347 mediawiki_extension "Renameuser" do
348 site new_resource.site
352 mediawiki_extension "SimpleAntiSpam" do
353 site new_resource.site
358 mediawiki_extension "SpamBlacklist" do
359 site new_resource.site
360 template "mw-ext-SpamBlacklist.inc.php.erb"
364 mediawiki_extension "SyntaxHighlight_GeSHi" do
365 site new_resource.site
366 template "mw-ext-SyntaxHighlight.inc.php.erb"
370 mediawiki_extension "TitleBlacklist" do
371 site new_resource.site
372 template "mw-ext-TitleBlacklist.inc.php.erb"
376 mediawiki_extension "WikiEditor" do
377 site new_resource.site
381 mediawiki_extension "Babel" do
382 site new_resource.site
383 template "mw-ext-Babel.inc.php.erb"
387 mediawiki_extension "cldr" do
388 site new_resource.site
389 template "mw-ext-cldr.inc.php.erb"
393 mediawiki_extension "CleanChanges" do
394 site new_resource.site
395 template "mw-ext-CleanChanges.inc.php.erb"
399 mediawiki_extension "LocalisationUpdate" do
400 site new_resource.site
401 template "mw-ext-LocalisationUpdate.inc.php.erb"
405 # mediawiki_extension "Translate" do
406 # site new_resource.site
407 # template "mw-ext-Translate.inc.php.erb"
411 mediawiki_extension "UniversalLanguageSelector" do
412 site new_resource.site
413 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
417 mediawiki_extension "AntiSpoof" do
418 site new_resource.site
419 template "mw-ext-AntiSpoof.inc.php.erb"
423 mediawiki_extension "AbuseFilter" do
424 site new_resource.site
425 template "mw-ext-AbuseFilter.inc.php.erb"
429 mediawiki_extension "CheckUser" do
430 site new_resource.site
431 template "mw-ext-CheckUser.inc.php.erb"
435 mediawiki_extension "DismissableSiteNotice" do
436 site new_resource.site
440 mediawiki_extension "Elastica" do
441 site new_resource.site
445 mediawiki_extension "CirrusSearch" do
446 site new_resource.site
447 template "mw-ext-CirrusSearch.inc.php.erb"
451 mediawiki_extension "osmtaginfo" do
452 site new_resource.site
453 template "mw-ext-osmtaginfo.inc.php.erb"
454 repository "https://github.com/Firefishy/osmtaginfo.git"
459 mediawiki_extension "OSMCALWikiWidget" do
460 site new_resource.site
461 repository "https://github.com/thomersch/OSMCALWikiWidget.git"
466 mediawiki_extension "SimpleMap" do
467 site new_resource.site
468 template "mw-ext-SimpleMap.inc.php.erb"
469 repository "https://github.com/Firefishy/SimpleMap.git"
474 mediawiki_extension "SlippyMap" do
475 site new_resource.site
480 mediawiki_extension "Mantle" do
481 site new_resource.site
486 mediawiki_extension "DisableAccount" do
487 site new_resource.site
488 template "mw-ext-DisableAccount.inc.php.erb"
492 mediawiki_extension "VisualEditor" do
493 site new_resource.site
494 template "mw-ext-VisualEditor.inc.php.erb"
498 mediawiki_extension "TemplateData" do
499 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