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
112 user node[:mediawiki][:user]
113 group node[:mediawiki][:group]
114 notifies :run, "execute[#{mediawiki_directory}/composer.json]", :immediately
115 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
116 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
119 execute "#{mediawiki_directory}/composer.json" do
121 command "composer update --no-dev"
122 cwd mediawiki_directory
123 user node[:mediawiki][:user]
124 group node[:mediawiki][:group]
127 template "#{mediawiki_directory}/composer.local.json" do
129 source "composer.local.json.erb"
130 owner node[:mediawiki][:user]
131 group node[:mediawiki][:group]
135 # Safety catch if git doesn't update but install.php hasn't run
136 ruby_block "catch-installer-localsettings-run" do
141 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
143 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
146 declare_resource :directory, "#{mediawiki_directory}/images" do
148 group node[:mediawiki][:group]
152 declare_resource :directory, "#{mediawiki_directory}/cache" do
154 group node[:mediawiki][:group]
158 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
159 user node[:mediawiki][:user]
160 group node[:mediawiki][:group]
164 template "#{mediawiki_directory}/LocalSettings.php" do
166 source "LocalSettings.php.erb"
167 owner node[:mediawiki][:user]
168 group node[:mediawiki][:group]
170 variables :name => new_resource.site,
171 :directory => mediawiki_directory,
172 :database_params => database_params,
173 :mediawiki => mediawiki_params
174 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
177 template "/etc/cron.d/mediawiki-#{cron_name}" do
179 source "mediawiki.cron.erb"
183 variables :name => new_resource.site, :directory => site_directory,
184 :user => node[:mediawiki][:user]
187 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
189 source "mediawiki-backup.cron.erb"
193 variables :name => new_resource.site,
194 :directory => site_directory,
195 :database_params => database_params
198 # MobileFrontend extension is required by MinervaNeue skin
199 mediawiki_extension "MobileFrontend" do
200 site new_resource.site
201 template "mw-ext-MobileFrontend.inc.php.erb"
204 # MobileFrontend extension is required by MinervaNeue skin
205 mediawiki_skin "MinervaNeue" do
206 site new_resource.site
211 mediawiki_skin "CologneBlue" do
212 site new_resource.site
217 mediawiki_skin "Modern" do
218 site new_resource.site
223 mediawiki_skin "MonoBook" do
224 site new_resource.site
229 mediawiki_skin "Vector" do
230 site new_resource.site
235 mediawiki_extension "Cite" do
236 site new_resource.site
240 mediawiki_extension "CiteThisPage" do
241 site new_resource.site
245 if new_resource.private_accounts || new_resource.private_site
246 mediawiki_extension "ConfirmEdit" do
247 site new_resource.site
252 mediawiki_extension "ConfirmEdit" do
253 site new_resource.site
254 template "mw-ext-ConfirmEdit.inc.php.erb"
255 variables :public_key => new_resource.recaptcha_public_key,
256 :private_key => new_resource.recaptcha_private_key
261 mediawiki_extension "Gadgets" do
262 site new_resource.site
266 mediawiki_extension "ImageMap" do
267 site new_resource.site
271 mediawiki_extension "InputBox" do
272 site new_resource.site
276 mediawiki_extension "Interwiki" do
277 site new_resource.site
278 template "mw-ext-Interwiki.inc.php.erb"
282 mediawiki_extension "Nuke" do
283 site new_resource.site
287 mediawiki_extension "ParserFunctions" do
288 site new_resource.site
289 template "mw-ext-ParserFunctions.inc.php.erb"
293 mediawiki_extension "PdfHandler" do
294 site new_resource.site
295 template "mw-ext-PdfHandler.inc.php.erb"
299 mediawiki_extension "Poem" do
300 site new_resource.site
304 mediawiki_extension "Renameuser" do
305 site new_resource.site
309 mediawiki_extension "SimpleAntiSpam" do
310 site new_resource.site
315 mediawiki_extension "SpamBlacklist" do
316 site new_resource.site
317 template "mw-ext-SpamBlacklist.inc.php.erb"
321 mediawiki_extension "SyntaxHighlight_GeSHi" do
322 site new_resource.site
323 template "mw-ext-SyntaxHighlight.inc.php.erb"
327 mediawiki_extension "TitleBlacklist" do
328 site new_resource.site
329 template "mw-ext-TitleBlacklist.inc.php.erb"
333 mediawiki_extension "WikiEditor" do
334 site new_resource.site
338 mediawiki_extension "Babel" do
339 site new_resource.site
340 template "mw-ext-Babel.inc.php.erb"
344 mediawiki_extension "cldr" do
345 site new_resource.site
346 template "mw-ext-cldr.inc.php.erb"
350 mediawiki_extension "CleanChanges" do
351 site new_resource.site
352 template "mw-ext-CleanChanges.inc.php.erb"
356 mediawiki_extension "LocalisationUpdate" do
357 site new_resource.site
358 template "mw-ext-LocalisationUpdate.inc.php.erb"
362 # LocalisationUpdate Update Cron
363 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
364 # cookbook "mediawiki"
365 # source "mediawiki-LocalisationUpdate.cron.erb"
369 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
372 # mediawiki_extension "Translate" do
373 # site new_resource.site
374 # template "mw-ext-Translate.inc.php.erb"
378 mediawiki_extension "UniversalLanguageSelector" do
379 site new_resource.site
380 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
384 mediawiki_extension "AntiSpoof" do
385 site new_resource.site
386 template "mw-ext-AntiSpoof.inc.php.erb"
390 mediawiki_extension "AbuseFilter" do
391 site new_resource.site
392 template "mw-ext-AbuseFilter.inc.php.erb"
396 mediawiki_extension "CheckUser" do
397 site new_resource.site
398 template "mw-ext-CheckUser.inc.php.erb"
402 mediawiki_extension "DismissableSiteNotice" do
403 site new_resource.site
407 mediawiki_extension "Elastica" do
408 site new_resource.site
412 mediawiki_extension "CirrusSearch" do
413 site new_resource.site
414 template "mw-ext-CirrusSearch.inc.php.erb"
418 mediawiki_extension "osmtaginfo" do
419 site new_resource.site
420 template "mw-ext-osmtaginfo.inc.php.erb"
421 repository "git://github.com/Firefishy/osmtaginfo.git"
426 mediawiki_extension "SimpleMap" do
427 site new_resource.site
428 template "mw-ext-SimpleMap.inc.php.erb"
429 repository "git://github.com/Firefishy/SimpleMap.git"
434 mediawiki_extension "SlippyMap" do
435 site new_resource.site
436 template "mw-ext-SlippyMap.inc.php.erb"
437 repository "git://github.com/Firefishy/SlippyMap.git"
442 mediawiki_extension "Mantle" do
443 site new_resource.site
448 mediawiki_extension "DisableAccount" do
449 site new_resource.site
450 template "mw-ext-DisableAccount.inc.php.erb"
454 mediawiki_extension "VisualEditor" do
455 site new_resource.site
456 template "mw-ext-VisualEditor.inc.php.erb"
460 mediawiki_extension "TemplateData" do
461 site new_resource.site
465 cookbook_file "#{site_directory}/cc-wiki.png" do
467 owner node[:mediawiki][:user]
468 group node[:mediawiki][:group]
473 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
475 owner node[:mediawiki][:user]
476 group node[:mediawiki][:group]
481 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
483 owner node[:mediawiki][:user]
484 group node[:mediawiki][:group]
489 ssl_certificate new_resource.site do
490 domains [new_resource.site] + Array(new_resource.aliases)
493 apache_site new_resource.site do
495 template "apache.erb"
496 directory site_directory
497 variables :aliases => Array(new_resource.aliases),
498 :private_site => new_resource.private_site
502 # FIXME: needs to run one
503 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
505 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
506 cwd mediawiki_directory
507 user node[:mediawiki][:user]
508 group node[:mediawiki][:group]
513 mediawiki_directory = "#{site_directory}/w"
515 template "#{mediawiki_directory}/LocalSettings.php" do
517 source "LocalSettings.php.erb"
518 owner node[:mediawiki][:user]
519 group node[:mediawiki][:group]
521 variables :name => new_resource.site,
522 :directory => mediawiki_directory,
523 :database_params => database_params,
524 :mediawiki => mediawiki_params
525 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
528 execute "#{mediawiki_directory}/maintenance/update.php" do
530 command "php maintenance/update.php --quick"
531 cwd mediawiki_directory
532 user node[:mediawiki][:user]
533 group node[:mediawiki][:group]
538 apache_site new_resource.site do
543 declare_resource :directory, site_directory do
548 mysql_database new_resource.database_name do
552 mysql_user "#{new_resource.database_user}@localhost" do
559 new_resource.directory || "/srv/#{new_resource.site}"
563 new_resource.site.tr(".", "_")
568 :host => "localhost",
569 :name => new_resource.database_name,
570 :username => new_resource.database_user,
571 :password => new_resource.database_password
577 :sitename => new_resource.sitename,
578 :metanamespace => new_resource.metanamespace,
579 :logo => new_resource.logo,
580 :email_contact => new_resource.email_contact,
581 :email_sender => new_resource.email_sender,
582 :email_sender_name => new_resource.email_sender_name,
583 :commons => new_resource.commons,
584 :skin => new_resource.skin,
585 :site_notice => new_resource.site_notice,
586 :site_readonly => new_resource.site_readonly,
587 :extra_file_extensions => new_resource.extra_file_extensions,
588 :private_accounts => new_resource.private_accounts,
589 :private_site => new_resource.private_site
595 notifies :reload, "service[apache2]" if reload_apache