Index: trunk/extensions/FeaturedFeeds/FeaturedFeedsWMF.php |
— | — | @@ -1,39 +1,51 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /* |
5 | 4 | * Feed settings for WMF projects |
6 | 5 | */ |
7 | 6 | |
| 7 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 8 | + die( 'Not a valid entry point' ); |
| 9 | +} |
| 10 | + |
8 | 11 | $wgHooks['FeaturedFeeds::getFeeds'][] = 'wfFeaturedFeedsWMF_getFeeds'; |
9 | 12 | |
10 | 13 | function wfFeaturedFeedsWMF_getFeeds( &$feeds ) { |
11 | 14 | global $wgConf, $wgDBname; |
12 | 15 | list( $site, $lang ) = $wgConf->siteFromDB( $wgDBname ); |
| 16 | + $media = array( |
| 17 | + 'potd' => array( // Picture Of The Day |
| 18 | + 'page' => 'ffeed-potd-page', |
| 19 | + 'feedName' => 'ffeed-potd-title', |
| 20 | + 'description' => 'ffeed-potd-desc', |
| 21 | + 'entryName' => 'ffeed-potd-entry', |
| 22 | + ), |
| 23 | + 'motd' => array( // Media Of The Day |
| 24 | + 'page' => 'ffeed-motd-page', |
| 25 | + 'feedName' => 'ffeed-motd-title', |
| 26 | + 'description' => 'ffeed-motd-desc', |
| 27 | + 'entryName' => 'ffeed-motd-entry', |
| 28 | + ), |
| 29 | + ); |
13 | 30 | switch ( $site ) { |
14 | 31 | case 'wikipedia': |
15 | 32 | $feeds += array( |
16 | 33 | 'featured' => array( |
17 | | - 'page' => 'ffeed-wp-featured-page', |
18 | | - 'feedName' => 'ffeed-wp-featured-title', |
19 | | - 'description' => 'ffeed-wp-featured-desc', |
20 | | - 'entryName' => 'ffeed-wp-featured-entry', |
| 34 | + 'page' => 'ffeed-fa-page', |
| 35 | + 'feedName' => 'ffeed-fa-title', |
| 36 | + 'description' => 'ffeed-fa-desc', |
| 37 | + 'entryName' => 'ffeed-fa-entry', |
21 | 38 | ), |
22 | 39 | 'onthisday' => array( |
23 | | - 'page' => 'ffeed-wp-onthisday-page', |
24 | | - 'feedName' => 'ffeed-wp-onthisday-title', |
25 | | - 'description' => 'ffeed-wp-onthisday-desc', |
26 | | - 'entryName' => 'ffeed-wp-onthisday-entry', |
| 40 | + 'page' => 'ffeed-onthisday-page', |
| 41 | + 'feedName' => 'ffeed-onthisday-title', |
| 42 | + 'description' => 'ffeed-onthisday-desc', |
| 43 | + 'entryName' => 'ffeed-onthisday-entry', |
27 | 44 | ), |
28 | 45 | ); |
| 46 | + $feeds += $media; |
29 | 47 | break; |
30 | 48 | case 'commons': |
31 | | - $feeds['featured'] = array( |
32 | | - 'page' => 'ffeed-com-featured-page', |
33 | | - 'feedName' => 'ffeed-com-featured-title', |
34 | | - 'description' => 'ffeed-com-featured-desc', |
35 | | - 'entryName' => 'ffeed-com-featured-entry', |
36 | | - 'inUserLanguage' => true, |
37 | | - ); |
| 49 | + $feeds += $media; |
38 | 50 | break; |
39 | 51 | } |
40 | 52 | return true; |
Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php |
— | — | @@ -24,12 +24,37 @@ |
25 | 25 | |
26 | 26 | if ( !$feeds ) { |
27 | 27 | $feeds = self::getFeedsInternal( $langCode ); |
28 | | - $wgMemc->set( $key, $feeds, 3600 ); //FIXME |
| 28 | + // add 10 seconds to cater for time deviation between servers |
| 29 | + $expiry = self::todaysStart() + 24 * 3600 - wfTimestamp() + 10; |
| 30 | + $wgMemc->set( $key, $feeds, min( $expiry, 3600 ) ); |
29 | 31 | } |
30 | 32 | $cache[$langCode] = $feeds; |
31 | 33 | return $feeds; |
32 | 34 | } |
33 | 35 | |
| 36 | + /** |
| 37 | + * Adds feeds to the page header |
| 38 | + * |
| 39 | + * @param OutputPage $out |
| 40 | + * @return bool |
| 41 | + */ |
| 42 | + public static function beforePageDisplay( OutputPage &$out ) { |
| 43 | + global $wgAdvertisedFeedTypes; |
| 44 | + if ( $out->getTitle()->isMainPage() ) { |
| 45 | + foreach ( self::getFeeds( $out->getLanguage()->getCode() ) as $feed ) { |
| 46 | + foreach ( $wgAdvertisedFeedTypes as $type ) { |
| 47 | + $out->addLink( array( |
| 48 | + 'rel' => 'alternate', |
| 49 | + 'type' => "application/$type+xml", |
| 50 | + 'title' => $feed['name'], |
| 51 | + 'href' => self::getFeedURL( $feed, $type ), |
| 52 | + ) ); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + return true; |
| 57 | + } |
| 58 | + |
34 | 59 | private static function getFeedsInternal( $langCode ) { |
35 | 60 | global $wgFeaturedFeeds, $wgFeaturedFeedsDefaults, $wgContLang; |
36 | 61 | |
— | — | @@ -113,6 +138,13 @@ |
114 | 139 | return $time; |
115 | 140 | } |
116 | 141 | |
| 142 | + /** |
| 143 | + * Returns a URL to the feed |
| 144 | + * |
| 145 | + * @param Array $feed: Feed description returned by getFeeds() |
| 146 | + * @param type $format: Feed format, 'rss' or 'atom' |
| 147 | + * @return String |
| 148 | + */ |
117 | 149 | public static function getFeedURL( $feed, $format ) { |
118 | 150 | global $wgContLang; |
119 | 151 | |
— | — | @@ -126,16 +158,4 @@ |
127 | 159 | } |
128 | 160 | return wfScript( 'api' ) . '?' . wfArrayToCGI( $options ); |
129 | 161 | } |
130 | | - |
131 | | - public static function beforePageDisplay( OutputPage &$out ) { |
132 | | -// global $wgFeedClasses; |
133 | | -// if ( $out->getTitle()->isMainPage() ) { |
134 | | -// foreach ( self::getFeeds( $out->getLanguage()->getCode() ) as $name => $feed ) { |
135 | | -// foreach ( array_keys( $wgFeedClasses ) as $format ) { |
136 | | -// $out->addFeedLink( $format, FeaturedFeeds::getFeedURL( $feed, $format ) ); |
137 | | -// } |
138 | | -// } |
139 | | -// } |
140 | | - return true; |
141 | | - } |
142 | 162 | } |
\ No newline at end of file |
Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.i18n.php |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation file for FeaturedFeeds extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Max Semenik |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + 'ffeed-desc' => 'Adds syndication feeds of wiki\'s featured content.', |
| 17 | + |
| 18 | + # Featured Article |
| 19 | + 'ffeed-fa-page' => '', # do not localise |
| 20 | + 'ffeed-fa-title' => '{{SITENAME}} featured articles feed', |
| 21 | + 'ffeed-fa-desc' => 'Best articles {{SITENAME}} has to offer', |
| 22 | + 'ffeed-fa-entry' => '{{LOCALMONTHNAME}} {{LOCALDAY}} {{SITENAME}} featured article', |
| 23 | + |
| 24 | + # On this day... |
| 25 | + 'ffeed-onthisday-page' => '', # do not localise |
| 26 | + 'ffeed-onthisday-title' => '{{SITENAME}} "On this day..." feed', |
| 27 | + 'ffeed-onthisday-desc' => 'Historical events on this day', |
| 28 | + 'ffeed-onthisday-entry' => 'On this day: {{LOCALMONTHNAME}} {{LOCALDAY}}', |
| 29 | + |
| 30 | + // Media Of The Day |
| 31 | + 'ffeed-motd-page' => '', # do not localise |
| 32 | + 'ffeed-motd-title' => '{{SITENAME}} media of the day feed', |
| 33 | + 'ffeed-motd-desc' => 'Some of the finest media on {{SITENAME}}', |
| 34 | + 'ffeed-motd-entry' => '{{SITENAME}} Media of the day for {{LOCALMONTHNAME}} {{LOCALDAY}}', |
| 35 | + |
| 36 | + # Picture Of The Day |
| 37 | + 'ffeed-potd-page' => '', # do not localise |
| 38 | + 'ffeed-potd-title' => '{{SITENAME}} Picture of the day feed', |
| 39 | + 'ffeed-potd-desc' => 'Some of the finest images on {{SITENAME}}', |
| 40 | + 'ffeed-potd-entry' => '{{SITENAME}} Picture of the day for {{LOCALMONTHNAME}} {{LOCALDAY}}', |
| 41 | +); |
Property changes on: trunk/extensions/FeaturedFeeds/FeaturedFeeds.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 42 | + native |
Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.php |
— | — | @@ -4,7 +4,11 @@ |
5 | 5 | * License: WTFPL 2.0 |
6 | 6 | */ |
7 | 7 | |
| 8 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 9 | + die( 'Not a valid entry point' ); |
| 10 | +} |
8 | 11 | |
| 12 | + |
9 | 13 | $wgExtensionCredits['other'][] = array( |
10 | 14 | 'path' => __FILE__, |
11 | 15 | 'name' => 'FeaturedFeeds', |
— | — | @@ -18,6 +22,8 @@ |
19 | 23 | $wgAutoloadClasses['FeaturedFeeds'] = "$dir/FeaturedFeeds.body.php"; |
20 | 24 | $wgAutoloadClasses['ApiFeaturedFeeds'] = "$dir/ApiFeaturedFeeds.php"; |
21 | 25 | |
| 26 | +$wgExtensionMessagesFiles['FeaturedFeeds'] = "$dir/FeaturedFeeds.i18n.php"; |
| 27 | + |
22 | 28 | $wgAPIModules['featuredfeed'] = 'ApiFeaturedFeeds'; |
23 | 29 | |
24 | 30 | $wgHooks['BeforePageDisplay'][] = 'FeaturedFeeds::beforePageDisplay'; |