--- /dev/null
+<?php
+
+$wgFeedClasses = array(
+ "rss" => "RSSFeed",
+ # "atom" => "AtomFeed",
+ );
+
+class FeedItem {
+ var $Title = "Wiki";
+ var $Description = "";
+ var $Url = "";
+
+ function FeedItem( $Title, $Description, $Url ) {
+ $this->Title = $Title;
+ $this->Description = $Description;
+ $this->Url = $Url;
+ }
+
+ /* Static... */
+ function xmlEncode( $string ) {
+ global $wgInputEncoding, $wgLang;
+ $string = str_replace( "\r\n", "\n", $string );
+ if( strcasecmp( $wgInputEncoding, "utf-8" ) != 0 ) {
+ $string = $wgLang->iconv( $wgInputEncoding, "utf-8" );
+ }
+ return htmlspecialchars( $string );
+ }
+ function getTitle() {
+ return $this->xmlEncode( $this->Title );
+ }
+ function getUrl() {
+ return $this->xmlEncode( $this->Url );
+ }
+ function getDescription() {
+ return $this->xmlEncode( $this->Description );
+ }
+ function getLanguage() {
+ global $wgLanguageCode;
+ return $wgLanguageCode;
+ }
+}
+
+class ChannelFeed extends FeedItem {
+ /* Abstract functions, override! */
+ function outHeader() {
+ # print "<feed>";
+ }
+ function outItem( $item ) {
+ # print "<item>...</item>";
+ }
+ function outFooter() {
+ # print "</feed>";
+ }
+}
+
+class RSSFeed extends ChannelFeed {
+ function outHeader() {
+ print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
+ ?><!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">
+<rss version="0.91">
+ <channel>
+ <title><?php print $this->getTitle() ?></title>
+ <link><?php print $this->getUrl() ?></link>
+ <description><?php print $this->getDescription() ?></description>
+ <language><?php print $this->getLanguage() ?></language>
+<?php
+ }
+
+ function outItem( $item ) {
+ ?>
+ <item>
+ <title><?php print $item->getTitle() ?></title>
+ <link><?php print $item->getUrl() ?></link>
+ <description><?php print $item->getDescription() ?></description>
+ </item>
+<?php
+ }
+
+ function outFooter() {
+ ?>
+ </channel>
+</rss><?php
+ }
+}
+
+?>
\ No newline at end of file
<?php
include_once ( "LogPage.php" ) ;
+include_once ( "Feed.php" );
# This is a class for doing query pages; since they're almost all the same,
# we factor out some of the functionality into a superclass, and let
function formatResult( $skin, $result ) {
return "";
}
-
+
# This is the actual workhorse. It does everything needed to make a
# real, honest-to-gosh query page.
$logpage->replaceContent( $s );
}
}
+
+ # Similar to above, but packaging in a syndicated feed instead of a web page
+ function doFeed( $class = "" ) {
+ global $wgFeedClasses;
+ global $wgOut, $wgLanguageCode, $wgLang;
+ if( $class == "rss" ) {
+ $wgOut->disable();
+
+ $feed = new RSSFeed(
+ $this->feedTitle(),
+ $this->feedDesc(),
+ $this->feedUrl() );
+ $feed->outHeader();
+
+ $sql = $this->getSQL( 0, 50 );
+ $res = wfQuery( $sql, DB_READ, "QueryPage::doFeed" );
+ while( $obj = wfFetchObject( $res ) ) {
+ $item = $this->feedResult( $obj );
+ if( $item ) $feed->outItem( $item );
+ }
+ wfFreeResult( $res );
+
+ $feed->outFooter();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ # Override for custom handling. If the titles/links are ok, just do feedItemDesc()
+ function feedResult( $result ) {
+ if( isset( $result->cur_title ) ) {
+ $title = Title::MakeTitle( $result->cur_namespace, $result->cur_title );
+ } elseif( isset( $result->old_title ) ) {
+ $title = Title::MakeTitle( $result->old_namespace, $result->old_title );
+ } elseif( isset( $result->rc_title ) ) {
+ $title = Title::MakeTitle( $result->rc_namespace, $result->rc_title );
+ } else {
+ return NULL;
+ }
+ if( $title ) {
+ return new FeedItem(
+ $title->getText(),
+ $this->feedItemDesc( $result ),
+ wfFullUrl( $title->getUrl() ) );
+ } else {
+ return NULL;
+ }
+ }
+
+ function feedItemDesc( $row ) {
+ if( isset( $row->cur_comment ) ) {
+ return $row->cur_comment;
+ } elseif( isset( $row->old_comment ) ) {
+ return $row->old_comment;
+ } elseif( isset( $row->rc_comment ) ) {
+ return $row->rc_comment;
+ }
+ return "";
+ }
+
+ function feedTitle() {
+ global $wgLanguageCode, $wgSitename, $wgLang;
+ $pages = $wgLang->getValidSpecialPages();
+ $title = $pages[$this->getName()];
+ return "$title - $wgSitename [$wgLanguageCode]";
+ }
+
+ function feedDesc() {
+ return wfMsg( "fromwikipedia" );
+ }
+
+ function feedUrl() {
+ global $wgLang;
+ return wfFullUrl( $wgLang->SpecialPage( $this->getName() ) );
+ }
}
# This is a subclass for very simple queries that are just looking for page