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"
400 repository "git://github.com/migurski/extension-checkuser.git"
401 reference "0fe3015e57bb6ee771ecaebf3b2d79a251bd4e3a"
405 mediawiki_extension "DismissableSiteNotice" do
406 site new_resource.site
410 mediawiki_extension "Elastica" do
411 site new_resource.site
415 mediawiki_extension "CirrusSearch" do
416 site new_resource.site
417 template "mw-ext-CirrusSearch.inc.php.erb"
421 mediawiki_extension "osmtaginfo" do
422 site new_resource.site
423 template "mw-ext-osmtaginfo.inc.php.erb"
424 repository "https://github.com/Firefishy/osmtaginfo.git"
429 mediawiki_extension "SimpleMap" do
430 site new_resource.site
431 template "mw-ext-SimpleMap.inc.php.erb"
432 repository "https://github.com/Firefishy/SimpleMap.git"
437 mediawiki_extension "SlippyMap" do
438 site new_resource.site
439 template "mw-ext-SlippyMap.inc.php.erb"
440 repository "https://github.com/Firefishy/SlippyMap.git"
445 mediawiki_extension "Mantle" do
446 site new_resource.site
451 mediawiki_extension "DisableAccount" do
452 site new_resource.site
453 template "mw-ext-DisableAccount.inc.php.erb"
457 mediawiki_extension "VisualEditor" do
458 site new_resource.site
459 template "mw-ext-VisualEditor.inc.php.erb"
463 mediawiki_extension "TemplateData" do
464 site new_resource.site
468 cookbook_file "#{site_directory}/cc-wiki.png" do
470 owner node[:mediawiki][:user]
471 group node[:mediawiki][:group]
476 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
478 owner node[:mediawiki][:user]
479 group node[:mediawiki][:group]
484 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
486 owner node[:mediawiki][:user]
487 group node[:mediawiki][:group]
492 ssl_certificate new_resource.site do
493 domains [new_resource.site] + Array(new_resource.aliases)
496 apache_site new_resource.site do
498 template "apache.erb"
499 directory site_directory
500 variables :aliases => Array(new_resource.aliases),
501 :private_site => new_resource.private_site
505 # FIXME: needs to run one
506 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
508 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
509 cwd mediawiki_directory
510 user node[:mediawiki][:user]
511 group node[:mediawiki][:group]
516 mediawiki_directory = "#{site_directory}/w"
518 template "#{mediawiki_directory}/LocalSettings.php" do
520 source "LocalSettings.php.erb"
521 owner node[:mediawiki][:user]
522 group node[:mediawiki][:group]
524 variables :name => new_resource.site,
525 :directory => mediawiki_directory,
526 :database_params => database_params,
527 :mediawiki => mediawiki_params
528 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
531 execute "#{mediawiki_directory}/maintenance/update.php" do
533 command "php maintenance/update.php --quick"
534 cwd mediawiki_directory
535 user node[:mediawiki][:user]
536 group node[:mediawiki][:group]
541 apache_site new_resource.site do
546 declare_resource :directory, site_directory do
551 mysql_database new_resource.database_name do
555 mysql_user "#{new_resource.database_user}@localhost" do
562 new_resource.directory || "/srv/#{new_resource.site}"
566 new_resource.site.tr(".", "_")
571 :host => "localhost",
572 :name => new_resource.database_name,
573 :username => new_resource.database_user,
574 :password => new_resource.database_password
580 :sitename => new_resource.sitename,
581 :metanamespace => new_resource.metanamespace,
582 :logo => new_resource.logo,
583 :email_contact => new_resource.email_contact,
584 :email_sender => new_resource.email_sender,
585 :email_sender_name => new_resource.email_sender_name,
586 :commons => new_resource.commons,
587 :skin => new_resource.skin,
588 :site_notice => new_resource.site_notice,
589 :site_readonly => new_resource.site_readonly,
590 :extra_file_extensions => new_resource.extra_file_extensions,
591 :private_accounts => new_resource.private_accounts,
592 :private_site => new_resource.private_site
598 notifies :reload, "service[apache2]" if reload_apache