+
+ if new_resource.template
+ declare_resource :template, "#{mediawiki_directory}/LocalSettings.d/Skin-#{new_resource.skin}.inc.php" do
+ cookbook "mediawiki"
+ source new_resource.template
+ user node[:mediawiki][:user]
+ group node[:mediawiki][:group]
+ mode "664"
+ variables new_resource.variables
+ end
+ else
+ if new_resource.legacy
+ file_content = "<?php require_once('#{skin_directory}/#{new_resource.skin}.php');\n"
+ skin_file = "#{skin_directory}/#{new_resource.skin}.php"
+ else
+ file_content = "<?php wfLoadSkin('#{new_resource.skin}');\n"
+ skin_file = "#{skin_directory}/skin.json"
+ end
+
+ file "#{mediawiki_directory}/LocalSettings.d/Skin-#{new_resource.skin}.inc.php" do
+ content file_content
+ user node[:mediawiki][:user]
+ group node[:mediawiki][:group]
+ mode "664"
+ only_if { ::File.exist?(skin_file) }
+ end
+ end
+end
+
+action :delete do
+ directory skin_directory do
+ action :delete
+ recursive true
+ end
+
+ file "#{mediawiki_directory}/LocalSettings.d/Skin-#{new_resource.skin}.inc.php" do
+ action :delete
+ end
+end
+
+action_class do
+ def site_directory
+ node[:mediawiki][:sites][new_resource.site][:directory]
+ end
+
+ def mediawiki_directory
+ "#{site_directory}/w"
+ end
+
+ def skin_directory
+ "#{mediawiki_directory}/skins/#{new_resource.skin}"
+ end
+
+ def skin_version
+ new_resource.version || node[:mediawiki][:sites][new_resource.site][:version]
+ end
+
+ def default_repository
+ "https://github.com/wikimedia/mediawiki-skins-#{new_resource.skin}.git"
+ end
+end
+
+def after_created
+ notifies :update, "mediawiki_site[#{site}]" if update_site