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\MediaWikiServices; |
25 | |
26 | /** |
27 | * Query module to get flagging information about pages via 'prop=flagged' |
28 | * |
29 | * @ingroup FlaggedRevs |
30 | */ |
31 | class ApiQueryFlagged extends ApiQueryBase { |
32 | |
33 | /** |
34 | * @inheritDoc |
35 | */ |
36 | public function execute() { |
37 | $pageSet = $this->getPageSet(); |
38 | $pageids = array_keys( $pageSet->getGoodTitles() ); |
39 | if ( !$pageids ) { |
40 | return; |
41 | } |
42 | |
43 | // Construct SQL Query |
44 | $this->addTables( 'flaggedpages' ); |
45 | $this->addFields( [ |
46 | 'fp_page_id', 'fp_stable', 'fp_quality', 'fp_pending_since' |
47 | ] ); |
48 | $this->addWhereFld( 'fp_page_id', $pageids ); |
49 | $res = $this->select( __METHOD__ ); |
50 | |
51 | $result = $this->getResult(); |
52 | foreach ( $res as $row ) { |
53 | $data = [ |
54 | 'stable_revid' => intval( $row->fp_stable ), |
55 | 'level' => intval( $row->fp_quality ), |
56 | 'level_text' => 'stable' |
57 | ]; |
58 | if ( $row->fp_pending_since ) { |
59 | $data['pending_since'] = wfTimestamp( TS_ISO_8601, $row->fp_pending_since ); |
60 | } |
61 | |
62 | $result->addValue( [ 'query', 'pages', $row->fp_page_id ], 'flagged', $data ); |
63 | } |
64 | |
65 | $this->resetQueryParams(); |
66 | $this->addTables( 'flaggedpage_config' ); |
67 | $this->addFields( [ 'fpc_page_id', 'fpc_level', 'fpc_expiry' ] ); |
68 | $this->addWhereFld( 'fpc_page_id', $pageids ); |
69 | |
70 | $contLang = MediaWikiServices::getInstance()->getContentLanguage(); |
71 | foreach ( $this->select( __METHOD__ ) as $row ) { |
72 | $result->addValue( |
73 | [ 'query', 'pages', $row->fpc_page_id, 'flagged' ], |
74 | 'protection_level', |
75 | $row->fpc_level |
76 | ); |
77 | $result->addValue( |
78 | [ 'query', 'pages', $row->fpc_page_id, 'flagged' ], |
79 | 'protection_expiry', |
80 | $contLang->formatExpiry( $row->fpc_expiry, TS_ISO_8601 ) |
81 | ); |
82 | } |
83 | } |
84 | |
85 | /** |
86 | * @inheritDoc |
87 | */ |
88 | public function getCacheMode( $params ) { |
89 | return 'public'; |
90 | } |
91 | |
92 | /** |
93 | * @inheritDoc |
94 | */ |
95 | protected function getExamplesMessages() { |
96 | return [ |
97 | 'action=query&prop=info|flagged&titles=Main%20Page' |
98 | => 'apihelp-query+flagged-example-1', |
99 | 'action=query&generator=allpages&gapfrom=K&prop=flagged' |
100 | => 'apihelp-query+flagged-example-2', |
101 | ]; |
102 | } |
103 | } |