[Home]WikiPatches/ModWiki

UseModWiki | WikiPatches | RecentChanges | Preferences

This feature is included in the 1.0 release. --CliffordAdams
Implements mod_wiki ala MeatBall:ModWiki. Unlike /RichSiteSummary, this uses the RecentChanges system directly, so you can parameterize the RSS feed in the exact same way as you would RecentChanges (this includes the MeatBall:TimeZone offset). To use it, just replace action=rc with action=rss on the parameter line e.g. MeatBall:action=rss&days=7&showedit=1 -- SunirShah

Now that it's working, it's will be put into the next version of UseModWiki. As it's a complex patch, you may just want to wait until then.


Fixed


To do


Good patch, but there is a little error, under the use strict pragma, yo have to send references to functions and not function name strings...

sub BrowsePage {
...
  if (($id eq $RCName) || (T($RCName) eq $id) || (T($id) eq $RCName)) {
    print $fullHtml;
    &DoRc(\&GetRcHtml);


Add $InterWikiMoniker, $SiteDescription, and $RssLogoUrl to use vars qw(), and then add the following two configurations lines somewhere:

 $InterWikiMoniker = '';              # InterWiki prefix for this wiki. (for RSS)
 $SiteDescription  = $SiteName;       # Description of this wiki. (for RSS)
 $RssLogoUrl       = <logo goes here> # URL to image to associate with your RSS feed

Then configure them in your config file.

 sub GetDiffHTML {
     ...
     $diffType = &GetParam("defaultdiff", 1)  if ($diffType == 4);
     if ($diffType == 1) {
     ...
 }

 sub BrowsePage
 {
     ...
   if (($id eq $RCName) || (T($RCName) eq $id) || (T($id) eq $RCName)) {
     print $fullHtml;
     &DoRc('GetRcHtml');
     print "<hr>\n"  if (!&GetParam('embed', $EmbedWiki));
     ...
 }

 sub DoPost {
     ...
   &SavePage();
   &WriteRcLog($id, $summary, $isEdit, $editTime, $Section{'revision'}, $user, $Section{'host'});
   if ($UseCache) {
     ...
 }

 sub GetOldPageParameters {
   my ($kind, $id, $revision) = @_;
 
   $id = &FreeToNormal($id) if $FreeLinks;
   return "action=$kind&id=$id&revision=$revision";
 }
 
 sub GetOldPageLink {
   my ($kind, $id, $revision, $name) = @_;
 
   $name =~ s/_/ /g if $FreeLinks;
   return &ScriptLink(&GetOldPageParameters($kind, $id, $revision), $name);
 }

 # Note: all diff and recent-list operations should be done within locks.
 sub WriteRcLog {
   my ($id, $summary, $isEdit, $editTime, $revision, $name, $rhost) = @_;
   my ($extraTemp, %extra);
 
   %extra = ();
   $extra{'id'} = $UserID         if ($UserID > 0);
   $extra{'name'} = $name         if ($name ne "");
   $extra{'revision'} = $revision if ($revision ne "");
   ...
 }

 sub DoOtherRequest {
     ...
     } elsif ($action eq "version") {
       &DoShowVersion();
     } elsif ($action eq "rss") {
       &DoRss();
     } else {
     ...
 }

 sub DoRc {
   my ($GetRC) = @_;
   my ($fileData, $rcline, $i, $daysago, $lastTs, $ts, $idOnly);
   my (@fullrc, $status, $oldFileData, $firstTs, $errorText);
   my $starttime = 0;
   my $showbar = 0;
   my $showHTML = $GetRC eq \&GetRcHtml; # Special (normative) case
 
   if (&GetParam("from", 0)) {
     $starttime = &GetParam("from", 0);
     if( $showHTML ) {
       print "<h2>" . Ts('Updates since %s', &TimeToText($starttime))
             . "</h2>\n";
     }
   } else {
     $daysago = &GetParam("days", 0);
     $daysago = &GetParam("rcdays", 0)  if ($daysago == 0);
     if ($daysago) {
       $starttime = $Now - ((24*60*60)*$daysago);
       if( $showHTML ) {
         print "<h2>" . Ts('Updates in the last %s day'
                           . (($daysago != 1)?"s":""), $daysago) . "</h2>\n";
       }
       # Note: must have two translations (for "day" and "days")
       # Following comment line is for translation helper script
       # Ts('Updates in the last %s days', '');
     }
   }
   if ($starttime == 0) {
     $starttime = $Now - ((24*60*60)*$RcDefault);
     if( $showHTML ) {
       print "<h2>" . Ts('Updates in the last %s day'
                         . (($RcDefault != 1)?"s":""), $RcDefault) . "</h2>\n";
     }
     # Translation of above line is identical to previous version
   }
 
   # Read rclog data (and oldrclog data if needed)
   ($status, $fileData) = &ReadFile($RcFile);
   $errorText = "";
   if (!$status) {
     # Save error text if needed.
     $errorText = '<p><strong>' . Ts('Could not open %s log file', $RCName)
                  . ":</strong> $RcFile<p>"
                  . T('Error was') . ":\n<pre>$!</pre>\n" . '<p>'
     . T('Note: This error is normal if no changes have been made.') . "\n";
   }
   @fullrc = split(/\n/, $fileData);
   $firstTs = 0;
   if (@fullrc > 0) {  # Only false if no lines in file
     ($firstTs) = split(/$FS3/, $fullrc[0]);
   }
   if (($firstTs == 0) || ($starttime <= $firstTs)) {
     ($status, $oldFileData) = &ReadFile($RcOldFile);
     if ($status) {
       @fullrc = split(/\n/, $oldFileData . $fileData);
     } else {
       if ($errorText ne "") {  # could not open either rclog file
         print $errorText;
         print "<p><strong>"
               . Ts('Could not open old %s log file', $RCName)
               . ":</strong> $RcOldFile<p>"
               . T('Error was') . ":\n<pre>$!</pre>\n";
         return;
       }
     }
   }
   $lastTs = 0;
   if (@fullrc > 0) {  # Only false if no lines in file
     ($lastTs) = split(/$FS3/, $fullrc[$#fullrc]);
   }
   $lastTs++  if (($Now - $lastTs) > 5);  # Skip last unless very recent
 
   $idOnly = &GetParam("rcidonly", "");
   if ($idOnly && $showHTML) {
     print '<b>(' . Ts('for %s only', &ScriptLink($idOnly, $idOnly))
           . ')</b><br>';
   }
 
   if( $showHTML ) {
     foreach $i (@RcDays) {
       print " | "  if $showbar;
       $showbar = 1;
       print &ScriptLink("action=rc&days=$i",
                         Ts('%s day' . (($i != 1)?'s':''), $i));
         # Note: must have two translations (for "day" and "days")
         # Following comment line is for translation helper script
         # Ts('%s days', '');
     }
     print "<br>" . &ScriptLink("action=rc&from=$lastTs",
                                T('List new changes starting from'));
     print " " . &TimeToText($lastTs) . "<br>\n";
   }
 
   # Later consider a binary search?
   $i = 0;
   while ($i < @fullrc) {  # Optimization: skip old entries quickly
     ($ts) = split(/$FS3/, $fullrc[$i]);
     if ($ts >= $starttime) {
       $i -= 1000  if ($i > 0);
       last;
     }
     $i += 1000;
   }
   $i -= 1000  if (($i > 0) && ($i >= @fullrc));
   for (; $i < @fullrc ; $i++) {
     ($ts) = split(/$FS3/, $fullrc[$i]);
     last if ($ts >= $starttime);
   }
   if ($i == @fullrc && $showHTML) {
     print '<br><strong>' . Ts('No updates since %s',
                               &TimeToText($starttime)) . "</strong><br>\n";
   } else {
     splice(@fullrc, 0, $i);  # Remove items before index $i
     # Later consider an end-time limit (items older than X)
     print &$GetRC(@fullrc);
   }
   print '<p>' . Ts('Page generated %s', &TimeToText($Now)), "<br>\n" if $showHTML;
 }
 
 sub GetRc {
   my $printDailyTear = shift;
   my $printRCLine = shift;
   my @outrc = @_;
   my ($rcline, $date, $newtop, $author);
   my ($showedit, $link, $all, $idOnly);
   my ($ts, $pagename, $summary, $isEdit, $host, $kind, $extraTemp);
   my %extra = ();
   my %changetime = ();
   my %pagecount = ();
 
   # Slice minor edits
   $showedit = &GetParam("rcshowedit", $ShowEdits);
   $showedit = &GetParam("showedit", $showedit);
   if ($showedit != 1) {
     my @temprc = ();
     foreach $rcline (@outrc) {
       ($ts, $pagename, $summary, $isEdit, $host) = split(/$FS3/, $rcline);
       if ($showedit == 0) {  # 0 = No edits
         push(@temprc, $rcline)  if (!$isEdit);
       } else {               # 2 = Only edits
         push(@temprc, $rcline)  if ($isEdit);
       }
     }
     @outrc = @temprc;
   }
 
   # Later consider folding into loop above?
   # Later add lines to assoc. pagename array (for new RC display)
   foreach $rcline (@outrc) {
     ($ts, $pagename) = split(/$FS3/, $rcline);
     $pagecount{$pagename}++;
     $changetime{$pagename} = $ts;
   }
   $date = "";
   $all = &GetParam("rcall", 0);
   $all = &GetParam("all", $all);
   $newtop = &GetParam("rcnewtop", $RecentTop);
   $newtop = &GetParam("newtop", $newtop);
   $idOnly = &GetParam("rcidonly", "");
 
   @outrc = reverse @outrc if ($newtop);
   foreach $rcline (@outrc) {
     ($ts, $pagename, $summary, $isEdit, $host, $kind, $extraTemp)
       = split(/$FS3/, $rcline);
     # Later: need to change $all for new-RC?
     next  if ((!$all) && ($ts < $changetime{$pagename}));
     next  if (($idOnly ne "") && ($idOnly ne $pagename));
     %extra = split(/$FS2/, $extraTemp, -1);
     if ($date ne &CalcDay($ts)) {
       $date = &CalcDay($ts);
       &$printDailyTear($date);
     }
   &$printRCLine( $pagename, $ts, $host, $extra{'name'}, $extra{'id'}, $summary, $isEdit, $pagecount{$pagename}, $extra{'revision'} );
   }
 }
 
 sub GetRcHtml {
   my ($html, $inlist, $all, $rcchangehist);
   my ($tEdit, $tChanges, $tDiff);
 
   # Optimize param fetches out of main loop
   $all = &GetParam("rcall", 0);
   $all = &GetParam("all", $all);
   $rcchangehist = &GetParam("rcchangehist", 1);
 
   # Optimize translations out of main loop
   $tEdit    = T('(edit)');
   $tDiff    = T('(diff)');
   $tChanges = T('changes');
 
   GetRc
 
     # printDailyTear
     sub {
       my $date = shift;
       if ($inlist) {
         $html .= "</UL>\n";
         $inlist = 0;
       }
 
       $html .= "<p><strong>" . $date . "</strong><p>\n";
 
       if (!$inlist) {
         $html .= "<UL>\n";
         $inlist = 1;
       }
     },
 
     # printRCLine
     sub {
     my( $pagename, $timestamp, $host, $userName, $userID, $summary, $isEdit, $pagecount, $revision ) = @_;
       my( $author, $sum, $edit, $count, $link );
       $host = &QuoteHtml($host);
       if (defined($userName) && defined($userID)) {
         $author = &GetAuthorLink($host, $userName, $userID);
       } else {
         $author = &GetAuthorLink($host, "", 0);
       }
       $sum = "";
       if (($summary ne "") && ($summary ne "*")) {
         $summary = &QuoteHtml($summary);
         $sum = "<strong>[$summary]</strong> ";
       }
       $edit = "";
       $edit = "<em>$tEdit</em> "  if ($isEdit);
       $count = "";
       if ((!$all) && ($pagecount > 1)) {
         $count = "($pagecount ";
         if ($rcchangehist) {
           $count .= &GetHistoryLink($pagename, $tChanges);
         } else {
           $count .= $tChanges;
         }
         $count .= ") ";
       }
       $link = "";
       if ($UseDiff && &GetParam("diffrclink", 1)) {
         $link .= &ScriptLinkDiff(4, $pagename, $tDiff, "") . "  ";
       }
       $link .= &GetPageLink($pagename);
       $html .= "<li>$link ";
       # Later do new-RC looping here.
       $html .=  &CalcTime($timestamp) . " $count$edit" . " $sum";
       $html .= ". . . . . $author\n";  # Make dots optional?
     },
 
     @_;
 
   $html .= "</UL>\n" if ($inlist);
   return $html;
 }

 sub GetRcRss {
   my ($rssHeader, $items, $historyPrefix, $diffPrefix);
   my ($QuotedFullUrl, $ChannelAbout);
 
   # Normally get URL from script, but allow override.
   $FullUrl = $q->url(-full=>1)  if ($FullUrl eq "");
   $QuotedFullUrl = &QuoteHtml($FullUrl);
   $SiteDescription = &QuoteHtml($SiteDescription);
   $ChannelAbout = &QuoteHtml($FullUrl . '?' . $ENV{QUERY_STRING});

 
   $diffPrefix = $QuotedFullUrl . &QuoteHtml("?action=browse\&diff=4\&id=");
   $historyPrefix = $QuotedFullUrl . &QuoteHtml("?action=history\&id=");
 
   $rssHeader = <<RSS ;
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <rdf:RDF
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns="http://purl.org/rss/1.0/"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wiki="http://purl.org/rss/1.0/modules/wiki/"
 >
     <channel rdf:about="$QuotedFullUrl">
         <title>${\(&QuoteHtml($SiteName))}</title>
         <link>${\($QuotedFullUrl . &QuoteHtml("?$RCName"))}</link>
         <description>${\(&QuoteHtml($SiteDescription))}</description>
         <wiki:interwiki>
             <rdf:Description link="$QuotedFullUrl">
                 <rdf:value>$InterWikiMoniker</rdf:value>
             </rdf:Description>
         </wiki:interwiki>
         <items>
             <rdf:Seq>
 RSS
 
   GetRc
 
     # printDailyTear
     sub {},
 
     # printRCLine
     sub {
       my( $pagename, $timestamp, $host, $userName, $userID, $summary, $isEdit, $pagecount, $revision ) = @_;
       my( $itemID, $description, $authorLink, $author, $status, $importance, $date );
 
       # Add to list of items in the <channel/>
       $itemID = $FullUrl . '?' . &GetOldPageParameters('browse', $pagename, $revision);
       $itemID = &QuoteHtml($itemID);
       $rssHeader .= "                <rdf:li rdf:resource=\"$itemID\"/>\n";
 
       # Add to list of items proper.
       if (($summary ne "") && ($summary ne "*")) {
         $description = &QuoteHtml($summary);
       }
 
       $host = &QuoteHtml($host);
 
       if( $userName ) {
         $author = &QuoteHtml($userName);
         $authorLink = "link=\"$QuotedFullUrl?$author\"";
       } else {
         $author = $host;
       }
 
       $status = (1 == $revision) ? 'new' : 'updated';
       $importance = $isEdit ? 'minor' : 'major';
 
       $timestamp += $TimeZoneOffset;
       my ($sec, $min, $hour, $mday, $mon, $year) = localtime($timestamp);
       $year += 1900;
       $date = sprintf( "%4d-%02d-%02dT%02d:%02d:%02d+%02d:00",
         $year, $mon+1, $mday, $hour, $min, $sec, $TimeZoneOffset/(60*60) );
 
       $pagename = &QuoteHtml($pagename);
 
       # Write it out longhand
       $items .= <<RSS
     <item rdf:about="$itemID">
         <title>$pagename</title>
         <link>$QuotedFullUrl?$pagename</link>
         <description>$description</description>
         <dc:date>$date</dc:date>
         <dc:contributor>
             <rdf:Description wiki:host="$host" $authorLink>
                 <rdf:value>$author</rdf:value>
             </rdf:Description>
         </dc:contributor>
         <wiki:status>$status</wiki:status>
         <wiki:importance>$importance</wiki:importance>
         <wiki:diff>$diffPrefix$pagename</wiki:diff>
         <wiki:version>$revision</wiki:version>
         <wiki:history>$historyPrefix$pagename</wiki:history>
     </item>
 RSS
     },
 
     @_;
 
   return <<RSS ;
 $rssHeader
             </rdf:Seq>
         </items>
     </channel>
     <image rdf:about="${\(&QuoteHtml($RssLogoUrl))}">
         <title>${\(&QuoteHtml($SiteName))}</title>
         <url>$RssLogoUrl</url>
         <link>$QuotedFullUrl</link>
     </image>
 $items
 </rdf:RDF>
 RSS
 }

 sub DoRss {
   print "Content-type: text/plain\n\n";
   &DoRc(\&GetRcRss);
 }

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited May 22, 2009 3:44 pm by JuanmaMP (diff)
Search: