|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SCI; |
|
4
|
|
|
|
|
5
|
|
|
use IContextSource; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Helper class to avoid making objects depend on the IContextSource and instead |
|
9
|
|
|
* provide dedicated methods to access a specific aspect of the context. |
|
10
|
|
|
* |
|
11
|
|
|
* @license GNU GPL v2+ |
|
12
|
|
|
* @since 1.0 |
|
13
|
|
|
* |
|
14
|
|
|
* @author mwjames |
|
15
|
|
|
*/ |
|
16
|
|
|
class MediaWikiContextInteractor { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var IContextSource |
|
20
|
|
|
*/ |
|
21
|
|
|
private $context; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @since 1.0 |
|
25
|
|
|
* |
|
26
|
|
|
* @param IContextSource $context |
|
27
|
|
|
*/ |
|
28
|
14 |
|
public function __construct( IContextSource $context ) { |
|
29
|
14 |
|
$this->context = $context; |
|
30
|
14 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @see RawAction::getOldId |
|
34
|
|
|
* |
|
35
|
|
|
* @since 1.0 |
|
36
|
|
|
* |
|
37
|
|
|
* @return int |
|
38
|
|
|
*/ |
|
39
|
12 |
|
public function getOldId() { |
|
40
|
|
|
|
|
41
|
12 |
|
$oldid = $this->context->getRequest()->getInt( 'oldid' ); |
|
42
|
12 |
|
$title = $this->context->getTitle(); |
|
43
|
|
|
|
|
44
|
12 |
|
switch ( $this->context->getRequest()->getText( 'direction' ) ) { |
|
45
|
12 |
|
case 'next': |
|
46
|
|
|
# output next revision, or nothing if there isn't one |
|
47
|
1 |
|
$nextid = 0; |
|
48
|
1 |
|
if ( $oldid ) { |
|
49
|
|
|
$nextid = $title->getNextRevisionID( $oldid ); |
|
50
|
|
|
} |
|
51
|
1 |
|
$oldid = $nextid ?: -1; |
|
52
|
1 |
|
break; |
|
53
|
11 |
|
case 'prev': |
|
54
|
|
|
# output previous revision, or nothing if there isn't one |
|
55
|
1 |
|
if ( !$oldid ) { |
|
56
|
|
|
# get the current revision so we can get the penultimate one |
|
57
|
1 |
|
$oldid = $title->getLatestRevID(); |
|
58
|
1 |
|
} |
|
59
|
1 |
|
$previd = $title->getPreviousRevisionID( $oldid ); |
|
60
|
1 |
|
$oldid = $previd ?: -1; |
|
61
|
1 |
|
break; |
|
62
|
10 |
|
case 'cur': |
|
63
|
1 |
|
$oldid = 0; |
|
64
|
1 |
|
break; |
|
65
|
12 |
|
} |
|
66
|
|
|
|
|
67
|
12 |
|
return (int)$oldid; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @since 1.0 |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $magicword |
|
74
|
|
|
* |
|
75
|
|
|
* @return boolean |
|
76
|
|
|
*/ |
|
77
|
9 |
|
public function hasMagicWord( $magicword ) { |
|
78
|
|
|
|
|
79
|
9 |
|
$outputPage = $this->context->getOutput(); |
|
80
|
|
|
|
|
81
|
9 |
|
if ( isset( $outputPage->smwmagicwords ) && in_array( $magicword, $outputPage->smwmagicwords ) ) { |
|
82
|
1 |
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
9 |
|
return false; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @since 1.0 |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $action |
|
92
|
|
|
* |
|
93
|
|
|
* @return boolean |
|
94
|
|
|
*/ |
|
95
|
10 |
|
public function hasAction( $action ) { |
|
96
|
10 |
|
return \Action::getActionName( $this->context ) === $action; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @since 1.0 |
|
101
|
|
|
* |
|
102
|
|
|
* @return Title |
|
103
|
|
|
*/ |
|
104
|
9 |
|
public function getTitle() { |
|
105
|
9 |
|
return $this->context->getTitle(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @since 1.0 |
|
110
|
|
|
* |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
9 |
|
public function getLanguageCode() { |
|
114
|
9 |
|
return $this->context->getLanguage()->getCode(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|