mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
ikiwiki: Create and manage wikis/blogs.
This commit is contained in:
parent
fbce204180
commit
1464ff3184
@ -47,6 +47,9 @@ def parse_arguments():
|
||||
# Disable ikiwiki site
|
||||
subparsers.add_parser('disable', help='Disable ikiwiki site')
|
||||
|
||||
# Get wikis and blogs
|
||||
subparsers.add_parser('get-sites', help='Get wikis and blogs')
|
||||
|
||||
# Create a wiki
|
||||
create_wiki = subparsers.add_parser('create-wiki', help='Create a wiki')
|
||||
create_wiki.add_argument('--name', help='Name of new wiki')
|
||||
@ -71,8 +74,9 @@ def subcommand_enable(_):
|
||||
if not os.path.isfile(CONFIG_FILE):
|
||||
setup()
|
||||
|
||||
subprocess.check_output(['a2enmod', 'cgi'])
|
||||
subprocess.check_output(['a2enconf', 'ikiwiki'])
|
||||
subprocess.check_output(['service', 'apache2', 'reload'])
|
||||
subprocess.check_output(['service', 'apache2', 'restart'])
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
@ -81,6 +85,12 @@ def subcommand_disable(_):
|
||||
subprocess.check_output(['service', 'apache2', 'reload'])
|
||||
|
||||
|
||||
def subcommand_get_sites(_):
|
||||
"""Get wikis and blogs"""
|
||||
sites = os.listdir(WIKI_PATH)
|
||||
print('\n'.join(sites))
|
||||
|
||||
|
||||
def subcommand_create_wiki(arguments):
|
||||
"""Create a wiki"""
|
||||
subprocess.check_output(['ikiwiki', '-setup', SETUP_WIKI, arguments.name])
|
||||
@ -163,18 +173,16 @@ def setup():
|
||||
' url => "/ikiwiki/$wikiname_short",\n',
|
||||
' cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
||||
' cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
||||
' add_plugins => [qw{goodstuff websetup comments blogspam calendar sidebar trail httpauth}],\n',
|
||||
' add_plugins => [qw{goodstuff websetup comments calendar sidebar trail httpauth}],\n',
|
||||
' rss => 1,\n',
|
||||
' atom => 1,\n',
|
||||
' syslog => 1,\n',
|
||||
'\n',
|
||||
' example => "blog",\n',
|
||||
' comments_pagespec => "posts/* and !*/Discussion",\n',
|
||||
' blogspam_pagespec => "postcomment(*)",\n',
|
||||
' archive_pagespec => "page(posts/*) and !*/Discussion",\n',
|
||||
' global_sidebars => 0,\n',
|
||||
' discussion => 0,\n',
|
||||
' locked_pages => "* and !postcomment(*)",\n',
|
||||
' tagbase => "tags",\n',
|
||||
')\n',
|
||||
])
|
||||
|
||||
@ -28,3 +28,11 @@ class IkiwikiForm(forms.Form):
|
||||
enabled = forms.BooleanField(
|
||||
label=_('Enable ikiwiki site'),
|
||||
required=False)
|
||||
|
||||
|
||||
class IkiwikiCreateForm(forms.Form):
|
||||
"""Form to create a wiki or blog."""
|
||||
type = forms.ChoiceField(
|
||||
label=_('Type'),
|
||||
choices=[('wiki', 'Wiki'), ('blog', 'Blog')])
|
||||
name = forms.CharField(label=_('Name'))
|
||||
|
||||
@ -22,8 +22,6 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>Wiki & Blog</h2>
|
||||
|
||||
<p>When enabled, the ikiwiki site will be available from <a href="/ikiwiki">
|
||||
/ikiwiki</a> path on the web server.</p>
|
||||
|
||||
|
||||
33
plinth/modules/ikiwiki/templates/ikiwiki_create.html
Normal file
33
plinth/modules/ikiwiki/templates/ikiwiki_create.html
Normal file
@ -0,0 +1,33 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
{% endcomment %}
|
||||
|
||||
{% load bootstrap %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
{{ form|bootstrap }}
|
||||
|
||||
<input type="submit" class="btn btn-primary" value="Update setup"/>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
61
plinth/modules/ikiwiki/templates/ikiwiki_manage.html
Normal file
61
plinth/modules/ikiwiki/templates/ikiwiki_manage.html
Normal file
@ -0,0 +1,61 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
{% endcomment %}
|
||||
|
||||
{% load bootstrap %}
|
||||
|
||||
{% block page_head %}
|
||||
<style type="text/css">
|
||||
.wiki-label {
|
||||
display: inline-block;
|
||||
width: 40%;
|
||||
}
|
||||
.list-group-item .btn {
|
||||
margin: -5px 0;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="list-group">
|
||||
{% for site in sites %}
|
||||
<div class="list-group-item clearfix">
|
||||
<a href="{% url 'ikiwiki:index' %}"
|
||||
class="btn btn-default btn-sm pull-right"
|
||||
role="button" title="Delete site {{ site }}">
|
||||
<span class="glyphicon glyphicon-trash"
|
||||
aria-hidden="true"></span>
|
||||
</a>
|
||||
|
||||
<a class="wiki-label"
|
||||
href="/ikiwiki/{{ site }}"
|
||||
title="Go to site {{ site }}">
|
||||
{{ site }}
|
||||
</a>
|
||||
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@ -25,4 +25,6 @@ from django.conf.urls import patterns, url
|
||||
urlpatterns = patterns(
|
||||
'plinth.modules.ikiwiki.views',
|
||||
url(r'^apps/ikiwiki/$', 'index', name='index'),
|
||||
url(r'^apps/ikiwiki/manage/$', 'manage', name='manage'),
|
||||
url(r'^apps/ikiwiki/create/$', 'create', name='create'),
|
||||
)
|
||||
|
||||
@ -21,17 +21,26 @@ Plinth module for configuring ikiwiki
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.template.response import TemplateResponse
|
||||
from gettext import gettext as _
|
||||
|
||||
from .forms import IkiwikiForm
|
||||
from .forms import IkiwikiForm, IkiwikiCreateForm
|
||||
from plinth import actions
|
||||
from plinth import package
|
||||
from plinth.modules import ikiwiki
|
||||
|
||||
|
||||
subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
|
||||
'text': _('Configure')},
|
||||
{'url': reverse_lazy('ikiwiki:manage'),
|
||||
'text': _('Manage')},
|
||||
{'url': reverse_lazy('ikiwiki:create'),
|
||||
'text': _('Create')}]
|
||||
|
||||
|
||||
@login_required
|
||||
@package.required(['ikiwiki'])
|
||||
@package.required(['ikiwiki', 'libcgi-formbuilder-perl', 'libcgi-session-perl'])
|
||||
def index(request):
|
||||
"""Serve configuration page."""
|
||||
status = get_status()
|
||||
@ -48,9 +57,10 @@ def index(request):
|
||||
form = IkiwikiForm(initial=status, prefix='ikiwiki')
|
||||
|
||||
return TemplateResponse(request, 'ikiwiki.html',
|
||||
{'title': _('Wiki'),
|
||||
{'title': _('Wiki & Blog'),
|
||||
'status': status,
|
||||
'form': form})
|
||||
'form': form,
|
||||
'subsubmenu': subsubmenu})
|
||||
|
||||
|
||||
def get_status():
|
||||
@ -73,3 +83,47 @@ def _apply_changes(request, old_status, new_status):
|
||||
messages.success(request, _('Configuration updated'))
|
||||
else:
|
||||
messages.info(request, _('Setting unchanged'))
|
||||
|
||||
|
||||
@login_required
|
||||
def manage(request):
|
||||
"""Manage existing wikis and blogs."""
|
||||
sites = actions.run('ikiwiki', ['get-sites']).split('\n')
|
||||
sites = [name for name in sites if name != '']
|
||||
|
||||
return TemplateResponse(request, 'ikiwiki_manage.html',
|
||||
{'title': _('Manage Wikis and Blogs'),
|
||||
'subsubmenu': subsubmenu,
|
||||
'sites': sites})
|
||||
|
||||
|
||||
@login_required
|
||||
def create(request):
|
||||
"""Form to create a wiki or blog."""
|
||||
form = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = IkiwikiCreateForm(request.POST, prefix='ikiwiki')
|
||||
if form.is_valid():
|
||||
if form.cleaned_data['type'] == 'wiki':
|
||||
_create_wiki(request, form.cleaned_data['name'])
|
||||
elif form.cleaned_data['type'] == 'blog':
|
||||
_create_blog(request, form.cleaned_data['name'])
|
||||
form = IkiwikiCreateForm(prefix='ikiwiki')
|
||||
else:
|
||||
form = IkiwikiCreateForm(prefix='ikiwiki')
|
||||
|
||||
return TemplateResponse(request, 'ikiwiki_create.html',
|
||||
{'title': _('Create Wiki/Blog'),
|
||||
'form': form,
|
||||
'subsubmenu': subsubmenu})
|
||||
|
||||
|
||||
def _create_wiki(request, name):
|
||||
"""Create wiki."""
|
||||
actions.superuser_run('ikiwiki', ['create-wiki', '--name', name])
|
||||
|
||||
|
||||
def _create_blog(request, name):
|
||||
"""Create blog."""
|
||||
actions.superuser_run('ikiwiki', ['create-blog', '--name', name])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user