Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SpecialRecordImpression | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| sendHeaders | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | use MediaWiki\SpecialPage\UnlistedSpecialPage; |
| 4 | |
| 5 | /** |
| 6 | * Null endpoint. This is a workaround to simplify analytics. |
| 7 | */ |
| 8 | class SpecialRecordImpression extends UnlistedSpecialPage { |
| 9 | // Cache this blank response for a day or so (60 * 60 * 24 s.) |
| 10 | public const CACHE_EXPIRY = 86400; |
| 11 | |
| 12 | public function __construct() { |
| 13 | // Register special page |
| 14 | parent::__construct( "RecordImpression" ); |
| 15 | } |
| 16 | |
| 17 | /** @inheritDoc */ |
| 18 | public function execute( $par ) { |
| 19 | $this->getOutput()->disable(); |
| 20 | |
| 21 | $this->sendHeaders(); |
| 22 | |
| 23 | // Output nothing else. |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Generate the HTTP response headers for the banner file |
| 28 | */ |
| 29 | private function sendHeaders() { |
| 30 | $expiry = static::CACHE_EXPIRY; |
| 31 | header( "Content-Type: image/png" ); |
| 32 | |
| 33 | // If we have a logged in user; do not cache (default for special pages) |
| 34 | // lest we capture a set-cookie header. Otherwise cache so we don't have |
| 35 | // too big of a DDoS hole. |
| 36 | if ( !$this->getUser()->isRegistered() ) { |
| 37 | header( "Cache-Control: public, s-maxage={$expiry}, max-age=0" ); |
| 38 | } |
| 39 | } |
| 40 | } |