mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
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:
parent
4a85167b5b
commit
6cd6742d8f
@ -21,6 +21,7 @@ Configuration helper for ikiwiki
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -65,14 +66,29 @@ def subcommand_setup(_):
|
|||||||
setup()
|
setup()
|
||||||
|
|
||||||
|
|
||||||
def subcommand_get_sites(_):
|
def get_title(site):
|
||||||
"""Get wikis and blogs."""
|
"""Get blog or wiki title"""
|
||||||
try:
|
try:
|
||||||
sites = os.listdir(SITE_PATH)
|
with open(os.path.join(SITE_PATH, site, 'index.html')) as index_file:
|
||||||
print('\n'.join(sites))
|
match = re.search(r'<title>(.*)</title>', index_file.read())
|
||||||
|
if match:
|
||||||
|
return match[1]
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
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):
|
def subcommand_create_wiki(arguments):
|
||||||
"""Create a wiki."""
|
"""Create a wiki."""
|
||||||
@ -80,7 +96,8 @@ def subcommand_create_wiki(arguments):
|
|||||||
proc = subprocess.Popen([
|
proc = subprocess.Popen([
|
||||||
'ikiwiki', '-setup', SETUP_WIKI, arguments.wiki_name,
|
'ikiwiki', '-setup', SETUP_WIKI, arguments.wiki_name,
|
||||||
arguments.admin_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)
|
outs, errs = proc.communicate(input=pw_bytes + b'\n' + pw_bytes)
|
||||||
print(outs)
|
print(outs)
|
||||||
print(errs)
|
print(errs)
|
||||||
@ -92,7 +109,8 @@ def subcommand_create_blog(arguments):
|
|||||||
proc = subprocess.Popen([
|
proc = subprocess.Popen([
|
||||||
'ikiwiki', '-setup', SETUP_BLOG, arguments.blog_name,
|
'ikiwiki', '-setup', SETUP_BLOG, arguments.blog_name,
|
||||||
arguments.admin_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)
|
outs, errs = proc.communicate(input=pw_bytes + b'\n' + pw_bytes)
|
||||||
print(outs)
|
print(outs)
|
||||||
print(errs)
|
print(errs)
|
||||||
|
|||||||
@ -79,10 +79,7 @@ class IkiwikiApp(app_module.App):
|
|||||||
parent_url_name='apps')
|
parent_url_name='apps')
|
||||||
self.add(menu_item)
|
self.add(menu_item)
|
||||||
|
|
||||||
sites = actions.run('ikiwiki', ['get-sites']).split('\n')
|
self.refresh_sites()
|
||||||
sites = [name for name in sites if name != '']
|
|
||||||
for site in sites:
|
|
||||||
self.add_shortcut(site)
|
|
||||||
|
|
||||||
firewall = Firewall('firewall-ikiwiki', name, ports=['http', 'https'],
|
firewall = Firewall('firewall-ikiwiki', name, ports=['http', 'https'],
|
||||||
is_external=True)
|
is_external=True)
|
||||||
@ -91,9 +88,9 @@ class IkiwikiApp(app_module.App):
|
|||||||
webserver = Webserver('webserver-ikiwiki', 'ikiwiki-plinth')
|
webserver = Webserver('webserver-ikiwiki', 'ikiwiki-plinth')
|
||||||
self.add(webserver)
|
self.add(webserver)
|
||||||
|
|
||||||
def add_shortcut(self, site):
|
def add_shortcut(self, site, title):
|
||||||
"""Add an ikiwiki shortcut to frontpage."""
|
"""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,
|
icon='ikiwiki', url='/ikiwiki/' + site,
|
||||||
clients=clients)
|
clients=clients)
|
||||||
self.add(shortcut)
|
self.add(shortcut)
|
||||||
@ -104,6 +101,17 @@ class IkiwikiApp(app_module.App):
|
|||||||
component = self.remove('shortcut-ikiwiki-' + site)
|
component = self.remove('shortcut-ikiwiki-' + site)
|
||||||
component.remove() # Remove from global list.
|
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():
|
def init():
|
||||||
"""Initialize the ikiwiki module."""
|
"""Initialize the ikiwiki module."""
|
||||||
|
|||||||
@ -10,7 +10,8 @@ if (($wikiname eq "") || ($admin eq "")) {
|
|||||||
exit;
|
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(
|
IkiWiki::Setup::Automator->import(
|
||||||
wikiname => $wikiname,
|
wikiname => $wikiname,
|
||||||
|
|||||||
@ -10,7 +10,8 @@ if (($wikiname eq "") || ($admin eq "")) {
|
|||||||
exit;
|
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(
|
IkiWiki::Setup::Automator->import(
|
||||||
wikiname => $wikiname,
|
wikiname => $wikiname,
|
||||||
|
|||||||
@ -21,7 +21,6 @@ Forms for configuring ikiwiki
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core.validators import RegexValidator
|
|
||||||
|
|
||||||
|
|
||||||
class IkiwikiCreateForm(forms.Form):
|
class IkiwikiCreateForm(forms.Form):
|
||||||
@ -30,10 +29,7 @@ class IkiwikiCreateForm(forms.Form):
|
|||||||
label=_('Type'),
|
label=_('Type'),
|
||||||
choices=[('wiki', 'Wiki'), ('blog', 'Blog')])
|
choices=[('wiki', 'Wiki'), ('blog', 'Blog')])
|
||||||
|
|
||||||
name = forms.CharField(
|
name = forms.CharField(label=_('Name'))
|
||||||
label=_('Name'),
|
|
||||||
help_text=_('Only alphanumeric characters are allowed.'),
|
|
||||||
validators=[RegexValidator(regex='^[a-zA-Z0-9]+$')])
|
|
||||||
|
|
||||||
admin_name = forms.CharField(label=_('Admin Account Name'))
|
admin_name = forms.CharField(label=_('Admin Account Name'))
|
||||||
|
|
||||||
|
|||||||
@ -48,17 +48,17 @@
|
|||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
{% for site in sites %}
|
{% for site in sites %}
|
||||||
<div class="list-group-item clearfix">
|
<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"
|
class="btn btn-default btn-sm pull-right"
|
||||||
role="button"
|
role="button"
|
||||||
title="{% blocktrans %}Delete site {{ site }}{% endblocktrans %}">
|
title="{% blocktrans with site=site.1 %}Delete site {{ site }}{% endblocktrans %}">
|
||||||
<span class="fa fa-trash-o"
|
<span class="fa fa-trash-o"
|
||||||
aria-hidden="true"></span>
|
aria-hidden="true"></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a class="wiki-label" href="/ikiwiki/{{ site }}"
|
<a class="wiki-label" href="/ikiwiki/{{ site.0 }}"
|
||||||
title="{% blocktrans %}Go to site {{ site }}{% endblocktrans %}">
|
title="{% blocktrans with site=site.1 %}Go to site {{ site }}{% endblocktrans %}">
|
||||||
{{ site }}
|
{{ site.1 }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@ -24,7 +24,6 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/ikiwiki/$', views.IkiwikiAppView.as_view(), name='index'),
|
url(r'^apps/ikiwiki/$', views.IkiwikiAppView.as_view(), name='index'),
|
||||||
url(r'^apps/ikiwiki/(?P<name>[\w.@+-]+)/delete/$', views.delete,
|
url(r'^apps/ikiwiki/(?P<name>.+)/delete/$', views.delete, name='delete'),
|
||||||
name='delete'),
|
|
||||||
url(r'^apps/ikiwiki/create/$', views.create, name='create'),
|
url(r'^apps/ikiwiki/create/$', views.create, name='create'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class IkiwikiAppView(views.AppView):
|
|||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
"""Return the context data for rendering the template view."""
|
"""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 != '']
|
sites = [name for name in sites if name != '']
|
||||||
|
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
@ -67,9 +67,9 @@ def create(request):
|
|||||||
form.cleaned_data['admin_name'],
|
form.cleaned_data['admin_name'],
|
||||||
form.cleaned_data['admin_password'])
|
form.cleaned_data['admin_password'])
|
||||||
|
|
||||||
site = form.cleaned_data['name'].replace(' ', '')
|
ikiwiki.app.refresh_sites()
|
||||||
shortcut = ikiwiki.app.add_shortcut(site)
|
if ikiwiki.app.is_enabled():
|
||||||
shortcut.enable()
|
ikiwiki.app.set_enabled(True)
|
||||||
|
|
||||||
return redirect(reverse_lazy('ikiwiki:index'))
|
return redirect(reverse_lazy('ikiwiki:index'))
|
||||||
else:
|
else:
|
||||||
@ -118,20 +118,22 @@ def delete(request, name):
|
|||||||
On GET, display a confirmation page.
|
On GET, display a confirmation page.
|
||||||
On POST, delete the wiki/blog.
|
On POST, delete the wiki/blog.
|
||||||
"""
|
"""
|
||||||
|
title = ikiwiki.app.components['shortcut-ikiwiki-' + name].name
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('ikiwiki', ['delete', '--name', name])
|
actions.superuser_run('ikiwiki', ['delete', '--name', name])
|
||||||
ikiwiki.app.remove_shortcut(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:
|
except actions.ActionError as error:
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
_('Could not delete {name}: {error}').format(
|
_('Could not delete {title}: {error}').format(
|
||||||
name=name, error=error))
|
title=title, error=error))
|
||||||
|
|
||||||
return redirect(reverse_lazy('ikiwiki:index'))
|
return redirect(reverse_lazy('ikiwiki:index'))
|
||||||
|
|
||||||
return TemplateResponse(request, 'ikiwiki_delete.html', {
|
return TemplateResponse(request, 'ikiwiki_delete.html', {
|
||||||
'title': ikiwiki.name,
|
'title': ikiwiki.name,
|
||||||
'name': name
|
'name': title
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user