1 | <?php |
||
15 | class MediawikiSession implements LoggerAwareInterface { |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $tokens = array(); |
||
21 | |||
22 | /** |
||
23 | * @var MediawikiApi |
||
24 | */ |
||
25 | private $api; |
||
26 | |||
27 | /** |
||
28 | * @var bool if this session is running against mediawiki version pre 1.25 |
||
29 | */ |
||
30 | private $usePre125TokensModule = false; |
||
31 | |||
32 | /** |
||
33 | * @var LoggerInterface |
||
34 | */ |
||
35 | private $logger; |
||
36 | |||
37 | /** |
||
38 | * @param MediawikiApi $api |
||
39 | */ |
||
40 | 10 | public function __construct( MediawikiApi $api ) { |
|
41 | 10 | $this->api = $api; |
|
42 | 10 | $this->logger = new NullLogger(); |
|
43 | 10 | } |
|
44 | |||
45 | /** |
||
46 | * Sets a logger instance on the object |
||
47 | * |
||
48 | * @since 1.1 |
||
49 | * |
||
50 | * @param LoggerInterface $logger |
||
51 | * |
||
52 | * @return null |
||
53 | */ |
||
54 | public function setLogger( LoggerInterface $logger ) { |
||
55 | $this->logger = $logger; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Tries to get the specified token from the API |
||
60 | * |
||
61 | * @since 0.1 |
||
62 | * |
||
63 | * @param string $type |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | 12 | public function getToken( $type = 'csrf' ) { |
|
84 | |||
85 | 4 | private function reallyGetPre125Token( $type ) { |
|
94 | |||
95 | 8 | private function reallyGetToken( $type ) { |
|
96 | // We suppress errors on this call so the user doesn't get get a warning that isn't their fault. |
||
116 | |||
117 | /** |
||
118 | * Tries to guess a new token type from an old token type |
||
119 | * |
||
120 | * @param string $type |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | 8 | private function getNewTokenType( $type ) { |
|
140 | |||
141 | /** |
||
142 | * Tries to guess an old token type from a new token type |
||
143 | * |
||
144 | * @param $type |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | 4 | private function getOldTokenType( $type ) { |
|
156 | |||
157 | /** |
||
158 | * Clears all tokens stored by the api |
||
159 | * |
||
160 | * @since 0.2 |
||
161 | */ |
||
162 | 4 | public function clearTokens() { |
|
166 | |||
167 | } |
||
168 |