1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?php
class SpecialCampaigns extends SpecialPage {
function __construct() {
parent::__construct( "Campaigns" );
}
public function execute( $subPage ) {
$request = $this->getRequest();
$dbr = wfGetDB( DB_REPLICA );
$start = (int)$request->getVal( 'start' );
$limit = 50;
$cond = [ 'campaign_enabled = 1' ];
if ( $start !== null ) {
// Not SQL Injection, since $start is cast to (int)
$cond[] = "campaign_id > $start";
}
$res = $dbr->select(
'uw_campaigns',
[ 'campaign_id', 'campaign_name' ],
$cond,
__METHOD__,
[ 'LIMIT' => $limit + 1 ]
);
$this->getOutput()->setPageTitle( $this->msg( 'mwe-upload-campaigns-list-title' ) );
$this->getOutput()->addModules( 'ext.uploadWizard.uploadCampaign.list' );
$this->getOutput()->addHTML( '<dl>' );
$curCount = 0;
$lastId = null;
foreach ( $res as $row ) {
$curCount++;
if ( $curCount > $limit ) {
// We've an extra element. Paginate!
$lastId = $row->campaign_id;
break;
} else {
$campaign = UploadWizardCampaign::newFromName( $row->campaign_name );
$this->getOutput()->addHTML( $this->getHtmlForCampaign( $campaign ) );
}
}
$this->getOutput()->addHTML( '</dl>' );
// Pagination links!
if ( $lastId !== null ) {
$this->getOutput()->addHTML( $this->getHtmlForPagination( $lastId ) );
}
}
private function getHtmlForCampaign( UploadWizardCampaign $campaign ) {
$config = $campaign->getParsedConfig();
$campaignURL = $campaign->getTitle()->getLocalURL();
$campaignTitle = array_key_exists( 'title', $config ) ? $config['title'] : $campaign->getName();
$campaignDescription = array_key_exists( 'description', $config ) ? $config['description'] : '';
$returnHTML =
Html::rawElement( 'dt', [],
Html::rawElement( 'a', [ 'href' => $campaignURL ], $campaignTitle )
) .
Html::element( 'dd', [], $campaignDescription );
return $returnHTML;
}
private function getHtmlForPagination( $firstId ) {
$nextHref = $this->getPageTitle()->getLocalURL( [ 'start' => $firstId ] );
return Html::rawElement( 'div',
[ 'id' => 'mwe-upload-campaigns-pagination' ],
Html::element( 'a',
[ 'href' => $nextHref ],
$this->msg( 'mwe-upload-campaigns-pagination-next' )->text()
)
);
}
protected function getGroupName() {
return 'media';
}
}
|