forked from bvibber/mediawiki-svn
/
SpecialNoticeLoader.php
60 lines (54 loc) · 1.48 KB
/
SpecialNoticeLoader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* The notice loader is a central point of contact; a single consistent
* URL used for the cluster, in all language and project versions.
*
* That central URL can be heavily cached, and centrally purged when
* updates do happen.
*
* It loads up a second page (Special:NoticeText) with specific project
* and language options and a version timestamp for clean cache breaking.
*/
class SpecialNoticeLoader extends NoticePage {
function __construct() {
parent::__construct("NoticeLoader");
}
/**
* Clients should recheck this fairly often, but not _constantly_.
* 5 minutes?
*/
protected function maxAge() {
global $wgNoticeTimeout;
return $wgNoticeTimeout;
}
function getJsOutput( $par ) {
global $wgNoticeTestMode;
$loader = $this->loaderScript();
if( $wgNoticeTestMode ) {
return $this->testCondition( $loader );
} else {
return $loader;
}
}
function testCondition( $code ) {
return
'if(/[?&]sitenotice=yes/.test(document.location.search)){'.
$code .
'}';
}
function loaderScript() {
global $wgNoticeText;
$encUrl = htmlspecialchars( $wgNoticeText );
$encEpoch = urlencode( $this->getEpoch() );
return "document.writeln(" .
Xml::encodeJsVar( "<script src=\"$encUrl/" ) .
'+wgNoticeProject+"/"+wgNoticeLang+' .
Xml::encodeJsVar( "?$encEpoch\"></script>" ).
');';
}
function getEpoch() {
global $wgNoticeEpoch;
// Time when we should invalidate all notices...
return wfTimestamp( TS_MW, $wgNoticeEpoch );
}
}