+++ /dev/null
-#
-# Cookbook Name:: mediawiki
-# Definition:: mediawiki_extension
-#
-# Copyright 2013, 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.
-#
-
-define :mediawiki_extension, :action => [:enable], :variables => {} do
- name = params[:name]
- site = params[:site]
- mediawiki_directory = node[:mediawiki][:sites][site][:directory]
- extension_directory = "#{mediawiki_directory}/extensions/#{name}"
- source = params[:source]
- template = params[:template]
- template_variables = params[:variables]
-
- if source
- remote_directory extension_directory do
- cookbook "mediawiki"
- source source
- owner node[:mediawiki][:user]
- group node[:mediawiki][:group]
- mode 0755
- files_owner node[:mediawiki][:user]
- files_group node[:mediawiki][:group]
- files_mode 0755
- end
- else
- repository = params[:repository] || "git://github.com/wikimedia/mediawiki-extensions-#{name}.git"
- version = params[:version] || node[:mediawiki][:sites][site][:version]
- tag = params[:tag]
- if tag
- reference = "refs/tags/#{tag}"
- else
- reference = "refs/heads/REL#{version}".tr(".", "_")
- end
-
- git extension_directory do
- action :sync
- repository repository
- reference reference
- # depth 1
- enable_submodules true
- user node[:mediawiki][:user]
- group node[:mediawiki][:group]
- ignore_failure repository.start_with?("git://github.com/wikimedia/mediawiki-extensions")
- notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
- end
- end
-
- if template # ~FC023
- template "#{mediawiki_directory}/LocalSettings.d/Ext-#{name}.inc.php" do
- cookbook "mediawiki"
- source template
- user node[:mediawiki][:user]
- group node[:mediawiki][:group]
- mode 0664
- variables template_variables
- notifies :create, "template[#{mediawiki_directory}/LocalSettings.php]"
- end
- end
-
- file "#{mediawiki_directory}/LocalSettings.d/Ext-#{name}.inc.php" do
- action :create_if_missing
- user node[:mediawiki][:user]
- group node[:mediawiki][:group]
- mode 0664
- content "<?php require_once('#{extension_directory}/#{name}.php');\n"
- only_if { File.exist?("#{extension_directory}/#{name}.php") }
- notifies :create, "template[#{mediawiki_directory}/LocalSettings.php]"
- end
-end
--- /dev/null
+#
+# Cookbook Name:: mediawiki
+# Provider:: mediawiki_extension
+#
+# 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.
+#
+
+def whyrun_supported?
+ true
+end
+
+use_inline_resources
+
+action :create do
+ if new_resource.source
+ remote_directory extension_directory do
+ cookbook "mediawiki"
+ source new_resource.source
+ owner node[:mediawiki][:user]
+ group node[:mediawiki][:group]
+ mode 0755
+ files_owner node[:mediawiki][:user]
+ files_group node[:mediawiki][:group]
+ files_mode 0755
+ end
+ else
+ extension_repository = new_resource.repository || default_repository
+ extension_reference = if new_resource.tag
+ "refs/tags/#{new_resource.tag}"
+ else
+ "refs/heads/REL#{extension_version}".tr(".", "_")
+ end
+
+ git extension_directory do
+ action :sync
+ repository extension_repository
+ reference extension_reference
+ enable_submodules true
+ user node[:mediawiki][:user]
+ group node[:mediawiki][:group]
+ ignore_failure extension_repository.start_with?("git://github.com/wikimedia/mediawiki-extensions")
+ end
+ end
+
+ if new_resource.template # ~FC023
+ template "#{site_directory}/LocalSettings.d/Ext-#{new_resource.name}.inc.php" do
+ cookbook "mediawiki"
+ source new_resource.template
+ user node[:mediawiki][:user]
+ group node[:mediawiki][:group]
+ mode 0664
+ variables new_resource.variables
+ end
+ end
+
+ extension_script = "#{extension_directory}/#{new_resource.name}.php"
+
+ file "#{site_directory}/LocalSettings.d/Ext-#{new_resource.name}.inc.php" do
+ action :create
+ content "<?php require_once('#{extension_script}');\n"
+ user node[:mediawiki][:user]
+ group node[:mediawiki][:group]
+ mode 0664
+ only_if { ::File.exist?(extension_script) }
+ end
+end
+
+action :delete do
+ directory extension_directory do
+ action :delete
+ recursive true
+ end
+
+ if new_resource.template # ~FC023
+ file "#{site_directory}/LocalSettings.d/Ext-#{new_resource.name}.inc.php" do
+ action :delete
+ end
+ end
+
+ file "#{site_directory}/LocalSettings.d/Ext-#{new_resource.name}.inc.php" do
+ action :delete
+ end
+end
+
+private
+
+def site_directory
+ node[:mediawiki][:sites][new_resource.site][:directory]
+end
+
+def extension_directory
+ "#{site_directory}/extensions/#{new_resource.name}"
+end
+
+def extension_version
+ new_resource.version || node[:mediawiki][:sites][new_resource.site][:version]
+end
+
+def default_repository
+ "git://github.com/wikimedia/mediawiki-extensions-#{new_resource.name}.git"
+end
--- /dev/null
+#
+# Cookbook Name:: mediawiki
+# Resource:: mediawiki_extension
+#
+# 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 :site, :kind_of => String, :required => true
+attribute :source, :kind_of => String
+attribute :template, :kind_of => String
+attribute :variables, :kind_of => Hash, :default => {}
+attribute :version, :kind_of => String
+attribute :repository, :kind_of => String
+attribute :tag, :kind_of => String
+attribute :update_site, :kind_of => [TrueClass, FalseClass], :default => false
+
+def after_created
+ if update_site
+ notifies :update, "mediawik_site[site]"
+ else
+ site_directory = node[:mediawiki][:sites][site][:directory]
+
+ notifies :create, "template[#{site_directory}/LocalSettings.php]"
+ notifies :run, "execute[#{site_directory}/maintenance/update.php]"
+ end
+end