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.33"
26 property :database_name, :kind_of => String, :required => true
27 property :database_user, :kind_of => String, :required => true
28 property :database_password, :kind_of => String, :required => true
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 => true
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 :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
50 node.normal_unless[:mediawiki][:sites][new_resource.site] = {}
52 node.normal[:mediawiki][:sites][new_resource.site][:directory] = site_directory
53 node.normal[:mediawiki][:sites][new_resource.site][:version] = new_resource.version
55 node.normal_unless[:mediawiki][:sites][new_resource.site][:wgSecretKey] = SecureRandom.base64(48)
57 mysql_user "#{new_resource.database_user}@localhost" do
58 password new_resource.database_password
61 mysql_database new_resource.database_name do
62 permissions "#{new_resource.database_user}@localhost" => :all
65 mediawiki_directory = "#{site_directory}/w"
67 ruby_block "rename-installer-localsettings" do
70 ::File.rename("#{mediawiki_directory}/LocalSettings.php", "#{mediawiki_directory}/LocalSettings-install.php")
74 execute "#{mediawiki_directory}/maintenance/install.php" do
76 # Use metanamespace as Site Name to ensure correct set namespace
77 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}'"
78 cwd mediawiki_directory
79 user node[:mediawiki][:user]
80 group node[:mediawiki][:group]
82 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
84 notifies :run, "ruby_block[rename-installer-localsettings]", :immediately
87 execute "#{mediawiki_directory}/maintenance/update.php" do
89 command "php maintenance/update.php --quick"
90 cwd mediawiki_directory
91 user node[:mediawiki][:user]
92 group node[:mediawiki][:group]
95 declare_resource :directory, site_directory do
96 owner node[:mediawiki][:user]
97 group node[:mediawiki][:group]
101 declare_resource :directory, mediawiki_directory do
102 owner node[:mediawiki][:user]
103 group node[:mediawiki][:group]
107 mediawiki_reference = "REL#{new_resource.version}".tr(".", "_")
109 git mediawiki_directory do
111 repository "https://gerrit.wikimedia.org/r/p/mediawiki/core.git"
112 revision mediawiki_reference
114 user node[:mediawiki][:user]
115 group node[:mediawiki][:group]
116 notifies :run, "execute[#{mediawiki_directory}/composer.json]", :immediately
117 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
118 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
121 execute "#{mediawiki_directory}/composer.json" do
123 command "composer update --no-dev"
124 cwd mediawiki_directory
125 user node[:mediawiki][:user]
126 group node[:mediawiki][:group]
129 template "#{mediawiki_directory}/composer.local.json" do
131 source "composer.local.json.erb"
132 owner node[:mediawiki][:user]
133 group node[:mediawiki][:group]
137 # Safety catch if git doesn't update but install.php hasn't run
138 ruby_block "catch-installer-localsettings-run" do
143 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
145 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
148 declare_resource :directory, "#{mediawiki_directory}/images" do
150 group node[:mediawiki][:group]
154 declare_resource :directory, "#{mediawiki_directory}/cache" do
156 group node[:mediawiki][:group]
160 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
161 user node[:mediawiki][:user]
162 group node[:mediawiki][:group]
166 template "#{mediawiki_directory}/LocalSettings.php" do
168 source "LocalSettings.php.erb"
169 owner node[:mediawiki][:user]
170 group node[:mediawiki][:group]
172 variables :name => new_resource.site,
173 :directory => mediawiki_directory,
174 :database_params => database_params,
175 :mediawiki => mediawiki_params
176 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
179 cron_d "mediawiki-#{cron_name}-sitemap" do
180 comment "Generate sitemap.xml daily"
183 user node[:mediawiki][:user]
184 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"
187 cron_d "mediawiki-#{cron_name}-jobs" do
188 comment "Run mediawiki jobs"
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/runJobs.php --server=https://#{new_resource.site} --maxtime=160 --memory-limit=2048M --procs=8 --quiet"
194 cron_d "mediawiki-#{cron_name}-email-jobs" do
195 comment "Run mediawiki email jobs"
196 user node[:mediawiki][:user]
197 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"
200 cron_d "mediawiki-#{cron_name}-refresh-links" do
201 comment "Run mediawiki refresh links table weekly"
205 user node[:mediawiki][:user]
206 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"
209 cron_d "mediawiki-#{cron_name}-cleanup-gs" do
210 comment "Clean up imagemagick garbage"
213 user node[:mediawiki][:user]
214 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'gs_*' -delete"
217 cron_d "mediawiki-#{cron_name}-cleanup-magick" do
218 comment "Clean up imagemagick garbage"
221 user node[:mediawiki][:user]
222 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'magick-*' -delete"
225 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
227 source "mediawiki-backup.cron.erb"
231 variables :name => new_resource.site,
232 :directory => site_directory,
233 :database_params => database_params
236 # MobileFrontend extension is required by MinervaNeue skin
237 mediawiki_extension "MobileFrontend" do
238 site new_resource.site
239 template "mw-ext-MobileFrontend.inc.php.erb"
242 # MobileFrontend extension is required by MinervaNeue skin
243 mediawiki_skin "MinervaNeue" do
244 site new_resource.site
249 mediawiki_skin "CologneBlue" do
250 site new_resource.site
255 mediawiki_skin "Modern" do
256 site new_resource.site
261 mediawiki_skin "MonoBook" do
262 site new_resource.site
267 mediawiki_skin "Vector" do
268 site new_resource.site
273 mediawiki_extension "Cite" do
274 site new_resource.site
278 mediawiki_extension "CiteThisPage" do
279 site new_resource.site
283 if new_resource.private_accounts || new_resource.private_site
284 mediawiki_extension "ConfirmEdit" do
285 site new_resource.site
290 mediawiki_extension "ConfirmEdit" do
291 site new_resource.site
292 template "mw-ext-ConfirmEdit.inc.php.erb"
293 variables :public_key => new_resource.recaptcha_public_key,
294 :private_key => new_resource.recaptcha_private_key
299 mediawiki_extension "Gadgets" do
300 site new_resource.site
304 mediawiki_extension "ImageMap" do
305 site new_resource.site
309 mediawiki_extension "InputBox" do
310 site new_resource.site
314 mediawiki_extension "Interwiki" do
315 site new_resource.site
316 template "mw-ext-Interwiki.inc.php.erb"
320 mediawiki_extension "Nuke" do
321 site new_resource.site
325 mediawiki_extension "ParserFunctions" do
326 site new_resource.site
327 template "mw-ext-ParserFunctions.inc.php.erb"
331 mediawiki_extension "PdfHandler" do
332 site new_resource.site
333 template "mw-ext-PdfHandler.inc.php.erb"
337 mediawiki_extension "Poem" do
338 site new_resource.site
342 mediawiki_extension "Renameuser" do
343 site new_resource.site
347 mediawiki_extension "SimpleAntiSpam" do
348 site new_resource.site
353 mediawiki_extension "SpamBlacklist" do
354 site new_resource.site
355 template "mw-ext-SpamBlacklist.inc.php.erb"
359 mediawiki_extension "SyntaxHighlight_GeSHi" do
360 site new_resource.site
361 template "mw-ext-SyntaxHighlight.inc.php.erb"
365 mediawiki_extension "TitleBlacklist" do
366 site new_resource.site
367 template "mw-ext-TitleBlacklist.inc.php.erb"
371 mediawiki_extension "WikiEditor" do
372 site new_resource.site
376 mediawiki_extension "Babel" do
377 site new_resource.site
378 template "mw-ext-Babel.inc.php.erb"
382 mediawiki_extension "cldr" do
383 site new_resource.site
384 template "mw-ext-cldr.inc.php.erb"
388 mediawiki_extension "CleanChanges" do
389 site new_resource.site
390 template "mw-ext-CleanChanges.inc.php.erb"
394 mediawiki_extension "LocalisationUpdate" do
395 site new_resource.site
396 template "mw-ext-LocalisationUpdate.inc.php.erb"
400 # mediawiki_extension "Translate" do
401 # site new_resource.site
402 # template "mw-ext-Translate.inc.php.erb"
406 mediawiki_extension "UniversalLanguageSelector" do
407 site new_resource.site
408 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
412 mediawiki_extension "AntiSpoof" do
413 site new_resource.site
414 template "mw-ext-AntiSpoof.inc.php.erb"
418 mediawiki_extension "AbuseFilter" do
419 site new_resource.site
420 template "mw-ext-AbuseFilter.inc.php.erb"
424 mediawiki_extension "CheckUser" do
425 site new_resource.site
426 template "mw-ext-CheckUser.inc.php.erb"
430 mediawiki_extension "DismissableSiteNotice" do
431 site new_resource.site
435 mediawiki_extension "Elastica" do
436 site new_resource.site
440 mediawiki_extension "CirrusSearch" do
441 site new_resource.site
442 template "mw-ext-CirrusSearch.inc.php.erb"
446 mediawiki_extension "osmtaginfo" do
447 site new_resource.site
448 template "mw-ext-osmtaginfo.inc.php.erb"
449 repository "https://github.com/Firefishy/osmtaginfo.git"
454 mediawiki_extension "SimpleMap" do
455 site new_resource.site
456 template "mw-ext-SimpleMap.inc.php.erb"
457 repository "https://github.com/Firefishy/SimpleMap.git"
462 mediawiki_extension "SlippyMap" do
463 site new_resource.site
464 template "mw-ext-SlippyMap.inc.php.erb"
465 repository "https://github.com/Firefishy/SlippyMap.git"
470 mediawiki_extension "Mantle" do
471 site new_resource.site
476 mediawiki_extension "DisableAccount" do
477 site new_resource.site
478 template "mw-ext-DisableAccount.inc.php.erb"
482 mediawiki_extension "VisualEditor" do
483 site new_resource.site
484 template "mw-ext-VisualEditor.inc.php.erb"
488 mediawiki_extension "TemplateData" do
489 site new_resource.site
493 cookbook_file "#{site_directory}/cc-wiki.png" do
495 owner node[:mediawiki][:user]
496 group node[:mediawiki][:group]
501 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
503 owner node[:mediawiki][:user]
504 group node[:mediawiki][:group]
509 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
511 owner node[:mediawiki][:user]
512 group node[:mediawiki][:group]
517 ssl_certificate new_resource.site do
518 domains [new_resource.site] + Array(new_resource.aliases)
521 php_fpm new_resource.site do
522 pm_max_children new_resource.fpm_max_children
523 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
524 php_values "memory_limit" => "500M",
525 "max_execution_time" => "240",
526 "upload_max_filesize" => "70M",
527 "post_max_size" => "100M"
530 apache_site new_resource.site do
532 template "apache.erb"
533 directory site_directory
534 variables :aliases => Array(new_resource.aliases),
535 :private_site => new_resource.private_site
539 # FIXME: needs to run one
540 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
542 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
543 cwd mediawiki_directory
544 user node[:mediawiki][:user]
545 group node[:mediawiki][:group]
550 mediawiki_directory = "#{site_directory}/w"
552 template "#{mediawiki_directory}/LocalSettings.php" do
554 source "LocalSettings.php.erb"
555 owner node[:mediawiki][:user]
556 group node[:mediawiki][:group]
558 variables :name => new_resource.site,
559 :directory => mediawiki_directory,
560 :database_params => database_params,
561 :mediawiki => mediawiki_params
562 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
565 execute "#{mediawiki_directory}/maintenance/update.php" do
567 command "php maintenance/update.php --quick"
568 cwd mediawiki_directory
569 user node[:mediawiki][:user]
570 group node[:mediawiki][:group]
575 apache_site new_resource.site do
580 declare_resource :directory, site_directory do
585 mysql_database new_resource.database_name do
589 mysql_user "#{new_resource.database_user}@localhost" do
596 new_resource.directory || "/srv/#{new_resource.site}"
600 new_resource.site.tr(".", "_")
605 :host => "localhost",
606 :name => new_resource.database_name,
607 :username => new_resource.database_user,
608 :password => new_resource.database_password
614 :sitename => new_resource.sitename,
615 :metanamespace => new_resource.metanamespace,
616 :logo => new_resource.logo,
617 :email_contact => new_resource.email_contact,
618 :email_sender => new_resource.email_sender,
619 :email_sender_name => new_resource.email_sender_name,
620 :commons => new_resource.commons,
621 :skin => new_resource.skin,
622 :site_notice => new_resource.site_notice,
623 :site_readonly => new_resource.site_readonly,
624 :extra_file_extensions => new_resource.extra_file_extensions,
625 :private_accounts => new_resource.private_accounts,
626 :private_site => new_resource.private_site
632 notifies :reload, "service[apache2]" if reload_apache