Index: trunk/extensions/CentralNotice/SpecialNoticeLoader.php |
— | — | @@ -0,0 +1,30 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class SpecialNoticeLoader extends SpecialPage { |
| 5 | + function __construct() { |
| 6 | + parent::__construct("NoticeLoader"); |
| 7 | + } |
| 8 | + |
| 9 | + function execute( $par ) { |
| 10 | + global $wgOut; |
| 11 | + $wgOut->disable(); |
| 12 | + |
| 13 | + echo $this->getJsOutput(); |
| 14 | + } |
| 15 | + |
| 16 | + function getJsOutput() { |
| 17 | + global $wgCentralNoticeText; |
| 18 | + $encUrl = Xml::escapeJsString( $wgCentralNoticeText ); |
| 19 | + $encEpoch = Xml::escapeJsString( $this->getEpoch() ); |
| 20 | + return <<<EOT |
| 21 | +document.writeln("<"+"script src=\"$encUrl/"+wgNoticeProject+"/"+wgNoticeLang+"?$encEpoch"+"\"><"+"/script>"); |
| 22 | +EOT; |
| 23 | + } |
| 24 | + |
| 25 | + function getEpoch() { |
| 26 | + // Time when we should invalidate all notices... |
| 27 | + return wfTimestamp( TS_MW ); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/CentralNotice/SpecialNoticeLoader.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 32 | + native |
Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -0,0 +1,41 @@ |
| 2 | +<?php |
| 3 | + |
| 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'; |
| 8 | + |
| 9 | +function wfCentralNotice( &$notice ) { |
| 10 | + global $wgCentralNoticeLoader; |
| 11 | + |
| 12 | + $encNoticeLoader = htmlspecialchars( $wgCentralNoticeLoader ); |
| 13 | + |
| 14 | + // Throw away the classic notice, use the central loader... |
| 15 | + $notice = <<<EOT |
| 16 | +<script type="text/javascript"> |
| 17 | +var wgNotice = ''; |
| 18 | +var wgNoticeLang = 'en'; |
| 19 | +var wgNoticeProject = 'wikipedia'; |
| 20 | +</script> |
| 21 | +<script type="text/javascript" src="$encNoticeLoader"></script> |
| 22 | +<script type="text/javascript"> |
| 23 | +if (wgNotice != '') { |
| 24 | + document.writeln(wgNotice); |
| 25 | +} |
| 26 | +</script> |
| 27 | +EOT; |
| 28 | + |
| 29 | + return true; |
| 30 | +} |
| 31 | + |
| 32 | +$wgHooks['SiteNoticeAfter'][] = 'wfCentralNotice'; |
| 33 | + |
| 34 | +$wgSpecialPages['NoticeLoader'] = 'SpecialNoticeLoader'; |
| 35 | +$wgAutoloadClasses['SpecialNoticeLoader'] = |
| 36 | + dirname( __FILE__ ) . '/SpecialNoticeLoader.php'; |
| 37 | + |
| 38 | +$wgSpecialPages['NoticeText'] = 'SpecialNoticeText'; |
| 39 | +$wgAutoloadClasses['SpecialNoticeText'] = |
| 40 | + dirname( __FILE__ ) . '/SpecialNoticeText.php'; |
| 41 | + |
| 42 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/CentralNotice/CentralNotice.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 43 | + native |
Index: trunk/extensions/CentralNotice/README |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +Proof of concept for the moment fiddling with an alternative sitenotice |
| 3 | +loading architecture. At the moment there's no backend logic or caching |
| 4 | +logic, I'm just testing the three-level loading. |
| 5 | + |
| 6 | + |
| 7 | +Wiki page HTML contains an unchanging bit that just sets JS variables about |
| 8 | +what site this is, then calls an external <script> to fetch site notice text. |
| 9 | + |
| 10 | + |
| 11 | +That second level can be a stable URL which can be heavily cached within squids |
| 12 | +*and* cleanly purged on sitewide updates. |
| 13 | + |
| 14 | +It itself is small, just calling out to a third <script>, this time with the |
| 15 | +site info (project and language) and a cache validation epoch / version marker |
| 16 | +in the query string. |
| 17 | + |
| 18 | + |
| 19 | +The third level is the bit that would provide the actual site notice text, and |
| 20 | +could be cached arbitrarily long in both squids and final user agents, since |
| 21 | +changed versions will get a new URL with a version number one level up. |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +The theory here is that it should interact better with big-site caching. |
| 26 | +A user agent's first hit to the wiki will look something like: |
| 27 | + |
| 28 | +* Load wiki page HTML |
| 29 | +* Load Special:NoticeLoader JS |
| 30 | +* Load Special:NoticeText JS |
| 31 | + |
| 32 | +A hit to another page on the same wiki can skip the third hit: |
| 33 | + |
| 34 | +* Load new wiki page HTML |
| 35 | +* Load unchanged Special:NoticeLoader JS |
| 36 | +* skip cached Special:NoticeText JS |
| 37 | + |
| 38 | +Then if the site notice changes, the system only has to purge that constant |
| 39 | +Special:NoticeLoader URL from squids, and right away at the next hit the user |
| 40 | +agent sees: |
| 41 | + |
| 42 | +* Load new wiki page HTML |
| 43 | +* Load new Special:NoticeLoader JS |
| 44 | +* Load new Special:NoticeText JS |
| 45 | + |
| 46 | +We could spare hits on the notice loader by letting clients cache it for a |
| 47 | +shorter term as well, so a typical second hit looks nicely like: |
| 48 | + |
| 49 | +* Load new wiki page HTML |
| 50 | +* skip cached Special:NoticeLoader JS |
| 51 | +* skip cached Special:NoticeText JS |
| 52 | + |
| 53 | +This could delay visibility of changed site notices until the allowed age |
| 54 | +runs out, but if we manage *scheduled* site notices, we could send cache |
| 55 | +headers which will run out at the expected changeover time. |
| 56 | + |
| 57 | +It might be nice to allow for quick corrections though, so caching for weeks |
| 58 | +at a time might not be wise. ;) |
| 59 | + |
| 60 | + |
| 61 | + |
Index: trunk/extensions/CentralNotice/SpecialNoticeText.php |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class SpecialNoticeText extends SpecialPage { |
| 5 | + function __construct() { |
| 6 | + parent::__construct( "NoticeText" ); |
| 7 | + } |
| 8 | + |
| 9 | + function execute( $par ) { |
| 10 | + global $wgOut; |
| 11 | + $wgOut->disable(); |
| 12 | + |
| 13 | + echo $this->getJsOutput(); |
| 14 | + } |
| 15 | + |
| 16 | + function getJsOutput() { |
| 17 | + global $wgSiteNotice; |
| 18 | + $encNotice = Xml::escapeJsString( $wgSiteNotice ); |
| 19 | + return <<<EOT |
| 20 | +wgNotice = "$encNotice"; |
| 21 | +EOT; |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/CentralNotice/SpecialNoticeText.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 26 | + native |