%global python_version %(python -c "import sys; print sys.version[:3]" || echo 0)
%{!?python_sitelib: %global python_sitelib %{_prefix}/lib/python%{python_version}/site-packages}

#global beta beta1

Summary:	MoinMoin is a WikiEngine to collaborate on easily editable web pages
Name:		moin
Version:	1.9.3
Release:	%{?beta:0.%{beta}.}5.0.cf%{?dist}
License:	GPLv2+
Group:		Applications/Internet
URL:		http://moinmo.in/
Source0:	http://static.moinmo.in/files/moin-%{version}%{?beta:%{beta}}.tar.gz
Source1:	README-rpm
Patch0:		97208f67798f-cve-2011-1058.patch
Patch100:	moin-1.8.5-email-links.patch
Patch101:	moin-1.9.3-FindPage.patch
Patch102:	moin-1.9.3-wikiconfig-cleanup.patch
Patch103:	moin-1.9.3-wsgi-pythonpath.patch
BuildArch:	noarch
BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(id -nu)
BuildRequires:	python2-devel >= 2.4, symlinks
Requires:	words

%description
MoinMoin is an advanced, easy to use and extensible WikiEngine with a large
community of users. Said in a few words, it is about collaboration on easily
editable web pages.

%prep
%setup -q -n moin-%{version}%{?beta:%{beta}}

# Remove support for javascript: URLs in the rst parser (dangerous, XSS)
# CVE-2011-1058 (#679523)
%patch0 -p1

# Better email notifications
%patch100 -p1

# Workaround for http://moinmo.in/MoinMoinBugs/FindPage
%patch101 -p0

# Recode as UTF-8 and don't assume that we're a root wiki
%patch102 -p1

# Add the directory containing moin.wsgi to the Python search path, as
# in the README-rpm example these files will be in the same directory
%patch103 -p1

# Fix missing exec permissions on files with valid shellbangs to silence rpmlint
chmod +x \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/config.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/connector.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/fckcommands.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/fckconnector.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/fckoutput.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/fckutil.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/upload.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/wsgi.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/zope.py' \
	'wiki/server/test.wsgi'

# Fix line endings
sed -i -e 's|\r$||' \
	'docs/licenses/pygments/LICENSE' \
	'docs/licenses/werkzeug/LICENSE' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts/spellchecker.pl' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/perl/connector.cgi' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/perl/upload.cgi' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/config.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/connector.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/fckcommands.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/fckconnector.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/fckoutput.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/fckutil.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/upload.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/wsgi.py' \
	'MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/py/zope.py'

# Remove spurious shellbangs
find MoinMoin jabberbot -name '*.py' | xargs \
	sed -i	-e '/^#! *\/usr\/bin\/env python/d' \
		-e '/^#! *\/usr\/bin\/python/d'

# Kludge to remove bogus local perl dependencies from FCKeditor
%global reqfilt /bin/sh -c "%{__perl_requires} | grep -Evx 'perl[(][a-z_0-9]*\\.pl[)]'"
%define __perl_requires %{reqfilt}

%build
python setup.py build

%install
rm -rf %{buildroot}
python setup.py install -O1 --skip-build --root=%{buildroot}
cp -a %{SOURCE1} README-rpm

# Install link for spellcheck dictionary
mkdir -p %{buildroot}{%{_datadir}/dict,%{python_sitelib}/MoinMoin/dict}
touch %{buildroot}%{_datadir}/dict/words
ln -s %{buildroot}%{_datadir}/dict/words %{buildroot}%{python_sitelib}/MoinMoin/dict/words
symlinks -cs %{buildroot}%{python_sitelib}/MoinMoin/dict
rm %{buildroot}%{_datadir}/dict/words

# Create directory for theme translations
install -d -m 755 %{buildroot}%{python_sitelib}/MoinMoin/i18n/themes

# Create compat placeholder for themes
install -d -m 755 %{buildroot}%{_datadir}/moin/htdocs

# Fix permissions on sample scripts to pacify rpmlint
chmod +x \
	%{buildroot}%{python_sitelib}/MoinMoin/web/static/htdocs/applets/FCKeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts/spellchecker.pl \
	%{buildroot}%{python_sitelib}/MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/perl/connector.cgi \
	%{buildroot}%{python_sitelib}/MoinMoin/web/static/htdocs/applets/FCKeditor/editor/filemanager/connectors/perl/upload.cgi

# See if there's any egg-info
if [ -f %{buildroot}%{python_sitelib}/moin-%{version}-py%{python_version}.egg-info ]; then
	echo %{python_sitelib}/moin-%{version}-py%{python_version}.egg-info
fi > egg-info

%clean
rm -rf %{buildroot}

%posttrans
# Create compat symlink for themes that symlink to modern icons
# Can't do this earlier due to %%{_datadir}/moin/htdocs/modern being a directory prior to moin 1.9.0
if [ ! -d %{_datadir}/moin/htdocs/modern -a ! -s %{_datadir}/moin/htdocs/modern ]; then
	ln -s -f %{python_sitelib}/MoinMoin/web/static/htdocs/modern %{_datadir}/moin/htdocs/modern
fi

%files -f egg-info
%defattr(-,root,root,-)
%doc README README-rpm docs/CHANGES* docs/INSTALL.html docs/README.migration
%doc docs/licenses/
%{_bindir}/moin
%{_datadir}/moin/
%{python_sitelib}/MoinMoin/
%{python_sitelib}/jabberbot/

%changelog
* Tue Apr 26 2011 Paul Howarth <paul@city-fan.org> 1.9.3-5.0.cf
- Create and own %%{_datadir}/moin/htdocs directory as a placeholder for theme
  data (thanks to Sean P. Kane for the bug report)
- Nobody else likes macros for commands

* Fri Feb 25 2011 Paul Howarth <paul@city-fan.org> 1.9.3-4.0.cf
- Drop support for javascript: URLs in the rst parser (#679523, CVE-2011-1058)
- Update README-rpm for mod_wsgi and merge mod_fcgid configuration in from
  README.fastcgi
- Re-code wikiconfig.py as UTF-8
- Fix up wikiconfig.py and moin.wsgi to better match README-rpm examples
- Drop mod_fastcgi support scripts and documentation

* Wed Aug  4 2010 Paul Howarth <paul@city-fan.org> 1.9.3-3.0.cf
- Add workaround for http://moinmo.in/MoinMoinBugs/FindPage

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

* Mon Jun  7 2010 Paul Howarth <paul@city-fan.org> 1.9.3-1.0.cf
- Update to 1.9.3 (see CHANGES for details)
- Drop upstreamed patch for CVE-2010-0828
- More line-ending fixes to placate rpmlint

* Mon Apr  5 2010 Paul Howarth <paul@city-fan.org> 1.9.2-2.0.cf
- Fix XSS bug in Despam action (CVE-2010-0828, #578801)

* Mon Mar  1 2010 Paul Howarth <paul@city-fan.org> 1.9.2-1.0.cf
- Update to 1.9.2
  - Fixed CVE-2010-0668: major security issues in various parts of moin
  - Fixed CVE-2010-0669: incomplete user profile input sanitizing
  - Various other bugfixes and enhancements (see CHANGES)
- Drop smiley icon, no longer used by solenoid theme

* Mon Jan 18 2010 Paul Howarth <paul@city-fan.org> 1.9.1-1.0.cf
- Update to 1.9.1

* Mon Dec  7 2009 Paul Howarth <paul@city-fan.org> 1.9.0-1.0.cf
- Update to 1.9.0 (see CHANGES for important upgrade information)
- Can no longer support distros with python < 2.4
- Fix a bunch of rpmlint warnings relating to scripts and permissions
- Remove bogus perl dependencies originating from FCKeditor
- Add symlink from %%{_datadir}/moin/htdocs/modern to new location
  %%{python_sitelib}/MoinMoin/web/static/htdocs/modern for benefit of themes
  symlinking to icons in the modern theme with relative symlinks
  (have to do this in %%posttrans due to famous rpm/dir/symlink issue)

* Fri Oct 30 2009 Paul Howarth <paul@city-fan.org> 1.8.5-2.0.cf
- Include directory for theme translations (used by Solenoid theme)
- Add question mark smiley <?> for use by Solenoid theme

* Tue Sep  8 2009 Paul Howarth <paul@city-fan.org> 1.8.5-1.0.cf
- Update to 1.8.5
- Make %%files list more explicit
- Restore filemanager directory in FCKeditor; bundled version now 2.6.4.1
- Add patch to include link to updated page in notification emails

* Tue Jul 28 2009 Paul Howarth <paul@city-fan.org> 1.8.4-3.0.cf
- Remove the filemanager directory from the embedded FCKeditor; it contains
  code with know security vulnerabilities, even though that code couldn't be
  invoked when moin was used with the default settings (#509924, CVE-2009-2265)

* Wed Jun 10 2009 Paul Howarth <paul@city-fan.org> 1.8.4-1.0.cf
- Update to 1.8.4 (fixes for hierarchical ACLs and MSIE8)

* Wed Apr 29 2009 Paul Howarth <paul@city-fan.org> 1.8.3-1.0.cf
- Update to 1.8.3

* Mon Feb  9 2009 Paul Howarth <paul@city-fan.org> 1.8.2-1.0.cf
- Update to 1.8.2

* Mon Jan 29 2009 Paul Howarth <paul@city-fan.org> 1.8.1-1.0.cf
- Update to 1.8.1

* Wed Nov  5 2008 Paul Howarth <paul@city-fan.org> 1.8.0-1.0.cf
- Update to 1.8.0

* Wed Sep 10 2008 Paul Howarth <paul@city-fan.org> 1.7.2-1.0.cf
- Update to 1.7.2

* Mon Jul 21 2008 Paul Howarth <paul@city-fan.org> 1.7.1-1.0.cf
- Update to 1.7.1
- Fix python_version macro definition to return 0 rather than %%{nil} if python
  is not in the buildroot

* Sun Jun 22 2008 Paul Howarth <paul@city-fan.org> 1.7.0-1.0.cf
- Update to 1.7.0

* Mon Apr 21 2008 Paul Howarth <paul@city-fan.org> 1.6.3-1.0.cf
- Update to 1.6.3

* Tue Mar 25 2008 Paul Howarth <paul@city-fan.org> 1.6.2-1.0.cf
- Update to 1.6.2

* Mon Feb  4 2008 Paul Howarth <paul@city-fan.org> 1.6.1-1.0.cf
- Update to 1.6.1

* Thu Jan 31 2008 Paul Howarth <paul@city-fan.org> 1.6.0-1.0.cf
- Update to 1.6.0
- Update source URL to use upstream's "home" site rather than sourceforge
- Update %%summary and %%description as per Fedora package
- Drop the config patch
- Tweak %%files list to pick up egg info file when present

* Mon Nov  5 2007 Paul Howarth <paul@city-fan.org> 1.6.0-0.beta1.1.CF
- Update to 1.6.0beta1
- New upstream URL is http://moinmo.in/
- Clarify license as GPL version 2 or later
- Update config patch
- Remove other patches, no longer applicable

* Mon May 14 2007 Paul Howarth <paul@city-fan.org> 1.5.8-1.CF
- Update to 1.5.8
- Changed download URL from dl.sf.net to downloads.sf.net
- Removed three security patches, now included upstream

* Wed May  9 2007 Matthias Saou <http://freshrpms.net/> 1.5.7-2.CF
- Remove obsolete for moin-fastcgi; nobody should need that any more

* Mon May  7 2007 Matthias Saou <http://freshrpms.net/> 1.5.7-2
- Include security fixes from the Debian package (Jonas Smedegaard)
- FIX_use_ACL_in_include_directive (Alexander Schremmer)
- fix_MonthCalendar_respect_ACLs (Thomas Waldmann)
- FIX_XSS_in_AttachFile_do_parameter (Thomas Waldmann)
- CVE-2007-0857

* Thu Feb  8 2007 Paul Howarth <paul@city-fan.org> 1.5.7-1
- Update to 1.5.7

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

* Mon Oct 30 2006 Paul Howarth <paul@city-fan.org> 1.5.6-1
- Update to 1.5.6

* Mon Sep 18 2006 Paul Howarth <paul@city-fan.org> 1.5.5a-1
- Update to 1.5.5a
- Don't ghost .pyo files

* Mon Jul  3 2006 Paul Howarth <paul@city-fan.org> 1.5.4-1
- Update to 1.5.4
- Include fastcgi subpackage material as documentation in the main package
  since I'm not using it any more, and know of nobody else that is either
- Script the generation of the python files list to clean up the spec

* Mon Apr 17 2006 Paul Howarth <paul@city-fan.org> 1.5.3-1
- Update to 1.5.3
- More new script directories

* Mon Apr 10 2006 Paul Howarth <paul@city-fan.org> 1.5.3-0.rc2.1
- Update to 1.5.3-rc2

* Mon Mar 27 2006 Paul Howarth <paul@city-fan.org> 1.5.3-0.rc1.1
- Update to 1.5.3-rc1
- Patch for http://moinmoin.wikiwikiweb.de/MoinMoinBugs/IncludeMacroBroken no
  longer needed
- Scripts in %%{_bindir} replaced by a single "moin" script wrapper
- Some python modules moved around

* Fri Mar 24 2006 Paul Howarth <paul@city-fan.org> 1.5.2-5
- Use buildsys-macros %%{?dist} tag instead of my proprietary stuff

* Mon Feb 27 2006 Paul Howarth <paul@city-fan.org> 1.5.2-4
- Update SELinux advice in README files

* Fri Feb 24 2006 Paul Howarth <paul@city-fan.org> 1.5.2-3
- Add fastcgi subpackage

* Thu Feb 16 2006 Paul Howarth <paul@city-fan.org> 1.5.2-2
- Add patch for http://moinmoin.wikiwikiweb.de/MoinMoinBugs/IncludeMacroBroken

* Wed Feb  8 2006 Paul Howarth <paul@city-fan.org> 1.5.2-1
- Update to 1.5.2
- Add new directories %%{python_sitelib}/MoinMoin/scripts/{import,packages}
- Update config patch for data directory locations in wikiconfig.py
- Add dependency on words package and make symlink to dictionary for
  use by spellchecker

* Fri Jan 13 2006 Paul Howarth <paul@city-fan.org> 1.5.0-1
- Update to 1.5.0
- Generate sane %%{python_sitelib} macro and use it
- General spec file tidy
- Update config patch (mostly now upstream)
- Some different docs
- Use standard python build and approach
- Add SELinux notes to README-rpm
- Bump python requirement to 2.3
- Clear up lots of rpmlint warnings about non-executable scripts
  (still plenty left though, most of which are I think ignorable)

* Sun Dec 18 2005 Tommy Reynolds <Tommy.Reynolds@MegaCoder.com> 1.3.5-3
- Remove extraneous '\' from XML output, so that <screen>..</screen>
  does not generate '\' 'n' outside of any markup.

* Mon Aug 15 2005 Matthias Saou <http://freshrpms.net/> 1.3.5-2
- Fix python modules path from _libdir to _prefix/lib so that build works on
  64bit systems too.

* Mon Aug 15 2005 Matthias Saou <http://freshrpms.net/> 1.3.5-1
- Update to 1.3.5.
- Update the config patch.
- Update %%doc section (many moved to docs/).

* Wed Jun 15 2005 Matthias Saou <http://freshrpms.net/> 1.3.4-1
- Update to 1.3.4.
- Update the config patch.
- Move the README.redhat file out from the patch and rename it to README-rpm.

* Tue Apr 19 2005 Matthias Saou <http://freshrpms.net/> 1.3.3-2
- Adapted for inclusion into Extras.
- Merge relevant bits from Jeff's pyvault version.

* Wed Dec 22 2004 Florian La Roche <Florian.LaRoche@redhat.de>
- 1.3.1

* Thu Dec 09 2004 Florian La Roche <Florian.LaRoche@redhat.de>
- 1.3.0

* Sun Nov 07 2004 Florian La Roche <Florian.LaRoche@redhat.de>
- 1.3beta4

* Fri Aug 06 2004 Florian La Roche <Florian.LaRoche@redhat.de>
- update to 1.2.3

* Wed May 19 2004 - Kai.Puolamaki@iki.fi
- Fix also directory permissions...

* Mon May 17 2004 - Kai.Puolamaki@iki.fi
- Fix file permissions

* Fri May 14 2004 - Kai.Puolamaki@iki.fi
- 1.2.1
- Home build