Skip to content

Commit b0f9354

Browse files
committed
Draft: Fix moin-nonexistent class in itemlinks starting with '+'
1 parent 704e08c commit b0f9354

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

src/moin/constants/misc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright: 2011 MoinMoin:ThomasWaldmann
2+
# Copyright: 2024 MoinMoin:UlrichB
23
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
34

45
"""
@@ -69,3 +70,6 @@
6970
NO_LOCK = 0 # false, someone else holds lock for current item
7071
LOCKED = 1 # true, current user has obtained or renewed lock
7172
LOCK = "lock"
73+
74+
# Valid views allowed for itemlinks
75+
VALID_ITEMLINK_VIEWS = ["+meta", "+history", "+download", "+highlight"]

src/moin/converters/link.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright: 2008 MoinMoin:BastianBlank
2+
# Copyright: 2024 MoinMoin:UlrichB
23
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
34

45
"""
@@ -10,6 +11,7 @@
1011

1112
from flask import g as flaskg
1213

14+
from moin.constants.misc import VALID_ITEMLINK_VIEWS
1315
from moin.utils.interwiki import is_known_wiki, url_for_item
1416
from moin.utils.iri import Iri
1517
from moin.utils.mime import type_moin_document
@@ -182,18 +184,27 @@ def handle_wiki_links(self, elem, input, to_tag=ConverterBase._tag_xlink_href):
182184
elem.set(to_tag, link)
183185

184186
def handle_wikilocal_links(self, elem, input, page, to_tag=ConverterBase._tag_xlink_href):
187+
view_name = ""
185188
if input.path:
186-
# this can be a relative path, make it absolute:
187-
path = input.path
189+
item_name = str(input.path)
190+
# Remove view from item_name before searching
191+
if item_name.startswith("+"):
192+
view_name = item_name.split("/")[0]
193+
if view_name in VALID_ITEMLINK_VIEWS:
194+
item_name = item_name.split(f"{view_name}/")[1]
188195
if page:
189-
path = self.absolute_path(path, page.path)
190-
item_name = str(path)
196+
# this can be a relative path, make it absolute:
197+
item_name = str(self.absolute_path(Iri(path=item_name).path, page.path))
191198
if not flaskg.storage.has_item(item_name):
192199
# XXX these index accesses slow down the link converter quite a bit
193200
elem.set(moin_page.class_, "moin-nonexistent")
194201
else:
195202
item_name = str(page.path[1:]) if page else ""
196203
endpoint, rev, query = self._get_do_rev(input.query)
204+
205+
if view_name == "+meta": # TODO: add other views
206+
endpoint = "frontend.show_item_meta"
207+
197208
url = url_for_item(item_name, rev=rev, endpoint=endpoint)
198209
if not page:
199210
url = url[1:]

src/moin/templates/utils.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
<li class="list-group-item">Item Links:&nbsp;
154154
{%- if meta['itemlinks'] -%}
155155
{%- for item in meta['itemlinks']|sort -%}
156-
<a href="{{ url_for('frontend.show_item', item_name=item) }}" {% if not theme_supp.item_exists(item) %}class="moin-nonexistent"{% endif %}>{{ item }}</a>
156+
<a href="{{ url_for('frontend.show_item', item_name=item) }}" {% if not theme_supp.itemlink_exists(item) %}class="moin-nonexistent"{% endif %}>{{ item }}</a>
157157
{%- if not loop.last %}, {% endif -%}
158158
{%- endfor -%}
159159
{%- else -%}

src/moin/themes/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright: 2003-2010 MoinMoin:ThomasWaldmann
22
# Copyright: 2008 MoinMoin:RadomirDopieralski
33
# Copyright: 2010 MoinMoin:DiogenesAugusto
4-
# Copyright: 2023 MoinMoin project
4+
# Copyright: 2023-2024 MoinMoin project
55
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
66

77
"""
@@ -26,6 +26,7 @@
2626
from moin import wikiutil, user
2727
from moin.constants.keys import USERID, ADDRESS, HOSTNAME, REVID, ITEMID, NAME_EXACT, ASSIGNED_TO, NAME, NAMESPACE
2828
from moin.constants.contenttypes import CONTENTTYPES_MAP, CONTENTTYPE_MARKUP, CONTENTTYPE_TEXT, CONTENTTYPE_MOIN_19
29+
from moin.constants.misc import VALID_ITEMLINK_VIEWS
2930
from moin.constants.namespaces import NAMESPACE_DEFAULT, NAMESPACE_USERS, NAMESPACE_ALL
3031
from moin.constants.rights import SUPERUSER
3132
from moin.search import SearchForm
@@ -591,6 +592,20 @@ def item_exists(self, itemname):
591592
"""
592593
return self.storage.has_item(itemname)
593594

595+
def itemlink_exists(self, itemlink):
596+
"""
597+
Check whether the item pointed to by the given itemlink exists or not
598+
599+
:rtype: boolean
600+
:returns: whether item pointed to by the link exists or not
601+
"""
602+
item_name = itemlink
603+
if itemlink.startswith("+"):
604+
view_name = itemlink.split("/")[0]
605+
if view_name in VALID_ITEMLINK_VIEWS:
606+
item_name = itemlink.split(f"{view_name}/")[1]
607+
return self.storage.has_item(item_name)
608+
594609
def variables_css(self):
595610
"""
596611
Check whether this theme has a variables.css file

0 commit comments

Comments
 (0)