2 # Cookbook Name:: mediawiki
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_attribute => true
23 property :aliases, :kind_of => [String, Array]
24 property :directory, :kind_of => String
25 property :version, :kind_of => String, :default => "1.29"
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, :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}/vendor" do
110 repository "https://gerrit.wikimedia.org/r/p/mediawiki/vendor.git"
111 revision mediawiki_reference
112 user node[:mediawiki][:user]
113 group node[:mediawiki][:group]
116 git mediawiki_directory do
118 repository "https://gerrit.wikimedia.org/r/p/mediawiki/core.git"
119 revision mediawiki_reference
120 user node[:mediawiki][:user]
121 group node[:mediawiki][:group]
122 notifies :sync, "git[#{mediawiki_directory}/vendor]", :immediately
123 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
124 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
127 # Safety catch if git doesn't update but install.php hasn't run
128 ruby_block "catch-installer-localsettings-run" do
134 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
136 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
139 declare_resource :directory, "#{mediawiki_directory}/images" do
141 group node[:mediawiki][:group]
145 declare_resource :directory, "#{mediawiki_directory}/cache" do
147 group node[:mediawiki][:group]
151 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
152 user node[:mediawiki][:user]
153 group node[:mediawiki][:group]
157 template "#{mediawiki_directory}/LocalSettings.php" do
159 source "LocalSettings.php.erb"
160 owner node[:mediawiki][:user]
161 group node[:mediawiki][:group]
163 variables :name => new_resource.site,
164 :directory => mediawiki_directory,
165 :database_params => database_params,
166 :mediawiki => mediawiki_params
167 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
170 template "/etc/cron.d/mediawiki-#{cron_name}" do
172 source "mediawiki.cron.erb"
176 variables :name => new_resource.site, :directory => site_directory,
177 :user => node[:mediawiki][:user]
180 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
182 source "mediawiki-backup.cron.erb"
186 variables :name => new_resource.site,
187 :directory => site_directory,
188 :database_params => database_params
191 mediawiki_skin "CologneBlue" do # ~FC005
192 site new_resource.site
196 mediawiki_skin "Modern" do
197 site new_resource.site
201 mediawiki_skin "MonoBook" do
202 site new_resource.site
206 mediawiki_skin "Vector" do
207 site new_resource.site
211 mediawiki_extension "Cite" do
212 site new_resource.site
216 mediawiki_extension "CiteThisPage" do
217 site new_resource.site
221 if new_resource.private_accounts || new_resource.private
222 mediawiki_extension "ConfirmEdit" do
223 site new_resource.site
228 mediawiki_extension "ConfirmEdit" do
229 site new_resource.site
230 template "mw-ext-ConfirmEdit.inc.php.erb"
231 variables :public_key => new_resource.recaptcha_public_key,
232 :private_key => new_resource.recaptcha_private_key
237 mediawiki_extension "Gadgets" do
238 site new_resource.site
242 mediawiki_extension "ImageMap" do
243 site new_resource.site
247 mediawiki_extension "InputBox" do
248 site new_resource.site
252 mediawiki_extension "Interwiki" do
253 site new_resource.site
257 mediawiki_extension "Nuke" do
258 site new_resource.site
262 mediawiki_extension "ParserFunctions" do
263 site new_resource.site
264 template "mw-ext-ParserFunctions.inc.php.erb"
268 mediawiki_extension "PdfHandler" do
269 site new_resource.site
270 template "mw-ext-PdfHandler.inc.php.erb"
274 mediawiki_extension "Poem" do
275 site new_resource.site
279 mediawiki_extension "Renameuser" do
280 site new_resource.site
284 mediawiki_extension "SimpleAntiSpam" do
285 site new_resource.site
290 mediawiki_extension "SpamBlacklist" do
291 site new_resource.site
292 template "mw-ext-SpamBlacklist.inc.php.erb"
296 mediawiki_extension "SyntaxHighlight_GeSHi" do
297 site new_resource.site
298 template "mw-ext-SyntaxHighlight.inc.php.erb"
302 mediawiki_extension "TitleBlacklist" do
303 site new_resource.site
304 template "mw-ext-TitleBlacklist.inc.php.erb"
308 mediawiki_extension "WikiEditor" do
309 site new_resource.site
313 # MediaWiki Language Extension Bundle
314 # FIXME: should automatically resolve tag
315 mw_lang_ext_bundle_tag = "2017.01"
317 mediawiki_extension "Babel" do
318 site new_resource.site
319 template "mw-ext-Babel.inc.php.erb"
320 # tag mw_lang_ext_bundle_tag
321 tag mw_lang_ext_bundle_tag
325 mediawiki_extension "cldr" do
326 site new_resource.site
327 template "mw-ext-cldr.inc.php.erb"
328 tag mw_lang_ext_bundle_tag
332 mediawiki_extension "CleanChanges" do
333 site new_resource.site
334 template "mw-ext-CleanChanges.inc.php.erb"
335 tag mw_lang_ext_bundle_tag
339 mediawiki_extension "LocalisationUpdate" do
340 site new_resource.site
341 template "mw-ext-LocalisationUpdate.inc.php.erb"
342 tag mw_lang_ext_bundle_tag
346 # LocalisationUpdate Update Cron
347 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
348 # cookbook "mediawiki"
349 # source "mediawiki-LocalisationUpdate.cron.erb"
353 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
356 # mediawiki_extension "Translate" do
357 # site new_resource.site
358 # template "mw-ext-Translate.inc.php.erb"
359 # tag mw_lang_ext_bundle_tag
363 mediawiki_extension "UniversalLanguageSelector" do
364 site new_resource.site
365 tag mw_lang_ext_bundle_tag
369 mediawiki_extension "AntiSpoof" do
370 site new_resource.site
371 template "mw-ext-AntiSpoof.inc.php.erb"
375 mediawiki_extension "AbuseFilter" do
376 site new_resource.site
377 template "mw-ext-AbuseFilter.inc.php.erb"
381 mediawiki_extension "CheckUser" do
382 site new_resource.site
383 template "mw-ext-CheckUser.inc.php.erb"
387 mediawiki_extension "DismissableSiteNotice" do
388 site new_resource.site
392 mediawiki_extension "Elastica" do
393 site new_resource.site
397 mediawiki_extension "CirrusSearch" do
398 site new_resource.site
399 template "mw-ext-CirrusSearch.inc.php.erb"
403 mediawiki_extension "osmtaginfo" do
404 site new_resource.site
405 template "mw-ext-osmtaginfo.inc.php.erb"
406 repository "git://github.com/Firefishy/osmtaginfo.git"
411 mediawiki_extension "SimpleMap" do
412 site new_resource.site
413 template "mw-ext-SimpleMap.inc.php.erb"
414 repository "git://github.com/Firefishy/SimpleMap.git"
419 mediawiki_extension "SlippyMap" do
420 site new_resource.site
421 template "mw-ext-SlippyMap.inc.php.erb"
422 repository "git://github.com/Firefishy/SlippyMap.git"
427 mediawiki_extension "Mantle" do
428 site new_resource.site
433 mediawiki_extension "MobileFrontend" do
434 site new_resource.site
435 template "mw-ext-MobileFrontend.inc.php.erb"
439 mediawiki_extension "DisableAccount" do
440 site new_resource.site
441 template "mw-ext-DisableAccount.inc.php.erb"
445 mediawiki_extension "VisualEditor" do
446 site new_resource.site
447 template "mw-ext-VisualEditor.inc.php.erb"
451 cookbook_file "#{site_directory}/cc-wiki.png" do
453 owner node[:mediawiki][:user]
454 group node[:mediawiki][:group]
459 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
461 owner node[:mediawiki][:user]
462 group node[:mediawiki][:group]
467 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
469 owner node[:mediawiki][:user]
470 group node[:mediawiki][:group]
475 ssl_certificate new_resource.site do
476 domains [new_resource.site] + Array(new_resource.aliases)
479 apache_site new_resource.site do
481 template "apache.erb"
482 directory site_directory
483 variables :aliases => Array(new_resource.aliases),
484 :private => new_resource.private
488 # FIXME: needs to run one
489 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
491 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
492 cwd mediawiki_directory
493 user node[:mediawiki][:user]
494 group node[:mediawiki][:group]
499 mediawiki_directory = "#{site_directory}/w"
501 template "#{mediawiki_directory}/LocalSettings.php" do
503 source "LocalSettings.php.erb"
504 owner node[:mediawiki][:user]
505 group node[:mediawiki][:group]
507 variables :name => new_resource.site,
508 :directory => mediawiki_directory,
509 :database_params => database_params,
510 :mediawiki => mediawiki_params
511 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
514 execute "#{mediawiki_directory}/maintenance/update.php" do
516 command "php maintenance/update.php --quick"
517 cwd mediawiki_directory
518 user node[:mediawiki][:user]
519 group node[:mediawiki][:group]
524 apache_site new_resource.site do
529 declare_resource :directory, site_directory do
534 mysql_database new_resource.database_name do
538 mysql_user "#{new_resource.database_user}@localhost" do
545 new_resource.directory || "/srv/#{new_resource.site}"
549 new_resource.site.tr(".", "_")
554 :host => "localhost",
555 :name => new_resource.database_name,
556 :username => new_resource.database_user,
557 :password => new_resource.database_password
563 :sitename => new_resource.sitename,
564 :metanamespace => new_resource.metanamespace,
565 :logo => new_resource.logo,
566 :email_contact => new_resource.email_contact,
567 :email_sender => new_resource.email_sender,
568 :email_sender_name => new_resource.email_sender_name,
569 :commons => new_resource.commons,
570 :skin => new_resource.skin,
571 :site_notice => new_resource.site_notice,
572 :site_readonly => new_resource.site_readonly,
573 :extra_file_extensions => new_resource.extra_file_extensions,
574 :private_accounts => new_resource.private_accounts,
575 :private => new_resource.private
581 notifies :reload, "service[apache2]" if reload_apache