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 # mediawiki_extension "Translate" do
404 # site new_resource.site
405 # template "mw-ext-Translate.inc.php.erb"
409 mediawiki_extension "UniversalLanguageSelector" do
410 site new_resource.site
411 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
415 mediawiki_extension "AntiSpoof" do
416 site new_resource.site
417 template "mw-ext-AntiSpoof.inc.php.erb"
421 mediawiki_extension "AbuseFilter" do
422 site new_resource.site
423 template "mw-ext-AbuseFilter.inc.php.erb"
427 mediawiki_extension "CheckUser" do
428 site new_resource.site
429 template "mw-ext-CheckUser.inc.php.erb"
433 mediawiki_extension "DismissableSiteNotice" do
434 site new_resource.site
438 mediawiki_extension "Elastica" do
439 site new_resource.site
443 mediawiki_extension "CirrusSearch" do
444 site new_resource.site
445 template "mw-ext-CirrusSearch.inc.php.erb"
449 mediawiki_extension "osmtaginfo" do
450 site new_resource.site
451 template "mw-ext-osmtaginfo.inc.php.erb"
452 repository "https://github.com/Firefishy/osmtaginfo.git"
457 mediawiki_extension "SimpleMap" do
458 site new_resource.site
459 template "mw-ext-SimpleMap.inc.php.erb"
460 repository "https://github.com/Firefishy/SimpleMap.git"
465 mediawiki_extension "SlippyMap" do
466 site new_resource.site
467 template "mw-ext-SlippyMap.inc.php.erb"
468 repository "https://github.com/Firefishy/SlippyMap.git"
473 mediawiki_extension "Mantle" do
474 site new_resource.site
479 mediawiki_extension "DisableAccount" do
480 site new_resource.site
481 template "mw-ext-DisableAccount.inc.php.erb"
485 mediawiki_extension "VisualEditor" do
486 site new_resource.site
487 template "mw-ext-VisualEditor.inc.php.erb"
491 mediawiki_extension "TemplateData" do
492 site new_resource.site
496 cookbook_file "#{site_directory}/cc-wiki.png" do
498 owner node[:mediawiki][:user]
499 group node[:mediawiki][:group]
504 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
506 owner node[:mediawiki][:user]
507 group node[:mediawiki][:group]
512 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
514 owner node[:mediawiki][:user]
515 group node[:mediawiki][:group]
520 ssl_certificate new_resource.site do
521 domains [new_resource.site] + Array(new_resource.aliases)
524 apache_site new_resource.site do
526 template "apache.erb"
527 directory site_directory
528 variables :aliases => Array(new_resource.aliases),
529 :private_site => new_resource.private_site
533 # FIXME: needs to run one
534 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
536 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
537 cwd mediawiki_directory
538 user node[:mediawiki][:user]
539 group node[:mediawiki][:group]
544 mediawiki_directory = "#{site_directory}/w"
546 template "#{mediawiki_directory}/LocalSettings.php" do
548 source "LocalSettings.php.erb"
549 owner node[:mediawiki][:user]
550 group node[:mediawiki][:group]
552 variables :name => new_resource.site,
553 :directory => mediawiki_directory,
554 :database_params => database_params,
555 :mediawiki => mediawiki_params
556 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
559 execute "#{mediawiki_directory}/maintenance/update.php" do
561 command "php maintenance/update.php --quick"
562 cwd mediawiki_directory
563 user node[:mediawiki][:user]
564 group node[:mediawiki][:group]
569 apache_site new_resource.site do
574 declare_resource :directory, site_directory do
579 mysql_database new_resource.database_name do
583 mysql_user "#{new_resource.database_user}@localhost" do
590 new_resource.directory || "/srv/#{new_resource.site}"
594 new_resource.site.tr(".", "_")
599 :host => "localhost",
600 :name => new_resource.database_name,
601 :username => new_resource.database_user,
602 :password => new_resource.database_password
608 :sitename => new_resource.sitename,
609 :metanamespace => new_resource.metanamespace,
610 :logo => new_resource.logo,
611 :email_contact => new_resource.email_contact,
612 :email_sender => new_resource.email_sender,
613 :email_sender_name => new_resource.email_sender_name,
614 :commons => new_resource.commons,
615 :skin => new_resource.skin,
616 :site_notice => new_resource.site_notice,
617 :site_readonly => new_resource.site_readonly,
618 :extra_file_extensions => new_resource.extra_file_extensions,
619 :private_accounts => new_resource.private_accounts,
620 :private_site => new_resource.private_site
626 notifies :reload, "service[apache2]" if reload_apache