r26347 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26346‎ | r26347 | r26348 >
Date:03:08, 3 October 2007
Author:brion
Status:old
Tags:
Comment:
Added some cache headers and a bumpable epoch.
Forced shared caching assumes a version of PHP that doesn't send out unnecessary session cookies... how to best handle ensuring this?
Ideally we wouldn't even have a session. Maybe we have to turn this into an entry point to force it for sure.
Todo: handle Last-Modified requests... and all the infrastructure for changing.. and... :)
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/NoticePage.php (added) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeLoader.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeText.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialNoticeLoader.php
@@ -1,20 +1,31 @@
22 <?php
33
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 {
515 function __construct() {
616 parent::__construct("NoticeLoader");
717 }
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;
1425 }
1526
1627 function getJsOutput() {
17 - global $wgCentralNoticeText;
18 - $encUrl = Xml::escapeJsString( $wgCentralNoticeText );
 28+ global $wgNoticeText;
 29+ $encUrl = Xml::escapeJsString( $wgNoticeText );
1930 $encEpoch = Xml::escapeJsString( $this->getEpoch() );
2031 return <<<EOT
2132 document.writeln("<"+"script src=\"$encUrl/"+wgNoticeProject+"/"+wgNoticeLang+"?$encEpoch"+"\"><"+"/script>");
@@ -22,8 +33,9 @@
2334 }
2435
2536 function getEpoch() {
 37+ global $wgNoticeEpoch;
2638 // Time when we should invalidate all notices...
27 - return wfTimestamp( TS_MW );
 39+ return wfTimestamp( TS_MW, $wgNoticeEpoch );
2840 }
2941 }
3042
Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -1,14 +1,14 @@
22 <?php
33
44 // 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';
88
99 function wfCentralNotice( &$notice ) {
10 - global $wgCentralNoticeLoader;
 10+ global $wgNoticeLoader;
1111
12 - $encNoticeLoader = htmlspecialchars( $wgCentralNoticeLoader );
 12+ $encNoticeLoader = htmlspecialchars( $wgNoticeLoader );
1313
1414 // Throw away the classic notice, use the central loader...
1515 $notice = <<<EOT
@@ -30,6 +30,9 @@
3131
3232 $wgHooks['SiteNoticeAfter'][] = 'wfCentralNotice';
3333
 34+$wgAutoloadClasses['NoticePage'] =
 35+ dirname( __FILE__ ) . '/NoticePage.php';
 36+
3437 $wgSpecialPages['NoticeLoader'] = 'SpecialNoticeLoader';
3538 $wgAutoloadClasses['SpecialNoticeLoader'] =
3639 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
137 + native
Index: trunk/extensions/CentralNotice/SpecialNoticeText.php
@@ -1,15 +1,18 @@
22 <?php
33
4 -class SpecialNoticeText extends SpecialPage {
 4+class SpecialNoticeText extends NoticePage {
55 function __construct() {
66 parent::__construct( "NoticeText" );
77 }
88
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;
1417 }
1518
1619 function getJsOutput() {

Status & tagging log