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 template "/etc/cron.d/mediawiki-#{cron_name}" do
180 source "mediawiki.cron.erb"
184 variables :name => new_resource.site, :directory => site_directory,
185 :user => node[:mediawiki][:user]
188 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
190 source "mediawiki-backup.cron.erb"
194 variables :name => new_resource.site,
195 :directory => site_directory,
196 :database_params => database_params
199 # MobileFrontend extension is required by MinervaNeue skin
200 mediawiki_extension "MobileFrontend" do
201 site new_resource.site
202 template "mw-ext-MobileFrontend.inc.php.erb"
205 # MobileFrontend extension is required by MinervaNeue skin
206 mediawiki_skin "MinervaNeue" do
207 site new_resource.site
212 mediawiki_skin "CologneBlue" do
213 site new_resource.site
218 mediawiki_skin "Modern" do
219 site new_resource.site
224 mediawiki_skin "MonoBook" do
225 site new_resource.site
230 mediawiki_skin "Vector" do
231 site new_resource.site
236 mediawiki_extension "Cite" do
237 site new_resource.site
241 mediawiki_extension "CiteThisPage" do
242 site new_resource.site
246 if new_resource.private_accounts || new_resource.private_site
247 mediawiki_extension "ConfirmEdit" do
248 site new_resource.site
253 mediawiki_extension "ConfirmEdit" do
254 site new_resource.site
255 template "mw-ext-ConfirmEdit.inc.php.erb"
256 variables :public_key => new_resource.recaptcha_public_key,
257 :private_key => new_resource.recaptcha_private_key
262 mediawiki_extension "Gadgets" do
263 site new_resource.site
267 mediawiki_extension "ImageMap" do
268 site new_resource.site
272 mediawiki_extension "InputBox" do
273 site new_resource.site
277 mediawiki_extension "Interwiki" do
278 site new_resource.site
279 template "mw-ext-Interwiki.inc.php.erb"
283 mediawiki_extension "Nuke" do
284 site new_resource.site
288 mediawiki_extension "ParserFunctions" do
289 site new_resource.site
290 template "mw-ext-ParserFunctions.inc.php.erb"
294 mediawiki_extension "PdfHandler" do
295 site new_resource.site
296 template "mw-ext-PdfHandler.inc.php.erb"
300 mediawiki_extension "Poem" do
301 site new_resource.site
305 mediawiki_extension "Renameuser" do
306 site new_resource.site
310 mediawiki_extension "SimpleAntiSpam" do
311 site new_resource.site
316 mediawiki_extension "SpamBlacklist" do
317 site new_resource.site
318 template "mw-ext-SpamBlacklist.inc.php.erb"
322 mediawiki_extension "SyntaxHighlight_GeSHi" do
323 site new_resource.site
324 template "mw-ext-SyntaxHighlight.inc.php.erb"
328 mediawiki_extension "TitleBlacklist" do
329 site new_resource.site
330 template "mw-ext-TitleBlacklist.inc.php.erb"
334 mediawiki_extension "WikiEditor" do
335 site new_resource.site
339 mediawiki_extension "Babel" do
340 site new_resource.site
341 template "mw-ext-Babel.inc.php.erb"
345 mediawiki_extension "cldr" do
346 site new_resource.site
347 template "mw-ext-cldr.inc.php.erb"
351 mediawiki_extension "CleanChanges" do
352 site new_resource.site
353 template "mw-ext-CleanChanges.inc.php.erb"
357 mediawiki_extension "LocalisationUpdate" do
358 site new_resource.site
359 template "mw-ext-LocalisationUpdate.inc.php.erb"
363 # LocalisationUpdate Update Cron
364 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
365 # cookbook "mediawiki"
366 # source "mediawiki-LocalisationUpdate.cron.erb"
370 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
373 # mediawiki_extension "Translate" do
374 # site new_resource.site
375 # template "mw-ext-Translate.inc.php.erb"
379 mediawiki_extension "UniversalLanguageSelector" do
380 site new_resource.site
381 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
385 mediawiki_extension "AntiSpoof" do
386 site new_resource.site
387 template "mw-ext-AntiSpoof.inc.php.erb"
391 mediawiki_extension "AbuseFilter" do
392 site new_resource.site
393 template "mw-ext-AbuseFilter.inc.php.erb"
397 mediawiki_extension "CheckUser" do
398 site new_resource.site
399 template "mw-ext-CheckUser.inc.php.erb"
403 mediawiki_extension "DismissableSiteNotice" do
404 site new_resource.site
408 mediawiki_extension "Elastica" do
409 site new_resource.site
413 mediawiki_extension "CirrusSearch" do
414 site new_resource.site
415 template "mw-ext-CirrusSearch.inc.php.erb"
419 mediawiki_extension "osmtaginfo" do
420 site new_resource.site
421 template "mw-ext-osmtaginfo.inc.php.erb"
422 repository "https://github.com/Firefishy/osmtaginfo.git"
427 mediawiki_extension "SimpleMap" do
428 site new_resource.site
429 template "mw-ext-SimpleMap.inc.php.erb"
430 repository "https://github.com/Firefishy/SimpleMap.git"
435 mediawiki_extension "SlippyMap" do
436 site new_resource.site
437 template "mw-ext-SlippyMap.inc.php.erb"
438 repository "https://github.com/Firefishy/SlippyMap.git"
443 mediawiki_extension "Mantle" do
444 site new_resource.site
449 mediawiki_extension "DisableAccount" do
450 site new_resource.site
451 template "mw-ext-DisableAccount.inc.php.erb"
455 mediawiki_extension "VisualEditor" do
456 site new_resource.site
457 template "mw-ext-VisualEditor.inc.php.erb"
461 mediawiki_extension "TemplateData" do
462 site new_resource.site
466 cookbook_file "#{site_directory}/cc-wiki.png" do
468 owner node[:mediawiki][:user]
469 group node[:mediawiki][:group]
474 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
476 owner node[:mediawiki][:user]
477 group node[:mediawiki][:group]
482 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
484 owner node[:mediawiki][:user]
485 group node[:mediawiki][:group]
490 ssl_certificate new_resource.site do
491 domains [new_resource.site] + Array(new_resource.aliases)
494 apache_site new_resource.site do
496 template "apache.erb"
497 directory site_directory
498 variables :aliases => Array(new_resource.aliases),
499 :private_site => new_resource.private_site
503 # FIXME: needs to run one
504 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
506 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
507 cwd mediawiki_directory
508 user node[:mediawiki][:user]
509 group node[:mediawiki][:group]
514 mediawiki_directory = "#{site_directory}/w"
516 template "#{mediawiki_directory}/LocalSettings.php" do
518 source "LocalSettings.php.erb"
519 owner node[:mediawiki][:user]
520 group node[:mediawiki][:group]
522 variables :name => new_resource.site,
523 :directory => mediawiki_directory,
524 :database_params => database_params,
525 :mediawiki => mediawiki_params
526 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
529 execute "#{mediawiki_directory}/maintenance/update.php" do
531 command "php maintenance/update.php --quick"
532 cwd mediawiki_directory
533 user node[:mediawiki][:user]
534 group node[:mediawiki][:group]
539 apache_site new_resource.site do
544 declare_resource :directory, site_directory do
549 mysql_database new_resource.database_name do
553 mysql_user "#{new_resource.database_user}@localhost" do
560 new_resource.directory || "/srv/#{new_resource.site}"
564 new_resource.site.tr(".", "_")
569 :host => "localhost",
570 :name => new_resource.database_name,
571 :username => new_resource.database_user,
572 :password => new_resource.database_password
578 :sitename => new_resource.sitename,
579 :metanamespace => new_resource.metanamespace,
580 :logo => new_resource.logo,
581 :email_contact => new_resource.email_contact,
582 :email_sender => new_resource.email_sender,
583 :email_sender_name => new_resource.email_sender_name,
584 :commons => new_resource.commons,
585 :skin => new_resource.skin,
586 :site_notice => new_resource.site_notice,
587 :site_readonly => new_resource.site_readonly,
588 :extra_file_extensions => new_resource.extra_file_extensions,
589 :private_accounts => new_resource.private_accounts,
590 :private_site => new_resource.private_site
596 notifies :reload, "service[apache2]" if reload_apache