-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathWikilogCommentPagerSwitcher.php
46 lines (41 loc) · 1.32 KB
/
WikilogCommentPagerSwitcher.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
<?php
if ( !defined( 'MEDIAWIKI' ) )
die();
class WikilogCommentPagerSwitcher {
public static function getType( $subject ) {
$info = static::getInfo( $subject );
return $info ? $info['type'] : 'thread';
}
public static function checkType( $subject ) {
if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
$info = static::getInfo( $subject );
$msince = strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
if ( $info && ( !isset( $info['time'] ) || $info['time'] > $msince ) ) {
unset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
}
}
}
public static function setType( $subject, $type ) {
global $wgRequest;
$id = $subject ? $subject->getArticleId() : 0;
$types = $wgRequest->getSessionData( 'wikilog-comments-pager-type' );
if ( !$types || !is_array( $types ) ) {
$types = array();
}
$types[$id] = array(
'type' => $type,
'time' => time(),
);
$wgRequest->setSessionData( 'wikilog-comments-pager-type', $types );
unset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
}
protected static function getInfo( $subject ) {
global $wgRequest;
$id = $subject ? $subject->getArticleId() : 0;
$types = $wgRequest->getSessionData( 'wikilog-comments-pager-type' );
if ( !$types || !is_array( $types ) || !isset( $types[$id] ) || !isset( $types[$id]['type'] ) ) {
return NULL;
}
return $types[$id];
}
}