[Home]WikiPatches/CSSskins

UseModWiki | WikiPatches | RecentChanges | Preferences

This patch is currently implemented on the UnrealWiki.
I like the idea, but I don't think I will have time to add this patch into 1.0 (with sufficient testing), especially since it conflicts with other changes made for 1.0. --CliffordAdams

Clifford, this has had major updates since I posted this patch. Instead of just reading in a truncated HTML file for the header, it takes in an entire HTML file as a template. -- tarquin -- Tarquin/SampleTemplate for the new system.

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.


It places 2 drop-down lists on the Preferences page, which allows users to choose a CSS stylesheet and a header HTML file for the site.

Simple version, just one HTML file with no user choice: /HtmlHeader

Email: tarquin at planetunreal dot com

Comments

My perl is still fairly clumsy, I'm a complete beginner. Some points that I want to try and clean up:

Implementation

Notes

Headers

These are truncated HTML files, that end by opening the <BODY> tag.

The following placeholders can be used:

%windowtitle%
intended for the HTML TITLE tag: gives the site name and page name
%title%
the page title
%url%
base URL for stylesheets and other files you may need for layout eg logos, buttons etc.

%contentstyles%
will insert full URL for the user's currently chosen stylesheet. Use with the LINK HTML tag.
%logo%
inserts full URL for the site's default logo
%quip%
inserts a random quip from a file

These create a complete HTML link with text to :

%random%
Random Page
%recent%
RecentChanges
%home%
homepage
%prefs%
preferences
%ref%
reference page (name of which is set by a new variable)
%page%MyPage?%
a link to MyPage? (will create an edit link if page doesnt exist)
%upload%
URL to upload page (make link yourself eg <a href="%upload%">text</a> -- this allows an image uploader script to be opened in a new browser window.)

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.

I'm having some trouble getting the styles to work. I don't know exactly where to put my stylesheets. Could someone provide an example of what the Ancillary variables should look like? --NickHusher?

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

$AncillaryDir? = "/Projects?/UnrealWiki?/wiki-ext/";
$AncillaryUrl? = "http://localhost/wiki-ext/" ;

Quips

These can be painlessly removed from this patch. The %quip% placeholder inserts a random line from a file; on Unreal Wiki this puts a quotation or amusing remark beneath the site title.

Patch

Several sections need patching:

Variables

add these lines the "use vars" blocks (line 56)
##########################
# 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 );
#
##########################

Config

In the config file, add the following block, changing names and filenames to suit:
############################
# 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

GetHeader()

Lines 948, 949 replace these two lines:
  $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

new sub

add this sub above:
 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
###################################

DoEdit Prefs

find "sub DoEditPrefs?"; above line 2735:
  print '
', $q->submit(-name=>'Save', -value=>T('Save')), "\n";
add this block:
  ###########################   
  # 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
  ###########################   

DoUpdatePrefs?

above line 2846:
  &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

I'm afraid my copy of UMW has long since been repatched. Dredging up backups & working on it... tarquin


unified Diff

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?

I haven't tried it, but it looks like the diff/patch below is "backwards"--it contains instructions for changing the new "patchwiki.pl" into the original 0.92 "wiki.pl". Some patch programs have an option to apply backwards diffs (maybe called "reverse" diffs?). You might be able to get the patch to work by trying that option. (The harder way would be to replace all '<' chars at the beginning of each line with '>' and vice-versa.) --CliffordAdams

I wish that was true. I tried that. If you look, the patch file must have been messed up when he pasted it. In the first hunk there aren't enough >'s, and there is an extra separator line between the first and second hunks. There are a few other inconsistencies in the patch, but those are the only ones that kill it. Even weirder, checking the unpatched source of the current version doesn't reveal some of the text that is supposed to be replaced. So I'm pretty sure a new patch is needed against the original source. -- DaveFayram?

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
<   ################

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited October 1, 2004 7:08 am by AdamKatz (diff)
Search: