I'm looking into making settings patchable; it's not that difficult except that getVars/setVars in Everything.pm is hardcoded to use the "vars" field (while patches have the data in a "code" field). Solutions:

  1. copy the ?etVars code into patch display/edit pages, adjusted to use code instead of vars
  2. make settings patches a new nodetype that uses the setting table instead of (or in addition to) htmlcode.
  3. Change Everything.pm something like: (Updated to factor out packVars/unpackVars:)(Updated to de-indent:)
--- Everything.pm.orig 2004-09-13 15:29:13.318740800 -0700 +++ Everything.pm 2004-09-14 09:23:15.763673600 -0700 @@ -258,16 +258,13 @@ ##################################################################### +######## -sub getVars +sub unpackVars { - my ($NODE) = @_; - getRef $NODE; - - return if ($NODE == -1); + my ($vars) = @_; - return {} unless $NODE->{vars}; + return {} unless $vars; - my %vars = map { split /=/ } split (/&/, $$NODE{vars}); + my %vars = map { split /=/ } split (/&/, $vars); foreach (keys %vars) { unescape $vars{$_}; if ($vars{$_} eq ' ') { $vars{$_} = ""; } @@ -277,46 +274,69 @@ } ##################################################################### +######## +sub getVars +{ + my ($NODE, $field) = @_; + getRef $NODE; + + return if ($NODE == -1); + + $field ||= "vars"; + + return unpackVars( $NODE->{$field} ); +} + +##################################################################### +######## +sub packVars +{ + my ($varsref) = @_; + + # Clean out the keys that have do not have a value. + foreach (sort keys %$varsref) { + $$varsref{$_} = " " unless $$varsref{$_}; + } + + return join("&", map( $_."=".escape($$varsref{$_}), keys %$varsre +f) ); +} + +##################################################################### +######## # Sub # setVars # # Purpose -# This takes a hash of variables and assigns it to the 'vars' o +f the -# given node. If the new vars are different, we will update th +e -# node. +# This takes a hash of variables and assigns it to a field of t +he +# given node. If the field is changed, we will update the node +. # # Parameters -# $NODE - a node id or hash of a node that joins on the +# $NODE - a node id or hash of a node, usually one that joins o +n the # "settings" table which has a "vars" field to assign the vars +to. # $varsref - the hashref to get the vars from +# $field - the field in which to put the vars; defaults to "var +s" # # Returns # Nothing # sub setVars { - my ($NODE, $varsref) = @_; - my $str; + my ($NODE, $varsref, $field) = @_; + $field ||= "vars"; getRef($NODE); - unless (exists $$NODE{vars}) { - warn ("setVars:\t'vars' field does not exist for node ".getId +($NODE)." - perhaps it doesn't join on the settings table?\n"); - } - - # Clean out the keys that have do not have a value. - foreach (keys %$varsref) { - $$varsref{$_} = " " unless $$varsref{$_}; + unless (exists $$NODE{$field}) { + warn ("setVars:\t'$field' field does not exist for node " + . getId($NODE) . "\n"); + warn ("\t\tperhaps it doesn't join on the settings table?\n") + if $field eq "vars"; } - $str = join("&", map( $_."=".escape($$varsref{$_}), keys %$varsre +f) ); + my $str = packVars( $varsref ); - return unless ($str ne $$NODE{vars}); #we don't need to update... + return unless ($str ne $$NODE{$field}); #we don't need to update. +.. # The new vars are different from what this user node contains, f +orce # an update on the user info. - $$NODE{vars} = $str; + $$NODE{$field} = $str; my $superuser = -1; $DB->updateNode($NODE, $superuser); }
I'm inclined toward number 3.

Once that's resolved, the rest is pretty easy; it will work differently from other patches in a couple of ways. First, there will be just a "Create Patch" button on the setting display page, not a form (since I don't see an easy way to feed op=new an editvars form). Second, it will just display the new settings, not a diff, at least until I figure out diff_strings enough to hack it to the purpose.


In reply to patchable settings by ysth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.