Tags:
create new tag
view all tags
WARNING: this topic applies only to TWiki releases prior to TWiki-4. Do not attempt to apply this patch to TWiki-4!

I tweaked TWiki.pm so that it will automatically render usernames as internal links.

That way, we at my company can use our existing authentication structure to let people login, and they can optionally decide to make a page for themselves. We don't need any information about the users that are using the site, since they are internal and we have a directory and everything.

One idea I have is to change edit so that upon creating a username topic, it will seed the form with a template. Or else, I could tweak the code more so that on initial login, the user page is created. I'm not sure what would be best yet.

The changes involve changing the renderer so that it recognizes a Main.username type of string (2 to 8 chars, lowercase, in the Main web), and tweaking the internal link creation routine so that it doesn't capitalize strings like that, so that the Prefs module finds the page.

This is the diff against the December release, as you can see the changes are minimal:

--- TWiki.pm.orig       Tue Dec  4 07:59:42 2001
+++ TWiki.pm    Sun Jul 21 17:23:23 2002
@@ -1742,7 +1742,8 @@
     # kill spaces and Wikify page name (ManpreetSingh - 15 Sep 2000)
     $theTopic =~ s/^\s*//;
     $theTopic =~ s/\s*$//;
-    $theTopic =~ s/^(.)/\U$1/;
+    #Only capitalize if not a username
+    ($theWeb eq $mainWebname && $theTopic =~ /^[a-z]{2,8}$/) || $theTopic =~ s/^(.)/\U$1/;
     $theTopic =~ s/\s([a-zA-Z0-9])/\U$1/g;
     # Add  before WikiWord inside text to prevent double links
     $theLinkText =~ s/([\s\(])([A-Z]+[a-z]+[A-Z])/$1$2/go;
@@ -2028,6 +2029,9 @@
                 s/([\s\(])([A-Z]+[a-z0-9]*)\.([A-Z]+[a-z]+[A-Z]+[a-zA-Z0-9]*)(\#[a-zA-Z0-9_]*)/&internalLink($1,$2,$3,"$TranslationToken$3$4$TranslationToken",$4,1)/geo;
                 # 'Web.TopicName' link:
                 s/([\s\(])([A-Z]+[a-z0-9]*)\.([A-Z]+[a-z]+[A-Z]+[a-zA-Z0-9]*)/&internalLink($1,$2,$3,"$TranslationToken$3$TranslationToken","",1)/geo;
+               # 'MainWeb.username' link:
+               # Added by wmertens@ciscoSTOPSPAM.com
+               s/([\s\(])($mainWebname)\.([a-z]{2,8})(\#[a-zA-Z0-9_]*)/&internalLink($1,$2,$3,"$TranslationToken$3$4$TranslationToken",$4,1)/geo;
+               s/([\s\(])($mainWebname)\.([a-z]{2,8})([^a-zA-Z0-9])/&internalLink($1,$2,$3,"$TranslationToken$3$TranslationToken","",1).$4/geo;
                 # 'TopicName#anchor' link:
                 s/([\s\(])([A-Z]+[a-z]+[A-Z]+[a-zA-Z0-9]*)(\#[a-zA-Z0-9_]*)/&internalLink($1,$theWeb,$2,"$TranslationToken$2$3$TranslationToken",$3,1)/geo;
                 # 'TopicName' link:

First I tried implementing it as a plugin, but that would mean code duplication with internalLink, and not having access to the noAutoLink variable.

Note that this setup means that the TWiki user directory is not really used, only for people who prefer having a TWiki name.

I realize this may be difficult to put in the codebase, although it could be done if it was protected by a preference setting. I think it would be very useful to all those corporate users out there.

-- WoutMertens - 21 Jul 2002

UPDATE I made a plugin that implements the above behaviour, and makes the edit link so that the field is filled in with a new user template.

I don't have time this week to figure out how to make this an official plugin, so I'll just attach the files here for now.

-- WoutMertens - 22 Jul 2002

I fixed a little bug in the plugin: It didn't render [<nop[link]] type links. I implemented it so that only one search is done, for both [[link]] and [[link][text]] type links, but I don't know if the extra complexity made the total slower frown

In any case, it would be faster to implement this in TWiki.pm.

-- WoutMertens - 01 Aug 2002

I'm using this, the patch not the plugin, with the current release (Feb2003) in conjunction with WindowsInstallModNTLM. There are no problems so far.

-- MattWilkie - 05 Aug 2003

Forgive my ignorance but on your TWiki.pm I am trying to either implement the above code or the plugin for this and I am not sure what part of above am I suppose to add and where should I put in the TWiki.pm. I am currently using TWIKI20030201.tar package, is this patch part of the default install and I just need to enable something. I think I need this feature above, I have a authen site where users already have an account of i.e Bob Brown is bbrown but it isn't a wikiname so it doesn't get created as website only his personal settings. Currently I am using this as the personal websites section but I figure this isn't the ideal setup. Thanks for your help.

-- SamCeb - 08 March 2004

Sam, this patch is not part of the default tiwki install. The text above is in what is called 'unified diff format'.Copy it to a file in the same dir as TWiki.pm, say use-login-name.patch. Then from a bash shell run 'patch TWiki.pm use-login-name.patch' in that directory.

Failing that, you can do it manually: the lines beginning with a minus (-) are to be deleted, and the lines beginning with a plus (+) are to be added. The lines with neither plus or minus are there for context; they don't change, they are just to help you find the right spot in the file.

-- MattWilkie - 17 Apr 2004


Category: TWikiPatches
Topic attachments
I Attachment History Action Size Date Who Comment
Perl source code filepm LoginNamePlugin.pm r2 r1 manage 5.5 K 2002-08-02 - 00:01 UnknownUser The module
Texttxt LoginNamePlugin.txt r1 manage 1.0 K 2002-07-22 - 03:55 UnknownUser The description file
Edit | Attach | Watch | Print version | History: r10 < r9 < r8 < r7 < r6 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r10 - 2006-08-29 - CrawfordCurrie
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.