Index: trunk/phase3/includes/Feed.php |
— | — | @@ -0,0 +1,86 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$wgFeedClasses = array( |
| 5 | + "rss" => "RSSFeed", |
| 6 | + # "atom" => "AtomFeed", |
| 7 | + ); |
| 8 | + |
| 9 | +class FeedItem { |
| 10 | + var $Title = "Wiki"; |
| 11 | + var $Description = ""; |
| 12 | + var $Url = ""; |
| 13 | + |
| 14 | + function FeedItem( $Title, $Description, $Url ) { |
| 15 | + $this->Title = $Title; |
| 16 | + $this->Description = $Description; |
| 17 | + $this->Url = $Url; |
| 18 | + } |
| 19 | + |
| 20 | + /* Static... */ |
| 21 | + function xmlEncode( $string ) { |
| 22 | + global $wgInputEncoding, $wgLang; |
| 23 | + $string = str_replace( "\r\n", "\n", $string ); |
| 24 | + if( strcasecmp( $wgInputEncoding, "utf-8" ) != 0 ) { |
| 25 | + $string = $wgLang->iconv( $wgInputEncoding, "utf-8" ); |
| 26 | + } |
| 27 | + return htmlspecialchars( $string ); |
| 28 | + } |
| 29 | + function getTitle() { |
| 30 | + return $this->xmlEncode( $this->Title ); |
| 31 | + } |
| 32 | + function getUrl() { |
| 33 | + return $this->xmlEncode( $this->Url ); |
| 34 | + } |
| 35 | + function getDescription() { |
| 36 | + return $this->xmlEncode( $this->Description ); |
| 37 | + } |
| 38 | + function getLanguage() { |
| 39 | + global $wgLanguageCode; |
| 40 | + return $wgLanguageCode; |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +class ChannelFeed extends FeedItem { |
| 45 | + /* Abstract functions, override! */ |
| 46 | + function outHeader() { |
| 47 | + # print "<feed>"; |
| 48 | + } |
| 49 | + function outItem( $item ) { |
| 50 | + # print "<item>...</item>"; |
| 51 | + } |
| 52 | + function outFooter() { |
| 53 | + # print "</feed>"; |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +class RSSFeed extends ChannelFeed { |
| 58 | + function outHeader() { |
| 59 | + print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n"; |
| 60 | + ?><!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd"> |
| 61 | +<rss version="0.91"> |
| 62 | + <channel> |
| 63 | + <title><?php print $this->getTitle() ?></title> |
| 64 | + <link><?php print $this->getUrl() ?></link> |
| 65 | + <description><?php print $this->getDescription() ?></description> |
| 66 | + <language><?php print $this->getLanguage() ?></language> |
| 67 | +<?php |
| 68 | + } |
| 69 | + |
| 70 | + function outItem( $item ) { |
| 71 | + ?> |
| 72 | + <item> |
| 73 | + <title><?php print $item->getTitle() ?></title> |
| 74 | + <link><?php print $item->getUrl() ?></link> |
| 75 | + <description><?php print $item->getDescription() ?></description> |
| 76 | + </item> |
| 77 | +<?php |
| 78 | + } |
| 79 | + |
| 80 | + function outFooter() { |
| 81 | + ?> |
| 82 | + </channel> |
| 83 | +</rss><?php |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +?> |
\ No newline at end of file |
Property changes on: trunk/phase3/includes/Feed.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 88 | + native |
Added: svn:keywords |
2 | 89 | + Author Date Id Revision |
Index: trunk/phase3/includes/QueryPage.php |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | include_once ( "LogPage.php" ) ; |
| 5 | +include_once ( "Feed.php" ); |
5 | 6 | |
6 | 7 | # This is a class for doing query pages; since they're almost all the same, |
7 | 8 | # we factor out some of the functionality into a superclass, and let |
— | — | @@ -36,7 +37,7 @@ |
37 | 38 | function formatResult( $skin, $result ) { |
38 | 39 | return ""; |
39 | 40 | } |
40 | | - |
| 41 | + |
41 | 42 | # This is the actual workhorse. It does everything needed to make a |
42 | 43 | # real, honest-to-gosh query page. |
43 | 44 | |
— | — | @@ -87,6 +88,82 @@ |
88 | 89 | $logpage->replaceContent( $s ); |
89 | 90 | } |
90 | 91 | } |
| 92 | + |
| 93 | + # Similar to above, but packaging in a syndicated feed instead of a web page |
| 94 | + function doFeed( $class = "" ) { |
| 95 | + global $wgFeedClasses; |
| 96 | + global $wgOut, $wgLanguageCode, $wgLang; |
| 97 | + if( $class == "rss" ) { |
| 98 | + $wgOut->disable(); |
| 99 | + |
| 100 | + $feed = new RSSFeed( |
| 101 | + $this->feedTitle(), |
| 102 | + $this->feedDesc(), |
| 103 | + $this->feedUrl() ); |
| 104 | + $feed->outHeader(); |
| 105 | + |
| 106 | + $sql = $this->getSQL( 0, 50 ); |
| 107 | + $res = wfQuery( $sql, DB_READ, "QueryPage::doFeed" ); |
| 108 | + while( $obj = wfFetchObject( $res ) ) { |
| 109 | + $item = $this->feedResult( $obj ); |
| 110 | + if( $item ) $feed->outItem( $item ); |
| 111 | + } |
| 112 | + wfFreeResult( $res ); |
| 113 | + |
| 114 | + $feed->outFooter(); |
| 115 | + return true; |
| 116 | + } else { |
| 117 | + return false; |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + # Override for custom handling. If the titles/links are ok, just do feedItemDesc() |
| 122 | + function feedResult( $result ) { |
| 123 | + if( isset( $result->cur_title ) ) { |
| 124 | + $title = Title::MakeTitle( $result->cur_namespace, $result->cur_title ); |
| 125 | + } elseif( isset( $result->old_title ) ) { |
| 126 | + $title = Title::MakeTitle( $result->old_namespace, $result->old_title ); |
| 127 | + } elseif( isset( $result->rc_title ) ) { |
| 128 | + $title = Title::MakeTitle( $result->rc_namespace, $result->rc_title ); |
| 129 | + } else { |
| 130 | + return NULL; |
| 131 | + } |
| 132 | + if( $title ) { |
| 133 | + return new FeedItem( |
| 134 | + $title->getText(), |
| 135 | + $this->feedItemDesc( $result ), |
| 136 | + wfFullUrl( $title->getUrl() ) ); |
| 137 | + } else { |
| 138 | + return NULL; |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + function feedItemDesc( $row ) { |
| 143 | + if( isset( $row->cur_comment ) ) { |
| 144 | + return $row->cur_comment; |
| 145 | + } elseif( isset( $row->old_comment ) ) { |
| 146 | + return $row->old_comment; |
| 147 | + } elseif( isset( $row->rc_comment ) ) { |
| 148 | + return $row->rc_comment; |
| 149 | + } |
| 150 | + return ""; |
| 151 | + } |
| 152 | + |
| 153 | + function feedTitle() { |
| 154 | + global $wgLanguageCode, $wgSitename, $wgLang; |
| 155 | + $pages = $wgLang->getValidSpecialPages(); |
| 156 | + $title = $pages[$this->getName()]; |
| 157 | + return "$title - $wgSitename [$wgLanguageCode]"; |
| 158 | + } |
| 159 | + |
| 160 | + function feedDesc() { |
| 161 | + return wfMsg( "fromwikipedia" ); |
| 162 | + } |
| 163 | + |
| 164 | + function feedUrl() { |
| 165 | + global $wgLang; |
| 166 | + return wfFullUrl( $wgLang->SpecialPage( $this->getName() ) ); |
| 167 | + } |
91 | 168 | } |
92 | 169 | |
93 | 170 | # This is a subclass for very simple queries that are just looking for page |
Index: trunk/phase3/includes/SpecialNewpages.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | function getName() { |
9 | 9 | return "Newpages"; |
10 | 10 | } |
11 | | - |
| 11 | + |
12 | 12 | function isExpensive() { |
13 | 13 | return parent::isExpensive(); |
14 | 14 | } |
— | — | @@ -54,7 +54,10 @@ |
55 | 55 | |
56 | 56 | $npp = new NewPagesPage(); |
57 | 57 | |
58 | | - $npp->doQuery( $offset, $limit ); |
| 58 | + |
| 59 | + if( !$npp->doFeed( $_GET["feed"] ) ) { |
| 60 | + $npp->doQuery( $offset, $limit ); |
| 61 | + } |
59 | 62 | } |
60 | 63 | |
61 | 64 | ?> |