3 # Resource:: mediawiki_skin
5 # Copyright:: 2015, 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 # https://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.
22 default_action :create
24 property :skin, :kind_of => String, :name_property => true
25 property :site, :kind_of => String, :required => true
26 property :source, :kind_of => String
27 property :template, :kind_of => String
28 property :variables, :kind_of => Hash, :default => {}
29 property :version, :kind_of => String
30 property :repository, :kind_of => String
31 property :revision, :kind_of => String
32 property :update_site, :kind_of => [TrueClass, FalseClass], :default => true
33 property :legacy, :kind_of => [TrueClass, FalseClass], :default => true
36 if new_resource.source
37 remote_directory skin_directory do
39 source new_resource.source
40 owner node[:mediawiki][:user]
41 group node[:mediawiki][:group]
43 files_owner node[:mediawiki][:user]
44 files_group node[:mediawiki][:group]
48 skin_repository = new_resource.repository || default_repository
49 skin_revision = new_resource.revision || "REL#{skin_version}".tr(".", "_")
53 repository skin_repository
54 revision skin_revision
55 enable_submodules true
56 user node[:mediawiki][:user]
57 group node[:mediawiki][:group]
58 ignore_failure skin_repository.start_with?("https://github.com/wikimedia/mediawiki-skins")
62 if new_resource.template
63 declare_resource :template, "#{mediawiki_directory}/LocalSettings.d/Skin-#{new_resource.skin}.inc.php" do
65 source new_resource.template
66 user node[:mediawiki][:user]
67 group node[:mediawiki][:group]
69 variables new_resource.variables
72 if new_resource.legacy
73 file_content = "<?php require_once('#{skin_directory}/#{new_resource.skin}.php');\n"
74 skin_file = "#{skin_directory}/#{new_resource.skin}.php"
76 file_content = "<?php wfLoadSkin('#{new_resource.skin}');\n"
77 skin_file = "#{skin_directory}/skin.json"
80 file "#{mediawiki_directory}/LocalSettings.d/Skin-#{new_resource.skin}.inc.php" do
82 user node[:mediawiki][:user]
83 group node[:mediawiki][:group]
85 only_if { ::File.exist?(skin_file) }
91 directory skin_directory do
96 file "#{mediawiki_directory}/LocalSettings.d/Skin-#{new_resource.skin}.inc.php" do
103 node[:mediawiki][:sites][new_resource.site][:directory]
106 def mediawiki_directory
107 "#{site_directory}/w"
111 "#{mediawiki_directory}/skins/#{new_resource.skin}"
115 new_resource.version || node[:mediawiki][:sites][new_resource.site][:version]
118 def default_repository
119 "https://github.com/wikimedia/mediawiki-skins-#{new_resource.skin}.git"
124 notifies :update, "mediawiki_site[#{site}]" if update_site