Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 49 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
MessageDumpPage | |
0.00% |
0 / 49 |
|
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 49 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\SecurePoll\Pages; |
4 | |
5 | class MessageDumpPage extends ActionPage { |
6 | /** |
7 | * @param array $params |
8 | * @suppress SecurityCheck-XSS Mime type is not html so all false positive |
9 | */ |
10 | public function execute( $params ) { |
11 | $out = $this->specialPage->getOutput(); |
12 | |
13 | if ( !count( $params ) ) { |
14 | $out->addWikiMsg( 'securepoll-too-few-params' ); |
15 | |
16 | return; |
17 | } |
18 | |
19 | $electionId = intval( $params[0] ); |
20 | $this->election = $this->context->getElection( $electionId ); |
21 | if ( !$this->election ) { |
22 | $out->addWikiMsg( 'securepoll-invalid-election', $electionId ); |
23 | |
24 | return; |
25 | } |
26 | |
27 | $out->disable(); |
28 | header( 'Content-Type: application/x-sql; charset=utf-8' ); |
29 | $filename = urlencode( "sp-msgs-$electionId-" . wfTimestampNow() . '.sql' ); |
30 | header( "Content-Disposition: attachment; filename=$filename" ); |
31 | $dbr = $this->context->getDB(); |
32 | |
33 | $entities = array_merge( [ $this->election ], $this->election->getDescendants() ); |
34 | $ids = []; |
35 | foreach ( $entities as $entity ) { |
36 | $ids[] = $entity->getId(); |
37 | } |
38 | |
39 | $res = $dbr->newSelectQueryBuilder() |
40 | ->select( '*' ) |
41 | ->from( 'securepoll_msgs' ) |
42 | ->where( [ 'msg_entity' => $ids ] ) |
43 | ->caller( __METHOD__ ) |
44 | ->fetchResultSet(); |
45 | |
46 | if ( !$res->numRows() ) { |
47 | return; |
48 | } |
49 | echo "INSERT INTO securepoll_msgs (msg_entity,msg_lang, msg_key, msg_text) VALUES\n"; |
50 | $first = true; |
51 | foreach ( $res as $row ) { |
52 | $values = [ |
53 | $row->msg_entity, |
54 | $row->msg_lang, |
55 | $row->msg_key, |
56 | $row->msg_text |
57 | ]; |
58 | if ( $first ) { |
59 | $first = false; |
60 | } else { |
61 | echo ",\n"; |
62 | } |
63 | echo '(' . implode( |
64 | ', ', |
65 | array_map( |
66 | [ |
67 | $dbr, |
68 | 'addQuotes' |
69 | ], |
70 | $values |
71 | ) |
72 | ) . ')'; |
73 | } |
74 | echo ";\n"; |
75 | } |
76 | } |