# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - RecommendPage Action Macro

    PURPOSE:
        This macro is used to show the first 180 chars of a wikipage

    CALLING SEQUENCE:
        [[ShortText(WikiName)]]

    PROCEDURE:
       This routine needs the macro RecommendPage

       Please remove the version number from the filename.

    MODIFICATION HISTORY:
        @copyright: 2005 by Reimar Bauer (R.Bauer@fz-juelich.de)
        @license: GNU GPL, see COPYING for details.
        Version: 1.3.4-1
        2005-09-09 : Version 1.3.5-2 : bug fixed if acl does not allow to read the routine has crashed before



"""

from MoinMoin.action import RecommendPage
from MoinMoin.Page import Page

Dependencies = ["pages"]


def execute(macro, pagename):
    request = macro.request
    _ = request.getText

    if request.user.may.read(pagename):
        thispage=Page(request,pagename)
        thisraw=thispage.get_raw_body()

        given_acl,thisraw = RecommendPage.ACLparse(request, thisraw)
        if (len(thisraw) > 180):
            return thisraw[0:180]
        else:
            return thisraw
    else:
      return "You are not allowed to read (please login)"