# Detect the distribution in use
%global __despace head -n 1 | tr -d '[:space:]' | sed -e 's/[(].*[)]//g'
%global __lower4 cut -c 1-4 | tr '[:upper:]' '[:lower:]'
%global __distfile %([ -f /etc/SuSE-release ] && echo /etc/SuSE-release || echo /etc/redhat-release)
%global __distinit %(sed -e 's/ release .*//' -e 's/\\([A-Za-z]\\)[^ ]*/\\1/g' %{__distfile} | %{__despace} | %{__lower4})
%global __distvers %(sed -e 's/.* release \\([^. ]*\\).*/\\1/' %{__distfile} | %{__despace})
# Identify Alma, CentOS, CentOS Stream and Rocky Linux as rhel
%if "%{__distinit}" == "a" || "%{__distinit}" == "c" || "%{__distinit}" == "cl" || "%{__distinit}" == "cs" || "%{__distinit}" == "rl"
%global __distinit rhel
%endif
# Dist tag for Fedora is still "fc"
%if "%{__distinit}" == "f"
%global __distinit fc
%endif

%global python2ver %(python2 -c "import sys; print sys.version[:3]" || echo none)
%{!?python2_sitelib: %global python2_sitelib %{_prefix}/lib/python%{python2ver}/site-packages}
%global moin_static_content_dir %{python2_sitelib}/MoinMoin/web/static/htdocs

Summary:	The "monobook" theme for the moin wiki engine
Name:		moin-theme-monobook
Version:	0.5
Release:	15.%{__distinit}%{__distvers}
URL:		http://moinmo.in/ThemeMarket/MonoBook
Source0:	monobook-%{version}.tar.gz
Source1:	moin-theme-monobook-README
Patch0:		moin-theme-monobook-0.5-images.patch
Patch1:		moin-theme-monobook-0.5-moin-1.7.2-compat.patch
Patch2:		moin-theme-monobook-0.5-moin-1.9.0-compat.patch
License:	GPL-2.0-or-later
BuildArch:	noarch
BuildRequires:	coreutils
BuildRequires:	python2
Requires:	moin >= 1.9.0
Requires:	python(abi) = %{python2ver}

%description
The monobook theme is an adaption of the default theme from Wikipedia. It uses
a complete copy of the css style sheet from Wikipedia, then applies some
moin-specific alterations afterwards. Hopefully this should mean any other
style sheets developed for MediaWiki can be used directly.

%prep
%setup -q -c

# Patch out references to non-existent images
%patch -P 0 -p1

# Support for moin ≥ 1.7.0
%patch -P 1 -p1

# Support for moin ≥ 1.9.0 (requires moin ≥ 1.9.0)
%patch -P 2 -p1

cat << EOF > README.rpm
After installing this package, any newly-created wiki instances should
automatically have the monobook theme available.

To make the monobook theme available to an existing wiki instance, copy
%{_datadir}/moin/data/plugin/theme/monobook.py*
to the data/plugin/theme directory of the wiki instance and do:
chown apache:apache /path/to/wiki/data/plugin/theme/monobook.py*
EOF

cp -p %{SOURCE1} README

%build
# Generate normal (.pyc) byte-compiled files.
python2 -c 'import compileall; compileall.compile_dir(".", 1, "/", 1)'
# Generate optimized (.pyo) byte-compiled files.
python2 -O -c 'import compileall; compileall.compile_dir(".", 1, "/", 1)'

%install
install -d -m 755 %{buildroot}%{_datadir}/moin/data/plugin/theme
install -p -m 644 monobook/monobook.py* %{buildroot}%{_datadir}/moin/data/plugin/theme/
install -d -m 755 %{buildroot}%{moin_static_content_dir}/monobook/{css,img}
install -p -m 644 monobook/css/*.css %{buildroot}%{moin_static_content_dir}/monobook/css/
install -p -m 644 monobook/img/*.gif %{buildroot}%{moin_static_content_dir}/monobook/img/
install -p -m 644 monobook/img/*.jpg %{buildroot}%{moin_static_content_dir}/monobook/img/
install -p -m 644 monobook/img/*.png %{buildroot}%{moin_static_content_dir}/monobook/img/

# Symlink to conflict and renamed icons from modern theme
ln -s ../../modern/img/moin-{conflict,renamed}.png %{buildroot}%{moin_static_content_dir}/monobook/img/
# Symlink to attach icon from modern theme
ln -s ../../modern/img/attach.png %{buildroot}%{moin_static_content_dir}/monobook/img/

%pretrans -p <lua>
-- Remove old compat symlink, if present
path = "%{moin_static_content_dir}/monobook"
st = posix.stat(path)
if st and st.type == "link" then
  os.remove(path)
end

%files
%doc README*
%{_datadir}/moin/data/plugin/theme/monobook.py*
%{moin_static_content_dir}/monobook/

%changelog
* Wed Mar 29 2023 Paul Howarth <paul@city-fan.org> - 0.5-15
- Use SPDX-format license tag
- Avoid deprecated patch syntax

* Sat Nov 10 2018 Paul Howarth <paul@city-fan.org> - 0.5-14
- Use python2 instead of generic python
- Manually add python(abi) dependency

* Sat Jan  6 2018 Paul Howarth <paul@city-fan.org> - 0.5-13
- Drop support for EOL distributions prior to F-13
  - Drop BuildRoot: and Group: tags
  - Drop explicit buildroot cleaning in %%install section
  - Drop explicit %%clean section

* Wed Feb 18 2015 Paul Howarth <paul@city-fan.org> - 0.5-12
- Drop support for old distributions prior to FC-5
  - No need to support python < 2.4 or moin < 1.9.0
  - Drop %%defattr, redundant since rpm 4.4
- Move static content from %%{_datadir} to %%{python_sitelib} as wanted by
  moin ≥ 1.9.0 and remove any old compat symlink with a %%pretrans script

* Thu Oct 13 2011 Paul Howarth <paul@city-fan.org> - 0.5-11
- Nobody else likes macros for commands
- Fix dist tag for CentOS 6 and Scientific Linux
- BR: python2 rather than just python

* Wed Jul 28 2010 Paul Howarth <paul@city-fan.org> - 0.5-10
- Rebuild for python 2.7 in Rawhide

* Wed May 26 2010 Paul Howarth <paul@city-fan.org> - 0.5-9
- Fix dist tag for RHEL-6 Beta

* Thu Dec 31 2009 Paul Howarth <paul@city-fan.org> - 0.5-8
- Add patch for moin-1.9.0 compatibility; require moin ≥ 1.9.0
  (unless we have python < 2.4)
- Add compat symlink to static content from
  %%{python_sitelib}/MoinMoin/web/static/htdocs for moin ≥ 1.9.0
- BR: symlinks
- Dist tag for Rawhide no longer needs special-casing

* Sat Jul 11 2009 Paul Howarth <paul@city-fan.org> - 0.5-7
- Define RPM macros in global scope
- Unbundle README as a separate source rather than a here document in the spec
- Use %%{__install} -p to maintain timestamps

* Wed Sep 10 2008 Paul Howarth <paul@city-fan.org> - 0.5-6
- Replace patches for compatibility with recent versions of moin with a new
  version based on the modern theme in moin 1.7.2 that also makes user
  preferences (settings) work again
- Tweak dist tag macros to work on current Rawhide with three-part releasenum
- Add symlink to attach icon from modern theme

* Mon Jun 23 2008 Paul Howarth <paul@city-fan.org> - 0.5-5
- Change logout link to avoid "Unknown action userform" error message on
  moin 1.7.0
- Require moin 1.7.0 or later
- Symlink missing icons moin-{conflict,renamed}.png to those in the modern
  them

* Mon Feb  4 2008 Paul Howarth <paul@city-fan.org> - 0.5-4
- Don't package patch backup files

* Wed Jan 30 2008 Paul Howarth <paul@city-fan.org> - 0.5-3
- Incorporate fix from Peter Sander for moin 1.6.x compatibility
- Update URL to point to new upstream website at moinmo.in
- Require moin >= 1.6.0

* Wed Nov 14 2007 Paul Howarth <paul@city-fan.org> - 0.5-2
- Updates images patch to fix another broken reference to headbg.jpg

* Wed Nov  7 2007 Paul Howarth <paul@city-fan.org> - 0.5-1
- Update to version 0.5
- Package JPEG files as well as GIFs and PNGs
- Replace nogif patch with a new images patch
- Remove login and rsslink patches, no longer needed
- Clarify license as GPL version 2 or later

* Thu Feb  8 2007 Paul Howarth <paul@city-fan.org> - 0.2-7
- Patch rsslink() call needed for moin > 1.5.6
- Bump moin requirement to moin > 1.5.6
- Fix dist tag for fc7 onwards

* Mon Dec 11 2006 Paul Howarth <paul@city-fan.org> - 0.2-6
- Rebuild for python 2.5 on Rawhide

* Tue Dec  5 2006 Paul Howarth <paul@city-fan.org> - 0.2-5
- Fix mock build where python is not in the initial buildroot

* Mon Sep 18 2006 Paul Howarth <paul@city-fan.org> - 0.2-4
- Fix dist tag for development builds
- Don't ghost .pyo files
- Buildreq python, not python-devel

* Thu Jun  8 2006 Paul Howarth <paul@city-fan.org> - 0.2-3
- Patch the username method to work with the new login method in moin > 1.5.2
- Define %%{__id_u} in a more portable way
- Only add python-abi dep for python 2.3
- Require moin > 1.5.2

* Tue Mar 28 2006 Paul Howarth <paul@city-fan.org> - 0.2-2
- Patch out references to non-existent GIF images
- Package img/user.gif

* Fri Feb 24 2006 Paul Howarth <paul@city-fan.org> - 0.2-1
- Initial package build