3 # Definition:: mediawiki_site
5 # Copyright 2012, 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 define :mediawiki_site, :action => [:create, :enable] do
23 # /etc/cron.d names cannot contain a dot
24 cron_name = name.tr(".", "_")
26 aliases = Array(params[:aliases])
28 site_directory = params[:directory] || "/srv/#{name}"
31 :host => params[:database_host] || "localhost",
32 :name => params[:database_name],
33 :username => params[:database_username],
34 :password => params[:database_password]
37 mediawiki_repository = "git://github.com/wikimedia/mediawiki-core"
38 mediawiki_version = params[:version] || "1.22"
39 mediawiki_reference = "refs/heads/REL#{mediawiki_version}".tr(".", "_")
42 :directory => "#{site_directory}/w",
44 :sitename => params[:sitename] || "OpenStreetMap Wiki",
45 :metanamespace => params[:metanamespace] || "OpenStreetMap",
46 :logo => params[:logo] || "$wgStylePath/common/images/wiki.png",
47 :email_contact => params[:email_contact] || "",
48 :email_sender => params[:email_sender] || "",
49 :email_sender_name => params[:email_sender_name] || "MediaWiki Mail",
50 :commons => params[:commons] || TRUE,
51 :skin => params[:skin] || "vector",
52 :site_notice => params[:site_notice] || "",
53 :site_readonly => params[:site_readonly] || FALSE,
54 :site_admin_user => "Admin",
55 :site_admin_pw => params[:admin_password],
56 :enable_ssl => params[:enable_ssl] || FALSE,
57 :private_accounts => params[:private_accounts] || FALSE,
58 :private => params[:private] || FALSE,
59 :recaptcha_public => params[:recaptcha_public_key],
60 :recaptcha_private => params[:recaptcha_private_key]
65 node.set_unless[:mediawiki][:sites][name] = {}
66 node.set[:mediawiki][:sites][name][:site_directory] = site_directory
67 node.set[:mediawiki][:sites][name][:directory] = mediawiki[:directory]
68 node.set[:mediawiki][:sites][name][:version] = mediawiki_version
69 node.set_unless[:mediawiki][:sites][name][:wgSecretKey] = random_password(64)
73 mysql_user "#{database_params[:username]}@localhost" do
74 password database_params[:password]
77 mysql_database database_params[:name] do
78 permissions "#{database_params[:username]}@localhost" => :all
81 ruby_block "rename-installer-localsettings" do
84 ::File.rename("#{mediawiki[:directory]}/LocalSettings.php", "#{mediawiki[:directory]}/LocalSettings-install.php")
88 execute "#{mediawiki[:directory]}/maintenance/install.php" do
90 # Use metanamespace as Site Name to ensure correct set namespace
91 command "php maintenance/install.php --server '#{name}' --dbtype 'mysql' --dbname '#{database_params[:name]}' --dbuser '#{database_params[:username]}' --dbpass '#{database_params[:password]}' --dbserver '#{database_params[:host]}' --scriptpath /w --pass '#{mediawiki[:site_admin_pw]}' '#{mediawiki[:metanamespace]}' '#{mediawiki[:site_admin_user]}'"
92 cwd mediawiki[:directory]
93 user node[:mediawiki][:user]
94 group node[:mediawiki][:group]
96 File.exist?("#{mediawiki[:directory]}/LocalSettings-install.php")
98 notifies :create, "ruby_block[rename-installer-localsettings]", :immediately
101 execute "#{mediawiki[:directory]}/maintenance/update.php" do
103 command "php maintenance/update.php --quick"
104 cwd mediawiki[:directory]
105 user node[:mediawiki][:user]
106 group node[:mediawiki][:group]
109 directory site_directory do
110 owner node[:mediawiki][:user]
111 group node[:mediawiki][:group]
115 directory mediawiki[:directory] do
116 owner node[:mediawiki][:user]
117 group node[:mediawiki][:group]
121 git mediawiki[:directory] do
123 repository mediawiki_repository
124 reference mediawiki_reference
126 user node[:mediawiki][:user]
127 group node[:mediawiki][:group]
128 notifies :run, "execute[#{mediawiki[:directory]}/maintenance/install.php]", :immediately
129 notifies :run, "execute[#{mediawiki[:directory]}/maintenance/update.php]"
132 # Safety catch if git doesn't update but install.php hasn't run
133 ruby_block "catch-installer-localsettings-run" do
138 File.exist?("#{mediawiki[:directory]}/LocalSettings-install.php")
140 notifies :run, "execute[#{mediawiki[:directory]}/maintenance/install.php]", :immediately
144 directory "#{mediawiki[:directory]}/images" do
150 directory "#{mediawiki[:directory]}/cache" do
156 directory "#{mediawiki[:directory]}/LocalSettings.d" do
157 user node[:mediawiki][:user]
158 group node[:mediawiki][:group]
162 template "#{mediawiki[:directory]}/LocalSettings.php" do
164 source "LocalSettings.php.erb"
165 owner node[:mediawiki][:user]
166 group node[:mediawiki][:group]
168 variables :name => name, :database_params => database_params, :mediawiki => mediawiki
169 notifies :run, "execute[#{mediawiki[:directory]}/maintenance/update.php]"
172 template "/etc/cron.d/mediawiki-#{cron_name}" do
174 source "mediawiki.cron.erb"
178 variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
181 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
183 source "mediawiki-backup.cron.erb"
187 variables :name => name, :directory => site_directory, :database_params => database_params
190 # MediaWiki Default Extension
192 mediawiki_extension "Cite" do
194 template "mw-ext-Cite.inc.php.erb"
197 mediawiki_extension "ConfirmEdit" do
199 template "mw-ext-ConfirmEdit.inc.php.erb"
200 variables :public_key => mediawiki[:recaptcha_public],
201 :private_key => mediawiki[:recaptcha_private]
204 mediawiki_extension "Gadgets" do
208 mediawiki_extension "ImageMap" do
212 mediawiki_extension "InputBox" do
216 mediawiki_extension "Interwiki" do
220 # "LocalisationUpdate" part of Language Extension Bundle, bundled per site
222 mediawiki_extension "Nuke" do
226 mediawiki_extension "ParserFunctions" do
228 template "mw-ext-ParserFunctions.inc.php.erb"
231 mediawiki_extension "PdfHandler" do
233 template "mw-ext-PdfHandler.inc.php.erb"
236 mediawiki_extension "Poem" do
240 mediawiki_extension "Renameuser" do
244 mediawiki_extension "SimpleAntiSpam" do
248 mediawiki_extension "SpamBlacklist" do
250 template "mw-ext-SpamBlacklist.inc.php.erb"
253 mediawiki_extension "SyntaxHighlight_GeSHi" do
257 mediawiki_extension "TitleBlacklist" do
259 template "mw-ext-TitleBlacklist.inc.php.erb"
262 mediawiki_extension "WikiEditor" do
266 # MediaWiki Language Extension Bundle
267 # FIXME: should automatically resolve tag
268 mw_lang_ext_bundle_tag = "2014.09"
270 mediawiki_extension "Babel" do
272 template "mw-ext-Babel.inc.php.erb"
273 tag mw_lang_ext_bundle_tag
276 mediawiki_extension "cldr" do
278 tag mw_lang_ext_bundle_tag
281 mediawiki_extension "CleanChanges" do
283 template "mw-ext-CleanChanges.inc.php.erb"
284 tag mw_lang_ext_bundle_tag
287 mediawiki_extension "LocalisationUpdate" do
289 template "mw-ext-LocalisationUpdate.inc.php.erb"
290 tag mw_lang_ext_bundle_tag
293 # LocalisationUpdate Update Cron
294 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
295 # cookbook "mediawiki"
296 # source "mediawiki-LocalisationUpdate.cron.erb"
300 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
303 # mediawiki_extension "Translate" do
305 # template "mw-ext-Translate.inc.php.erb"
306 # tag mw_lang_ext_bundle_tag
309 mediawiki_extension "UniversalLanguageSelector" do
311 tag mw_lang_ext_bundle_tag
314 # Global Extra Mediawiki Extensions
316 mediawiki_extension "AntiSpoof" do
320 mediawiki_extension "AbuseFilter" do
322 template "mw-ext-AbuseFilter.inc.php.erb"
325 mediawiki_extension "CheckUser" do
327 template "mw-ext-CheckUser.inc.php.erb"
330 mediawiki_extension "DismissableSiteNotice" do
334 mediawiki_extension "Elastica" do
338 mediawiki_extension "CirrusSearch" do
340 template "mw-ext-CirrusSearch.inc.php.erb"
343 # OSM specifc extensions
345 mediawiki_extension "osmtaginfo" do
347 repository "git://github.com/Firefishy/osmtaginfo.git"
350 mediawiki_extension "SimpleMap" do
352 repository "git://github.com/Firefishy/SimpleMap.git"
356 mediawiki_extension "SlippyMap" do
358 repository "git://github.com/Firefishy/SlippyMap.git"
362 cookbook_file "#{site_directory}/cc-wiki.png" do
364 owner node[:mediawiki][:user]
365 group node[:mediawiki][:group]
370 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
372 owner node[:mediawiki][:user]
373 group node[:mediawiki][:group]
378 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
380 owner node[:mediawiki][:user]
381 group node[:mediawiki][:group]
388 template "apache.erb"
389 directory site_directory
390 variables :aliases => aliases, :mediawiki => mediawiki
391 notifies :reload, "service[apache2]"
394 # FIXME: needs to run once
395 execute "#{mediawiki[:directory]}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
397 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
398 cwd mediawiki[:directory]
399 user node[:mediawiki][:user]
400 group node[:mediawiki][:group]