ikiwiki: Allow full Unicode text in wiki/blog title names

Closes: #1523

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil@medhas.org Fix issue with enabling shortcuts on daemon start]
[sunil@medhas.org Run isort and yapf]
[sunil@medhas.org Prevent change in i18n string]
[sunil@medhas.org Fix flake8 warning about uniform return values]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Veiko Aasa 2019-10-03 15:17:05 +00:00 committed by Sunil Mohan Adapa
parent 4a85167b5b
commit 6cd6742d8f
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
8 changed files with 60 additions and 35 deletions

View File

@ -21,6 +21,7 @@ Configuration helper for ikiwiki
import argparse
import os
import re
import shutil
import subprocess
import sys
@ -65,14 +66,29 @@ def subcommand_setup(_):
setup()
def subcommand_get_sites(_):
"""Get wikis and blogs."""
def get_title(site):
"""Get blog or wiki title"""
try:
sites = os.listdir(SITE_PATH)
print('\n'.join(sites))
with open(os.path.join(SITE_PATH, site, 'index.html')) as index_file:
match = re.search(r'<title>(.*)</title>', index_file.read())
if match:
return match[1]
except FileNotFoundError:
pass
return site
def subcommand_get_sites(_):
"""Get wikis and blogs."""
if os.path.exists(SITE_PATH):
for site in os.listdir(SITE_PATH):
if not os.path.isdir(os.path.join(SITE_PATH, site)):
continue
title = get_title(site)
print(site, title)
def subcommand_create_wiki(arguments):
"""Create a wiki."""
@ -80,7 +96,8 @@ def subcommand_create_wiki(arguments):
proc = subprocess.Popen([
'ikiwiki', '-setup', SETUP_WIKI, arguments.wiki_name,
arguments.admin_name
], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE,
env=dict(os.environ, PERL_UNICODE='AS'))
outs, errs = proc.communicate(input=pw_bytes + b'\n' + pw_bytes)
print(outs)
print(errs)
@ -92,7 +109,8 @@ def subcommand_create_blog(arguments):
proc = subprocess.Popen([
'ikiwiki', '-setup', SETUP_BLOG, arguments.blog_name,
arguments.admin_name
], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE,
env=dict(os.environ, PERL_UNICODE='AS'))
outs, errs = proc.communicate(input=pw_bytes + b'\n' + pw_bytes)
print(outs)
print(errs)

View File

@ -29,7 +29,7 @@ from plinth.modules.firewall.components import Firewall
from plinth.modules.users import register_group
from plinth.utils import format_lazy
from .manifest import backup, clients # noqa, pylint: disable=unused-import
from .manifest import backup, clients # noqa, pylint: disable=unused-import
version = 1
@ -79,10 +79,7 @@ class IkiwikiApp(app_module.App):
parent_url_name='apps')
self.add(menu_item)
sites = actions.run('ikiwiki', ['get-sites']).split('\n')
sites = [name for name in sites if name != '']
for site in sites:
self.add_shortcut(site)
self.refresh_sites()
firewall = Firewall('firewall-ikiwiki', name, ports=['http', 'https'],
is_external=True)
@ -91,9 +88,9 @@ class IkiwikiApp(app_module.App):
webserver = Webserver('webserver-ikiwiki', 'ikiwiki-plinth')
self.add(webserver)
def add_shortcut(self, site):
def add_shortcut(self, site, title):
"""Add an ikiwiki shortcut to frontpage."""
shortcut = frontpage.Shortcut('shortcut-ikiwiki-' + site, site,
shortcut = frontpage.Shortcut('shortcut-ikiwiki-' + site, title,
icon='ikiwiki', url='/ikiwiki/' + site,
clients=clients)
self.add(shortcut)
@ -104,6 +101,17 @@ class IkiwikiApp(app_module.App):
component = self.remove('shortcut-ikiwiki-' + site)
component.remove() # Remove from global list.
def refresh_sites(self):
"""Refresh blog and wiki list"""
sites = actions.run('ikiwiki', ['get-sites']).split('\n')
sites = [name.split(' ', 1) for name in sites if name != '']
for site in sites:
if not 'shortcut-ikiwiki-' + site[0] in self.components:
self.add_shortcut(site[0], site[1])
return sites
def init():
"""Initialize the ikiwiki module."""

View File

@ -10,7 +10,8 @@ if (($wikiname eq "") || ($admin eq "")) {
exit;
}
our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname);
our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname . "_");
if (length($wikiname_short)>1) { chop($wikiname_short) };
IkiWiki::Setup::Automator->import(
wikiname => $wikiname,

View File

@ -10,7 +10,8 @@ if (($wikiname eq "") || ($admin eq "")) {
exit;
}
our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname);
our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname . "_");
if (length($wikiname_short)>1) { chop($wikiname_short) };
IkiWiki::Setup::Automator->import(
wikiname => $wikiname,

View File

@ -21,7 +21,6 @@ Forms for configuring ikiwiki
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.core.validators import RegexValidator
class IkiwikiCreateForm(forms.Form):
@ -30,10 +29,7 @@ class IkiwikiCreateForm(forms.Form):
label=_('Type'),
choices=[('wiki', 'Wiki'), ('blog', 'Blog')])
name = forms.CharField(
label=_('Name'),
help_text=_('Only alphanumeric characters are allowed.'),
validators=[RegexValidator(regex='^[a-zA-Z0-9]+$')])
name = forms.CharField(label=_('Name'))
admin_name = forms.CharField(label=_('Admin Account Name'))

View File

@ -48,17 +48,17 @@
<div class="list-group">
{% for site in sites %}
<div class="list-group-item clearfix">
<a href="{% url 'ikiwiki:delete' site %}"
<a href="{% url 'ikiwiki:delete' site.0 %}"
class="btn btn-default btn-sm pull-right"
role="button"
title="{% blocktrans %}Delete site {{ site }}{% endblocktrans %}">
title="{% blocktrans with site=site.1 %}Delete site {{ site }}{% endblocktrans %}">
<span class="fa fa-trash-o"
aria-hidden="true"></span>
</a>
<a class="wiki-label" href="/ikiwiki/{{ site }}"
title="{% blocktrans %}Go to site {{ site }}{% endblocktrans %}">
{{ site }}
<a class="wiki-label" href="/ikiwiki/{{ site.0 }}"
title="{% blocktrans with site=site.1 %}Go to site {{ site }}{% endblocktrans %}">
{{ site.1 }}
</a>
</div>
{% endfor %}

View File

@ -24,7 +24,6 @@ from . import views
urlpatterns = [
url(r'^apps/ikiwiki/$', views.IkiwikiAppView.as_view(), name='index'),
url(r'^apps/ikiwiki/(?P<name>[\w.@+-]+)/delete/$', views.delete,
name='delete'),
url(r'^apps/ikiwiki/(?P<name>.+)/delete/$', views.delete, name='delete'),
url(r'^apps/ikiwiki/create/$', views.create, name='create'),
]

View File

@ -43,7 +43,7 @@ class IkiwikiAppView(views.AppView):
def get_context_data(self, **kwargs):
"""Return the context data for rendering the template view."""
sites = actions.run('ikiwiki', ['get-sites']).split('\n')
sites = ikiwiki.app.refresh_sites()
sites = [name for name in sites if name != '']
context = super().get_context_data(**kwargs)
@ -67,9 +67,9 @@ def create(request):
form.cleaned_data['admin_name'],
form.cleaned_data['admin_password'])
site = form.cleaned_data['name'].replace(' ', '')
shortcut = ikiwiki.app.add_shortcut(site)
shortcut.enable()
ikiwiki.app.refresh_sites()
if ikiwiki.app.is_enabled():
ikiwiki.app.set_enabled(True)
return redirect(reverse_lazy('ikiwiki:index'))
else:
@ -118,20 +118,22 @@ def delete(request, name):
On GET, display a confirmation page.
On POST, delete the wiki/blog.
"""
title = ikiwiki.app.components['shortcut-ikiwiki-' + name].name
if request.method == 'POST':
try:
actions.superuser_run('ikiwiki', ['delete', '--name', name])
ikiwiki.app.remove_shortcut(name)
messages.success(request, _('{name} deleted.').format(name=name))
messages.success(request,
_('{title} deleted.').format(title=title))
except actions.ActionError as error:
messages.error(
request,
_('Could not delete {name}: {error}').format(
name=name, error=error))
_('Could not delete {title}: {error}').format(
title=title, error=error))
return redirect(reverse_lazy('ikiwiki:index'))
return TemplateResponse(request, 'ikiwiki_delete.html', {
'title': ikiwiki.name,
'name': name
'name': title
})