← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands-website/wiki_no_delete into lp:widelands-website

 

kaputtnik has proposed merging lp:~widelands-dev/widelands-website/wiki_no_delete into lp:widelands-website.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1735435 in Widelands Website: "Deleting a wikipage should not really delete it"
  https://bugs.launchpad.net/widelands-website/+bug/1735435

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands-website/wiki_no_delete/+merge/334639

Prevent deleting of wiki articles over the admin page by:

1. Disable the 'Action' selection box in https://wl.widelands.org/admin/wiki/article/
2. Remove permission 'delete' for model Article. This removes the 'Delete' button from the admin page detail view of an article. This change do not apply to users who already had the permission (the permission get not removed from the django model user_user_permission). To remove the permission from users who have this permission formerly, i have added the Django permission model to the admins interface. Deleting the permission over the admin will make sure Djangos orm is used.

Additionally:
1. Serve a HTTP404 if an article isn't found in backlinks view to prevent server errors
2. Reworked the logic of backlinks, because it didn't worked correct under some circumstances, e.g. if a copied url from browsers addressbar contain percent encoding and is pasted into the article. E.g. [[ Go back to main page | Main%20Page ]]
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/wiki_no_delete into lp:widelands-website.
=== added file 'mainpage/admin.py'
--- mainpage/admin.py	1970-01-01 00:00:00 +0000
+++ mainpage/admin.py	2017-12-03 12:34:33 +0000
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""Get acces to additional models which are not set by Django by default.
+
+So Djangos orm is used when changing things, e.g. delete a permission.
+
+"""
+
+from django.contrib import admin
+from django.contrib.auth.models import Permission
+admin.site.register(Permission)

=== modified file 'wiki/admin.py'
--- wiki/admin.py	2016-12-19 07:33:38 +0000
+++ wiki/admin.py	2017-12-03 12:34:33 +0000
@@ -14,6 +14,8 @@
 
 
 class ArticleAdmin(admin.ModelAdmin):
+    # Do not show 'Action' to prevent deleting:
+    actions = None
     search_fields = ['title']
     list_display = ('title', 'creator', 'last_update',)
     list_filter = ('title',)

=== modified file 'wiki/models.py'
--- wiki/models.py	2017-09-12 18:04:34 +0000
+++ wiki/models.py	2017-12-03 12:34:33 +0000
@@ -70,6 +70,7 @@
         verbose_name = _(u'Article')
         verbose_name_plural = _(u'Articles')
         app_label = 'wiki'
+        default_permissions = ('change', 'add',)
 
     def get_absolute_url(self):
         if self.group is None:

=== modified file 'wiki/views.py'
--- wiki/views.py	2017-02-24 19:15:17 +0000
+++ wiki/views.py	2017-12-03 12:34:33 +0000
@@ -21,6 +21,7 @@
 
 from wl_utils import get_real_ip
 import re
+import urllib
 
 # Settings
 #  lock duration in minutes
@@ -632,14 +633,19 @@
     """
 
     # Find old title(s) of this article
-    this_article = Article.objects.get(title=title)
+    this_article = get_object_or_404(Article, title=title)
     changesets = this_article.changeset_set.all()
     old_titles = []
     for cs in changesets:
         if cs.old_title and cs.old_title != title and cs.old_title not in old_titles:
             old_titles.append(cs.old_title)
 
-    search_title = [re.compile(r"\[\[\s*%s\s*\]\]" % title)]
+    # Search for semantic wiki links. The regexpr was copied from there
+    # and slightly modified
+    search_title = [re.compile(r"\[\[\s*(%s)/?\s*(\|\s*.+?\s*)?\]\]" % title)]
+
+    # Search for links in MarkDown syntax, like [Foo](wiki/FooBar)
+    # The regexpr matches the title between '/' and ')'
     search_title.append(re.compile(r"\/%s\)" % title))
 
     # Search for current and previous titles
@@ -648,13 +654,16 @@
     articles_all = Article.objects.all().exclude(title=title)
     for article in articles_all:
         for regexp in search_title:
-            match = regexp.search(article.content)
+            # Need to unqoute the content to match
+            # e.g. [[ Back | Title%20of%20Page ]]
+            match = regexp.search(urllib.unquote(article.content))
             if match:
                 found_links.append({'title': article.title})
 
         for old_title in old_titles:
             if old_title in article.content:
-                found_old_links.append({'old_title': old_title, 'title': article.title })
+                found_old_links.append(
+                    {'old_title': old_title, 'title': article.title })
 
     context = {'found_links': found_links,
                'found_old_links': found_old_links,


Follow ups