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 => [: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 :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
50 node.default[:mediawiki][:sites][new_resource.site] = {
51 :directory => site_directory,
52 :version => new_resource.version
55 secret_key = persistent_token("mediawiki", new_resource.site, "wgSecretKey")
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 :secret_key => secret_key
177 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
180 cron_d "mediawiki-#{cron_name}-sitemap" do
181 comment "Generate sitemap.xml daily"
184 user node[:mediawiki][:user]
185 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"
188 cron_d "mediawiki-#{cron_name}-jobs" do
189 comment "Run mediawiki jobs"
191 user node[:mediawiki][:user]
192 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"
195 cron_d "mediawiki-#{cron_name}-email-jobs" do
196 comment "Run mediawiki email 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=30 --type=enotifNotify --memory-limit=2048M --procs=4 --quiet"
201 cron_d "mediawiki-#{cron_name}-refresh-links" do
202 comment "Run mediawiki refresh links table weekly"
206 user node[:mediawiki][:user]
207 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"
210 cron_d "mediawiki-#{cron_name}-cleanup-gs" do
211 comment "Clean up imagemagick garbage"
214 user node[:mediawiki][:user]
215 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'gs_*' -delete"
218 cron_d "mediawiki-#{cron_name}-cleanup-magick" do
219 comment "Clean up imagemagick garbage"
222 user node[:mediawiki][:user]
223 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'magick-*' -delete"
226 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
228 source "mediawiki-backup.cron.erb"
232 variables :name => new_resource.site,
233 :directory => site_directory,
234 :database_params => database_params
237 # MobileFrontend extension is required by MinervaNeue skin
238 mediawiki_extension "MobileFrontend" do
239 site new_resource.site
240 template "mw-ext-MobileFrontend.inc.php.erb"
243 # MobileFrontend extension is required by MinervaNeue skin
244 mediawiki_skin "MinervaNeue" do
245 site new_resource.site
250 mediawiki_skin "CologneBlue" do
251 site new_resource.site
256 mediawiki_skin "Modern" do
257 site new_resource.site
262 mediawiki_skin "MonoBook" do
263 site new_resource.site
268 mediawiki_skin "Vector" do
269 site new_resource.site
274 mediawiki_extension "Cite" do
275 site new_resource.site
279 mediawiki_extension "CiteThisPage" do
280 site new_resource.site
284 if new_resource.private_accounts || new_resource.private_site
285 mediawiki_extension "ConfirmEdit" do
286 site new_resource.site
291 mediawiki_extension "ConfirmEdit" do
292 site new_resource.site
293 template "mw-ext-ConfirmEdit.inc.php.erb"
294 variables :public_key => new_resource.recaptcha_public_key,
295 :private_key => new_resource.recaptcha_private_key
300 mediawiki_extension "Gadgets" do
301 site new_resource.site
305 mediawiki_extension "ImageMap" do
306 site new_resource.site
310 mediawiki_extension "InputBox" do
311 site new_resource.site
315 mediawiki_extension "Interwiki" do
316 site new_resource.site
317 template "mw-ext-Interwiki.inc.php.erb"
321 mediawiki_extension "Nuke" do
322 site new_resource.site
326 mediawiki_extension "ParserFunctions" do
327 site new_resource.site
328 template "mw-ext-ParserFunctions.inc.php.erb"
332 mediawiki_extension "PdfHandler" do
333 site new_resource.site
334 template "mw-ext-PdfHandler.inc.php.erb"
338 mediawiki_extension "Poem" do
339 site new_resource.site
343 mediawiki_extension "Renameuser" do
344 site new_resource.site
348 mediawiki_extension "SimpleAntiSpam" do
349 site new_resource.site
354 mediawiki_extension "SpamBlacklist" do
355 site new_resource.site
356 template "mw-ext-SpamBlacklist.inc.php.erb"
360 mediawiki_extension "SyntaxHighlight_GeSHi" do
361 site new_resource.site
362 template "mw-ext-SyntaxHighlight.inc.php.erb"
366 mediawiki_extension "TitleBlacklist" do
367 site new_resource.site
368 template "mw-ext-TitleBlacklist.inc.php.erb"
372 mediawiki_extension "WikiEditor" do
373 site new_resource.site
377 mediawiki_extension "Babel" do
378 site new_resource.site
379 template "mw-ext-Babel.inc.php.erb"
383 mediawiki_extension "cldr" do
384 site new_resource.site
385 template "mw-ext-cldr.inc.php.erb"
389 mediawiki_extension "CleanChanges" do
390 site new_resource.site
391 template "mw-ext-CleanChanges.inc.php.erb"
395 mediawiki_extension "LocalisationUpdate" do
396 site new_resource.site
397 template "mw-ext-LocalisationUpdate.inc.php.erb"
401 # mediawiki_extension "Translate" do
402 # site new_resource.site
403 # template "mw-ext-Translate.inc.php.erb"
407 mediawiki_extension "UniversalLanguageSelector" do
408 site new_resource.site
409 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
413 mediawiki_extension "AntiSpoof" do
414 site new_resource.site
415 template "mw-ext-AntiSpoof.inc.php.erb"
419 mediawiki_extension "AbuseFilter" do
420 site new_resource.site
421 template "mw-ext-AbuseFilter.inc.php.erb"
425 mediawiki_extension "CheckUser" do
426 site new_resource.site
427 template "mw-ext-CheckUser.inc.php.erb"
431 mediawiki_extension "DismissableSiteNotice" do
432 site new_resource.site
436 mediawiki_extension "Elastica" do
437 site new_resource.site
441 mediawiki_extension "CirrusSearch" do
442 site new_resource.site
443 template "mw-ext-CirrusSearch.inc.php.erb"
447 mediawiki_extension "osmtaginfo" do
448 site new_resource.site
449 template "mw-ext-osmtaginfo.inc.php.erb"
450 repository "https://github.com/Firefishy/osmtaginfo.git"
455 mediawiki_extension "SimpleMap" do
456 site new_resource.site
457 template "mw-ext-SimpleMap.inc.php.erb"
458 repository "https://github.com/Firefishy/SimpleMap.git"
463 mediawiki_extension "SlippyMap" do
464 site new_resource.site
465 template "mw-ext-SlippyMap.inc.php.erb"
466 repository "https://github.com/Firefishy/SlippyMap.git"
471 mediawiki_extension "Mantle" do
472 site new_resource.site
477 mediawiki_extension "DisableAccount" do
478 site new_resource.site
479 template "mw-ext-DisableAccount.inc.php.erb"
483 mediawiki_extension "VisualEditor" do
484 site new_resource.site
485 template "mw-ext-VisualEditor.inc.php.erb"
489 mediawiki_extension "TemplateData" do
490 site new_resource.site
494 cookbook_file "#{site_directory}/cc-wiki.png" do
496 owner node[:mediawiki][:user]
497 group node[:mediawiki][:group]
502 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
504 owner node[:mediawiki][:user]
505 group node[:mediawiki][:group]
510 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
512 owner node[:mediawiki][:user]
513 group node[:mediawiki][:group]
518 ssl_certificate new_resource.site do
519 domains [new_resource.site] + Array(new_resource.aliases)
522 php_fpm new_resource.site do
523 pm_max_children new_resource.fpm_max_children
524 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
525 php_values "memory_limit" => "500M",
526 "max_execution_time" => "240",
527 "upload_max_filesize" => "70M",
528 "post_max_size" => "100M"
531 apache_site new_resource.site do
533 template "apache.erb"
534 directory site_directory
535 variables :aliases => Array(new_resource.aliases),
536 :private_site => new_resource.private_site
540 # FIXME: needs to run one
541 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
543 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
544 cwd mediawiki_directory
545 user node[:mediawiki][:user]
546 group node[:mediawiki][:group]
551 mediawiki_directory = "#{site_directory}/w"
553 template "#{mediawiki_directory}/LocalSettings.php" do
555 source "LocalSettings.php.erb"
556 owner node[:mediawiki][:user]
557 group node[:mediawiki][:group]
559 variables :name => new_resource.site,
560 :directory => mediawiki_directory,
561 :database_params => database_params,
562 :mediawiki => mediawiki_params
563 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
566 execute "#{mediawiki_directory}/maintenance/update.php" do
568 command "php maintenance/update.php --quick"
569 cwd mediawiki_directory
570 user node[:mediawiki][:user]
571 group node[:mediawiki][:group]
576 apache_site new_resource.site do
581 declare_resource :directory, site_directory do
586 mysql_database new_resource.database_name do
590 mysql_user "#{new_resource.database_user}@localhost" do
596 include Chef::Mixin::PersistentToken
599 new_resource.directory || "/srv/#{new_resource.site}"
603 new_resource.site.tr(".", "_")
608 :host => "localhost",
609 :name => new_resource.database_name,
610 :username => new_resource.database_user,
611 :password => new_resource.database_password
617 :sitename => new_resource.sitename,
618 :metanamespace => new_resource.metanamespace,
619 :logo => new_resource.logo,
620 :email_contact => new_resource.email_contact,
621 :email_sender => new_resource.email_sender,
622 :email_sender_name => new_resource.email_sender_name,
623 :commons => new_resource.commons,
624 :skin => new_resource.skin,
625 :site_notice => new_resource.site_notice,
626 :site_readonly => new_resource.site_readonly,
627 :extra_file_extensions => new_resource.extra_file_extensions,
628 :private_accounts => new_resource.private_accounts,
629 :private_site => new_resource.private_site
635 notifies :reload, "service[apache2]" if reload_apache