Yuvipanda has uploaded a new change for review.
https://gerrit.wikimedia.org/r/80782
Change subject: Add API to query campaigns
......................................................................
Add API to query campaigns
Change-Id: I308df2ca47ff4f98c88ccab5af8aee2584cb5a29
---
M UploadWizard.php
A includes/ApiQueryAllCampaigns.php
2 files changed, 102 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/82/80782/1
diff --git a/UploadWizard.php b/UploadWizard.php
index 3699ad9..24ac3e0 100644
--- a/UploadWizard.php
+++ b/UploadWizard.php
@@ -56,8 +56,12 @@
// Special Pages
'SpecialUploadWizard' => $wgUpwizDir .
'/includes/specials/SpecialUploadWizard.php',
+
+ // API
+ 'ApiQueryAllCampaigns' => $wgUpwizDir .
'/includes/ApiQueryAllCampaigns.php'
);
+$wgAPIListModules['allcampaigns'] = 'ApiQueryAllCampaigns';
// $wgAPIModules['titlecheck'] = 'ApiTitleCheck';
// $wgAPIListModules['titlecheck'] = 'ApiTitleCheck';
diff --git a/includes/ApiQueryAllCampaigns.php
b/includes/ApiQueryAllCampaigns.php
new file mode 100644
index 0000000..64b1a4c
--- /dev/null
+++ b/includes/ApiQueryAllCampaigns.php
@@ -0,0 +1,98 @@
+<?php
+/**
+ *
+ *
+ * Copyright © 2007 Yuvi Panda <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Query module to enumerate all registered campaigns
+ *
+ * @ingroup API
+ */
+class ApiQueryAllCampaigns extends ApiQueryBase {
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'uc' );
+ }
+
+ public function execute() {
+ $db = $this->getDB();
+ $params = $this->extractRequestParams();
+
+ $this->addTables( 'uw_campaigns' );
+ $useIndex = true;
+
+ $this->addWhereIf( array( 'campaign_enabled' => 1 ),
$params['enabledonly'] );
+
+ $this->addFields( array(
+ 'campaign_name',
+ 'campaign_enabled'
+ ) );
+
+ $res = $this->select( __METHOD__ );
+
+ $result = $this->getResult();
+
+ foreach ( $res as $row ) {
+ $campaign = UploadWizardCampaign::newFromName(
$row->campaign_name );
+ $result->addValue(
+ array( 'query', $this->getModuleName() ),
+ 'campaign',
+ array(
+ '*' => json_encode(
$campaign->getConfig() ),
+ )
+ );
+ }
+ }
+
+ public function getCacheMode( $params ) {
+ return 'public';
+ }
+
+ public function getAllowedParams() {
+ $userGroups = User::getAllGroups();
+ return array(
+ 'enabledonly' => false
+ );
+ }
+
+ public function getParamDescription() {
+ global $wgActiveUserDays;
+ return array(
+ 'enabledonly' => 'Only list campaigns that are enabled'
+ );
+ }
+
+ public function getDescription() {
+ return 'Enumerate all Campaigns';
+ }
+
+
+ public function getExamples() {
+ return array(
+ 'api.php?action=query&list=allcampaigns&ucenabled=true',
+ );
+ }
+
+ public function getHelpUrls() {
+ return
'https://www.mediawiki.org/wiki/Extension:UploadWizard/API';
+ }
+}
+
--
To view, visit https://gerrit.wikimedia.org/r/80782
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I308df2ca47ff4f98c88ccab5af8aee2584cb5a29
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits