|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mediawiki\Api\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Mediawiki\Api\Generator\ApiGenerator; |
|
6
|
|
|
use Mediawiki\Api\MediawikiApi; |
|
7
|
|
|
use Mediawiki\Api\SimpleRequest; |
|
8
|
|
|
use Mediawiki\DataModel\Pages; |
|
9
|
|
|
use Mediawiki\DataModel\Page; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @access private |
|
13
|
|
|
* |
|
14
|
|
|
* @author Addshore |
|
15
|
|
|
* @author Thomas Arrow |
|
16
|
|
|
*/ |
|
17
|
|
|
class PagePurger { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var MediawikiApi |
|
21
|
|
|
*/ |
|
22
|
|
|
private $api; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param MediawikiApi $api |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function __construct( MediawikiApi $api ) { |
|
28
|
2 |
|
$this->api = $api; |
|
29
|
2 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @since 0.3 |
|
33
|
|
|
* |
|
34
|
|
|
* @brief Purge a single page |
|
35
|
|
|
* |
|
36
|
|
|
* Purges a single page by submitting a |
|
37
|
|
|
* 'purge' action to the wikipedia api |
|
38
|
|
|
* with the parameter 'pageids' set to |
|
39
|
|
|
* the singe page id |
|
40
|
|
|
* |
|
41
|
|
|
* @param Page $page the page that is going to be purged |
|
42
|
|
|
* |
|
43
|
|
|
* @return bool |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function purge( Page $page ) { |
|
46
|
1 |
|
$this->api->postRequest( |
|
47
|
1 |
|
new SimpleRequest( 'purge', [ 'pageids' => $page->getId() ] ) |
|
|
|
|
|
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
1 |
|
return true; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @since 0.7 |
|
55
|
|
|
* |
|
56
|
|
|
* @brief Purge multiple pages |
|
57
|
|
|
* |
|
58
|
|
|
* Purges all the pages of the Pages object |
|
59
|
|
|
* by submitting a 'purge' action to the wikipedia |
|
60
|
|
|
* api with the parameter 'pageids' set to be the |
|
61
|
|
|
* pages ids in multiple-value seperation. |
|
62
|
|
|
* |
|
63
|
|
|
* @param Pages $pages the pages that are going to be purged |
|
64
|
|
|
* |
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
|
|
public function purgePages( Pages $pages ) { |
|
68
|
|
|
$pagesArray = $pages->toArray(); |
|
69
|
|
|
$pagesIds = []; |
|
70
|
|
|
|
|
71
|
|
|
foreach ( $pagesArray as $page ) { |
|
72
|
|
|
array_push( $pagesIds, $page->getId() ); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
// convert an array to multiple-value format |
|
76
|
|
|
// because the wikipedia api require multiple |
|
77
|
|
|
// values to be seperated like the example |
|
78
|
|
|
// ex: [111, 222, 333] => "111|222|333" |
|
79
|
|
|
$pageIdsMultiple = implode( "|", $pagesIds ); |
|
80
|
|
|
|
|
81
|
|
|
$this->api->postRequest( |
|
82
|
|
|
new SimpleRequest( 'purge', [ 'pageids' => $pageIdsMultiple ] ) |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
return true; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @since 0.6 |
|
90
|
|
|
* |
|
91
|
|
|
* @param ApiGenerator $generator |
|
92
|
|
|
* |
|
93
|
|
|
* @return bool |
|
94
|
|
|
*/ |
|
95
|
|
|
public function purgeGenerator( ApiGenerator $generator ) { |
|
96
|
|
|
$this->api->postRequest( |
|
97
|
|
|
new SimpleRequest( 'purge', $generator->getParams() ) |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
return true; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.