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 # http://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.28"
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 :ssl_enabled, :kind_of => [TrueClass, FalseClass], :default => false
42 property :private_accounts, :kind_of => [TrueClass, FalseClass], :default => false
43 property :private, :kind_of => [TrueClass, FalseClass], :default => false
44 property :recaptcha_public_key, :kind_of => String
45 property :recaptcha_private_key, :kind_of => String
46 property :extra_file_extensions, :kind_of => [String, Array], :default => []
47 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
50 node.normal_unless[:mediawiki][:sites][new_resource.site] = {}
52 node.normal[:mediawiki][:sites][new_resource.site][:directory] = site_directory
53 node.normal[:mediawiki][:sites][new_resource.site][:version] = new_resource.version
55 node.normal_unless[:mediawiki][:sites][new_resource.site][:wgSecretKey] = SecureRandom.base64(48)
57 mysql_user "#{new_resource.database_user}@localhost" do
58 password new_resource.database_password
61 mysql_database new_resource.database_name do
62 permissions "#{new_resource.database_user}@localhost" => :all
65 mediawiki_directory = "#{site_directory}/w"
67 ruby_block "rename-installer-localsettings" do
70 ::File.rename("#{mediawiki_directory}/LocalSettings.php", "#{mediawiki_directory}/LocalSettings-install.php")
74 execute "#{mediawiki_directory}/maintenance/install.php" do
76 # Use metanamespace as Site Name to ensure correct set namespace
77 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}'"
78 cwd mediawiki_directory
79 user node[:mediawiki][:user]
80 group node[:mediawiki][:group]
82 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
84 notifies :run, "ruby_block[rename-installer-localsettings]", :immediately
87 execute "#{mediawiki_directory}/maintenance/update.php" do
89 command "php maintenance/update.php --quick"
90 cwd mediawiki_directory
91 user node[:mediawiki][:user]
92 group node[:mediawiki][:group]
95 declare_resource :directory, site_directory do
96 owner node[:mediawiki][:user]
97 group node[:mediawiki][:group]
101 declare_resource :directory, mediawiki_directory do
102 owner node[:mediawiki][:user]
103 group node[:mediawiki][:group]
107 mediawiki_reference = "REL#{new_resource.version}".tr(".", "_")
109 git "#{mediawiki_directory}/vendor" do
111 repository "https://gerrit.wikimedia.org/r/p/mediawiki/vendor.git"
112 revision mediawiki_reference
113 user node[:mediawiki][:user]
114 group node[:mediawiki][:group]
117 git mediawiki_directory do
119 repository "https://gerrit.wikimedia.org/r/p/mediawiki/core.git"
120 revision mediawiki_reference
121 user node[:mediawiki][:user]
122 group node[:mediawiki][:group]
123 notifies :sync, "git[#{mediawiki_directory}/vendor]", :immediately
124 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
125 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
128 # Safety catch if git doesn't update but install.php hasn't run
129 ruby_block "catch-installer-localsettings-run" do
135 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
137 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
140 declare_resource :directory, "#{mediawiki_directory}/images" do
142 group node[:mediawiki][:group]
146 declare_resource :directory, "#{mediawiki_directory}/cache" do
148 group node[:mediawiki][:group]
152 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
153 user node[:mediawiki][:user]
154 group node[:mediawiki][:group]
158 template "#{mediawiki_directory}/LocalSettings.php" do
160 source "LocalSettings.php.erb"
161 owner node[:mediawiki][:user]
162 group node[:mediawiki][:group]
164 variables :name => new_resource.site,
165 :directory => mediawiki_directory,
166 :database_params => database_params,
167 :mediawiki => mediawiki_params
168 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
171 template "/etc/cron.d/mediawiki-#{cron_name}" do
173 source "mediawiki.cron.erb"
177 variables :name => new_resource.site, :directory => site_directory,
178 :user => node[:mediawiki][:user]
181 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
183 source "mediawiki-backup.cron.erb"
187 variables :name => new_resource.site,
188 :directory => site_directory,
189 :database_params => database_params
192 mediawiki_skin "CologneBlue" do # ~FC005
193 site new_resource.site
197 mediawiki_skin "Modern" do
198 site new_resource.site
202 mediawiki_skin "MonoBook" do
203 site new_resource.site
207 mediawiki_skin "Vector" do
208 site new_resource.site
212 mediawiki_extension "Cite" do
213 site new_resource.site
217 mediawiki_extension "CiteThisPage" do
218 site new_resource.site
222 if new_resource.private_accounts || new_resource.private
223 mediawiki_extension "ConfirmEdit" do
224 site new_resource.site
229 mediawiki_extension "ConfirmEdit" do
230 site new_resource.site
231 template "mw-ext-ConfirmEdit.inc.php.erb"
232 variables :public_key => new_resource.recaptcha_public_key,
233 :private_key => new_resource.recaptcha_private_key
238 mediawiki_extension "Gadgets" do
239 site new_resource.site
243 mediawiki_extension "ImageMap" do
244 site new_resource.site
248 mediawiki_extension "InputBox" do
249 site new_resource.site
253 mediawiki_extension "Interwiki" do
254 site new_resource.site
258 mediawiki_extension "Nuke" do
259 site new_resource.site
263 mediawiki_extension "ParserFunctions" do
264 site new_resource.site
265 template "mw-ext-ParserFunctions.inc.php.erb"
269 mediawiki_extension "PdfHandler" do
270 site new_resource.site
271 template "mw-ext-PdfHandler.inc.php.erb"
275 mediawiki_extension "Poem" do
276 site new_resource.site
280 mediawiki_extension "Renameuser" do
281 site new_resource.site
285 mediawiki_extension "SimpleAntiSpam" do
286 site new_resource.site
291 mediawiki_extension "SpamBlacklist" do
292 site new_resource.site
293 template "mw-ext-SpamBlacklist.inc.php.erb"
297 mediawiki_extension "SyntaxHighlight_GeSHi" do
298 site new_resource.site
299 template "mw-ext-SyntaxHighlight.inc.php.erb"
303 mediawiki_extension "TitleBlacklist" do
304 site new_resource.site
305 template "mw-ext-TitleBlacklist.inc.php.erb"
309 mediawiki_extension "WikiEditor" do
310 site new_resource.site
314 # MediaWiki Language Extension Bundle
315 # FIXME: should automatically resolve tag
316 mw_lang_ext_bundle_tag = "2017.01"
318 mediawiki_extension "Babel" do
319 site new_resource.site
320 template "mw-ext-Babel.inc.php.erb"
321 # tag mw_lang_ext_bundle_tag
322 tag mw_lang_ext_bundle_tag
326 mediawiki_extension "cldr" do
327 site new_resource.site
328 template "mw-ext-cldr.inc.php.erb"
329 tag mw_lang_ext_bundle_tag
333 mediawiki_extension "CleanChanges" do
334 site new_resource.site
335 template "mw-ext-CleanChanges.inc.php.erb"
336 tag mw_lang_ext_bundle_tag
340 mediawiki_extension "LocalisationUpdate" do
341 site new_resource.site
342 template "mw-ext-LocalisationUpdate.inc.php.erb"
343 tag mw_lang_ext_bundle_tag
347 # LocalisationUpdate Update Cron
348 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
349 # cookbook "mediawiki"
350 # source "mediawiki-LocalisationUpdate.cron.erb"
354 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
357 # mediawiki_extension "Translate" do
358 # site new_resource.site
359 # template "mw-ext-Translate.inc.php.erb"
360 # tag mw_lang_ext_bundle_tag
364 mediawiki_extension "UniversalLanguageSelector" do
365 site new_resource.site
366 tag mw_lang_ext_bundle_tag
370 mediawiki_extension "AntiSpoof" do
371 site new_resource.site
372 template "mw-ext-AntiSpoof.inc.php.erb"
376 mediawiki_extension "AbuseFilter" do
377 site new_resource.site
378 template "mw-ext-AbuseFilter.inc.php.erb"
382 mediawiki_extension "CheckUser" do
383 site new_resource.site
384 template "mw-ext-CheckUser.inc.php.erb"
388 mediawiki_extension "DismissableSiteNotice" do
389 site new_resource.site
393 mediawiki_extension "Elastica" do
394 site new_resource.site
398 mediawiki_extension "CirrusSearch" do
399 site new_resource.site
400 template "mw-ext-CirrusSearch.inc.php.erb"
404 mediawiki_extension "osmtaginfo" do
405 site new_resource.site
406 template "mw-ext-osmtaginfo.inc.php.erb"
407 repository "git://github.com/Firefishy/osmtaginfo.git"
412 mediawiki_extension "SimpleMap" do
413 site new_resource.site
414 template "mw-ext-SimpleMap.inc.php.erb"
415 repository "git://github.com/Firefishy/SimpleMap.git"
420 mediawiki_extension "SlippyMap" do
421 site new_resource.site
422 template "mw-ext-SlippyMap.inc.php.erb"
423 repository "git://github.com/Firefishy/SlippyMap.git"
428 mediawiki_extension "Mantle" do
429 site new_resource.site
434 mediawiki_extension "MobileFrontend" do
435 site new_resource.site
436 template "mw-ext-MobileFrontend.inc.php.erb"
440 mediawiki_extension "DisableAccount" do
441 site new_resource.site
442 template "mw-ext-DisableAccount.inc.php.erb"
446 mediawiki_extension "VisualEditor" do
447 site new_resource.site
448 template "mw-ext-VisualEditor.inc.php.erb"
452 cookbook_file "#{site_directory}/cc-wiki.png" do
454 owner node[:mediawiki][:user]
455 group node[:mediawiki][:group]
460 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
462 owner node[:mediawiki][:user]
463 group node[:mediawiki][:group]
468 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
470 owner node[:mediawiki][:user]
471 group node[:mediawiki][:group]
476 ports = new_resource.ssl_enabled ? [80, 443] : [80]
478 ssl_certificate new_resource.site do
479 domains [new_resource.site] + Array(new_resource.aliases)
480 only_if { new_resource.ssl_enabled }
483 apache_site new_resource.site do
485 template "apache.erb"
486 directory site_directory
487 variables :aliases => Array(new_resource.aliases),
488 :private => new_resource.private,
489 :ssl_enabled => new_resource.ssl_enabled,
494 # FIXME: needs to run one
495 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
497 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
498 cwd mediawiki_directory
499 user node[:mediawiki][:user]
500 group node[:mediawiki][:group]
505 mediawiki_directory = "#{site_directory}/w"
507 template "#{mediawiki_directory}/LocalSettings.php" do
509 source "LocalSettings.php.erb"
510 owner node[:mediawiki][:user]
511 group node[:mediawiki][:group]
513 variables :name => new_resource.site,
514 :directory => mediawiki_directory,
515 :database_params => database_params,
516 :mediawiki => mediawiki_params
517 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
520 execute "#{mediawiki_directory}/maintenance/update.php" do
522 command "php maintenance/update.php --quick"
523 cwd mediawiki_directory
524 user node[:mediawiki][:user]
525 group node[:mediawiki][:group]
530 apache_site new_resource.site do
535 declare_resource :directory, site_directory do
540 mysql_database new_resource.database_name do
544 mysql_user "#{new_resource.database_user}@localhost" do
551 new_resource.directory || "/srv/#{new_resource.site}"
555 new_resource.site.tr(".", "_")
560 :host => "localhost",
561 :name => new_resource.database_name,
562 :username => new_resource.database_user,
563 :password => new_resource.database_password
569 :sitename => new_resource.sitename,
570 :metanamespace => new_resource.metanamespace,
571 :logo => new_resource.logo,
572 :email_contact => new_resource.email_contact,
573 :email_sender => new_resource.email_sender,
574 :email_sender_name => new_resource.email_sender_name,
575 :commons => new_resource.commons,
576 :skin => new_resource.skin,
577 :site_notice => new_resource.site_notice,
578 :site_readonly => new_resource.site_readonly,
579 :ssl_enabled => new_resource.ssl_enabled,
580 :extra_file_extensions => new_resource.extra_file_extensions,
581 :private_accounts => new_resource.private_accounts,
582 :private => new_resource.private
588 notifies :reload, "service[apache2]" if reload_apache