Contact: diafygi (curvy thing) gmail (period) com Description: PageFeed is a recipe for PmWiki that creates an RSS feed from a single wiki page's history, where each edit is an entry in the feed. The resulting RSS feed can be called by using ?action=pagefeed (http://example.com/pmwiki.php?n=Main.HomePage&action=pagefeed) or (http://example.com/pmwiki.php/Main/HomePage?action=pagefeed if you have $EnablePathInfo=1) Installation: To enable PageFeed, save this file in your cookbook folder, and include the following line in your config.php: include_once("$FarmD/cookbook/pagefeed.php"); Count Option: You can define how many items are in the feed (default is 25) by adding &count=n to the url, where n is the number of items you want to appear. (i.e. http://example.com/pmwiki.php?n=Main.HomePage&action=pagefeed&count=10 will only show the 10 most recent history items) Minor Edit Option: You can choose to not include minor edits in the page feed by turing the minor option to 0 in the feed url. By default, PageFeed displays all edits. (i.e. http://example.com/pmwiki.php?n=Main.HomePage&action=pagefeed&minor=0 will only show non-minor feeds) Format: The format for the feed xml is saved in the template $FeedFmt['pagefeed'] and follows the same formatting guidelines as PmWiki's feeds.php system (see http://pmwiki.org/wiki/PmWiki/WebFeeds) There are several special variables you can include to make the PageFeed more dynamic. These can be included in any part of the $FeedFmt['pagefeed'] array: $FeedRSSTime Most recent edit in standard UTC format $FeedISOTime Most recent edit in standard ISO time $ItemRSSTime Time of edit in standard UTC format $ItemAuthor Author of edit $ItemSummary Summary of edit $ItemDiff Raw revision data (not recommended for inclusion) $ItemUnique Time of edit in Unix format $ItemMinor "Yes" if edit was minor, "No" if not $ItemHost IP address of author You may also use any other PmWiki variables ($FarmD, $pagename, etc.), including Page Variables (i.e. {$PageUrl}, {$Title}, etc.) For example, each item has a default description of "Author: $ItemAuthor" (i.e. $FeedFmt['item']['description']['content'] = 'Author: $ItemAuthor') */ ## Recipe version information $RecipeInfo['PageFeed']['Version'] = '2010-03-14'; ## PageFeed format SDVA($FeedFmt['pagefeed']['feed'], array( '_count' => 25, '_minor' => 1, '_header' => 'Content-type: text/xml; charset="$Charset"', '_start' => ' '."\n", '_end' => "\n\n", 'title' => '$WikiTitle | {$Group} / {$Title}', 'link' => '{$PageUrl}?action=pagefeed', 'description' => '{$Group}.{$Title}', 'lastBuildDate' => '$FeedRSSTime')); SDVA($FeedFmt['pagefeed']['item'], array( '_start' => "\n", '_end' => "\n", 'title' => '{$Group} / {$Title} - $ItemSummary', 'link' => '{$PageUrl}', 'description' => "Edit by: \$ItemAuthor\nMinor: \$ItemMinor", 'pubDate' => '$ItemRSSTime', 'guid' => '{$PageUrl}?action=diff#$ItemUnique')); ## Add action for pagefeed SDV($HandleActions['pagefeed'], 'PageFeed'); ## Create feed from page history function PageFeed($pagename, $auth = 'read') { global $FeedFmt, $FmtV, $EntitiesTable, $TimeISOZFmt, $RSSTimeFmt; SDV($RSSTimeFmt, 'D, d M Y H:i:s \G\M\T'); $f = &$FeedFmt['pagefeed']; ## get options $count = ($_REQUEST['count'] !== null) ? $_REQUEST['count'] : $f['feed']['_count']; $minor = ($_REQUEST['minor'] !== null) ? $_REQUEST['minor'] : $f['feed']['_minor']; ## get page $page = RetrieveAuthPage($pagename, $auth, true, 0); if (!$page) Abort("?cannot generate feed"); ## Create feed start $time = $page['time']; $FmtV['$FeedISOTime'] = gmstrftime($TimeISOZFmt, $time); $FmtV['$FeedRSSTime'] = gmdate($RSSTimeFmt, $time); $out = FmtPageName($f['feed']['_start'], $pagename); foreach($f['feed'] as $k => $v) { if ($k[0] == '_' || !$v) continue; $x = FmtPageName($v, $pagename); if (!$x) continue; $out .= ($v[0] == '<') ? $x : "<$k>$x\n"; } ## Create feed items for($n = 0; $n < $count; $n++) { $key = ''; foreach($page as $k => $v) { if(preg_match("/diff:$time:/", $k)) {$key = $k; break;} } if(!$key) break; if(preg_match("/minor/", $key) && !$minor) { $time = substr($key,16,10); $n--; continue; } $FmtV['$ItemMinor'] = (preg_match("/minor/", $key)) ? 'Yes' : 'No'; $FmtV['$ItemTime'] = $time; $FmtV['$ItemUnique'] = "diff".$time; $FmtV['$ItemRSSTime'] = gmdate($RSSTimeFmt, $time); $FmtV['$ItemAuthor'] = ($page["author:$time"]) ? $page["author:$time"] : ''; $FmtV['$ItemSummary'] = ($page["csum:$time"]) ? $page["csum:$time"] : ''; $FmtV['$ItemDiff'] = $page[$key]; $FmtV['$ItemHost'] = ($page["host:$time"]) ? $page["host:$time"] : ''; $out .= FmtPageName($f['item']['_start'], $pagename); foreach($f['item'] as $k => $v) { if ($k[0] == '_' || !$v) continue; $x = FmtPageName($v, $pagename); if (!$x) continue; $out .= ($v[0] == '<') ? $x : "<$k>$x\n"; } $out .= FmtPageName($f['item']['_end'], $pagename); if($time == substr($key,16,10)) break; $time = substr($key,16,10); } ## Create feed end and print $out .= FmtPageName($f['feed']['_end'], $pagename); foreach((array)@$f['feed']['_header'] as $fmt) header(FmtPageName($fmt, $pagename)); print str_replace(array_keys($EntitiesTable), array_values($EntitiesTable), $out); } ## Since most feeds don't understand html character entities, we ## convert the common ones to their numeric form here. ## Taken from /scripts/feeds.php SDVA($EntitiesTable, array( # entities defined in "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent" ' ' => ' ', '¡' => '¡', '¢' => '¢', '£' => '£', '¤' => '¤', '¥' => '¥', '¦' => '¦', '§' => '§', '¨' => '¨', '©' => '©', 'ª' => 'ª', '«' => '«', '¬' => '¬', '­' => '­', '®' => '®', '¯' => '¯', '°' => '°', '±' => '±', '²' => '²', '³' => '³', '´' => '´', 'µ' => 'µ', '¶' => '¶', '·' => '·', '¸' => '¸', '¹' => '¹', 'º' => 'º', '»' => '»', '¼' => '¼', '½' => '½', '¾' => '¾', '¿' => '¿', 'À' => 'À', 'Á' => 'Á', 'Â' => 'Â', 'Ã' => 'Ã', 'Ä' => 'Ä', 'Å' => 'Å', 'Æ' => 'Æ', 'Ç' => 'Ç', 'È' => 'È', 'É' => 'É', 'Ê' => 'Ê', 'Ë' => 'Ë', 'Ì' => 'Ì', 'Í' => 'Í', 'Î' => 'Î', 'Ï' => 'Ï', 'Ð' => 'Ð', 'Ñ' => 'Ñ', 'Ò' => 'Ò', 'Ó' => 'Ó', 'Ô' => 'Ô', 'Õ' => 'Õ', 'Ö' => 'Ö', '×' => '×', 'Ø' => 'Ø', 'Ù' => 'Ù', 'Ú' => 'Ú', 'Û' => 'Û', 'Ü' => 'Ü', 'Ý' => 'Ý', 'Þ' => 'Þ', 'ß' => 'ß', 'à' => 'à', 'á' => 'á', 'â' => 'â', 'ã' => 'ã', 'ä' => 'ä', 'å' => 'å', 'æ' => 'æ', 'ç' => 'ç', 'è' => 'è', 'é' => 'é', 'ê' => 'ê', 'ë' => 'ë', 'ì' => 'ì', 'í' => 'í', 'î' => 'î', 'ï' => 'ï', 'ð' => 'ð', 'ñ' => 'ñ', 'ò' => 'ò', 'ó' => 'ó', 'ô' => 'ô', 'õ' => 'õ', 'ö' => 'ö', '÷' => '÷', 'ø' => 'ø', 'ù' => 'ù', 'ú' => 'ú', 'û' => 'û', 'ü' => 'ü', 'ý' => 'ý', 'þ' => 'þ', 'ÿ' => 'ÿ', # entities defined in "http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent" '"' => '"', #'&' => '&#38;', #'<' => '&#60;', #'>' => '>', ''' => ''', 'Œ' => 'Œ', 'œ' => 'œ', 'Š' => 'Š', 'š' => 'š', 'Ÿ' => 'Ÿ', 'ˆ' => 'ˆ', '˜' => '˜', ' ' => ' ', ' ' => ' ', ' ' => ' ', '‌' => '‌', '‍' => '‍', '‎' => '‎', '‏' => '‏', '–' => '–', '—' => '—', '‘' => '‘', '’' => '’', '‚' => '‚', '“' => '“', '”' => '”', '„' => '„', '†' => '†', '‡' => '‡', '‰' => '‰', '‹' => '‹', '›' => '›', '€' => '€', # entities defined in "http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent" 'ƒ' => 'ƒ', 'Α' => 'Α', 'Β' => 'Β', 'Γ' => 'Γ', 'Δ' => 'Δ', 'Ε' => 'Ε', 'Ζ' => 'Ζ', 'Η' => 'Η', 'Θ' => 'Θ', 'Ι' => 'Ι', 'Κ' => 'Κ', 'Λ' => 'Λ', 'Μ' => 'Μ', 'Ν' => 'Ν', 'Ξ' => 'Ξ', 'Ο' => 'Ο', 'Π' => 'Π', 'Ρ' => 'Ρ', 'Σ' => 'Σ', 'Τ' => 'Τ', 'Υ' => 'Υ', 'Φ' => 'Φ', 'Χ' => 'Χ', 'Ψ' => 'Ψ', 'Ω' => 'Ω', 'α' => 'α', 'β' => 'β', 'γ' => 'γ', 'δ' => 'δ', 'ε' => 'ε', 'ζ' => 'ζ', 'η' => 'η', 'θ' => 'θ', 'ι' => 'ι', 'κ' => 'κ', 'λ' => 'λ', 'μ' => 'μ', 'ν' => 'ν', 'ξ' => 'ξ', 'ο' => 'ο', 'π' => 'π', 'ρ' => 'ρ', 'ς' => 'ς', 'σ' => 'σ', 'τ' => 'τ', 'υ' => 'υ', 'φ' => 'φ', 'χ' => 'χ', 'ψ' => 'ψ', 'ω' => 'ω', 'ϑ' => 'ϑ', 'ϒ' => 'ϒ', 'ϖ' => 'ϖ', '•' => '•', '…' => '…', '′' => '′', '″' => '″', '‾' => '‾', '⁄' => '⁄', '℘' => '℘', 'ℑ' => 'ℑ', 'ℜ' => 'ℜ', '™' => '™', 'ℵ' => 'ℵ', '←' => '←', '↑' => '↑', '→' => '→', '↓' => '↓', '↔' => '↔', '↵' => '↵', '⇐' => '⇐', '⇑' => '⇑', '⇒' => '⇒', '⇓' => '⇓', '⇔' => '⇔', '∀' => '∀', '∂' => '∂', '∃' => '∃', '∅' => '∅', '∇' => '∇', '∈' => '∈', '∉' => '∉', '∋' => '∋', '∏' => '∏', '∑' => '∑', '−' => '−', '∗' => '∗', '√' => '√', '∝' => '∝', '∞' => '∞', '∠' => '∠', '∧' => '∧', '∨' => '∨', '∩' => '∩', '∪' => '∪', '∫' => '∫', '∴' => '∴', '∼' => '∼', '≅' => '≅', '≈' => '≈', '≠' => '≠', '≡' => '≡', '≤' => '≤', '≥' => '≥', '⊂' => '⊂', '⊃' => '⊃', '⊄' => '⊄', '⊆' => '⊆', '⊇' => '⊇', '⊕' => '⊕', '⊗' => '⊗', '⊥' => '⊥', '⋅' => '⋅', '⌈' => '⌈', '⌉' => '⌉', '⌊' => '⌊', '⌋' => '⌋', '⟨' => '〈', '⟩' => '〉', '◊' => '◊', '♠' => '♠', '♣' => '♣', '♥' => '♥', '♦' => '♦'));