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, resources(:execute => "#{mediawiki[:directory]}/maintenance/install.php"), :immediately
129 notifies :run, resources(: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, resources(: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]
170 :database_params => database_params,
171 :mediawiki => mediawiki
173 notifies :run, resources(:execute => "#{mediawiki[:directory]}/maintenance/update.php")
176 template "/etc/cron.d/mediawiki-#{cron_name}" do
178 source "mediawiki.cron.erb"
184 :directory => site_directory,
185 :user => node[:mediawiki][:user]
189 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
191 source "mediawiki-backup.cron.erb"
197 :directory => site_directory,
198 :database_params => database_params
202 #MediaWiki Default Extension
204 mediawiki_extension "Cite" do
206 template "mw-ext-Cite.inc.php.erb"
209 mediawiki_extension "ConfirmEdit" do
211 template "mw-ext-ConfirmEdit.inc.php.erb"
212 variables :public_key => mediawiki[:recaptcha_public],
213 :private_key => mediawiki[:recaptcha_private]
216 mediawiki_extension "Gadgets" do
220 mediawiki_extension "ImageMap" do
224 mediawiki_extension "InputBox" do
228 mediawiki_extension "Interwiki" do
232 # "LocalisationUpdate" part of Language Extension Bundle, bundled per site
234 mediawiki_extension "Nuke" do
238 mediawiki_extension "ParserFunctions" do
240 template "mw-ext-ParserFunctions.inc.php.erb"
243 mediawiki_extension "PdfHandler" do
245 template "mw-ext-PdfHandler.inc.php.erb"
248 mediawiki_extension "Poem" do
252 mediawiki_extension "Renameuser" do
256 mediawiki_extension "SimpleAntiSpam" do
260 mediawiki_extension "SpamBlacklist" do
262 template "mw-ext-SpamBlacklist.inc.php.erb"
265 mediawiki_extension "SyntaxHighlight_GeSHi" do
269 mediawiki_extension "TitleBlacklist" do
271 template "mw-ext-TitleBlacklist.inc.php.erb"
274 mediawiki_extension "WikiEditor" do
278 # MediaWiki Language Extension Bundle
279 #fixme should automatically resolve tag
280 mw_lang_ext_bundle_tag = "2014.09"
282 mediawiki_extension "Babel" do
284 template "mw-ext-Babel.inc.php.erb"
285 tag mw_lang_ext_bundle_tag
288 mediawiki_extension "cldr" do
290 tag mw_lang_ext_bundle_tag
293 mediawiki_extension "CleanChanges" do
295 template "mw-ext-CleanChanges.inc.php.erb"
296 tag mw_lang_ext_bundle_tag
299 mediawiki_extension "LocalisationUpdate" do
301 template "mw-ext-LocalisationUpdate.inc.php.erb"
302 tag mw_lang_ext_bundle_tag
305 #LocalisationUpdate Update Cron
306 #template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
307 # cookbook "mediawiki"
308 # source "mediawiki-LocalisationUpdate.cron.erb"
314 # :directory => site_directory,
315 # :user => node[:mediawiki][:user]
319 #mediawiki_extension "Translate" do
321 # template "mw-ext-Translate.inc.php.erb"
322 # tag mw_lang_ext_bundle_tag
325 mediawiki_extension "UniversalLanguageSelector" do
327 tag mw_lang_ext_bundle_tag
330 # Global Extra Mediawiki Extensions
332 mediawiki_extension "AntiSpoof" do
336 mediawiki_extension "AbuseFilter" do
338 template "mw-ext-AbuseFilter.inc.php.erb"
341 mediawiki_extension "CheckUser" do
343 template "mw-ext-CheckUser.inc.php.erb"
346 mediawiki_extension "DismissableSiteNotice" do
350 mediawiki_extension "Elastica" do
354 mediawiki_extension "CirrusSearch" do
356 template "mw-ext-CirrusSearch.inc.php.erb"
359 #OSM specifc extensions
361 mediawiki_extension "osmtaginfo" do
363 repository "git://github.com/Firefishy/osmtaginfo.git"
366 mediawiki_extension "SimpleMap" do
368 repository "git://github.com/Firefishy/SimpleMap.git"
372 mediawiki_extension "SlippyMap" do
374 repository "git://github.com/Firefishy/SlippyMap.git"
378 cookbook_file "#{site_directory}/cc-wiki.png" do
380 owner node[:mediawiki][:user]
381 group node[:mediawiki][:group]
386 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
388 owner node[:mediawiki][:user]
389 group node[:mediawiki][:group]
394 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
396 owner node[:mediawiki][:user]
397 group node[:mediawiki][:group]
404 template "apache.erb"
405 directory site_directory
408 :mediawiki => mediawiki
410 notifies :reload, "service[apache2]"
413 #Fixme - Needs to run once
414 execute "#{mediawiki[:directory]}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
416 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
417 cwd mediawiki[:directory]
418 user node[:mediawiki][:user]
419 group node[:mediawiki][:group]