A disclaimer, I am quite proficient in shell scripting and in good software design, but I do not count Perl as a language I am terribly proficient in. There are likely places in this code that could use some help, including code with formatting that was mimicked imporperly or sub-optimally.
This patch takes the contents of the CSSLocalDir (which MUST be directory hosed online as CSSUriDir) directory on your filesystem and adds each stylesheet it contains to a list of alternate stylesheets for each page.
Two config variables:
$CSSLocalDir = ""; # Path to directory of alt. CSS stylesheets $CSSUrlDir = ""; # URL matching CSSLocalDir
Add CSSLocalDir and CSSUrlDir to the 'use vars qw(' Configuration/constant variables declaration.
In both your configuration file and in the wiki code, add the two above config lines under
StyleSheet = ""; # URL for CSS stylesheet (like "/wiki.css")
Insert the following function somewhere (advice needed as to where!), I chose between 'sub GetHistoryLink' and 'sub GetHeader'
# AlternateStyleSheets patch by AdamKatz # https://www.usemod.org/cgi-bin/wiki.pl?WikiPatches/AlternateStyleSheets sub GetAlternateStyleSheets { if ($CSSLocalDir ne '' and $CSSUrlDir ne '') { my ($arg) = @_; my $sheet; my $altsheets; my %menuitems = ('' => "User Specified"); # allow 'use URL' option opendir DIRH, "$CSSLocalDir" or die "couldn't open: $!"; foreach (sort readdir DIRH) { $sheet = $_; if ($sheet =~ m/\.css$/) { open(INFILE,$CSSLocalDir.'/'.$sheet) or return 0; chomp ($_ = <INFILE>); close INFILE; if (defined $_ and $_ =~ m:/\* *(.*?) *\*/:) {# line 1 has a comment $_ = $1; # grab only the comment } else { # no comment, use filename $_ = $sheet; $_ =~ s/\.css$//; } if ($arg =~ m/head/) { $altsheets .= qq(<link rel="alternate stylesheet" title="$_" ); $altsheets .= qq(href="$CSSUrlDir/$sheet">\n); } else { %menuitems = (%menuitems, "$CSSUrlDir/$sheet"=>"$_"); } } } if (not $arg =~ m/head/) { my @menuvalues = keys(%menuitems); # if using a stylesheet URL (not an altss), blank altss (user-specified) if (not exists($menuitems{$arg})) { $arg = ''; } $altsheets .= '<br />' . T('StyleSheet:') . ' '; $altsheets .= $q->popup_menu(-name=>'p_altstylesheet', -values=>\@menuvalues, -default=>$arg, -labels=>\%menuitems); $altsheets .= ' ' . T('or enter a'); } closedir DIRH; return $altsheets; } return ""; } # End of AlternateStyleSheets patch
Find these lines:
if ($stylesheet ne '') { $html .= qq(<link rel="stylesheet" href="$stylesheet">\n); }Add this after them:
$html .= GetAlternateStyleSheets("head");
Find these lines:
print '<br>' . T('StyleSheet URL:') . ' ', &GetFormText('stylesheet', "", 30, 150);Add this before them:
print GetAlternateStyleSheets(&GetParam('stylesheet', 1));
Find thie line:
$stylesheet = &GetParam('p_stylesheet', '');Add this after it:
my $altstylesheet = &GetParam('p_altstylesheet', ''); my $currentstyle = $UserData{'stylesheet'}; # use altss only if it is changed and not blank (blank=user-specified) # and only if the user-specified stylesheet is unchanged or blank) if (($altstylesheet ne $currentstyle and $altstylesheet ne '') and ($stylesheet eq $currentstyle or $stylesheet eq '')) { $stylesheet = $altstylesheet; # trump user-specified stylesheet URL }