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 :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
49 node.normal_unless[:mediawiki][:sites][new_resource.site] = {}
51 node.normal[:mediawiki][:sites][new_resource.site][:directory] = site_directory
52 node.normal[:mediawiki][:sites][new_resource.site][:version] = new_resource.version
54 node.normal_unless[:mediawiki][:sites][new_resource.site][:wgSecretKey] = SecureRandom.base64(48)
56 mysql_user "#{new_resource.database_user}@localhost" do
57 password new_resource.database_password
60 mysql_database new_resource.database_name do
61 permissions "#{new_resource.database_user}@localhost" => :all
64 mediawiki_directory = "#{site_directory}/w"
66 ruby_block "rename-installer-localsettings" do
69 ::File.rename("#{mediawiki_directory}/LocalSettings.php", "#{mediawiki_directory}/LocalSettings-install.php")
73 execute "#{mediawiki_directory}/maintenance/install.php" do
75 # Use metanamespace as Site Name to ensure correct set namespace
76 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}'"
77 cwd mediawiki_directory
78 user node[:mediawiki][:user]
79 group node[:mediawiki][:group]
81 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
83 notifies :run, "ruby_block[rename-installer-localsettings]", :immediately
86 execute "#{mediawiki_directory}/maintenance/update.php" do
88 command "php maintenance/update.php --quick"
89 cwd mediawiki_directory
90 user node[:mediawiki][:user]
91 group node[:mediawiki][:group]
94 declare_resource :directory, site_directory do
95 owner node[:mediawiki][:user]
96 group node[:mediawiki][:group]
100 declare_resource :directory, mediawiki_directory do
101 owner node[:mediawiki][:user]
102 group node[:mediawiki][:group]
106 mediawiki_reference = "REL#{new_resource.version}".tr(".", "_")
108 git mediawiki_directory do
110 repository "https://gerrit.wikimedia.org/r/p/mediawiki/core.git"
111 revision mediawiki_reference
113 user node[:mediawiki][:user]
114 group node[:mediawiki][:group]
115 notifies :run, "execute[#{mediawiki_directory}/composer.json]", :immediately
116 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
117 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
120 execute "#{mediawiki_directory}/composer.json" do
122 command "composer update --no-dev"
123 cwd mediawiki_directory
124 user node[:mediawiki][:user]
125 group node[:mediawiki][:group]
128 template "#{mediawiki_directory}/composer.local.json" do
130 source "composer.local.json.erb"
131 owner node[:mediawiki][:user]
132 group node[:mediawiki][:group]
136 # Safety catch if git doesn't update but install.php hasn't run
137 ruby_block "catch-installer-localsettings-run" do
142 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
144 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
147 declare_resource :directory, "#{mediawiki_directory}/images" do
149 group node[:mediawiki][:group]
153 declare_resource :directory, "#{mediawiki_directory}/cache" do
155 group node[:mediawiki][:group]
159 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
160 user node[:mediawiki][:user]
161 group node[:mediawiki][:group]
165 template "#{mediawiki_directory}/LocalSettings.php" do
167 source "LocalSettings.php.erb"
168 owner node[:mediawiki][:user]
169 group node[:mediawiki][:group]
171 variables :name => new_resource.site,
172 :directory => mediawiki_directory,
173 :database_params => database_params,
174 :mediawiki => mediawiki_params
175 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
178 file "/etc/cron.d/mediawiki-#{cron_name}" do
182 cron_d "mediawiki-#{cron_name}-sitemap" do
183 comment "Generate sitemap.xml daily"
186 user node[:mediawiki][:user]
187 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"
190 cron_d "mediawiki-#{cron_name}-jobs" do
191 comment "Run mediawiki jobs"
193 user node[:mediawiki][:user]
194 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"
197 cron_d "mediawiki-#{cron_name}-email-jobs" do
198 comment "Run mediawiki email jobs"
199 user node[:mediawiki][:user]
200 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"
203 cron_d "mediawiki-#{cron_name}-refresh-links" do
204 comment "Run mediawiki refresh links table weekly"
208 user node[:mediawiki][:user]
209 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"
212 cron_d "mediawiki-#{cron_name}-cleanup-gs" do
213 comment "Clean up imagemagick garbage"
216 user node[:mediawiki][:user]
217 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'gs_*' -delete"
220 cron_d "mediawiki-#{cron_name}-cleanup-magick" do
221 comment "Clean up imagemagick garbage"
224 user node[:mediawiki][:user]
225 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'magick-*' -delete"
228 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
230 source "mediawiki-backup.cron.erb"
234 variables :name => new_resource.site,
235 :directory => site_directory,
236 :database_params => database_params
239 # MobileFrontend extension is required by MinervaNeue skin
240 mediawiki_extension "MobileFrontend" do
241 site new_resource.site
242 template "mw-ext-MobileFrontend.inc.php.erb"
245 # MobileFrontend extension is required by MinervaNeue skin
246 mediawiki_skin "MinervaNeue" do
247 site new_resource.site
252 mediawiki_skin "CologneBlue" do
253 site new_resource.site
258 mediawiki_skin "Modern" do
259 site new_resource.site
264 mediawiki_skin "MonoBook" do
265 site new_resource.site
270 mediawiki_skin "Vector" do
271 site new_resource.site
276 mediawiki_extension "Cite" do
277 site new_resource.site
281 mediawiki_extension "CiteThisPage" do
282 site new_resource.site
286 if new_resource.private_accounts || new_resource.private_site
287 mediawiki_extension "ConfirmEdit" do
288 site new_resource.site
293 mediawiki_extension "ConfirmEdit" do
294 site new_resource.site
295 template "mw-ext-ConfirmEdit.inc.php.erb"
296 variables :public_key => new_resource.recaptcha_public_key,
297 :private_key => new_resource.recaptcha_private_key
302 mediawiki_extension "Gadgets" do
303 site new_resource.site
307 mediawiki_extension "ImageMap" do
308 site new_resource.site
312 mediawiki_extension "InputBox" do
313 site new_resource.site
317 mediawiki_extension "Interwiki" do
318 site new_resource.site
319 template "mw-ext-Interwiki.inc.php.erb"
323 mediawiki_extension "Nuke" do
324 site new_resource.site
328 mediawiki_extension "ParserFunctions" do
329 site new_resource.site
330 template "mw-ext-ParserFunctions.inc.php.erb"
334 mediawiki_extension "PdfHandler" do
335 site new_resource.site
336 template "mw-ext-PdfHandler.inc.php.erb"
340 mediawiki_extension "Poem" do
341 site new_resource.site
345 mediawiki_extension "Renameuser" do
346 site new_resource.site
350 mediawiki_extension "SimpleAntiSpam" do
351 site new_resource.site
356 mediawiki_extension "SpamBlacklist" do
357 site new_resource.site
358 template "mw-ext-SpamBlacklist.inc.php.erb"
362 mediawiki_extension "SyntaxHighlight_GeSHi" do
363 site new_resource.site
364 template "mw-ext-SyntaxHighlight.inc.php.erb"
368 mediawiki_extension "TitleBlacklist" do
369 site new_resource.site
370 template "mw-ext-TitleBlacklist.inc.php.erb"
374 mediawiki_extension "WikiEditor" do
375 site new_resource.site
379 mediawiki_extension "Babel" do
380 site new_resource.site
381 template "mw-ext-Babel.inc.php.erb"
385 mediawiki_extension "cldr" do
386 site new_resource.site
387 template "mw-ext-cldr.inc.php.erb"
391 mediawiki_extension "CleanChanges" do
392 site new_resource.site
393 template "mw-ext-CleanChanges.inc.php.erb"
397 mediawiki_extension "LocalisationUpdate" do
398 site new_resource.site
399 template "mw-ext-LocalisationUpdate.inc.php.erb"
403 # LocalisationUpdate Update Cron
404 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
405 # cookbook "mediawiki"
406 # source "mediawiki-LocalisationUpdate.cron.erb"
410 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
413 # mediawiki_extension "Translate" do
414 # site new_resource.site
415 # template "mw-ext-Translate.inc.php.erb"
419 mediawiki_extension "UniversalLanguageSelector" do
420 site new_resource.site
421 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
425 mediawiki_extension "AntiSpoof" do
426 site new_resource.site
427 template "mw-ext-AntiSpoof.inc.php.erb"
431 mediawiki_extension "AbuseFilter" do
432 site new_resource.site
433 template "mw-ext-AbuseFilter.inc.php.erb"
437 mediawiki_extension "CheckUser" do
438 site new_resource.site
439 template "mw-ext-CheckUser.inc.php.erb"
443 mediawiki_extension "DismissableSiteNotice" do
444 site new_resource.site
448 mediawiki_extension "Elastica" do
449 site new_resource.site
453 mediawiki_extension "CirrusSearch" do
454 site new_resource.site
455 template "mw-ext-CirrusSearch.inc.php.erb"
459 mediawiki_extension "osmtaginfo" do
460 site new_resource.site
461 template "mw-ext-osmtaginfo.inc.php.erb"
462 repository "https://github.com/Firefishy/osmtaginfo.git"
467 mediawiki_extension "SimpleMap" do
468 site new_resource.site
469 template "mw-ext-SimpleMap.inc.php.erb"
470 repository "https://github.com/Firefishy/SimpleMap.git"
475 mediawiki_extension "SlippyMap" do
476 site new_resource.site
477 template "mw-ext-SlippyMap.inc.php.erb"
478 repository "https://github.com/Firefishy/SlippyMap.git"
483 mediawiki_extension "Mantle" do
484 site new_resource.site
489 mediawiki_extension "DisableAccount" do
490 site new_resource.site
491 template "mw-ext-DisableAccount.inc.php.erb"
495 mediawiki_extension "VisualEditor" do
496 site new_resource.site
497 template "mw-ext-VisualEditor.inc.php.erb"
501 mediawiki_extension "TemplateData" do
502 site new_resource.site
506 cookbook_file "#{site_directory}/cc-wiki.png" do
508 owner node[:mediawiki][:user]
509 group node[:mediawiki][:group]
514 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
516 owner node[:mediawiki][:user]
517 group node[:mediawiki][:group]
522 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
524 owner node[:mediawiki][:user]
525 group node[:mediawiki][:group]
530 ssl_certificate new_resource.site do
531 domains [new_resource.site] + Array(new_resource.aliases)
534 apache_site new_resource.site do
536 template "apache.erb"
537 directory site_directory
538 variables :aliases => Array(new_resource.aliases),
539 :private_site => new_resource.private_site
543 # FIXME: needs to run one
544 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
546 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
547 cwd mediawiki_directory
548 user node[:mediawiki][:user]
549 group node[:mediawiki][:group]
554 mediawiki_directory = "#{site_directory}/w"
556 template "#{mediawiki_directory}/LocalSettings.php" do
558 source "LocalSettings.php.erb"
559 owner node[:mediawiki][:user]
560 group node[:mediawiki][:group]
562 variables :name => new_resource.site,
563 :directory => mediawiki_directory,
564 :database_params => database_params,
565 :mediawiki => mediawiki_params
566 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
569 execute "#{mediawiki_directory}/maintenance/update.php" do
571 command "php maintenance/update.php --quick"
572 cwd mediawiki_directory
573 user node[:mediawiki][:user]
574 group node[:mediawiki][:group]
579 apache_site new_resource.site do
584 declare_resource :directory, site_directory do
589 mysql_database new_resource.database_name do
593 mysql_user "#{new_resource.database_user}@localhost" do
600 new_resource.directory || "/srv/#{new_resource.site}"
604 new_resource.site.tr(".", "_")
609 :host => "localhost",
610 :name => new_resource.database_name,
611 :username => new_resource.database_user,
612 :password => new_resource.database_password
618 :sitename => new_resource.sitename,
619 :metanamespace => new_resource.metanamespace,
620 :logo => new_resource.logo,
621 :email_contact => new_resource.email_contact,
622 :email_sender => new_resource.email_sender,
623 :email_sender_name => new_resource.email_sender_name,
624 :commons => new_resource.commons,
625 :skin => new_resource.skin,
626 :site_notice => new_resource.site_notice,
627 :site_readonly => new_resource.site_readonly,
628 :extra_file_extensions => new_resource.extra_file_extensions,
629 :private_accounts => new_resource.private_accounts,
630 :private_site => new_resource.private_site
636 notifies :reload, "service[apache2]" if reload_apache