Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
50.00% |
16 / 32 |
|
28.57% |
2 / 7 |
CRAP | |
0.00% |
0 / 1 |
ApiReadingListsDeleteEntry | |
50.00% |
16 / 32 |
|
28.57% |
2 / 7 |
19.12 | |
0.00% |
0 / 1 |
execute | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
getAllowedParams | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
getHelpUrls | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
isWriteMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
mustBePosted | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isInternal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\ReadingLists\Api; |
4 | |
5 | use MediaWiki\Api\ApiBase; |
6 | use Wikimedia\ParamValidator\ParamValidator; |
7 | |
8 | /** |
9 | * API module for all write operations. |
10 | * Each operation (command) is implemented as a submodule. |
11 | */ |
12 | class ApiReadingListsDeleteEntry extends ApiBase { |
13 | |
14 | use ApiTrait; |
15 | |
16 | /** @var string API module prefix */ |
17 | private static $prefix = ''; |
18 | |
19 | /** |
20 | * Entry point for executing the module |
21 | * @inheritDoc |
22 | */ |
23 | public function execute() { |
24 | $params = $this->extractRequestParams(); |
25 | $this->requireOnlyOneParameter( $params, 'entry', 'batch' ); |
26 | |
27 | $repository = $this->getReadingListRepository( $this->getUser() ); |
28 | if ( isset( $params['entry'] ) ) { |
29 | $repository->deleteListEntry( $params['entry'] ); |
30 | } else { |
31 | foreach ( $this->getBatchOps( $params['batch'] ) as $op ) { |
32 | $this->requireAtLeastOneBatchParameter( $op, 'entry' ); |
33 | $repository->deleteListEntry( $op['entry'] ); |
34 | } |
35 | } |
36 | } |
37 | |
38 | /** |
39 | * @inheritDoc |
40 | */ |
41 | protected function getAllowedParams() { |
42 | return [ |
43 | 'entry' => [ |
44 | ParamValidator::PARAM_TYPE => 'integer', |
45 | ], |
46 | 'batch' => [ |
47 | ParamValidator::PARAM_TYPE => 'string', |
48 | ] |
49 | ]; |
50 | } |
51 | |
52 | /** |
53 | * @inheritDoc |
54 | */ |
55 | public function getHelpUrls() { |
56 | return [ |
57 | 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:ReadingLists#API', |
58 | ]; |
59 | } |
60 | |
61 | /** |
62 | * @inheritDoc |
63 | */ |
64 | protected function getExamplesMessages() { |
65 | $batch = wfArrayToCgi( [ 'batch' => json_encode( [ |
66 | [ 'entry' => 8 ], |
67 | [ 'entry' => 9 ], |
68 | ] ) ] ); |
69 | return [ |
70 | 'action=readinglists&command=deleteentry&entry=8&token=123ABC' |
71 | => 'apihelp-readinglists+deleteentry-example-1', |
72 | "action=readinglists&command=deleteentry&$batch&token=123ABC" |
73 | => 'apihelp-readinglists+deleteentry-example-2', |
74 | ]; |
75 | } |
76 | |
77 | // The parent module already enforces these but they make documentation nicer. |
78 | |
79 | /** |
80 | * @inheritDoc |
81 | */ |
82 | public function isWriteMode() { |
83 | return true; |
84 | } |
85 | |
86 | /** |
87 | * @inheritDoc |
88 | */ |
89 | public function mustBePosted() { |
90 | return true; |
91 | } |
92 | |
93 | /** |
94 | * @inheritDoc |
95 | */ |
96 | public function isInternal() { |
97 | // ReadingLists API is still experimental |
98 | return true; |
99 | } |
100 | |
101 | } |