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.
22 default_action :create
24 property :site, :kind_of => String, :name_property => true
25 property :aliases, :kind_of => [String, Array]
26 property :version, :kind_of => String, :default => "1.39"
27 property :database_name, :kind_of => String, :required => true
28 property :database_user, :kind_of => String, :required => [:create, :update]
29 property :database_password, :kind_of => String, :required => [:create, :update]
30 property :sitename, :kind_of => String, :default => "OpenStreetMap Wiki"
31 property :metanamespace, :kind_of => String, :default => "OpenStreetMap"
32 property :logo, :kind_of => String, :default => "$wgStylePath/common/images/wiki.png"
33 property :email_contact, :kind_of => String, :default => ""
34 property :email_sender, :kind_of => String, :default => ""
35 property :email_sender_name, :kind_of => String, :default => "MediaWiki Mail"
36 property :commons, :kind_of => [TrueClass, FalseClass], :default => true
37 property :skin, :kind_of => String, :default => "vector"
38 property :site_notice, :kind_of => [String, TrueClass, FalseClass], :default => false
39 property :site_readonly, :kind_of => [String, TrueClass, FalseClass], :default => false
40 property :admin_user, :kind_of => String, :default => "Admin"
41 property :admin_password, :kind_of => String, :required => [:create]
42 property :private_accounts, :kind_of => [TrueClass, FalseClass], :default => false
43 property :private_site, :kind_of => [TrueClass, FalseClass], :default => false
44 property :hcaptcha_public_key, :kind_of => String, :default => ""
45 property :hcaptcha_private_key, :kind_of => String, :default => ""
46 property :extra_file_extensions, :kind_of => [String, Array], :default => []
47 property :fpm_max_children, :kind_of => Integer, :default => 5
48 property :fpm_start_servers, :kind_of => Integer, :default => 2
49 property :fpm_min_spare_servers, :kind_of => Integer, :default => 1
50 property :fpm_max_spare_servers, :kind_of => Integer, :default => 3
51 property :fpm_request_terminate_timeout, :kind_of => Integer, :default => 300
52 property :fpm_prometheus_port, :kind_of => Integer
53 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
56 node.default[:mediawiki][:sites][new_resource.site] = {
57 :directory => site_directory,
58 :version => new_resource.version
61 mysql_user "#{new_resource.database_user}@localhost" do
62 password new_resource.database_password
66 mysql_database new_resource.database_name do
67 permissions "#{new_resource.database_user}@localhost" => :all
70 mediawiki_directory = "#{site_directory}/w"
72 declare_resource :directory, site_directory do
73 owner node[:mediawiki][:user]
74 group node[:mediawiki][:group]
78 declare_resource :directory, mediawiki_directory do
79 owner node[:mediawiki][:user]
80 group node[:mediawiki][:group]
84 git mediawiki_directory do
86 repository "https://gerrit.wikimedia.org/r/mediawiki/core.git"
87 revision mediawiki_reference
89 user node[:mediawiki][:user]
90 group node[:mediawiki][:group]
93 template "#{mediawiki_directory}/composer.local.json" do
95 source "composer.local.json.erb"
96 owner node[:mediawiki][:user]
97 group node[:mediawiki][:group]
101 execute "#{mediawiki_directory}/composer.json" do
102 command "composer update --no-dev"
103 cwd mediawiki_directory
104 user node[:mediawiki][:user]
105 group node[:mediawiki][:group]
106 environment "COMPOSER_HOME" => site_directory
107 not_if { ::File.exist?("#{mediawiki_directory}/composer.lock") }
110 execute "#{mediawiki_directory}/maintenance/install.php" do
111 # Use metanamespace as Site Name to ensure correct set namespace
112 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}'"
113 cwd mediawiki_directory
114 user node[:mediawiki][:user]
115 group node[:mediawiki][:group]
116 not_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
119 declare_resource :directory, "#{mediawiki_directory}/images" do
121 group node[:mediawiki][:group]
125 declare_resource :directory, "#{mediawiki_directory}/cache" do
127 group node[:mediawiki][:group]
131 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
132 user node[:mediawiki][:user]
133 group node[:mediawiki][:group]
137 template "#{mediawiki_directory}/LocalSettings.php" do
139 source "LocalSettings.php.erb"
140 owner node[:mediawiki][:user]
141 group node[:mediawiki][:group]
143 variables :name => new_resource.site,
144 :directory => mediawiki_directory,
145 :database_params => database_params,
146 :mediawiki => mediawiki_params,
147 :secret_key => secret_key
150 service "mediawiki-sitemap@#{new_resource.site}.timer" do
151 action [:enable, :start]
152 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
155 service "mediawiki-jobs@#{new_resource.site}.timer" do
156 action [:enable, :start]
157 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
160 service "mediawiki-email-jobs@#{new_resource.site}.timer" do
161 action [:enable, :start]
162 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
165 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
167 source "mediawiki-backup.cron.erb"
171 variables :name => new_resource.site,
172 :directory => site_directory,
173 :database_params => database_params
174 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
177 # MobileFrontend extension is required by MinervaNeue skin
178 mediawiki_extension "MobileFrontend" do
179 site new_resource.site
180 template "mw-ext-MobileFrontend.inc.php.erb"
184 # MobileFrontend extension is required by MinervaNeue skin
185 mediawiki_skin "MinervaNeue" do
186 site new_resource.site
191 mediawiki_skin "CologneBlue" do
192 site new_resource.site
197 mediawiki_skin "Modern" do
198 site new_resource.site
203 mediawiki_skin "MonoBook" do
204 site new_resource.site
209 mediawiki_skin "Vector" do
210 site new_resource.site
215 mediawiki_extension "Cite" do
216 site new_resource.site
220 mediawiki_extension "CiteThisPage" do
221 site new_resource.site
225 if new_resource.private_accounts || new_resource.private_site
226 mediawiki_extension "ConfirmEdit" do
227 site new_resource.site
232 mediawiki_extension "ConfirmEdit" do
233 site new_resource.site
234 template "mw-ext-ConfirmEdit.inc.php.erb"
235 variables :public_key => new_resource.hcaptcha_public_key,
236 :private_key => new_resource.hcaptcha_private_key
241 mediawiki_extension "Gadgets" do
242 site new_resource.site
246 mediawiki_extension "ImageMap" do
247 site new_resource.site
251 mediawiki_extension "InputBox" do
252 site new_resource.site
256 mediawiki_extension "Interwiki" do
257 site new_resource.site
258 template "mw-ext-Interwiki.inc.php.erb"
262 mediawiki_extension "Nuke" do
263 site new_resource.site
267 mediawiki_extension "ParserFunctions" do
268 site new_resource.site
269 template "mw-ext-ParserFunctions.inc.php.erb"
273 mediawiki_extension "PdfHandler" do
274 site new_resource.site
275 template "mw-ext-PdfHandler.inc.php.erb"
279 mediawiki_extension "Poem" do
280 site new_resource.site
284 mediawiki_extension "Renameuser" do
285 site new_resource.site
289 mediawiki_extension "SimpleAntiSpam" do
290 site new_resource.site
295 mediawiki_extension "SpamBlacklist" do
296 site new_resource.site
297 template "mw-ext-SpamBlacklist.inc.php.erb"
301 mediawiki_extension "SyntaxHighlight_GeSHi" do
302 site new_resource.site
303 template "mw-ext-SyntaxHighlight.inc.php.erb"
307 mediawiki_extension "TitleBlacklist" do
308 site new_resource.site
309 template "mw-ext-TitleBlacklist.inc.php.erb"
313 mediawiki_extension "WikiEditor" do
314 site new_resource.site
318 mediawiki_extension "Babel" do
319 site new_resource.site
320 template "mw-ext-Babel.inc.php.erb"
324 mediawiki_extension "CategoryTree" do
325 site new_resource.site
329 mediawiki_extension "cldr" do
330 site new_resource.site
331 template "mw-ext-cldr.inc.php.erb"
335 mediawiki_extension "CleanChanges" do
336 site new_resource.site
337 template "mw-ext-CleanChanges.inc.php.erb"
341 mediawiki_extension "LocalisationUpdate" do
342 site new_resource.site
343 template "mw-ext-LocalisationUpdate.inc.php.erb"
347 # mediawiki_extension "Translate" do
348 # site new_resource.site
349 # template "mw-ext-Translate.inc.php.erb"
353 mediawiki_extension "UniversalLanguageSelector" do
354 site new_resource.site
355 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
359 mediawiki_extension "AntiSpoof" do
360 site new_resource.site
361 template "mw-ext-AntiSpoof.inc.php.erb"
365 mediawiki_extension "AbuseFilter" do
366 site new_resource.site
367 template "mw-ext-AbuseFilter.inc.php.erb"
371 mediawiki_extension "CheckUser" do
372 site new_resource.site
373 template "mw-ext-CheckUser.inc.php.erb"
377 mediawiki_extension "DismissableSiteNotice" do
378 site new_resource.site
382 mediawiki_extension "Elastica" do
383 site new_resource.site
387 mediawiki_extension "CirrusSearch" do
388 site new_resource.site
389 template "mw-ext-CirrusSearch.inc.php.erb"
393 mediawiki_extension "osmtaginfo" do
394 site new_resource.site
395 repository "https://github.com/openstreetmap/osmtaginfo.git"
400 mediawiki_extension "OSMCALWikiWidget" do
401 site new_resource.site
402 repository "https://github.com/thomersch/OSMCALWikiWidget.git"
407 mediawiki_extension "DisableAccount" do
408 site new_resource.site
409 template "mw-ext-DisableAccount.inc.php.erb"
413 mediawiki_extension "VisualEditor" do
414 site new_resource.site
415 template "mw-ext-VisualEditor.inc.php.erb"
416 variables :version => new_resource.version
420 mediawiki_extension "TemplateData" do
421 site new_resource.site
425 if new_resource.commons
426 mediawiki_extension "QuickInstantCommons" do
427 site new_resource.site
431 mediawiki_extension "QuickInstantCommons" do
432 site new_resource.site
438 cookbook_file "#{site_directory}/cc-wiki.png" do
440 owner node[:mediawiki][:user]
441 group node[:mediawiki][:group]
446 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
448 owner node[:mediawiki][:user]
449 group node[:mediawiki][:group]
454 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
456 owner node[:mediawiki][:user]
457 group node[:mediawiki][:group]
462 ssl_certificate new_resource.site do
463 domains [new_resource.site] + Array(new_resource.aliases)
466 php_fpm new_resource.site do
467 pm_max_children new_resource.fpm_max_children
468 pm_start_servers new_resource.fpm_start_servers
469 pm_min_spare_servers new_resource.fpm_min_spare_servers
470 pm_max_spare_servers new_resource.fpm_max_spare_servers
471 request_terminate_timeout new_resource.fpm_request_terminate_timeout
472 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
473 php_values "memory_limit" => "500M",
474 "max_execution_time" => "240",
475 "upload_max_filesize" => "70M",
476 "post_max_size" => "100M"
477 prometheus_port new_resource.fpm_prometheus_port
480 apache_site new_resource.site do
482 template "apache.erb"
483 directory site_directory
484 variables :aliases => Array(new_resource.aliases),
485 :private_site => new_resource.private_site
489 # FIXME: needs to run one
490 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
492 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
493 cwd mediawiki_directory
494 user node[:mediawiki][:user]
495 group node[:mediawiki][:group]
500 mediawiki_directory = "#{site_directory}/w"
502 execute "#{mediawiki_directory}/composer.json" do
503 command "composer update --no-dev"
504 cwd mediawiki_directory
505 user node[:mediawiki][:user]
506 group node[:mediawiki][:group]
507 environment "COMPOSER_HOME" => site_directory
510 template "#{mediawiki_directory}/LocalSettings.php" do
512 source "LocalSettings.php.erb"
513 owner node[:mediawiki][:user]
514 group node[:mediawiki][:group]
516 variables :name => new_resource.site,
517 :directory => mediawiki_directory,
518 :database_params => database_params,
519 :mediawiki => mediawiki_params,
520 :secret_key => secret_key
523 execute "#{mediawiki_directory}/maintenance/update.php" do
525 command "php maintenance/update.php --quick"
526 cwd mediawiki_directory
527 user node[:mediawiki][:user]
528 group node[:mediawiki][:group]
534 apache_site new_resource.site do
539 declare_resource :directory, site_directory do
544 mysql_database new_resource.database_name do
548 mysql_user "#{new_resource.database_user}@localhost" do
554 include OpenStreetMap::Mixin::PersistentToken
557 "/srv/#{new_resource.site}"
560 def mediawiki_reference
561 shell_out!("git", "ls-remote", "--refs", "--sort=-version:refname",
562 "https://gerrit.wikimedia.org/r/mediawiki/core.git",
563 "refs/tags/#{new_resource.version}.*")
572 new_resource.site.tr(".", "_")
577 :host => "localhost",
578 :name => new_resource.database_name,
579 :username => new_resource.database_user,
580 :password => new_resource.database_password
586 :sitename => new_resource.sitename,
587 :metanamespace => new_resource.metanamespace,
588 :logo => new_resource.logo,
589 :email_contact => new_resource.email_contact,
590 :email_sender => new_resource.email_sender,
591 :email_sender_name => new_resource.email_sender_name,
592 :commons => new_resource.commons,
593 :skin => new_resource.skin,
594 :site_notice => new_resource.site_notice,
595 :site_readonly => new_resource.site_readonly,
596 :extra_file_extensions => new_resource.extra_file_extensions,
597 :private_accounts => new_resource.private_accounts,
598 :private_site => new_resource.private_site
603 persistent_token("mediawiki", new_resource.site, "wgSecretKey")
608 notifies :update, "mediawiki_site[#{site}]"
609 notifies :reload, "service[apache2]" if reload_apache