Tags:
create new tag
view all tags
A Twiki administrator would like to keep people from overriding the variables that he/she uses in templates/topics.

What if the variables names, once processed, are prepended with the SITE/WEB/"" prefix and stored in 3 arrays?

We could just (at preference read time):

  • read Site var VAR1 and store SITE_VAR1, WEB_VAR1, VAR1
  • read Web preference VAR2 and store WEB_VAR2 and VAR2 (replacing the values if present)
  • read User preferences and store only VARn

Then, we apply the replacements in the order: first SITE_VARs, then WEB_VARs, then VARs

This way when we write %SITE_VAR1% we know that it will not be overridden by WEB/USER preferences, %WEB_VAR1% will not be overridden by user preferences, and %VAR1% works like now.

Implementation

Here is the implementation of the above idea: (in wiki.pl towards the end of sub initialize )

[ehi, mom, I'm programming in Perl! smile ]

    getPrefsList( "$twikiWebname\.$wikiPrefsTopicname" ); # site-level
#AS
    # let create a site variable list
    my @sitePrefsKeys   = ();
    my @sitePrefsValues = ( @prefsValues );
    my $key   = "";
    foreach $key ( @prefsKeys ) {
        $sitePrefsKeys[@sitePrefsKeys] = "SITE_$key";
    };

    getPrefsList( "$webName\.$webPrefsTopicname" );      # web-level
    # let create a site variable list
    my @webPrefsKeys   = ();
    my @webPrefsValues = ( @prefsValues );
    foreach $key ( @prefsKeys ) {
        $webPrefsKeys[@webPrefsKeys] = "WEB_$key";
    };

    getPrefsList( $wikiUserName );                       # user-level

    # Now we just need to concatenate the lists
    @prefsKeys   = (@sitePrefsKeys   , @webPrefsKeys   , @prefsKeys  ) ;
    @prefsValues = (@sitePrefsValues , @webPrefsValues , @prefsValues) ;
#AS


[Part moved to WhoIsTheRemoteUserInView ] (-- AndreaSterbini - 12 Sep 2000 )


If I understand the above code. There is nothing to prevent a user from making a variable called SITE_xxx or WEB_xxx on his page?

[... see WhoIsTheRemoteUserInView ]

-- AlWilliams - 12 Sep 2000

  • The user can use SITE_xxx and WEB_xxx vars where he/she likes.
  • The code above keeps separate lists of SITE/WEB/USER vars and then joins the lists in the order SITE/WEB/USER. Suppose a user defines a SITE_xxx var in his/her user page to override some SITE_xxx value. The (user)variable value is never replaced in the text because when the variable replacement process gets to that (user)variable the SITE %SITE_xxx% tag has been already processed and replaced.

Suggestion

  • We could move to 3 different associative arrays and repeat the replacement process until no replacement is left.

-- AndreaSterbini - 12 Sep 2000

You might be interested in some code I added (see LockedPages ). This allows you to set up a Web setting for administrator IDs and locked pages (of course, WebPreferences has to be one of these and also SitePreferences). This brings up the same problem -- What if a user adds his own list of admins or locked pages? I added code that allows you to disallow the user from setting any particular preference. They can add them of course, but we just throw them out.

It wouldn't be hard to even make these match regexp, so you could disallow patterns of preferences.

-- AlWilliams - 12 Sep 2000

Marking variables in topics as FINAL has been implemented. Marking this as "MergedToCore".

-- RafaelAlvarez - 13 Mar 2006

Edit | Attach | Watch | Print version | History: r11 < r10 < r9 < r8 < r7 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r11 - 2006-03-13 - RafaelAlvarez
 
  • 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-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.