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.35"
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/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]
128 environment "COMPOSER_HOME" => site_directory
131 template "#{mediawiki_directory}/composer.local.json" do
133 source "composer.local.json.erb"
134 owner node[:mediawiki][:user]
135 group node[:mediawiki][:group]
139 # Safety catch if git doesn't update but install.php hasn't run
140 ruby_block "catch-installer-localsettings-run" do
145 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
147 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
150 declare_resource :directory, "#{mediawiki_directory}/images" do
152 group node[:mediawiki][:group]
156 declare_resource :directory, "#{mediawiki_directory}/cache" do
158 group node[:mediawiki][:group]
162 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
163 user node[:mediawiki][:user]
164 group node[:mediawiki][:group]
168 template "#{mediawiki_directory}/LocalSettings.php" do
170 source "LocalSettings.php.erb"
171 owner node[:mediawiki][:user]
172 group node[:mediawiki][:group]
174 variables :name => new_resource.site,
175 :directory => mediawiki_directory,
176 :database_params => database_params,
177 :mediawiki => mediawiki_params,
178 :secret_key => secret_key
179 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
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
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 request_terminate_timeout new_resource.fpm_request_terminate_timeout
525 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
526 php_values "memory_limit" => "500M",
527 "max_execution_time" => "240",
528 "upload_max_filesize" => "70M",
529 "post_max_size" => "100M"
532 apache_site new_resource.site do
534 template "apache.erb"
535 directory site_directory
536 variables :aliases => Array(new_resource.aliases),
537 :private_site => new_resource.private_site
541 # FIXME: needs to run one
542 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
544 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
545 cwd mediawiki_directory
546 user node[:mediawiki][:user]
547 group node[:mediawiki][:group]
552 mediawiki_directory = "#{site_directory}/w"
554 template "#{mediawiki_directory}/LocalSettings.php" do
556 source "LocalSettings.php.erb"
557 owner node[:mediawiki][:user]
558 group node[:mediawiki][:group]
560 variables :name => new_resource.site,
561 :directory => mediawiki_directory,
562 :database_params => database_params,
563 :mediawiki => mediawiki_params
564 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
567 execute "#{mediawiki_directory}/maintenance/update.php" do
569 command "php maintenance/update.php --quick"
570 cwd mediawiki_directory
571 user node[:mediawiki][:user]
572 group node[:mediawiki][:group]
577 apache_site new_resource.site do
582 declare_resource :directory, site_directory do
587 mysql_database new_resource.database_name do
591 mysql_user "#{new_resource.database_user}@localhost" do
597 include Chef::Mixin::PersistentToken
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