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
133 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
135 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
138 declare_resource :directory, "#{mediawiki_directory}/images" do
140 group node[:mediawiki][:group]
144 declare_resource :directory, "#{mediawiki_directory}/cache" do
146 group node[:mediawiki][:group]
150 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
151 user node[:mediawiki][:user]
152 group node[:mediawiki][:group]
156 template "#{mediawiki_directory}/LocalSettings.php" do
158 source "LocalSettings.php.erb"
159 owner node[:mediawiki][:user]
160 group node[:mediawiki][:group]
162 variables :name => new_resource.site,
163 :directory => mediawiki_directory,
164 :database_params => database_params,
165 :mediawiki => mediawiki_params
166 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
169 template "/etc/cron.d/mediawiki-#{cron_name}" do
171 source "mediawiki.cron.erb"
175 variables :name => new_resource.site, :directory => site_directory,
176 :user => node[:mediawiki][:user]
179 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
181 source "mediawiki-backup.cron.erb"
185 variables :name => new_resource.site,
186 :directory => site_directory,
187 :database_params => database_params
190 mediawiki_skin "CologneBlue" do # ~FC005
191 site new_resource.site
195 mediawiki_skin "Modern" do
196 site new_resource.site
200 mediawiki_skin "MonoBook" do
201 site new_resource.site
205 mediawiki_skin "Vector" do
206 site new_resource.site
210 mediawiki_extension "Cite" do
211 site new_resource.site
215 mediawiki_extension "CiteThisPage" do
216 site new_resource.site
220 if new_resource.private_accounts || new_resource.private
221 mediawiki_extension "ConfirmEdit" do
222 site new_resource.site
227 mediawiki_extension "ConfirmEdit" do
228 site new_resource.site
229 template "mw-ext-ConfirmEdit.inc.php.erb"
230 variables :public_key => new_resource.recaptcha_public_key,
231 :private_key => new_resource.recaptcha_private_key
236 mediawiki_extension "Gadgets" do
237 site new_resource.site
241 mediawiki_extension "ImageMap" do
242 site new_resource.site
246 mediawiki_extension "InputBox" do
247 site new_resource.site
251 mediawiki_extension "Interwiki" do
252 site new_resource.site
256 mediawiki_extension "Nuke" do
257 site new_resource.site
261 mediawiki_extension "ParserFunctions" do
262 site new_resource.site
263 template "mw-ext-ParserFunctions.inc.php.erb"
267 mediawiki_extension "PdfHandler" do
268 site new_resource.site
269 template "mw-ext-PdfHandler.inc.php.erb"
273 mediawiki_extension "Poem" do
274 site new_resource.site
278 mediawiki_extension "Renameuser" do
279 site new_resource.site
283 mediawiki_extension "SimpleAntiSpam" do
284 site new_resource.site
289 mediawiki_extension "SpamBlacklist" do
290 site new_resource.site
291 template "mw-ext-SpamBlacklist.inc.php.erb"
295 mediawiki_extension "SyntaxHighlight_GeSHi" do
296 site new_resource.site
297 template "mw-ext-SyntaxHighlight.inc.php.erb"
301 mediawiki_extension "TitleBlacklist" do
302 site new_resource.site
303 template "mw-ext-TitleBlacklist.inc.php.erb"
307 mediawiki_extension "WikiEditor" do
308 site new_resource.site
312 # MediaWiki Language Extension Bundle
313 # FIXME: should automatically resolve tag
314 mw_lang_ext_bundle_tag = "2017.01"
316 mediawiki_extension "Babel" do
317 site new_resource.site
318 template "mw-ext-Babel.inc.php.erb"
319 # tag mw_lang_ext_bundle_tag
320 tag mw_lang_ext_bundle_tag
324 mediawiki_extension "cldr" do
325 site new_resource.site
326 template "mw-ext-cldr.inc.php.erb"
327 tag mw_lang_ext_bundle_tag
331 mediawiki_extension "CleanChanges" do
332 site new_resource.site
333 template "mw-ext-CleanChanges.inc.php.erb"
334 tag mw_lang_ext_bundle_tag
338 mediawiki_extension "LocalisationUpdate" do
339 site new_resource.site
340 template "mw-ext-LocalisationUpdate.inc.php.erb"
341 tag mw_lang_ext_bundle_tag
345 # LocalisationUpdate Update Cron
346 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
347 # cookbook "mediawiki"
348 # source "mediawiki-LocalisationUpdate.cron.erb"
352 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
355 # mediawiki_extension "Translate" do
356 # site new_resource.site
357 # template "mw-ext-Translate.inc.php.erb"
358 # tag mw_lang_ext_bundle_tag
362 mediawiki_extension "UniversalLanguageSelector" do
363 site new_resource.site
364 tag mw_lang_ext_bundle_tag
368 mediawiki_extension "AntiSpoof" do
369 site new_resource.site
370 template "mw-ext-AntiSpoof.inc.php.erb"
374 mediawiki_extension "AbuseFilter" do
375 site new_resource.site
376 template "mw-ext-AbuseFilter.inc.php.erb"
380 mediawiki_extension "CheckUser" do
381 site new_resource.site
382 template "mw-ext-CheckUser.inc.php.erb"
386 mediawiki_extension "DismissableSiteNotice" do
387 site new_resource.site
391 mediawiki_extension "Elastica" do
392 site new_resource.site
396 mediawiki_extension "CirrusSearch" do
397 site new_resource.site
398 template "mw-ext-CirrusSearch.inc.php.erb"
402 mediawiki_extension "osmtaginfo" do
403 site new_resource.site
404 template "mw-ext-osmtaginfo.inc.php.erb"
405 repository "git://github.com/Firefishy/osmtaginfo.git"
410 mediawiki_extension "SimpleMap" do
411 site new_resource.site
412 template "mw-ext-SimpleMap.inc.php.erb"
413 repository "git://github.com/Firefishy/SimpleMap.git"
418 mediawiki_extension "SlippyMap" do
419 site new_resource.site
420 template "mw-ext-SlippyMap.inc.php.erb"
421 repository "git://github.com/Firefishy/SlippyMap.git"
426 mediawiki_extension "Mantle" do
427 site new_resource.site
432 mediawiki_extension "DisableAccount" do
433 site new_resource.site
434 template "mw-ext-DisableAccount.inc.php.erb"
438 mediawiki_extension "VisualEditor" do
439 site new_resource.site
440 template "mw-ext-VisualEditor.inc.php.erb"
444 cookbook_file "#{site_directory}/cc-wiki.png" do
446 owner node[:mediawiki][:user]
447 group node[:mediawiki][:group]
452 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
454 owner node[:mediawiki][:user]
455 group node[:mediawiki][:group]
460 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
462 owner node[:mediawiki][:user]
463 group node[:mediawiki][:group]
468 ssl_certificate new_resource.site do
469 domains [new_resource.site] + Array(new_resource.aliases)
472 apache_site new_resource.site do
474 template "apache.erb"
475 directory site_directory
476 variables :aliases => Array(new_resource.aliases),
477 :private => new_resource.private
481 # FIXME: needs to run one
482 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
484 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
485 cwd mediawiki_directory
486 user node[:mediawiki][:user]
487 group node[:mediawiki][:group]
492 mediawiki_directory = "#{site_directory}/w"
494 template "#{mediawiki_directory}/LocalSettings.php" do
496 source "LocalSettings.php.erb"
497 owner node[:mediawiki][:user]
498 group node[:mediawiki][:group]
500 variables :name => new_resource.site,
501 :directory => mediawiki_directory,
502 :database_params => database_params,
503 :mediawiki => mediawiki_params
504 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
507 execute "#{mediawiki_directory}/maintenance/update.php" do
509 command "php maintenance/update.php --quick"
510 cwd mediawiki_directory
511 user node[:mediawiki][:user]
512 group node[:mediawiki][:group]
517 apache_site new_resource.site do
522 declare_resource :directory, site_directory do
527 mysql_database new_resource.database_name do
531 mysql_user "#{new_resource.database_user}@localhost" do
538 new_resource.directory || "/srv/#{new_resource.site}"
542 new_resource.site.tr(".", "_")
547 :host => "localhost",
548 :name => new_resource.database_name,
549 :username => new_resource.database_user,
550 :password => new_resource.database_password
556 :sitename => new_resource.sitename,
557 :metanamespace => new_resource.metanamespace,
558 :logo => new_resource.logo,
559 :email_contact => new_resource.email_contact,
560 :email_sender => new_resource.email_sender,
561 :email_sender_name => new_resource.email_sender_name,
562 :commons => new_resource.commons,
563 :skin => new_resource.skin,
564 :site_notice => new_resource.site_notice,
565 :site_readonly => new_resource.site_readonly,
566 :extra_file_extensions => new_resource.extra_file_extensions,
567 :private_accounts => new_resource.private_accounts,
568 :private => new_resource.private
574 notifies :reload, "service[apache2]" if reload_apache