This patch, which applies to UseMod 1.0, duplicates the "edit bar" at the top of the page, making access to the EditThisPage more convenient.
Other versions of this patch follow, but this first one is known to be applicable to 1.0, and is a comprehensive patch that works as expected with all types of pages.
I split GetFooterText into GetFooterText and GetEditBar?. In GetHeader, I call GetEditBar? after GetGotoBar, but only if $id is not empty, which is the case only when BrowsePage calls GetHeader. Also in that case, I give GetHeader an extra parameter for the revision, which gets passed on to GetEditBar?. This seems to work as desired for all the cases I've tried -- the edit page, preferences, and viewing old revisions. However, it's not conditionalized. It would be nice for this to be settable in the config file or, perhaps even better, in the user's Preferences.
(Updated the diff on 2005-05-14 to be a bit more readable, by rearranging some code. This is a unified diff.)
You can play with a wiki running this patch at http://www.spookydistance.com/cgi-bin/public-wiki.pl.
-- DanMuller
--- wiki.pl 2005-05-14 11:56:11.370742256 -0400 +++ wiki-edit-on-top.pl 2005-05-14 12:00:15.949560624 -0400 @@ -540,7 +540,7 @@ } $MainPage = $id; $MainPage =~ s|/.*||; # Only the main page name (remove subpage) - $fullHtml = &GetHeader($id, &QuoteHtml($id), $oldId); + $fullHtml = &GetHeader($id, &QuoteHtml($id), $oldId, $revision); if ($revision ne '') { if (($revision eq $Page{'revision'}) || ($goodRevision ne '')) { $fullHtml .= '<b>' . Ts('Showing revision %s', $revision) . "</b><br>"; @@ -1280,7 +1280,7 @@ } sub GetHeader { - my ($id, $title, $oldId) = @_; + my ($id, $title, $oldId, $rev) = @_; my $header = ""; my $logoImage = ""; my $result = ""; @@ -1312,7 +1312,11 @@ $result .= $q->h1($header . $title); } if (&GetParam("toplinkbar", 1)) { - $result .= &GetGotoBar($id) . "<hr class=wikilineheader>"; + $result .= &GetGotoBar($id); + if ($id ne '') { + $result .= &GetEditBar($id, $rev); + } + $result .= "<hr class=wikilineheader>"; } $result .= '</div>'; return $result; @@ -1389,22 +1393,7 @@ $result = '<div class=wikifooter>'; $result .= &GetFormStart(); $result .= &GetGotoBar($id); - if (&UserCanEdit($id, 0)) { - if ($rev ne '') { - $result .= &GetOldPageLink('edit', $id, $rev, - Ts('Edit revision %s of this page', $rev)); - } else { - $result .= &GetEditLink($id, T('Edit text of this page')); - } - } else { - $result .= T('This page is read-only'); - } - $result .= ' | '; - $result .= &GetHistoryLink($id, T('View other revisions')); - if ($rev ne '') { - $result .= ' | '; - $result .= &GetPageLinkText($id, T('View current revision')); - } + $result .= &GetEditBar($id, $rev); if ($UseMetaWiki) { $result .= ' | <a href="http://sunir.org/apps/meta.pl?' . $id . '">' . T('Search MetaWiki') . '</a>'; @@ -1447,6 +1436,29 @@ return $result; } +sub GetEditBar { + my ($id, $rev) = @_; + my $result; + + if (&UserCanEdit($id, 0)) { + if ($rev ne '') { + $result .= &GetOldPageLink('edit', $id, $rev, + Ts('Edit revision %s of this page', $rev)); + } else { + $result .= &GetEditLink($id, T('Edit text of this page')); + } + } else { + $result .= T('This page is read-only'); + } + $result .= ' | '; + $result .= &GetHistoryLink($id, T('View other revisions')); + if ($rev ne '') { + $result .= ' | '; + $result .= &GetPageLinkText($id, T('View current revision')); + } + return $result; +} + sub GetCommonFooter { my ($html);
Appreciation
This patch works great! What a pleasure to be able to have the edit on top and to not be forced to spend precious time going down the page to reach the edit command. Many thanks DanMuller! -- RobertAbitbol?
http://meatballwiki.org/wiki/EasySubmission
(*) The trivial patch is to add one line at the end of subroutine GetHeader:
sub GetHeader { ... if (&GetParam("toplinkbar", 1)) { # EditFromTop Patch: $result .= &GetEditLink($id, T('<b>Edit text of this page</b>')) . ' | ' if ($EditFromTop && &UserCanEdit($id, 0)); $result .= &GetGotoBar($id) . "<hr class=wikilineheader>"; } $result .= '</div>'; return $result; } ...
where $EditFromTop? is yet another config variable. But notice how the link bar interacts with the logo when it gets too long as it does in my environment.
Just noticed this patch on this page, and I was playing around with doing the same thing, except I started by modifying the GetGotoBar() and how it gets called. Not quite done with this mod, but here's the gist:
435c435 < $fullHtml = &GetHeader($id, &QuoteHtml($id), $oldId); --- > $fullHtml = &GetHeader($id, &QuoteHtml($id), $oldId, $goodRevision); 937c945 < my ($id, $title, $oldId) = @_; --- > my ($id, $title, $oldId, $rev) = @_; 969c977 < $result .= &GetGotoBar($id) . "<hr>"; --- > $result .= &GetGotoBar($id, $rev) . "<hr>"; 1087c1101 < my ($id) = @_; --- > my ($id, $rev) = @_; 1100a1115,1123 > if ( (&UserCanEdit($id, 0)) && ($id ne '') && ($rev ne '')) { > $bartext .= " | "; > if ($rev ne '') { > $bartext .= &GetOldPageLink('edit', $id, $rev, > Ts('Edit revision %s of this page', $rev)); > } else { > $bartext .= &GetEditLink($id, T('Edit this page')); > } > }
-- LesOrchard
Ok, here is my go at it. I just introduced a new global variable called $CurrentMode? which I set to "edit" inside the DoEdit subroutine. I later check this variable in GetHeader and if it is not set to "edit" (you don't want to edit the edit page, right?) I add the edit link to the header. Here are the changes needed:
1. Add a global variable someplace (I added it among the other ones in one of those big variable declarations at the top of the file):
$CurrentMode
2. In the DoEdit sub, right after the block that checks if the user has the right to edit the page, add this:
$CurrentMode = "edit";
3. And last, in GetHeader, add a check that $CurrentMode? is not "edit", and if not add the link. Change this:
if (&GetParam("toplinkbar", 1)) { # Later consider smaller size? $result .= &GetGotoBar($id) . "<hr>"; }
to this:
if (&GetParam("toplinkbar", 1)) { # Later consider smaller size? $result .= &GetGotoBar($id); } if (&UserCanEdit($id, 0)) { if ($CurrentMode ne "edit") { $result .= &GetEditLink($id, T('Edit text of this page')); } } $result .= "<hr>";
Simple and it seems to work pretty good here. If it don't, please notify me. :)
-- MathiasDahl
I added these two lines just before the last line of MathiasDahl's patch - it puts the Revisions link and Search bar at the top as well.
$result .= &GetHistoryLink($id, T('View other revisions')); $result .= '<br>' . &GetSearchForm() if $CurrentMode ne "edit";
Personally I think it would look better with the links all on one line - but I haven't got around to this yet.
Also - additional links still appear on Preferences page with this version & edit of previous releases probably doesn't work either.
For my money, the GetHeader and GetFooterText functions really ought to be combined in some way to make it easier to pick and choose which bits appear at the top and bottom.
1. Add $EditPageLink to vars at top.
2. Add the following line to the beginning of BrowsePage:
$EditPageLink = "true";
3. Make the following change to GetGotoBar:
if (&GetParam("linkrandom", 0)) { $bartext .= " | " . &GetRandomLink(); } ## Insert start if (&UserCanEdit($id, 0)) { if ($EditPageLink eq "true") { my $revision = &GetParam('revision', ''); if ($revision ne '') { $bartext .= " | " . &GetOldPageLink('edit', $id, $revision, Ts('Edit rev %s of Page', $revision)); } else { $bartext .= " | " . &GetEditLink($id, T('Edit Page')); } } } ## Insert end if ($UserGotoBar ne '') { $bartext .= " | " . $UserGotoBar; }
This change avoids having the Edit Page link for pages that cannot be edited (e.g. Preferences), and copes with editing revisions of pages also.
The "Edit text on this page" link at the bottom can be removed if you don't want it, but my patch leaves it.