1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mediawiki\Api\Service; |
4
|
|
|
|
5
|
|
|
use Mediawiki\Api\SimpleRequest; |
6
|
|
|
use Mediawiki\DataModel\Page; |
7
|
|
|
use Mediawiki\DataModel\PageIdentifier; |
8
|
|
|
use Mediawiki\DataModel\Revision; |
9
|
|
|
use Mediawiki\DataModel\Title; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @access private |
13
|
|
|
* |
14
|
|
|
* @author Addshore |
15
|
|
|
*/ |
16
|
|
|
class PageDeleter extends Service { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @since 0.2 |
20
|
|
|
* |
21
|
|
|
* @param Page $page |
22
|
|
|
* @param array $extraParams |
23
|
|
|
* |
24
|
|
|
* @return bool |
25
|
|
|
*/ |
26
|
|
|
public function delete( Page $page, array $extraParams = [] ) { |
27
|
|
|
$this->api->postRequest( new SimpleRequest( |
28
|
|
|
'delete', |
29
|
|
|
$this->getDeleteParams( $page->getPageIdentifier(), $extraParams ) |
30
|
|
|
) ); |
31
|
|
|
return true; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @since 0.2 |
36
|
|
|
* |
37
|
|
|
* @param Revision $revision |
38
|
|
|
* @param array $extraParams |
39
|
|
|
* |
40
|
|
|
* @return bool |
41
|
|
|
*/ |
42
|
|
|
public function deleteFromRevision( Revision $revision, array $extraParams = [] ) { |
43
|
|
|
$this->api->postRequest( new SimpleRequest( |
44
|
|
|
'delete', |
45
|
|
|
$this->getDeleteParams( $revision->getPageIdentifier(), $extraParams ) |
|
|
|
|
46
|
|
|
) ); |
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @since 0.2 |
52
|
|
|
* |
53
|
|
|
* @param int $pageid |
54
|
|
|
* @param array $extraParams |
55
|
|
|
* |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
|
|
public function deleteFromPageId( $pageid, array $extraParams = [] ) { |
59
|
|
|
$this->api->postRequest( new SimpleRequest( |
60
|
|
|
'delete', |
61
|
|
|
$this->getDeleteParams( new PageIdentifier( null, $pageid ), $extraParams ) |
62
|
|
|
) ); |
63
|
|
|
return true; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @since 0.5 |
68
|
|
|
* |
69
|
|
|
* @param Title|string $title |
70
|
|
|
* @param array $extraParams |
71
|
|
|
* |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
|
|
public function deleteFromPageTitle( $title, array $extraParams = [] ) { |
75
|
|
|
if ( is_string( $title ) ) { |
76
|
|
|
$title = new Title( $title ); |
77
|
|
|
} |
78
|
|
|
$this->api->postRequest( new SimpleRequest( |
79
|
|
|
'delete', |
80
|
|
|
$this->getDeleteParams( new PageIdentifier( $title ), $extraParams ) |
81
|
|
|
) ); |
82
|
|
|
return true; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param PageIdentifier $identifier |
87
|
|
|
* @param array $extraParams |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
private function getDeleteParams( PageIdentifier $identifier, $extraParams ) { |
92
|
|
|
$params = []; |
93
|
|
|
|
94
|
|
|
if ( !is_null( $identifier->getId() ) ) { |
95
|
|
|
$params['pageid'] = $identifier->getId(); |
96
|
|
|
} else { |
97
|
|
|
$params['title'] = $identifier->getTitle()->getTitle(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$params['token'] = $this->api->getToken( 'delete' ); |
101
|
|
|
|
102
|
|
|
return array_merge( $extraParams, $params ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: