r73571 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73570‎ | r73571 | r73572 >
Date:21:03, 22 September 2010
Author:kaldari
Status:ok
Tags:
Comment:
use $wgJsMimeType, ensure cachability of JSONP requests, escape $wgCentralPagePath before putting into javascript (fixes for r73554)
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialBannerController.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialBannerListLoader.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialBannerLoader.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialBannerListLoader.php
@@ -10,7 +10,6 @@
1111 public $centralNoticeDB;
1212 protected $sharedMaxAge = 900; // Cache for 15 minutes on the server side
1313 protected $maxAge = 900; // Cache for 15 minutes on the client side
14 - protected $contentType = 'text/javascript';
1514
1615 function __construct() {
1716 // Register special page
@@ -49,7 +48,8 @@
5049 * Generate the HTTP response headers for the banner file
5150 */
5251 function sendHeaders() {
53 - header( "Content-type: $this->contentType; charset=utf-8" );
 52+ global $wgJsMimeType;
 53+ header( "Content-type: $wgJsMimeType; charset=utf-8" );
5454 header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" );
5555 }
5656
Index: trunk/extensions/CentralNotice/SpecialBannerLoader.php
@@ -8,7 +8,6 @@
99 public $language = 'en'; // User language
1010 protected $sharedMaxAge = 900; // Cache for 15 minutes on the server side
1111 protected $maxAge = 0; // No client-side banner caching so we get all impressions
12 - protected $contentType = 'text/js';
1312
1413 function __construct() {
1514 // Register special page
@@ -47,7 +46,8 @@
4847 * Generate the HTTP response headers for the banner file
4948 */
5049 function sendHeaders() {
51 - header( "Content-type: $this->contentType; charset=utf-8" );
 50+ global $wgJsMimeType;
 51+ header( "Content-type: $wgJsMimeType; charset=utf-8" );
5252 header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" );
5353 }
5454
Index: trunk/extensions/CentralNotice/SpecialBannerController.php
@@ -6,7 +6,6 @@
77 class SpecialBannerController extends UnlistedSpecialPage {
88 protected $sharedMaxAge = 7200; // Cache for 2 hours on the server side
99 protected $maxAge = 7200; // Cache for 2 hours on the client side
10 - protected $contentType = 'text/javascript';
1110
1211 function __construct() {
1312 // Register special page
@@ -34,7 +33,8 @@
3534 * Generate the HTTP response headers for the banner controller
3635 */
3736 function sendHeaders() {
38 - header( "Content-type: $this->contentType; charset=utf-8" );
 37+ global $wgJsMimeType;
 38+ header( "Content-type: $wgJsMimeType; charset=utf-8" );
3939 header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" );
4040 }
4141
@@ -47,6 +47,7 @@
4848 $js = $this->getScriptFunctions() . $this->getToggleScripts();
4949 $js .= <<<EOT
5050 ( function( $ ) {
 51+ $.ajaxSetup({ cache: true });
5152 $.centralNotice = {
5253 'data': {
5354 'getVars': {}
@@ -56,7 +57,7 @@
5758 // Get the requested banner
5859 var bannerPage = 'Special:BannerLoader?banner='+bannerName+'&userlang='+wgContentLanguage+'&sitename='+wgNoticeProject;
5960 EOT;
60 - $js .= "\n\t\t\t\tvar bannerScript = '<script type=\"text/javascript\" src=\"$wgCentralPagePath' + bannerPage + '\"></script>';\n";
 61+ $js .= "\n\t\t\t\tvar bannerScript = '<script type=\"text/javascript\" src=\"".Xml::escapeJsString( $wgCentralPagePath )."' + bannerPage + '\"></script>';\n";
6162 $js .= <<<EOT
6263 $( '#siteNotice' ).prepend( '<div id="centralNotice" class="' + ( wgNoticeToggleState ? 'expanded' : 'collapsed' ) + '">'+bannerScript+'</div>' );
6364 },

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r73554switching to JSONP for retrieving banners, getting rid of stand-alone param f...kaldari18:09, 22 September 2010

Status & tagging log