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.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 :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 ssl_certificate new_resource.site do
477 domains [new_resource.site] + Array(new_resource.aliases)
478 only_if { new_resource.ssl_enabled }
481 apache_site new_resource.site do
483 template "apache.erb"
484 directory site_directory
485 variables :aliases => Array(new_resource.aliases),
486 :private => new_resource.private,
487 :ssl_enabled => new_resource.ssl_enabled
491 # FIXME: needs to run one
492 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
494 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
495 cwd mediawiki_directory
496 user node[:mediawiki][:user]
497 group node[:mediawiki][:group]
502 mediawiki_directory = "#{site_directory}/w"
504 template "#{mediawiki_directory}/LocalSettings.php" do
506 source "LocalSettings.php.erb"
507 owner node[:mediawiki][:user]
508 group node[:mediawiki][:group]
510 variables :name => new_resource.site,
511 :directory => mediawiki_directory,
512 :database_params => database_params,
513 :mediawiki => mediawiki_params
514 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
517 execute "#{mediawiki_directory}/maintenance/update.php" do
519 command "php maintenance/update.php --quick"
520 cwd mediawiki_directory
521 user node[:mediawiki][:user]
522 group node[:mediawiki][:group]
527 apache_site new_resource.site do
532 declare_resource :directory, site_directory do
537 mysql_database new_resource.database_name do
541 mysql_user "#{new_resource.database_user}@localhost" do
548 new_resource.directory || "/srv/#{new_resource.site}"
552 new_resource.site.tr(".", "_")
557 :host => "localhost",
558 :name => new_resource.database_name,
559 :username => new_resource.database_user,
560 :password => new_resource.database_password
566 :sitename => new_resource.sitename,
567 :metanamespace => new_resource.metanamespace,
568 :logo => new_resource.logo,
569 :email_contact => new_resource.email_contact,
570 :email_sender => new_resource.email_sender,
571 :email_sender_name => new_resource.email_sender_name,
572 :commons => new_resource.commons,
573 :skin => new_resource.skin,
574 :site_notice => new_resource.site_notice,
575 :site_readonly => new_resource.site_readonly,
576 :ssl_enabled => new_resource.ssl_enabled,
577 :extra_file_extensions => new_resource.extra_file_extensions,
578 :private_accounts => new_resource.private_accounts,
579 :private => new_resource.private
585 notifies :reload, "service[apache2]" if reload_apache