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 cron_d "mediawiki-#{cron_name}-sitemap" do
179 comment "Generate sitemap.xml daily"
182 user node[:mediawiki][:user]
183 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"
186 cron_d "mediawiki-#{cron_name}-jobs" do
187 comment "Run mediawiki jobs"
189 user node[:mediawiki][:user]
190 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"
193 cron_d "mediawiki-#{cron_name}-email-jobs" do
194 comment "Run mediawiki email 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=30 --type=enotifNotify --memory-limit=2048M --procs=4 --quiet"
199 cron_d "mediawiki-#{cron_name}-refresh-links" do
200 comment "Run mediawiki refresh links table weekly"
204 user node[:mediawiki][:user]
205 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"
208 cron_d "mediawiki-#{cron_name}-cleanup-gs" do
209 comment "Clean up imagemagick garbage"
212 user node[:mediawiki][:user]
213 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'gs_*' -delete"
216 cron_d "mediawiki-#{cron_name}-cleanup-magick" 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 'magick-*' -delete"
224 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
226 source "mediawiki-backup.cron.erb"
230 variables :name => new_resource.site,
231 :directory => site_directory,
232 :database_params => database_params
235 # MobileFrontend extension is required by MinervaNeue skin
236 mediawiki_extension "MobileFrontend" do
237 site new_resource.site
238 template "mw-ext-MobileFrontend.inc.php.erb"
241 # MobileFrontend extension is required by MinervaNeue skin
242 mediawiki_skin "MinervaNeue" do
243 site new_resource.site
248 mediawiki_skin "CologneBlue" do
249 site new_resource.site
254 mediawiki_skin "Modern" do
255 site new_resource.site
260 mediawiki_skin "MonoBook" do
261 site new_resource.site
266 mediawiki_skin "Vector" do
267 site new_resource.site
272 mediawiki_extension "Cite" do
273 site new_resource.site
277 mediawiki_extension "CiteThisPage" do
278 site new_resource.site
282 if new_resource.private_accounts || new_resource.private_site
283 mediawiki_extension "ConfirmEdit" do
284 site new_resource.site
289 mediawiki_extension "ConfirmEdit" do
290 site new_resource.site
291 template "mw-ext-ConfirmEdit.inc.php.erb"
292 variables :public_key => new_resource.recaptcha_public_key,
293 :private_key => new_resource.recaptcha_private_key
298 mediawiki_extension "Gadgets" do
299 site new_resource.site
303 mediawiki_extension "ImageMap" do
304 site new_resource.site
308 mediawiki_extension "InputBox" do
309 site new_resource.site
313 mediawiki_extension "Interwiki" do
314 site new_resource.site
315 template "mw-ext-Interwiki.inc.php.erb"
319 mediawiki_extension "Nuke" do
320 site new_resource.site
324 mediawiki_extension "ParserFunctions" do
325 site new_resource.site
326 template "mw-ext-ParserFunctions.inc.php.erb"
330 mediawiki_extension "PdfHandler" do
331 site new_resource.site
332 template "mw-ext-PdfHandler.inc.php.erb"
336 mediawiki_extension "Poem" do
337 site new_resource.site
341 mediawiki_extension "Renameuser" do
342 site new_resource.site
346 mediawiki_extension "SimpleAntiSpam" do
347 site new_resource.site
352 mediawiki_extension "SpamBlacklist" do
353 site new_resource.site
354 template "mw-ext-SpamBlacklist.inc.php.erb"
358 mediawiki_extension "SyntaxHighlight_GeSHi" do
359 site new_resource.site
360 template "mw-ext-SyntaxHighlight.inc.php.erb"
364 mediawiki_extension "TitleBlacklist" do
365 site new_resource.site
366 template "mw-ext-TitleBlacklist.inc.php.erb"
370 mediawiki_extension "WikiEditor" do
371 site new_resource.site
375 mediawiki_extension "Babel" do
376 site new_resource.site
377 template "mw-ext-Babel.inc.php.erb"
381 mediawiki_extension "cldr" do
382 site new_resource.site
383 template "mw-ext-cldr.inc.php.erb"
387 mediawiki_extension "CleanChanges" do
388 site new_resource.site
389 template "mw-ext-CleanChanges.inc.php.erb"
393 mediawiki_extension "LocalisationUpdate" do
394 site new_resource.site
395 template "mw-ext-LocalisationUpdate.inc.php.erb"
399 # mediawiki_extension "Translate" do
400 # site new_resource.site
401 # template "mw-ext-Translate.inc.php.erb"
405 mediawiki_extension "UniversalLanguageSelector" do
406 site new_resource.site
407 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
411 mediawiki_extension "AntiSpoof" do
412 site new_resource.site
413 template "mw-ext-AntiSpoof.inc.php.erb"
417 mediawiki_extension "AbuseFilter" do
418 site new_resource.site
419 template "mw-ext-AbuseFilter.inc.php.erb"
423 mediawiki_extension "CheckUser" do
424 site new_resource.site
425 template "mw-ext-CheckUser.inc.php.erb"
429 mediawiki_extension "DismissableSiteNotice" do
430 site new_resource.site
434 mediawiki_extension "Elastica" do
435 site new_resource.site
439 mediawiki_extension "CirrusSearch" do
440 site new_resource.site
441 template "mw-ext-CirrusSearch.inc.php.erb"
445 mediawiki_extension "osmtaginfo" do
446 site new_resource.site
447 template "mw-ext-osmtaginfo.inc.php.erb"
448 repository "https://github.com/Firefishy/osmtaginfo.git"
453 mediawiki_extension "SimpleMap" do
454 site new_resource.site
455 template "mw-ext-SimpleMap.inc.php.erb"
456 repository "https://github.com/Firefishy/SimpleMap.git"
461 mediawiki_extension "SlippyMap" do
462 site new_resource.site
463 template "mw-ext-SlippyMap.inc.php.erb"
464 repository "https://github.com/Firefishy/SlippyMap.git"
469 mediawiki_extension "Mantle" do
470 site new_resource.site
475 mediawiki_extension "DisableAccount" do
476 site new_resource.site
477 template "mw-ext-DisableAccount.inc.php.erb"
481 mediawiki_extension "VisualEditor" do
482 site new_resource.site
483 template "mw-ext-VisualEditor.inc.php.erb"
487 mediawiki_extension "TemplateData" do
488 site new_resource.site
492 cookbook_file "#{site_directory}/cc-wiki.png" do
494 owner node[:mediawiki][:user]
495 group node[:mediawiki][:group]
500 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
502 owner node[:mediawiki][:user]
503 group node[:mediawiki][:group]
508 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
510 owner node[:mediawiki][:user]
511 group node[:mediawiki][:group]
516 ssl_certificate new_resource.site do
517 domains [new_resource.site] + Array(new_resource.aliases)
520 apache_site new_resource.site do
522 template "apache.erb"
523 directory site_directory
524 variables :aliases => Array(new_resource.aliases),
525 :private_site => new_resource.private_site
529 # FIXME: needs to run one
530 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
532 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
533 cwd mediawiki_directory
534 user node[:mediawiki][:user]
535 group node[:mediawiki][:group]
540 mediawiki_directory = "#{site_directory}/w"
542 template "#{mediawiki_directory}/LocalSettings.php" do
544 source "LocalSettings.php.erb"
545 owner node[:mediawiki][:user]
546 group node[:mediawiki][:group]
548 variables :name => new_resource.site,
549 :directory => mediawiki_directory,
550 :database_params => database_params,
551 :mediawiki => mediawiki_params
552 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
555 execute "#{mediawiki_directory}/maintenance/update.php" do
557 command "php maintenance/update.php --quick"
558 cwd mediawiki_directory
559 user node[:mediawiki][:user]
560 group node[:mediawiki][:group]
565 apache_site new_resource.site do
570 declare_resource :directory, site_directory do
575 mysql_database new_resource.database_name do
579 mysql_user "#{new_resource.database_user}@localhost" do
586 new_resource.directory || "/srv/#{new_resource.site}"
590 new_resource.site.tr(".", "_")
595 :host => "localhost",
596 :name => new_resource.database_name,
597 :username => new_resource.database_user,
598 :password => new_resource.database_password
604 :sitename => new_resource.sitename,
605 :metanamespace => new_resource.metanamespace,
606 :logo => new_resource.logo,
607 :email_contact => new_resource.email_contact,
608 :email_sender => new_resource.email_sender,
609 :email_sender_name => new_resource.email_sender_name,
610 :commons => new_resource.commons,
611 :skin => new_resource.skin,
612 :site_notice => new_resource.site_notice,
613 :site_readonly => new_resource.site_readonly,
614 :extra_file_extensions => new_resource.extra_file_extensions,
615 :private_accounts => new_resource.private_accounts,
616 :private_site => new_resource.private_site
622 notifies :reload, "service[apache2]" if reload_apache