diff options
Diffstat (limited to 'www/wiki/extensions/UploadWizard/includes/specials/SpecialCampaigns.php')
-rw-r--r-- | www/wiki/extensions/UploadWizard/includes/specials/SpecialCampaigns.php | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/www/wiki/extensions/UploadWizard/includes/specials/SpecialCampaigns.php b/www/wiki/extensions/UploadWizard/includes/specials/SpecialCampaigns.php new file mode 100644 index 00000000..e0561593 --- /dev/null +++ b/www/wiki/extensions/UploadWizard/includes/specials/SpecialCampaigns.php @@ -0,0 +1,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'; + } +} |