Changeset 3040
- Timestamp:
- 10/28/05 01:19:43 (8 years ago)
- File:
-
- 1 edited
-
trac/trunk/wiki-macros/redirect.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trac/trunk/wiki-macros/redirect.py
r3026 r3040 1 1 # vim: expandtab tabstop=4 2 from StringIO import StringIO3 2 import re 4 3 import string 5 from trac import WikiFormatter 6 from trac.WikiFormatter import CommonFormatter 4 from StringIO import StringIO 5 from trac.wiki.formatter import Formatter 6 from trac.wiki.api import WikiSystem 7 7 8 NL = "\n" 8 class MyFormatter(Formatter): 9 10 def format(self, text): 11 self.formatted_link = None 12 self.missing = False 13 class NullOut(object): 14 def write(self, data): pass 15 Formatter.format(self, text, NullOut()) 16 return self.formatted_link, self.missing 17 18 def _shref_formatter(self, match, fullmatch): 19 if not self.formatted_link: 20 namespace = fullmatch.group('sns') 21 target = fullmatch.group('stgt') 22 if target[0] in "'\"": 23 target = target[1:-1] 24 if namespace == 'wiki': 25 wiki = WikiSystem(self.env) 26 if not wiki.has_page(target): 27 self.missing = True 28 self.formatted_link = self._make_link(namespace, target, match, match) 29 return 9 30 10 31 def execute(hdf, args, env): 11 curpage = hdf.getValue(' args.page', "")32 curpage = hdf.getValue('wiki.page_name', "") 12 33 if not curpage: 13 34 curpage = 'WikiStart' … … 15 36 preview = hdf.getValue('args.preview', "") 16 37 shouldRedirect = (hdf.getValue('args.redirect', "yes") == "yes") and (not preview) 38 17 39 db = env.get_db_cnx() 18 40 out = StringIO() 19 fmt = CommonFormatter(hdf, env, db) 20 21 if args: 22 link, _, missing, _ = fmt._expand_module_link(args) 23 24 if not link and not missing: 25 # This is an external non-trac link 26 link = args 41 link, missing = MyFormatter(env, True, db).format(args) 27 42 28 43 if link and not missing: 29 44 out.write('<div class="system-message">') 30 45 out.write('<strong>Redirect: </strong>') 31 out.write("This page is an alias for the real page located at ") 32 out.write('<a href="') 33 out.write(link) 34 out.write('">') 35 out.write(args) 36 out.write('</a>') 46 out.write('This page redirects to %s ' % link) 37 47 out.write('</div>') 38 48 39 49 if shouldRedirect: 40 out.write('<form id="redirect" method="POST" action="' + link + '">') 41 out.write('<input type="hidden" name="redirectedfrom" value="' + curpage + '">') 50 link_target = re.sub(r'^.*href="([^"]*)".*$', r'\1', link) 51 52 out.write('<form id="redirect" method="POST" action="%s">' % link_target) 53 out.write('<input type="hidden" name="redirectedfrom" value="%s">' % curpage) 42 54 out.write('</form>') 43 55 44 out.write( NL)45 out.write('<script language="JavaScript"> ' + NL)46 out.write('document.forms["redirect"].submit(); ' + NL)47 out.write('</script> ' + NL)56 out.write('\n') 57 out.write('<script language="JavaScript">\n') 58 out.write('document.forms["redirect"].submit();\n') 59 out.write('</script>\n') 48 60 49 61 elif link and missing: … … 51 63 out.write('<div class="system-message">') 52 64 out.write('<strong>Redirection Error: </strong>') 53 out.write('Redirection target not found: ') 54 out.write('<a href="') 55 out.write(link) 56 out.write('">') 57 out.write(args) 58 out.write('</a>') 65 out.write('Redirection target not found: %s' % link) 59 66 out.write('</div>') 60 67
Note: See TracChangeset
for help on using the changeset viewer.
