FeedLinks

Summary: Add HTML-header links to enable autodiscovery of RSS/Atom feeds.
Version: 0.3 (2018-02-10)
Prerequisites: pmwiki-2.0
Status: Active
Maintainer: Hagan
License: GPL2
Categories: RSS, CMS, PHP55, PHP72
Users: +3 (view / edit)
Discussion: FeedLinks-Talk
Download: feedlinks.phpΔ
Votes: 5

Questions answered by this recipe

  • How can I add links that will enable autodiscovery of my site's Atom and/or RSS feeds?
  • How can I encourage people (and machines) to use my site's web feeds?

Description

Add RSS and/or Atom feed link tags as alternate link elements to your pages' HTML Headers. Typical feed links look like this:

<link rel='alternate' title='Your Site : Main - RSS Feed'
    href='http://example.com/wiki/Main/RecentChanges?action=rss'
    type='application/rss+xml' />
<link rel='alternate' title='Your Site : Main - Atom Feed'
    href='http://example.com/wiki/Main/RecentChanges?action=atom'
    type='application/atom+xml' />

These alternate link elements make audodiscovery of your feeds possible, meaning browsers and other software will be able to automatically find the feeds you've made available.

Installation

Download feedlinks.phpΔ and place it to your cookbook/ directory, then insert the following line in your local/config.php file:

include_once("$FarmD/cookbook/feedlinks.php");

Configuration

By default the script produces links to RSS 2.0 and Atom feeds from the site-wide $SiteGroup/AllRecentChanges page. You can customize the links to your preference using settings.

$EnableSitewideFeed
Enabled by default, this can be disabled to advertise by-group from the $Group/RecentChanges page instead.
$EnableRssLink
Enabled by default, this produces a link to an RSS 2.0 feed.
$EnableAtomLink
Enabled by default, this produces a link to an Atom feed.
$FeedLinkSourcePath
This allows you to override the feed link's source path and use a custom one instead.

Examples

To advertise only an RSS feed of WikiGroup changes from the $Group/RecentChanges page instead of $SiteGroup/AllRecentChanges, use

##  Enable the FeedLinks recipe, which adds links to the HTML header that
##  enable autodiscovery of RSS and/or Atom web feeds.
$EnableSitewideFeed = 0; 
$EnableAtomLink = 0;
include_once("$FarmD/cookbook/feedlinks.php");  # RSS feed by group

You can run the script multiple times, so if you want site-wide and by-group RSS and Atom feed links (four links total), use

##  Enable the FeedLinks recipe, which adds links to the HTML header that
##  enable autodiscovery of RSS and/or Atom web feeds.
include("$FarmD/cookbook/feedlinks.php");  # Site-wide feeds
$EnableSitewideFeed = 0;
include("$FarmD/cookbook/feedlinks.php");  # By-group feeds

Feed-Friendly AllRecentChanges Page

The CMS Mode recipe creates a special feed-friendly AllRecentChanges page in the Main/ group. Here's the code from cmsmode.php that does that:

## Maintain a special "public" RSS/Atom feed changelog page.
SDV($FeedAllRecentChanges, 'Main.AllRecentChanges');
## Get the group and page names.
$CMSpage = explode(".", $pagename);
$CMSgroup = $CMSpage[0]; // same as {$Group}
$CMSname = $CMSpage[1]; // same as {$Name}
## group and page names excluded from public A.R.C page.
SDVA($CMSExclARCGroups,array(
  'Temp' => 'Temp',
  'Test' => 'Test',
  'PmWiki' => 'PmWiki',
  'Profiles' => 'Profiles'));
SDVA($CMSExclARCNames,array(
  'WikiSandbox' => 'WikiSandbox',
  'Search' => 'Search'));
#
## Customize (All)RecentChanges pages for better web feeds.
if (preg_match('!^'."($SiteGroup|$SiteAdminGroup)".'\\.!', $pagename)
  || in_array($CMSgroup,$CMSExclARCGroups)
  || preg_match('!\\.(GroupHeader|GroupFooter|GroupAttributes|'
    .'RecentDraftChanges|AllRecentChanges)$!', $pagename)
  || in_array($CMSname,$CMSExclARCNames)) {
  $RecentChangesFmt['$Group.RecentChanges'] = '';
  $RecentChangesFmt[$FeedAllRecentChanges] = '';
} else {
  $RecentChangesFmt[$FeedAllRecentChanges] =
    '* [[{$Group}.{$Name}]]  $[was modified] $CurrentTime. [=$ChangeSummary=]';
}

To advertise both RSS and Atom links to the special sitewide feed at Main/AllRecentChanges rather than the default $SiteGroup/AllRecentChanges, use

## Enable the FeedLinks recipe - Add links to RSS and Atom web feeds
## from the special "public" sitewide changelog page.
include_once("$FarmD/cookbook/feedlinks.php");

Notes

Make sure your feeds are enabled. You can enable both RSS and Atom feeds using the following in your local/config.php file:

##  Enable RSS 2.0 and Atom web feeds.
if ($action == 'rss' || $action == 'atom') {
include_once("scripts/feeds.php"); }

A version of the scriptΔ was uploaded that provides compatibility with the PageFeed recipe at the expense of the script's original simplicity. Those changes were significant enough, and narrow enough in scope, to merit forking the recipe into a separate one. See: FeedLinks-Talk#feedlinks4pagefeed

Change log / Release notes

  • 2006-01-13: Version 0.01 (Initial release)
  • 2006-01-15: Version 0.02
  • 2006-03-19: Version 0.03 Now can be run multiple times with setting changes in between.
  • 2017-11-04: Version 0.1 Now the feed source and title can be set on a per-group basis.
  • 2018-02-08: Version 0.2 Extension for pagefeed.php links and UrlVariables FranzFrese.
  • 2018-02-10: Version 0.3 Revert pagefeed extensions and add / improve code comments.

See also

Contributors

  • Hagan 2006-01-13 Created the recipe on a suggestion by HansB.
  • Said Achmiz - Added set-per-group and run-multiple-times capabilities.
  • Franz Frese - Contributed a version that adds compatibility with the PageFeed recipe.

Comments

See discussion at FeedLinks-Talk