I have implemented a more lightweight way to do this for UseModWiki 1.0 which features on-the-fly selection of stylesheets via alternate stylesheets as well as a quick-fix to the preferences to always use one of them. Take a look at /AlternateStyleSheets --AdamKatz
Note: the patches below are for UseModWiki 0.92.
Simple version, just one HTML file with no user choice: /HtmlHeader
Email: tarquin at planetunreal dot com
The following placeholders can be used:
These create a complete HTML link with text to :
You can let the user choose content style and header independently (at the risk of colour clash if the header isn't written carefully).
Alternatively, by using a hard reference to a content style sheet, a header can force content style. If doing this, remember to prefix the filename with %url%.
It would be good style to mark this disctinction in the drop-down list the user chooses from -- eg a header that forces content style is described as "myHeader*", say. That way the user is not left wondering why changing content style has no effect.
Ancillary Dir is a path for something within the filesystem. Anc Url is a path for the browser. Because of web servers setting up a virtual directory system, the path to the same folder can be wildly different
########################## # patch: skins # name of reference page use vars qw($ManPage); # for external files use vars qw($AncillaryPath $AncillaryURL); # for user-set styles & headers use vars qw(%StyleSheetData %HeaderFileData ); # ##########################
############################
# tarquin: skins
$AncillaryDir = ""; # path for extra files to read in
$AncillaryUrl = "../wiki-ext/" ; # url for all the extras like style sheets
$ImgUrl = "../gif/"; # path to image files as used by the @X@ markup; TRAIL A / !
$ManPage = "Wiki_Markup"; # Name of reference page (change space to _)
$UploadLink = "" target=\"_blank " ; # link HTML for uploader page
%StyleSheetData = (
0=> [ "name", "filename.css" ],
);
%HeaderFileData = (
0=> [ "name", "filename.html" ],
);
# end
$result .= &GetHtmlHeader("$SiteName?: $title"); return $result if ($embed);
with this:
############################
# tarq: external user-selected headers
# UseMod's original GetHtmlHeader is still required if config is set to "embed"
return $result . &GetHtmlHeader("$SiteName: $title") if ($embed);
# get the full custom header if the file exists. Otherwise, supply built-in header
# the DIV and CSS can give fairly ugly results, but at least it doesn't terminate
return $result . &GetUserFullHeader("$SiteName: $title", $id, $title, $oldId)
if -f $AncillaryDir . $HeaderFileData{&GetParam('header', 0)}[1];
$result .= &GetHtmlHeader("$SiteName: $title");
# endtarq
sub GetFooterText { line 1021
#########################################################
# tarq: get full header specified by user
sub GetUserFullHeader {
my ( $windowtitle, $id, $title, $oldId) = @_;
# we've been passed: ("$SiteName: $title", $id, $title, $oldId)
my ( $header, $main , $sub , $complextitle, @quips , $randomquip );
# may as well use existing opening function.
$header = &ReadFileOrDie($AncillaryDir . $HeaderFileData{&GetParam("header", 0)}[1]);
$header =~ s/%windowtitle%/$windowtitle/eg;
$header =~ s/%contentstyles%/$AncillaryUrl . $StyleSheetData{&GetParam("stylesheet", 0)}[1]/eg;
#simple version: $header =~ s/%title%/$title/g;
if ($id =~ m|/|) {
# we are dealing with a subpage
$main = $sub = $id;
$main =~ s|/.*||; # Only the main page name (remove subpage)
$sub =~ s|\w*/|| ;
# why won't the next line work?
#$header =~ s/%title%/&GetPageLink($main) . "/" . &GetSearchLink($id)/eg;
$complextitle = &GetPageLink($main) . " / " . &GetSearchLink($sub) ;
$header =~ s/%title%/$complextitle/eg;
# note that GetSearchLink handles trimming the sub from the main.
} else {
# we're not
$header =~ s/%title%/&GetSearchLink($title)/eg;
}
$header =~ s/%url%/$AncillaryURL/eg;
$header =~ s/%path%/$AncillaryPath/eg;
$header =~ s/%logo%/$LogoUrl /eg;
$header =~ s/%home%/&GetPageLink($HomePage)/eg;
$header =~ s/%prefs%/&GetPrefsLink()/eg;
$header =~ s/%random%/&GetRandomLink()/eg;
$header =~ s/%recent%/&GetPageLink($RCName)/eg;
$header =~ s/%ref%/&GetPageLink($ManPage)/eg;
$header =~ s/%page%(\S+)%/&GetPageOrEditLink($1)/eg;
# ========== quip
if( $header =~ m/%quip%/ ) {
open QUIPS, $AncillaryPath . 'quips.txt';
#open QUIPS, &GetPageFile($1);
@quips = <QUIPS>;
close QUIPS;
$randomquip = $quips[rand @quips];
$header =~ s/%quip%/$randomquip/eg;
}
# ========== endquip
$header .= " ";
}
# end tarq
###################################
print 'add this block:
', $q->submit(-name=>'Save', -value=>T('Save')), "\n";
###########################
# tarq: custom header files & style sheets
{
my %myhash ;
# use a local hash to create the correct structure for popup_menu()
print '<hr><b>' . T('Skins:') . "</b><br>\n";
%myhash = map { $_ => $HeaderFileData{$_}[0] } keys %HeaderFileData;
print T('Page header:'), $q->popup_menu(-name=>'p_header',
-values=>[0..((scalar keys %HeaderFileData) -1)],
-labels=>\%myhash,
-default=>&GetParam("header", 1));
print '<br>', T('(A header with a name ending in * loads its own content stylesheet)') . "<br>\n";
%myhash = map { $_ => $StyleSheetData{$_}[0] } keys %StyleSheetData;
print T('Content stylesheet:'), $q->popup_menu(-name=>'p_stylesheet',
-values=>[0..((scalar keys %StyleSheetData) -1)],
-labels=>\%myhash,
-default=>&GetParam("stylesheet", 1));
}
# end
###########################
&SaveUserData();add this block:
#################
# tarq: user styles & header
&UpdatePrefNumber("stylesheet", 1, 0, scalar keys %StyleSheetData );
&UpdatePrefNumber("header", 1, 0, scalar keys %HeaderFileData );
print '<b>', T('Skin changes will be visible on next page load.'), '</b><br>';
# end tarq
################
Could you provide a unified diff for convenience, please? --jl
This patch doesn't seem to work, or even be a valid patch file! What gives? I had to play with the first entry to even get patch to accept it, and then all the hunks failed. Does anyone have a working patch file we can use?
Compare: (<)E:\Apache Group\Apache\cgi-bin\older versions of wiki perl\pre-config file patchwiki.pl (135485 bytes)
with: (>)E:\Apache Group\Apache\cgi-bin\older versions of wiki perl\original wiki.pl (124379 bytes)
59,89c56,58
< #########################
< # tarquin: extra config variables
< # path for embedded images
< use vars qw($ImgUrl);
< # name of reference page & upload link
< use vars qw($ManPage $UploadLink);
< # for external files
< use vars qw($AncillaryDir $AncillaryUrl);
< # for user-set styles & headers
< use vars qw(%StyleSheetData %HeaderFileData );
---
989,999c948,949
< ############################
< # tarq: external user-selected headers
< # UseMod's original GetHtmlHeader is still required if config is set to "embed"
< return $result . &GetHtmlHeader("$SiteName: $title") if ($embed);
<
< return $result . &GetUserFullHeader("$SiteName: $title", $id, $title, $oldId);
< #$result .= &GetHtmlHeader("$SiteName: $title");
< #return $result if ($embed);
< # tarq: this is where we optionally fetch the external header
< #return $result . &GetExternalHeader($id, $title, $oldId) if ($UseExternalHeader);
< # endtarq
---
> $result .= &GetHtmlHeader("$SiteName: $title");
> return $result if ($embed);
---
>
1067,1072c1007,1009
< # tarq: user-selected stylesheet
< #if ($StyleSheet ne '') {
< # $html .= qq(<LINK REL="stylesheet" HREF="$AncillaryUrl$StyleSheet">\n);
< #}
< #$html .= qq(<LINK REL="stylesheet" HREF="$AncillaryUrl$StyleSheetFile[&GetParam("stylesheet", 1)]">\n);
< $html .= qq(<LINK REL="stylesheet" HREF="$AncillaryUrl$StyleSheetData{&GetParam("stylesheet", 1)}[1]">\n);
---
> if ($StyleSheet ne '') {
> $html .= qq(<LINK REL="stylesheet" HREF="$StyleSheet">\n);
> }
1084,1145d1021
< #########################################################
< # tarq: get full header specified by user
< sub GetUserFullHeader {
< my ( $windowtitle, $id, $title, $oldId) = @_;
< # we've been passed: ("$SiteName: $title", $id, $title, $oldId)
<
< my ( $header, $main , $sub , $complextitle, @quips , $randomquip );
< # may as well use existing opening function.
< $header = &ReadFileOrDie($AncillaryDir . $HeaderFileData{&GetParam("header", 0)}[1]);
<
< $header =~ s/%windowtitle%/$windowtitle/eg;
< $header =~ s/%contentstyles%/$AncillaryUrl . $StyleSheetData{&GetParam("stylesheet", 0)}[1]/eg;
<
< #simple version: $header =~ s/%title%/$title/g;
< if ($id =~ m|/|) {
< # we are dealing with a subpage
< $main = $sub = $id;
< $main =~ s|/.*||; # Only the main page name (remove subpage)
< $sub =~ s|\w*/|| ;
< # mych if you spot this: why won't the next line work?
< #$header =~ s/%title%/&GetPageLink($main) . "/" . &GetSearchLink($id)/eg;
< $complextitle = &GetPageLink($main) . " / " . &GetSearchLink($sub) ;
< $header =~ s/%title%/$complextitle/eg;
< # note that GetSearchLink handles trimming the sub from the main.
< } else {
< # we're not
< $header =~ s/%title%/&GetSearchLink($title)/eg;
< #$header =~ s/%title%/blickle/g;
< }
< $header =~ s/%url%/$AncillaryUrl/eg;
< $header =~ s/%path%/$AncillaryDir/eg;
< $header =~ s/%logo%/$AncillaryUrl$LogoUrl/g;
< # links:
< $header =~ s/%home%/&GetPageLink($HomePage)/eg;
< $header =~ s/%prefs%/&GetPrefsLink()/eg;
< $header =~ s/%random%/&GetRandomLink()/eg;
< $header =~ s/%recent%/&GetPageLink($RCName)/eg;
< $header =~ s/%ref%/&GetPageLink($ManPage)/eg;
< # handle | links too
< $header =~ s/%page%(\S+)\|(\S+)%/&GetPageOrEditLink($1, $2)/eg;
< $header =~ s/%page%(\S+)%/&GetPageOrEditLink($1)/eg;
<
< $header =~ s/%upload%/$UploadLink/g;
<
< # ========== quip
< if( $header =~ m/%quip%/ ) {
< open QUIPS, $AncillaryDir . 'quips.txt';
< #open QUIPS, &GetPageFile($1);
< @quips = <QUIPS>;
< close QUIPS;
< $randomquip = $quips[rand @quips];
<
< $header =~ s/%quip%/$randomquip/eg;
< }
< # ========== endquip
< # for mysterious reasons it won't work without this line
< $header .= " ";
<
< }
< # end tarq
< ###################################
<
2996,3016d2735
< ###########################
< # tarq: custom header files & style sheets
< {
< my %myhash ;
< # use a local hash to create the correct structure for popup_menu()
< print '<hr><b>' . T('Skins:') . "</b><br>\n";
< %myhash = map { $_ => $HeaderFileData{$_}[0] } keys %HeaderFileData;
< print T('Page header:'), $q->popup_menu(-name=>'p_header',
< -values=>[0..((scalar keys %HeaderFileData) -1)],
< -labels=>\%myhash,
< -default=>&GetParam("header", 1));
< print '<br>', T('(A header with a name ending in * loads its own content stylesheet)') . "<br>\n";
< %myhash = map { $_ => $StyleSheetData{$_}[0] } keys %StyleSheetData;
< print T('Content stylesheet:'), $q->popup_menu(-name=>'p_stylesheet',
< -values=>[0..((scalar keys %StyleSheetData) -1)],
< -labels=>\%myhash,
< -default=>&GetParam("stylesheet", 1));
< }
<
< # end
< ###########################
3126,3132c2844
< #################
< # tarq: user styles & header
< &UpdatePrefNumber("stylesheet", 1, 0, scalar keys %StyleSheetData );
< &UpdatePrefNumber("header", 1, 0, scalar keys %HeaderFileData );
< print '<b>', T('Skin changes will be visible on next page load.'), '</b><br>';
< # end tarq
< ################