Index: trunk/extensions/CentralNotice/SpecialNoticeLoader.php |
— | — | @@ -1,20 +1,31 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class SpecialNoticeLoader extends SpecialPage { |
| 4 | +/** |
| 5 | + * The notice loader is a central point of contact; a single consistent |
| 6 | + * URL used for the cluster, in all language and project versions. |
| 7 | + * |
| 8 | + * That central URL can be heavily cached, and centrally purged when |
| 9 | + * updates do happen. |
| 10 | + * |
| 11 | + * It loads up a second page (Special:NoticeText) with specific project |
| 12 | + * and language options and a version timestamp for clean cache breaking. |
| 13 | + */ |
| 14 | +class SpecialNoticeLoader extends NoticePage { |
5 | 15 | function __construct() { |
6 | 16 | parent::__construct("NoticeLoader"); |
7 | 17 | } |
8 | | - |
9 | | - function execute( $par ) { |
10 | | - global $wgOut; |
11 | | - $wgOut->disable(); |
12 | | - |
13 | | - echo $this->getJsOutput(); |
| 18 | + |
| 19 | + /** |
| 20 | + * Clients should recheck this fairly often, but not _constantly_. |
| 21 | + * 10 minutes? |
| 22 | + */ |
| 23 | + protected function maxAge() { |
| 24 | + return 600; |
14 | 25 | } |
15 | 26 | |
16 | 27 | function getJsOutput() { |
17 | | - global $wgCentralNoticeText; |
18 | | - $encUrl = Xml::escapeJsString( $wgCentralNoticeText ); |
| 28 | + global $wgNoticeText; |
| 29 | + $encUrl = Xml::escapeJsString( $wgNoticeText ); |
19 | 30 | $encEpoch = Xml::escapeJsString( $this->getEpoch() ); |
20 | 31 | return <<<EOT |
21 | 32 | document.writeln("<"+"script src=\"$encUrl/"+wgNoticeProject+"/"+wgNoticeLang+"?$encEpoch"+"\"><"+"/script>"); |
— | — | @@ -22,8 +33,9 @@ |
23 | 34 | } |
24 | 35 | |
25 | 36 | function getEpoch() { |
| 37 | + global $wgNoticeEpoch; |
26 | 38 | // Time when we should invalidate all notices... |
27 | | - return wfTimestamp( TS_MW ); |
| 39 | + return wfTimestamp( TS_MW, $wgNoticeEpoch ); |
28 | 40 | } |
29 | 41 | } |
30 | 42 | |
Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -1,14 +1,14 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | // http://meta.wikimedia.org/wiki/Special:NoticeLoader |
5 | | -global $wgCentralNoticeLoader, $wgCentralNoticeText; |
6 | | -$wgCentralNoticeLoader = 'http://smorgasbord.local/trunk/index.php/Special:NoticeLoader'; |
7 | | -$wgCentralNoticeText = 'http://smorgasbord.local/trunk/index.php/Special:NoticeText'; |
| 5 | +$wgNoticeLoader = 'http://smorgasbord.local/trunk/index.php/Special:NoticeLoader'; |
| 6 | +$wgNoticeText = 'http://smorgasbord.local/trunk/index.php/Special:NoticeText'; |
| 7 | +$wgNoticeEpoch = '20071003015645'; |
8 | 8 | |
9 | 9 | function wfCentralNotice( &$notice ) { |
10 | | - global $wgCentralNoticeLoader; |
| 10 | + global $wgNoticeLoader; |
11 | 11 | |
12 | | - $encNoticeLoader = htmlspecialchars( $wgCentralNoticeLoader ); |
| 12 | + $encNoticeLoader = htmlspecialchars( $wgNoticeLoader ); |
13 | 13 | |
14 | 14 | // Throw away the classic notice, use the central loader... |
15 | 15 | $notice = <<<EOT |
— | — | @@ -30,6 +30,9 @@ |
31 | 31 | |
32 | 32 | $wgHooks['SiteNoticeAfter'][] = 'wfCentralNotice'; |
33 | 33 | |
| 34 | +$wgAutoloadClasses['NoticePage'] = |
| 35 | + dirname( __FILE__ ) . '/NoticePage.php'; |
| 36 | + |
34 | 37 | $wgSpecialPages['NoticeLoader'] = 'SpecialNoticeLoader'; |
35 | 38 | $wgAutoloadClasses['SpecialNoticeLoader'] = |
36 | 39 | dirname( __FILE__ ) . '/SpecialNoticeLoader.php'; |
Index: trunk/extensions/CentralNotice/NoticePage.php |
— | — | @@ -0,0 +1,35 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class NoticePage extends SpecialPage { |
| 5 | + function execute( $par ) { |
| 6 | + global $wgOut; |
| 7 | + $wgOut->disable(); |
| 8 | + $this->sendHeaders(); |
| 9 | + echo $this->getJsOutput(); |
| 10 | + } |
| 11 | + |
| 12 | + protected function sharedMaxAge() { |
| 13 | + return 86400; |
| 14 | + } |
| 15 | + |
| 16 | + protected function maxAge() { |
| 17 | + return 86400; |
| 18 | + } |
| 19 | + |
| 20 | + private function sendHeaders() { |
| 21 | + global $wgNoticeEpoch; |
| 22 | + $smaxage = $this->sharedMaxAge(); |
| 23 | + $maxage = $this->maxAge(); |
| 24 | + $epoch = wfTimestamp( TS_RFC2822, $wgNoticeEpoch ); |
| 25 | + |
| 26 | + header( "Content-type: text/javascript; charset=utf-8" ); |
| 27 | + header( "Cache-Control: public, s-maxage=$smaxage, max-age=$maxage" ); |
| 28 | + header( "Last-modified: $epoch" ); |
| 29 | + } |
| 30 | + |
| 31 | + function getJsOutput() { |
| 32 | + return ""; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/CentralNotice/NoticePage.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 37 | + native |
Index: trunk/extensions/CentralNotice/SpecialNoticeText.php |
— | — | @@ -1,15 +1,18 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class SpecialNoticeText extends SpecialPage { |
| 4 | +class SpecialNoticeText extends NoticePage { |
5 | 5 | function __construct() { |
6 | 6 | parent::__construct( "NoticeText" ); |
7 | 7 | } |
8 | 8 | |
9 | | - function execute( $par ) { |
10 | | - global $wgOut; |
11 | | - $wgOut->disable(); |
12 | | - |
13 | | - echo $this->getJsOutput(); |
| 9 | + /** |
| 10 | + * Clients can cache this as long as they like -- if it changes, |
| 11 | + * we'll be bumping things at the loader level, bringing a new URL. |
| 12 | + * |
| 13 | + * Let's say a week. |
| 14 | + */ |
| 15 | + protected function maxAge() { |
| 16 | + return 86400 * 7; |
14 | 17 | } |
15 | 18 | |
16 | 19 | function getJsOutput() { |