본문 바로가기
OldStory/Home Linux

wiki expand variables 추가

by Alnilam 2009. 5. 14.

expand variable @PAGENAME@ 를 subpage에 사용하면 "mainpage/subpage" 로 변환된다.  subpage만 얻어오는 expand variable @SUBPAGE@를 /usr/lib/python2.5/site-packages/MoinMoin/PageEdit.py 의 def_expand_variables()함수에 추가함.

  def _expand_variables(self, text):
        """ Expand @VARIABLE@ in `text`and return the expanded text.

        @param text: current text of wikipage
        @rtype: string
        @return: new text of wikipage, variables replaced
        """
        # TODO: Allow addition of variables via wikiconfig or a global wiki dict.
        request = self.request
        now = self._get_local_timestamp()
        u = request.user
        obfuscated_email_address = encodeSpamSafeEmail(u.email)
        signature = u.signature()
        variables = {
            'PAGE': self.page_name,
            'TIME': "<<DateTime(%s)>>" % now,
            'DATE': "<<Date(%s)>>" % now,
            'ME': u.name,
            'USERNAME': signature,
            'USER': "-- %s" % signature,
            'SIG': "-- %s <<DateTime(%s)>>" % (signature, now),
            'EMAIL': "<<MailTo(%s)>>" % (obfuscated_email_address),
            'SUBNAME': self.page_name.split('/')[-1]
        }

        if u.valid and u.name:
            if u.email:
                variables['MAILTO'] = "<<MailTo(%s)>>" % u.email
            # Users can define their own variables via
            # UserHomepage/MyDict, which override the default variables.
            userDictPage = u.name + "/MyDict"
            if request.dicts.has_dict(userDictPage):
                variables.update(request.dicts.dict(userDictPage))

        for name in variables:
            text = text.replace('@%s@' % name, variables[name])
        return text

'OldStory > Home Linux' 카테고리의 다른 글

Wandering In The Sky  (0) 2009.05.15
Zebra  (0) 2009.05.15
Wall-E  (0) 2009.04.07
Cabo Blanco I (Nouadibou)  (0) 2009.04.02
kin-dza-dza  (0) 2009.03.27