Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryFlagged | |
0.00% |
0 / 43 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 36 |
|
0.00% |
0 / 1 |
30 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Created on Sep 17, 2008 |
5 | * |
6 | * API module for MediaWiki's FlaggedRevs extension |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; if not, write to the Free Software Foundation, Inc., |
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
21 | * http://www.gnu.org/copyleft/gpl.html |
22 | */ |
23 | |
24 | use MediaWiki\Api\ApiQueryBase; |
25 | use MediaWiki\MediaWikiServices; |
26 | |
27 | /** |
28 | * Query module to get flagging information about pages via 'prop=flagged' |
29 | * |
30 | * @ingroup FlaggedRevs |
31 | */ |
32 | class ApiQueryFlagged extends ApiQueryBase { |
33 | |
34 | /** |
35 | * @inheritDoc |
36 | */ |
37 | public function execute() { |
38 | $pageSet = $this->getPageSet(); |
39 | $pageids = array_keys( $pageSet->getGoodPages() ); |
40 | if ( !$pageids ) { |
41 | return; |
42 | } |
43 | |
44 | // Construct SQL Query |
45 | $this->addTables( 'flaggedpages' ); |
46 | $this->addFields( [ |
47 | 'fp_page_id', 'fp_stable', 'fp_quality', 'fp_pending_since' |
48 | ] ); |
49 | $this->addWhereFld( 'fp_page_id', $pageids ); |
50 | $res = $this->select( __METHOD__ ); |
51 | |
52 | $result = $this->getResult(); |
53 | foreach ( $res as $row ) { |
54 | $data = [ |
55 | 'stable_revid' => intval( $row->fp_stable ), |
56 | 'level' => intval( $row->fp_quality ), |
57 | 'level_text' => 'stable' |
58 | ]; |
59 | if ( $row->fp_pending_since ) { |
60 | $data['pending_since'] = wfTimestamp( TS_ISO_8601, $row->fp_pending_since ); |
61 | } |
62 | |
63 | $result->addValue( [ 'query', 'pages', $row->fp_page_id ], 'flagged', $data ); |
64 | } |
65 | |
66 | $this->resetQueryParams(); |
67 | $this->addTables( 'flaggedpage_config' ); |
68 | $this->addFields( [ 'fpc_page_id', 'fpc_level', 'fpc_expiry' ] ); |
69 | $this->addWhereFld( 'fpc_page_id', $pageids ); |
70 | |
71 | $contLang = MediaWikiServices::getInstance()->getContentLanguage(); |
72 | foreach ( $this->select( __METHOD__ ) as $row ) { |
73 | $result->addValue( |
74 | [ 'query', 'pages', $row->fpc_page_id, 'flagged' ], |
75 | 'protection_level', |
76 | $row->fpc_level |
77 | ); |
78 | $result->addValue( |
79 | [ 'query', 'pages', $row->fpc_page_id, 'flagged' ], |
80 | 'protection_expiry', |
81 | $contLang->formatExpiry( $row->fpc_expiry, TS_ISO_8601 ) |
82 | ); |
83 | } |
84 | } |
85 | |
86 | /** |
87 | * @inheritDoc |
88 | */ |
89 | public function getCacheMode( $params ) { |
90 | return 'public'; |
91 | } |
92 | |
93 | /** |
94 | * @inheritDoc |
95 | */ |
96 | protected function getExamplesMessages() { |
97 | return [ |
98 | 'action=query&prop=info|flagged&titles=Main%20Page' |
99 | => 'apihelp-query+flagged-example-1', |
100 | 'action=query&generator=allpages&gapfrom=K&prop=flagged' |
101 | => 'apihelp-query+flagged-example-2', |
102 | ]; |
103 | } |
104 | } |