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 :fpm_request_terminate_timeout, :kind_of => Integer, :default => 300
48 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
51 node.default[:mediawiki][:sites][new_resource.site] = {
52 :directory => site_directory,
53 :version => new_resource.version
56 secret_key = persistent_token("mediawiki", new_resource.site, "wgSecretKey")
58 mysql_user "#{new_resource.database_user}@localhost" do
59 password new_resource.database_password
62 mysql_database new_resource.database_name do
63 permissions "#{new_resource.database_user}@localhost" => :all
66 mediawiki_directory = "#{site_directory}/w"
68 ruby_block "rename-installer-localsettings" do
71 ::File.rename("#{mediawiki_directory}/LocalSettings.php", "#{mediawiki_directory}/LocalSettings-install.php")
75 execute "#{mediawiki_directory}/maintenance/install.php" do
77 # Use metanamespace as Site Name to ensure correct set namespace
78 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}'"
79 cwd mediawiki_directory
80 user node[:mediawiki][:user]
81 group node[:mediawiki][:group]
83 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
85 notifies :run, "ruby_block[rename-installer-localsettings]", :immediately
88 execute "#{mediawiki_directory}/maintenance/update.php" do
90 command "php maintenance/update.php --quick"
91 cwd mediawiki_directory
92 user node[:mediawiki][:user]
93 group node[:mediawiki][:group]
96 declare_resource :directory, site_directory do
97 owner node[:mediawiki][:user]
98 group node[:mediawiki][:group]
102 declare_resource :directory, mediawiki_directory do
103 owner node[:mediawiki][:user]
104 group node[:mediawiki][:group]
108 mediawiki_reference = "REL#{new_resource.version}".tr(".", "_")
110 git mediawiki_directory do
112 repository "https://gerrit.wikimedia.org/r/p/mediawiki/core.git"
113 revision mediawiki_reference
115 user node[:mediawiki][:user]
116 group node[:mediawiki][:group]
117 notifies :run, "execute[#{mediawiki_directory}/composer.json]", :immediately
118 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
119 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
122 execute "#{mediawiki_directory}/composer.json" do
124 command "composer update --no-dev"
125 cwd mediawiki_directory
126 user node[:mediawiki][:user]
127 group node[:mediawiki][:group]
130 template "#{mediawiki_directory}/composer.local.json" do
132 source "composer.local.json.erb"
133 owner node[:mediawiki][:user]
134 group node[:mediawiki][:group]
138 # Safety catch if git doesn't update but install.php hasn't run
139 ruby_block "catch-installer-localsettings-run" do
144 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
146 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
149 declare_resource :directory, "#{mediawiki_directory}/images" do
151 group node[:mediawiki][:group]
155 declare_resource :directory, "#{mediawiki_directory}/cache" do
157 group node[:mediawiki][:group]
161 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
162 user node[:mediawiki][:user]
163 group node[:mediawiki][:group]
167 template "#{mediawiki_directory}/LocalSettings.php" do
169 source "LocalSettings.php.erb"
170 owner node[:mediawiki][:user]
171 group node[:mediawiki][:group]
173 variables :name => new_resource.site,
174 :directory => mediawiki_directory,
175 :database_params => database_params,
176 :mediawiki => mediawiki_params,
177 :secret_key => secret_key
178 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
181 cron_d "mediawiki-#{cron_name}-sitemap" do
182 comment "Generate sitemap.xml daily"
185 user node[:mediawiki][:user]
186 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"
189 cron_d "mediawiki-#{cron_name}-jobs" do
190 comment "Run mediawiki jobs"
192 user node[:mediawiki][:user]
193 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"
196 cron_d "mediawiki-#{cron_name}-email-jobs" do
197 comment "Run mediawiki email jobs"
198 user node[:mediawiki][:user]
199 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"
202 cron_d "mediawiki-#{cron_name}-refresh-links" do
203 comment "Run mediawiki refresh links table weekly"
207 user node[:mediawiki][:user]
208 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"
211 cron_d "mediawiki-#{cron_name}-cleanup-gs" do
212 comment "Clean up imagemagick garbage"
215 user node[:mediawiki][:user]
216 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'gs_*' -delete"
219 cron_d "mediawiki-#{cron_name}-cleanup-magick" do
220 comment "Clean up imagemagick garbage"
223 user node[:mediawiki][:user]
224 command "/usr/bin/find /tmp/ -maxdepth 1 -type f -user www-data -mmin +90 -name 'magick-*' -delete"
227 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
229 source "mediawiki-backup.cron.erb"
233 variables :name => new_resource.site,
234 :directory => site_directory,
235 :database_params => database_params
238 # MobileFrontend extension is required by MinervaNeue skin
239 mediawiki_extension "MobileFrontend" do
240 site new_resource.site
241 template "mw-ext-MobileFrontend.inc.php.erb"
244 # MobileFrontend extension is required by MinervaNeue skin
245 mediawiki_skin "MinervaNeue" do
246 site new_resource.site
251 mediawiki_skin "CologneBlue" do
252 site new_resource.site
257 mediawiki_skin "Modern" do
258 site new_resource.site
263 mediawiki_skin "MonoBook" do
264 site new_resource.site
269 mediawiki_skin "Vector" do
270 site new_resource.site
275 mediawiki_extension "Cite" do
276 site new_resource.site
280 mediawiki_extension "CiteThisPage" do
281 site new_resource.site
285 if new_resource.private_accounts || new_resource.private_site
286 mediawiki_extension "ConfirmEdit" do
287 site new_resource.site
292 mediawiki_extension "ConfirmEdit" do
293 site new_resource.site
294 template "mw-ext-ConfirmEdit.inc.php.erb"
295 variables :public_key => new_resource.recaptcha_public_key,
296 :private_key => new_resource.recaptcha_private_key
301 mediawiki_extension "Gadgets" do
302 site new_resource.site
306 mediawiki_extension "ImageMap" do
307 site new_resource.site
311 mediawiki_extension "InputBox" do
312 site new_resource.site
316 mediawiki_extension "Interwiki" do
317 site new_resource.site
318 template "mw-ext-Interwiki.inc.php.erb"
322 mediawiki_extension "Nuke" do
323 site new_resource.site
327 mediawiki_extension "ParserFunctions" do
328 site new_resource.site
329 template "mw-ext-ParserFunctions.inc.php.erb"
333 mediawiki_extension "PdfHandler" do
334 site new_resource.site
335 template "mw-ext-PdfHandler.inc.php.erb"
339 mediawiki_extension "Poem" do
340 site new_resource.site
344 mediawiki_extension "Renameuser" do
345 site new_resource.site
349 mediawiki_extension "SimpleAntiSpam" do
350 site new_resource.site
355 mediawiki_extension "SpamBlacklist" do
356 site new_resource.site
357 template "mw-ext-SpamBlacklist.inc.php.erb"
361 mediawiki_extension "SyntaxHighlight_GeSHi" do
362 site new_resource.site
363 template "mw-ext-SyntaxHighlight.inc.php.erb"
367 mediawiki_extension "TitleBlacklist" do
368 site new_resource.site
369 template "mw-ext-TitleBlacklist.inc.php.erb"
373 mediawiki_extension "WikiEditor" do
374 site new_resource.site
378 mediawiki_extension "Babel" do
379 site new_resource.site
380 template "mw-ext-Babel.inc.php.erb"
384 mediawiki_extension "cldr" do
385 site new_resource.site
386 template "mw-ext-cldr.inc.php.erb"
390 mediawiki_extension "CleanChanges" do
391 site new_resource.site
392 template "mw-ext-CleanChanges.inc.php.erb"
396 mediawiki_extension "LocalisationUpdate" do
397 site new_resource.site
398 template "mw-ext-LocalisationUpdate.inc.php.erb"
402 # mediawiki_extension "Translate" do
403 # site new_resource.site
404 # template "mw-ext-Translate.inc.php.erb"
408 mediawiki_extension "UniversalLanguageSelector" do
409 site new_resource.site
410 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
414 mediawiki_extension "AntiSpoof" do
415 site new_resource.site
416 template "mw-ext-AntiSpoof.inc.php.erb"
420 mediawiki_extension "AbuseFilter" do
421 site new_resource.site
422 template "mw-ext-AbuseFilter.inc.php.erb"
426 mediawiki_extension "CheckUser" do
427 site new_resource.site
428 template "mw-ext-CheckUser.inc.php.erb"
432 mediawiki_extension "DismissableSiteNotice" do
433 site new_resource.site
437 mediawiki_extension "Elastica" do
438 site new_resource.site
442 mediawiki_extension "CirrusSearch" do
443 site new_resource.site
444 template "mw-ext-CirrusSearch.inc.php.erb"
448 mediawiki_extension "osmtaginfo" do
449 site new_resource.site
450 template "mw-ext-osmtaginfo.inc.php.erb"
451 repository "https://github.com/Firefishy/osmtaginfo.git"
456 mediawiki_extension "SimpleMap" do
457 site new_resource.site
458 template "mw-ext-SimpleMap.inc.php.erb"
459 repository "https://github.com/Firefishy/SimpleMap.git"
464 mediawiki_extension "SlippyMap" do
465 site new_resource.site
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 request_terminate_timeout new_resource.fpm_request_terminate_timeout
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