changeset 5994:50e82729b826

implement backlink_method to solve the load issues caused by crawlers triggering too many linkto-fullsearches (see docs/CHANGES for details)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 08 Jun 2013 19:03:07 +0200
parents 006b3a2ef9d9
children 2beb3bd18d53
files MoinMoin/config/multiconfig.py MoinMoin/theme/__init__.py docs/CHANGES
diffstat 3 files changed, 40 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Sat Jun 08 17:51:06 2013 +0200
+++ b/MoinMoin/config/multiconfig.py	Sat Jun 08 19:03:07 2013 +0200
@@ -694,6 +694,9 @@
     # the options dictionary.
 
 
+_default_backlink_method = lambda cfg, req: 'backlink' if req.user.valid else 'pagelink'
+
+
 def _default_password_checker(cfg, request, username, password,
                               min_length=6, min_different=4):
     """ Check if a password is secure enough.
@@ -947,6 +950,9 @@
     ('show_version', False, "show moin's version at the bottom of a page"),
     ('show_rename_redirect', False, "if True, offer creation of redirect pages when renaming wiki pages"),
 
+    ('backlink_method', DefaultExpression('_default_backlink_method'),
+     "function determining how the (last part of the) pagename should be rendered in the title area"),
+
     ('packagepages_actions_excluded',
      ['setthemename',  # related to questionable theme stuff, see below
       'copythemefile', # maybe does not work, e.g. if no fs write permissions or real theme file path is unknown to moin
--- a/MoinMoin/theme/__init__.py	Sat Jun 08 17:51:06 2013 +0200
+++ b/MoinMoin/theme/__init__.py	Sat Jun 08 19:03:07 2013 +0200
@@ -225,8 +225,9 @@
     def backlink(self, page, page_name, link_text):
         """ Create html for the "backlink" part of the title.
 
-        This can be a link, but to lighten the server load, we may also
-        give something else to bots, crawlers or not-logged-in users.
+        What it will be is determined by calling cfg.backlink_method,
+        which can return 'backlink' (render a linkto-fullsearch link),
+        'pagelink' (render a link to same page) or 'text' (render just text).
 
         @param page: page object
         @param page_name: the (full) page name
@@ -235,10 +236,16 @@
         """
         request = self.request
         _ = request.getText
-        link_title = _('Click to do a full-text search for this title')
-        link_query = dict(action='fullsearch', value='linkto:"%s"' % page_name, context='180')
-        link = page.link_to(request, link_text, querystr=link_query, title=link_title,
-                            css_class='backlink', rel='nofollow')
+        method = request.cfg.backlink_method(request)
+        if method == 'backlink':
+            link_title = _('Click to do a full-text search for this title')
+            link_query = dict(action='fullsearch', value='linkto:"%s"' % page_name, context='180')
+            link = page.link_to(request, link_text, querystr=link_query, title=link_title,
+                                css_class='backlink', rel='nofollow')
+        elif method == 'pagelink':
+            link = page.link_to(request, link_text)
+        else:  # == 'text'
+            link = wikiutil.escape(link_text)
         return link
 
     def title(self, d):
--- a/docs/CHANGES	Sat Jun 08 17:51:06 2013 +0200
+++ b/docs/CHANGES	Sat Jun 08 19:03:07 2013 +0200
@@ -43,6 +43,27 @@
     TIME is in seconds, the slowness indicator is "." for sub-second requests
     or N times "!" for requests taking N seconds (so you easily can grep for
     slow stuff).
+  * backlinks performance tuning: the pagename in the theme has historically
+    been used to trigger a "linkto:ThisPage" search. While this is a nice
+    feature for human users of the wiki (esp. on category pages), it has one
+    big issue: as it is a normal link, stupid crawlers (ignoring "nofollow")
+    follow it and cause a lot of unneccessary load.
+
+    What moin shows in that "backlinks" place can now be configured in your
+    wiki config:
+
+    # always render the backlink as in moin < 1.9.8 (bad bots causing high load!):
+    backlink_method = lambda cfg, req: 'backlink'
+
+    # always render a simple link to same page, as in moin 2.0:
+    backlink_method = lambda cfg, req: 'pagelink'
+
+    # logged-in users get the backlink, anon users/bots get a pagelink (default):
+    backlink_method = lambda cfg, req: 'backlink' if req.user.valid else 'pagelink'
+
+    # logged-in users get the backlink, anon users/bots get simple text:
+    backlink_method = lambda cfg, req: 'backlink' if req.user.valid else 'text'
+
 
   Fixes:
   * do not create empty pagedirs (with empty edit-log). To clean up all the