From 5a5da58a56a7e3a87c60584a91cd5a27aa8383fa Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 10 Aug 2008 21:54:12 -0400 Subject: [PATCH] Implement RSSFromGit, a substitute for RSSFromSVN. Signed-off-by: Edward Z. Yang --- XHTMLCompiler/DOMFilter/RSSFromGit.php | 82 ++++++++++++++++++++++++++++++++++ XHTMLCompiler/Page.php | 4 +- config.filters.php | 1 + 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 XHTMLCompiler/DOMFilter/RSSFromGit.php diff --git a/XHTMLCompiler/DOMFilter/RSSFromGit.php b/XHTMLCompiler/DOMFilter/RSSFromGit.php new file mode 100644 index 0000000..227e56a --- /dev/null +++ b/XHTMLCompiler/DOMFilter/RSSFromGit.php @@ -0,0 +1,82 @@ + and other places */ + protected $title = 'Log for %s'; + protected $xcAttr = array('rss-from-git'); + + public function process(DOMDocument $dom, $page, $manager) { + $xc = XHTMLCompiler::getInstance(); + // implement gitweb/repo.or.cz support + + $logs = $page->getLog(); + + // see if we need to make the link ourself + $trigger = $this->confiscateAttr($dom->documentElement, $this->ns, 'rss-from-git'); + if ($trigger == 'yes') { + // this shows up twice because we have to perform all + // confiscations before aborting + if (!$logs) return; + $link = $dom->createElement('link'); + $link->setAttribute('rel', 'alternate'); + $link->setAttribute('type', 'application/rss+xml'); + $link->setAttribute('title', str_replace('%s', $page->getCachePath(), $this->title)); + $link->setAttribute('href', $page->getPathStem() . '.rss'); + $head = $this->query('//html:head')->item(0); + $head->appendChild($link); + } else { + // grab the document's links to RSS feeds + // link must be marked with xc:rss-from-svn + // only one allowed + $link = $this->query('//html:link[@xc:rss-from-svn]')->item(0); + if (!$link) return; // nothing to do + + $trigger = $this->confiscateAttr($link, $this->ns, 'rss-from-svn'); + if ($trigger != 'yes') return; + if (!$logs) return; + } + + $path = $page->getWebPath(); + + $rss = new XHTMLCompiler_RSSFeed( + $link->getAttribute('title'), + $path, + str_replace('%s', $page->getCachePath(), $this->description), + $dom->documentElement->getAttribute('xml:lang') + ); + + for ($i = 0; $i < $this->limit && isset($logs[$i]); $i++) { + $commit = $logs[$i]; + + // :TODO: link to gitweb commitdiff + $item_link = $path . '#git_' . $commit->id; + + // generate short message (first line) for title\ + + $rss->addItem( + $item_link, + htmlspecialchars($commit->message), + $d = $commit->committedDate->format('r'), + // :TODO: Extend phpgit so that we can retrieve full message + htmlspecialchars($commit->message) + ); + } + + $rss->save( + $page->normalizePath( + $link->getAttribute('href') + ) + ); + + + } +} diff --git a/XHTMLCompiler/Page.php b/XHTMLCompiler/Page.php index d54da6d..758ac7c 100644 --- a/XHTMLCompiler/Page.php +++ b/XHTMLCompiler/Page.php @@ -283,10 +283,10 @@ class XHTMLCompiler_Page /** * Retrieves the log that represents this page. */ - public function getLog() { + public function getLog($kwargs = array()) { // This doesn't account for sub-repositories $repo = $this->getRepo(); - return $repo->log('master', array($this->getGitPath()), array('follow' => true)); + return $repo->log('master', array($this->getGitPath()), array_merge(array('follow' => true), $kwargs)); } // this is metadata stuff that needs to be moved and cached diff --git a/config.filters.php b/config.filters.php index 30a07ae..fd691c7 100644 --- a/config.filters.php +++ b/config.filters.php @@ -8,6 +8,7 @@ $filters->addDOMFilter('NewsLinker'); $filters->addDOMFilter('GenerateTableOfContents'); $filters->addDOMFilter('Acronymizer'); $filters->addDOMFilter('Quoter'); +$filters->addDOMFilter('RSSFromGit'); $filters->addDOMFilter('RSSGenerator'); $filters->addDOMFilter('AbsolutePath'); $filters->addDOMFilter('IEConditionalComments'); -- 2.11.4.GIT