#
-# Cookbook Name:: web
-# Definition:: mediawiki_site
+# Cookbook Name:: mediawiki
+# Provider:: mediawiki_site
#
-# Copyright 2012, OpenStreetMap Foundation
+# Copyright 2015, OpenStreetMap Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# limitations under the License.
#
-define :mediawiki_site, :action => [:create, :enable] do
- name = params[:name]
+require "securerandom"
- # /etc/cron.d names cannot contain a dot
- cron_name = name.tr(".", "_")
+include Chef::Mixin::EditFile
- aliases = Array(params[:aliases])
-
- site_directory = params[:directory] || "/srv/#{name}"
-
- database_params = {
- :host => params[:database_host] || "localhost",
- :name => params[:database_name],
- :username => params[:database_username],
- :password => params[:database_password]
- }
-
- mediawiki_repository = "git://github.com/wikimedia/mediawiki-core"
- mediawiki_version = params[:version] || "1.22"
- mediawiki_reference = "refs/heads/REL#{mediawiki_version}".tr(".", "_")
+def whyrun_supported?
+ true
+end
- mediawiki = {
- :directory => "#{site_directory}/w",
- :site => name,
- :sitename => params[:sitename] || "OpenStreetMap Wiki",
- :metanamespace => params[:metanamespace] || "OpenStreetMap",
- :logo => params[:logo] || "$wgStylePath/common/images/wiki.png",
- :email_contact => params[:email_contact] || "",
- :email_sender => params[:email_sender] || "",
- :email_sender_name => params[:email_sender_name] || "MediaWiki Mail",
- :commons => params[:commons] || TRUE,
- :skin => params[:skin] || "vector",
- :site_notice => params[:site_notice] || "",
- :site_readonly => params[:site_readonly] || FALSE,
- :site_admin_user => "Admin",
- :site_admin_pw => params[:admin_password],
- :enable_ssl => params[:enable_ssl] || FALSE,
- :private_accounts => params[:private_accounts] || FALSE,
- :private => params[:private] || FALSE,
- :recaptcha_public => params[:recaptcha_public_key],
- :recaptcha_private => params[:recaptcha_private_key]
- }
+use_inline_resources
- #----------------
+action :create do
+ node.set_unless[:mediawiki][:sites][new_resource.name] = {}
- node.set_unless[:mediawiki][:sites][name] = {}
- node.set[:mediawiki][:sites][name][:site_directory] = site_directory
- node.set[:mediawiki][:sites][name][:directory] = mediawiki[:directory]
- node.set[:mediawiki][:sites][name][:version] = mediawiki_version
- node.set_unless[:mediawiki][:sites][name][:wgSecretKey] = random_password(64)
+ node.set[:mediawiki][:sites][new_resource.name][:directory] = site_directory
+ node.set[:mediawiki][:sites][new_resource.name][:version] = new_resource.version
- #----------------
+ node.set_unless[:mediawiki][:sites][new_resource.name][:wgSecretKey] = SecureRandom.base64(48)
- mysql_user "#{database_params[:username]}@localhost" do
- password database_params[:password]
+ mysql_user "#{new_resource.database_user}@localhost" do
+ password new_resource.database_password
end
- mysql_database database_params[:name] do
- permissions "#{database_params[:username]}@localhost" => :all
+ mysql_database new_resource.database_name do
+ permissions "#{new_resource.database_user}@localhost" => :all
end
+ mediawiki_directory = "#{site_directory}/w"
+
ruby_block "rename-installer-localsettings" do
action :nothing
block do
- ::File.rename("#{mediawiki[:directory]}/LocalSettings.php", "#{mediawiki[:directory]}/LocalSettings-install.php")
+ ::File.rename("#{mediawiki_directory}/LocalSettings.php", "#{mediawiki_directory}/LocalSettings-install.php")
end
end
- execute "#{mediawiki[:directory]}/maintenance/install.php" do
+ execute "#{mediawiki_directory}/maintenance/install.php" do
action :nothing
# Use metanamespace as Site Name to ensure correct set namespace
- 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]}'"
- cwd mediawiki[:directory]
+ 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}'"
+ cwd mediawiki_directory
user node[:mediawiki][:user]
group node[:mediawiki][:group]
not_if do
- File.exist?("#{mediawiki[:directory]}/LocalSettings-install.php")
+ ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
end
notifies :create, "ruby_block[rename-installer-localsettings]", :immediately
end
- execute "#{mediawiki[:directory]}/maintenance/update.php" do
+ execute "#{mediawiki_directory}/maintenance/update.php" do
action :nothing
command "php maintenance/update.php --quick"
- cwd mediawiki[:directory]
+ cwd mediawiki_directory
user node[:mediawiki][:user]
group node[:mediawiki][:group]
end
mode 0775
end
- directory mediawiki[:directory] do
+ directory mediawiki_directory do
owner node[:mediawiki][:user]
group node[:mediawiki][:group]
mode 0775
end
- git mediawiki[:directory] do
+ mediawiki_reference = "refs/heads/REL#{new_resource.version}".tr(".", "_")
+
+ git site_directory do
action :sync
- repository mediawiki_repository
+ repository "git://github.com/wikimedia/mediawiki-core"
reference mediawiki_reference
# depth 1
user node[:mediawiki][:user]
group node[:mediawiki][:group]
- notifies :run, "execute[#{mediawiki[:directory]}/maintenance/install.php]", :immediately
- notifies :run, "execute[#{mediawiki[:directory]}/maintenance/update.php]"
+ notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
+ notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
end
# Safety catch if git doesn't update but install.php hasn't run
ruby_block "catch-installer-localsettings-run" do
+ action :create
block do
#
end
not_if do
- File.exist?("#{mediawiki[:directory]}/LocalSettings-install.php")
+ ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
end
- notifies :run, "execute[#{mediawiki[:directory]}/maintenance/install.php]", :immediately
- action :create
+ notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
end
- directory "#{mediawiki[:directory]}/images" do
+ directory "#{mediawiki_directory}/images" do
owner "www-data"
- group "wiki"
+ group node[:mediawiki][:group]
mode 0775
end
- directory "#{mediawiki[:directory]}/cache" do
+ directory "#{mediawiki_directory}/cache" do
owner "www-data"
- group "wiki"
+ group node[:mediawiki][:group]
mode 0775
end
- directory "#{mediawiki[:directory]}/LocalSettings.d" do
+ directory "#{mediawiki_directory}/LocalSettings.d" do
user node[:mediawiki][:user]
group node[:mediawiki][:group]
mode 0775
end
- template "#{mediawiki[:directory]}/LocalSettings.php" do
+ template "#{mediawiki_directory}/LocalSettings.php" do
cookbook "mediawiki"
source "LocalSettings.php.erb"
owner node[:mediawiki][:user]
group node[:mediawiki][:group]
mode 0664
- variables :name => name, :database_params => database_params, :mediawiki => mediawiki
- notifies :run, "execute[#{mediawiki[:directory]}/maintenance/update.php]"
+ variables :name => new_resource.name,
+ :directory => mediawiki_directory,
+ :database_params => new_resource.database_params,
+ :mediawiki => new_resource.mediawiki_params
+ notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
end
template "/etc/cron.d/mediawiki-#{cron_name}" do
owner "root"
group "root"
mode 0644
- variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
+ variables :name => new_resource.name, :directory => site_directory,
+ :user => node[:mediawiki][:user]
end
template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
owner "root"
group "root"
mode 0700
- variables :name => name, :directory => site_directory, :database_params => database_params
+ variables :name => new_resource.name, :directory => site_directory,
+ :database_params => new_resource.database_params
end
- # MediaWiki Default Extension
-
mediawiki_extension "Cite" do
- site name
+ site new_resource.name
template "mw-ext-Cite.inc.php.erb"
+ update_site false
end
mediawiki_extension "ConfirmEdit" do
- site name
+ site new_resource.name
template "mw-ext-ConfirmEdit.inc.php.erb"
- variables :public_key => mediawiki[:recaptcha_public],
- :private_key => mediawiki[:recaptcha_private]
+ variables :public_key => new_resource.recaptcha_public_key,
+ :private_key => new_resource.recaptcha_private_key
+ update_site false
end
mediawiki_extension "Gadgets" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "ImageMap" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "InputBox" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "Interwiki" do
- site name
+ site new_resource.name
+ update_site false
end
- # "LocalisationUpdate" part of Language Extension Bundle, bundled per site
-
mediawiki_extension "Nuke" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "ParserFunctions" do
- site name
+ site new_resource.name
template "mw-ext-ParserFunctions.inc.php.erb"
+ update_site false
end
mediawiki_extension "PdfHandler" do
- site name
+ site new_resource.name
template "mw-ext-PdfHandler.inc.php.erb"
+ update_site false
end
mediawiki_extension "Poem" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "Renameuser" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "SimpleAntiSpam" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "SpamBlacklist" do
- site name
+ site new_resource.name
template "mw-ext-SpamBlacklist.inc.php.erb"
+ update_site false
end
mediawiki_extension "SyntaxHighlight_GeSHi" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "TitleBlacklist" do
- site name
+ site new_resource.name
template "mw-ext-TitleBlacklist.inc.php.erb"
+ update_site false
end
mediawiki_extension "WikiEditor" do
- site name
+ site new_resource.name
+ update_site false
end
# MediaWiki Language Extension Bundle
mw_lang_ext_bundle_tag = "2014.09"
mediawiki_extension "Babel" do
- site name
+ site new_resource.name
template "mw-ext-Babel.inc.php.erb"
tag mw_lang_ext_bundle_tag
+ update_site false
end
mediawiki_extension "cldr" do
- site name
+ site new_resource.name
tag mw_lang_ext_bundle_tag
+ update_site false
end
mediawiki_extension "CleanChanges" do
- site name
+ site new_resource.name
template "mw-ext-CleanChanges.inc.php.erb"
tag mw_lang_ext_bundle_tag
+ update_site false
end
mediawiki_extension "LocalisationUpdate" do
- site name
+ site new_resource.name
template "mw-ext-LocalisationUpdate.inc.php.erb"
tag mw_lang_ext_bundle_tag
+ update_site false
end
# LocalisationUpdate Update Cron
# end
# mediawiki_extension "Translate" do
- # site name
+ # site new_resource.name
# template "mw-ext-Translate.inc.php.erb"
# tag mw_lang_ext_bundle_tag
+ # update_site false
# end
mediawiki_extension "UniversalLanguageSelector" do
- site name
+ site new_resource.name
tag mw_lang_ext_bundle_tag
+ update_site false
end
- # Global Extra Mediawiki Extensions
-
mediawiki_extension "AntiSpoof" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "AbuseFilter" do
- site name
+ site new_resource.name
template "mw-ext-AbuseFilter.inc.php.erb"
+ update_site false
end
mediawiki_extension "CheckUser" do
- site name
+ site new_resource.name
template "mw-ext-CheckUser.inc.php.erb"
+ update_site false
end
mediawiki_extension "DismissableSiteNotice" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "Elastica" do
- site name
+ site new_resource.name
+ update_site false
end
mediawiki_extension "CirrusSearch" do
- site name
+ site new_resource.name
template "mw-ext-CirrusSearch.inc.php.erb"
+ update_site false
end
- # OSM specifc extensions
-
mediawiki_extension "osmtaginfo" do
- site name
+ site new_resource.name
repository "git://github.com/Firefishy/osmtaginfo.git"
tag "live"
+ update_site false
end
+
mediawiki_extension "SimpleMap" do
- site name
+ site new_resource.name
repository "git://github.com/Firefishy/SimpleMap.git"
tag "live"
+ update_site false
end
mediawiki_extension "SlippyMap" do
- site name
+ site new_resource.name
repository "git://github.com/Firefishy/SlippyMap.git"
tag "live"
+ update_site false
end
cookbook_file "#{site_directory}/cc-wiki.png" do
backup false
end
- apache_site name do
+ apache_site new_resource.name do
cookbook "mediawiki"
template "apache.erb"
directory site_directory
- variables :aliases => aliases, :mediawiki => mediawiki
- notifies :reload, "service[apache2]"
+ variables :aliases => Array(new_resource.aliases),
+ :private => new_resource.private,
+ :ssl_enabled => new_resource.ssl_enabled,
+ :ssl_certificate => new_resource.ssl_certificate,
+ :ssl_certificate_chain => new_resource.ssl_certificate_chain
+ reload_apache false
end
- # FIXME: needs to run once
- execute "#{mediawiki[:directory]}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
+ # FIXME: needs to run one
+ execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
action :nothing
command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
- cwd mediawiki[:directory]
+ cwd mediawiki_directory
user node[:mediawiki][:user]
group node[:mediawiki][:group]
end
end
+
+action :delete do
+ apache_site new_resource.name do
+ action :delete
+ reload_apache false
+ end
+
+ directory site_directory do
+ action :delete
+ recursive true
+ end
+
+ mysql_database new_resource.database_name do
+ action :drop
+ end
+
+ mysql_user "#{new_resource.database_user}@localhost" do
+ action :drop
+ end
+end
+
+def site_directory
+ new_resource.directory || "/srv/#{new_resource.name}"
+end
+
+def cron_name
+ new_resource.name.tr(".", "_")
+end
--- /dev/null
+#
+# Cookbook Name:: mediawiki
+# Resource:: mediawiki_site
+#
+# Copyright 2015, OpenStreetMap Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+actions :create, :delete
+default_action :create
+
+attribute :name, :kind_of => String, :name_attribute => true
+attribute :aliases, :kind_of => [String, Array]
+attribute :directory, :kind_of => String
+attribute :version, :kind_of => String, :default => "1.22"
+attribute :database_name, :kind_of => String, :required => true
+attribute :database_user, :kind_of => String, :required => true
+attribute :database_password, :kind_of => String, :required => true
+attribute :sitename, :kind_of => String, :default => "OpenStreetMap Wiki"
+attribute :metanamespace, :kind_of => String, :default => "OpenStreetMap"
+attribute :logo, :kind_of => String, :default => "$wgStylePath/common/images/wiki.png"
+attribute :email_contact, :kind_of => String, :default => ""
+attribute :email_sender, :kind_of => String, :default => ""
+attribute :email_sender_name, :kind_of => String, :default => "MediaWiki Mail"
+attribute :commons, :kind_of => [TrueClass, FalseClass], :default => true
+attribute :skin, :kind_of => String, :default => "vector"
+attribute :site_notice, :kind_of => String, :default => ""
+attribute :site_readonly, :kind_of => [TrueClass, FalseClass], :default => false
+attribute :admin_user, :kind_of => String, :default => "Admin"
+attribute :admin_password, :kind_of => String, :required => true
+attribute :ssl_enabled, :kind_of => [TrueClass, FalseClass], :default => false
+attribute :ssl_certificate, :kind_of => String
+attribute :ssl_certificate_chain, :kind_of => String
+attribute :private_accounts, :kind_of => [TrueClass, FalseClass], :default => false
+attribute :private, :kind_of => [TrueClass, FalseClass], :default => false
+attribute :recaptcha_public_key, :kind_of => String
+attribute :recaptcha_private_key, :kind_of => String
+attribute :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
+
+def after_created
+ notifies :reload, "service[apache2]" if reload_apache
+end
+
+def database_params
+ {
+ :host => "localhost",
+ :name => database_name,
+ :username => database_user,
+ :password => database_password
+ }
+end
+
+def mediawiki_params
+ {
+ :sitename => sitename,
+ :metanamespace => metanamespace,
+ :logo => logo,
+ :email_contact => email_contact,
+ :email_sender => email_sender,
+ :email_sender_name => email_sender_name,
+ :commons => commons,
+ :skin => skin,
+ :site_notice => site_notice,
+ :site_readonly => site_readonly,
+ :private_accounts => private_accounts,
+ :private => private
+ }
+end
RedirectMatch 301 ^/api\.php$ /w/api.php
RedirectMatch 301 ^/opensearch_desc\.php$ /w/opensearch_desc.php
- Alias /wiki <%= @mediawiki[:directory] %>/index.php
+ Alias /wiki <%= @directory %>/w/index.php
#Support /pagename -> /wiki/pagename
RewriteEngine on
Require all granted
</Directory>
- <Directory <%= @mediawiki[:directory] %>/images/>
+ <Directory <%= @directory %>/w/images/>
# No php execution in the upload area
php_admin_flag engine off
Options -ExecCGI -Includes -Indexes
AllowOverride None
AddType text/plain .html .htm .shtml
-<% if @mediawiki[:private] -%>
+<% if @private -%>
Require all denied
<% end -%>
</Directory>
- <Directory <%= @mediawiki[:directory] %>/images/thumb/>
+ <Directory <%= @directory %>/w/images/thumb/>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
</Directory>
- <Directory <%= @mediawiki[:directory] %>/maintenance/>
+ <Directory <%= @directory %>/w/maintenance/>
Require all denied
</Directory>
- <Files <%= @mediawiki[:directory] %>/LocalSettings.php>
+ <Files <%= @directory %>/w/LocalSettings.php>
Require all denied
</Files>
- <Directory <%= @mediawiki[:directory] %>/cache/>
+ <Directory <%= @directory %>/w/cache/>
Options -ExecCGI -Includes -Indexes
AllowOverride None
AddType text/plain .html .htm .shtml
Require all denied
</Files>
</VirtualHost>
-<% if @mediawiki[:enable_ssl] -%>
+<% if @ssl_enabled -%>
<VirtualHost *:443>
ServerName <%= @name %>
<% @aliases.each do |alias_name| -%>
RedirectMatch 301 ^/api\.php$ /w/api.php
RedirectMatch 301 ^/opensearch_desc\.php$ /w/opensearch_desc.php
- Alias /wiki <%= @mediawiki[:directory] %>/index.php
+ Alias /wiki <%= @directory %>/w/index.php
#Support /pagename -> /wiki/pagename
RewriteEngine on
Require all granted
</Directory>
- <Directory <%= @mediawiki[:directory] %>/images/>
+ <Directory <%= @directory %>/w/images/>
# No php execution in the upload area
php_admin_flag engine off
Options -ExecCGI -Includes -Indexes
AllowOverride None
-<% if @mediawiki[:private] -%>
+<% if @private -%>
Require all denied
<% end -%>
</Directory>
- <Directory <%= @mediawiki[:directory] %>/images/thumb/>
+ <Directory <%= @directory %>/w/images/thumb/>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
</Directory>
- <Directory <%= @mediawiki[:directory] %>/maintenance/>
+ <Directory <%= @directory %>/w/maintenance/>
Require all denied
</Directory>
- <Files <%= @mediawiki[:directory] %>/LocalSettings.php>
+ <Files <%= @directory %>/w/LocalSettings.php>
Require all denied
</Files>
- <Directory <%= @mediawiki[:directory] %>/images/>
+ <Directory <%= @directory %>/w/images/>
Options -ExecCGI -Includes -Indexes
AllowOverride None
AddType text/plain .html .htm .shtml
php_admin_flag engine off
</Directory>
- <Directory <%= @mediawiki[:directory] %>/cache/>
+ <Directory <%= @directory %>/w/cache/>
Options -ExecCGI -Includes -Indexes
AllowOverride None
AddType text/plain .html .htm .shtml