/**
  * Fetches appropriate HTML for the tutorial portion of the wizard.
  * Looks up an image on the current wiki. This will work as is on Commons, and will also work
  * on test wikis that enable instantCommons.
  * @param String|null $campaign Upload Wizard campaign for which the tutorial should be displayed.
  * @return String html that will display the tutorial.
  */
 public static function getHtml($campaign = null)
 {
     global $wgLang;
     $error = null;
     $errorHtml = '';
     $tutorialHtml = '';
     $langCode = $wgLang->getCode();
     $tutorial = UploadWizardConfig::getSetting('tutorial', $campaign);
     // getFile returns false if it can't find the right file
     $tutorialFile = self::getFile($langCode, $tutorial);
     if ($tutorialFile === false) {
         $error = 'localized-file-missing';
         foreach ($wgLang->getFallbackLanguages() as $langCode) {
             $tutorialFile = self::getFile($langCode, $tutorial);
             if ($tutorialFile !== false) {
                 // $langCode remains as the code where a file is found.
                 break;
             }
         }
     }
     // at this point, we have one of the following situations:
     // $error is null, and tutorialFile is the right one for this language
     // $error notes we couldn't find the tutorialFile for your language, and $tutorialFile is the english one
     // $error notes we couldn't find the tutorialFile for your language, and $tutorialFile is still false (major file failure)
     if ($tutorialFile) {
         // XXX TODO if the client can handle SVG, we could also just send it the unscaled thumb, client-scaled into a DIV or something.
         // if ( client can handle SVG ) {
         //   $tutorialThumbnailImage->getUnscaledThumb();
         // }
         // put it into a div of appropriate dimensions.
         // n.b. File::transform() returns false if failed, MediaTransformOutput otherwise
         $thumbnailImage = $tutorialFile->transform(array('width' => $tutorial['width']));
         if ($thumbnailImage) {
             $tutorialHtml = self::getImageHtml($thumbnailImage, $tutorial);
         } else {
             $error = 'cannot-transform';
         }
     } else {
         $error = 'file-missing';
     }
     if ($error !== null) {
         // Messages:
         // mwe-upwiz-tutorial-error-localized-file-missing, mwe-upwiz-tutorial-error-file-missing,
         // mwe-upwiz-tutorial-error-cannot-transform
         $errorMsg = wfMessage('mwe-upwiz-tutorial-error-' . $error);
         if ($error === 'localized-file-missing') {
             $errorMsg->params(Language::fetchLanguageName($langCode, $wgLang->getCode()));
         }
         $errorHtml = Html::element('p', array('class' => 'errorbox', 'style' => 'float: none;'), $errorMsg->text());
     }
     return $errorHtml . $tutorialHtml;
 }
 /**
  * Returns the globally configuration, optionaly combined with campaign sepcific
  * configuration.
  *
  * @since 1.2
  *
  * @param string|null $campaignName
  *
  * @return array
  */
 public static function getConfig($campaignName = null)
 {
     global $wgUploadWizardConfig;
     static $mergedConfig = false;
     if (!$mergedConfig) {
         $wgUploadWizardConfig = UploadWizardConfig::array_replace_sanely(self::getDefaultConfig(), $wgUploadWizardConfig);
         $mergedConfig = true;
     }
     if (!is_null($campaignName)) {
         $wgUploadWizardConfig = UploadWizardConfig::array_replace_sanely($wgUploadWizardConfig, self::getCampaignConfig($campaignName));
     }
     return array_replace_recursive($wgUploadWizardConfig, self::$urlConfig);
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $this->requireOnlyOneParameter($params, 'url', 'list');
     $flickrBlacklist = new UploadWizardFlickrBlacklist(UploadWizardConfig::getConfig(), $this->getContext());
     if ($params['list']) {
         $list = $flickrBlacklist->getBlacklist();
         $this->getResult()->setIndexedTagName($list, 'item');
         $this->getResult()->addValue('flickrblacklist', 'list', $list);
     }
     if (!is_null($params['url'])) {
         if ($flickrBlacklist->isBlacklisted($params['url'])) {
             $this->getResult()->addValue('flickrblacklist', 'result', 'bad');
         } else {
             $this->getResult()->addValue('flickrblacklist', 'result', 'ok');
         }
     }
 }
 public function generateReadHtml()
 {
     $config = $this->campaign->getParsedConfig();
     $campaignTitle = array_key_exists('title', $config) ? $config['title'] : $this->campaign->getName();
     $campaignDescription = array_key_exists('description', $config) ? $config['description'] : '';
     $campaignViewMoreLink = $this->campaign->getTrackingCategory()->getFullURL();
     $gallery = ImageGalleryBase::factory('packed-hover');
     $gallery->setContext($this->context);
     $gallery->setWidths(180);
     $gallery->setHeights(180);
     $gallery->setShowBytes(false);
     $this->context->getOutput()->setSquidMaxage(UploadWizardConfig::getSetting('campaignSquidMaxAge'));
     $this->context->getOutput()->setHTMLTitle($this->context->msg('pagetitle', $campaignTitle));
     $images = $this->campaign->getUploadedMedia();
     if ($this->context->getUser()->isAnon()) {
         $urlParams = array('returnto' => $this->campaign->getTitle()->getPrefixedText());
         if ($this->isCampaignExtensionEnabled()) {
             $campaignTemplate = UploadWizardConfig::getSetting('campaignCTACampaignTemplate');
             $urlParams['campaign'] = str_replace('$1', $this->campaign->getName(), $campaignTemplate);
         }
         $createAccountUrl = Skin::makeSpecialUrlSubpage('UserLogin', 'signup', $urlParams);
         $uploadLink = Html::element('a', array('class' => 'mw-ui-big mw-ui-button mw-ui-primary', 'href' => $createAccountUrl), wfMessage('mwe-upwiz-campaign-create-account-button')->text());
     } else {
         $uploadUrl = Skin::makeSpecialUrl('UploadWizard', array('campaign' => $this->campaign->getName()));
         $uploadLink = Html::element('a', array('class' => 'mw-ui-big mw-ui-button mw-ui-primary', 'href' => $uploadUrl), wfMessage('mwe-upwiz-campaign-upload-button')->text());
     }
     if (count($images) === 0) {
         $body = Html::element('div', array('id' => 'mw-campaign-no-uploads-yet'), wfMessage('mwe-upwiz-campaign-no-uploads-yet')->plain());
     } else {
         foreach ($images as $image) {
             $gallery->add($image);
         }
         $body = Html::rawElement('div', array('id' => 'mw-campaign-images'), $gallery->toHTML()) . Html::rawElement('a', array('id' => 'mw-campaign-view-all', 'href' => $campaignViewMoreLink), Html::rawElement('span', array('class' => 'mw-campaign-chevron mw-campaign-float-left'), '&nbsp') . wfMessage('mwe-upwiz-campaign-view-all-media')->escaped() . Html::rawElement('span', array('class' => 'mw-campaign-chevron mw-campaign-float-right'), '&nbsp'));
     }
     if (UploadWizardConfig::getSetting('campaignExpensiveStatsEnabled') === true) {
         $uploaderCount = $this->campaign->getTotalContributorsCount();
         $campaignExpensiveStats = Html::rawElement('div', array('class' => 'mw-campaign-number-container'), Html::element('div', array('class' => 'mw-campaign-number'), $this->context->getLanguage()->formatNum($uploaderCount)) . Html::element('span', array('class' => 'mw-campaign-number-desc'), wfMessage('mwe-upwiz-campaign-contributors-count-desc')->numParams($uploaderCount)->text()));
     } else {
         $campaignExpensiveStats = '';
     }
     $uploadCount = $this->campaign->getUploadedMediaCount();
     $result = Html::rawElement('div', array('id' => 'mw-campaign-container'), Html::rawElement('div', array('id' => 'mw-campaign-header'), Html::rawElement('div', array('id' => 'mw-campaign-primary-info'), Html::rawElement('p', array('id' => 'mw-campaign-title'), $campaignTitle) . Html::rawElement('p', array('id' => 'mw-campaign-description'), $campaignDescription) . $uploadLink) . Html::rawElement('div', array('id' => 'mw-campaign-numbers'), $campaignExpensiveStats . Html::rawElement('div', array('class' => 'mw-campaign-number-container'), Html::element('div', array('class' => 'mw-campaign-number'), $this->context->getLanguage()->formatNum($uploadCount)) . Html::element('span', array('class' => 'mw-campaign-number-desc'), wfMessage('mwe-upwiz-campaign-media-count-desc')->numParams($uploadCount)->text())))) . $body);
     return $result;
 }
 /**
  * Checks user input JSON to make sure that it produces a valid campaign object
  *
  * @throws JsonSchemaException: If invalid.
  * @return bool: True if valid.
  */
 function validate()
 {
     $campaign = $this->getJsonData();
     if (!is_array($campaign)) {
         throw new JsonSchemaException(wfMessage('eventlogging-invalid-json')->parse());
     }
     $schema = (include __DIR__ . '/CampaignSchema.php');
     // Only validate fields we care about
     $campaignFields = array_keys($schema['properties']);
     $fullConfig = UploadWizardConfig::getConfig();
     $defaultCampaignConfig = array();
     foreach ($fullConfig as $key => $value) {
         if (in_array($key, $campaignFields)) {
             $defaultCampaignConfig[$key] = $value;
         }
     }
     $mergedConfig = UploadWizardConfig::array_replace_sanely($defaultCampaignConfig, $campaign);
     return efSchemaValidate($mergedConfig, $schema);
 }
Example #6
0
 /**
  * Adds the preferences of UploadWizard to the list of available ones.
  * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
  *
  * @since 1.2
  *
  * @param User $user
  * @param array $preferences
  *
  * @return true
  */
 public static function onGetPreferences(User $user, array &$preferences)
 {
     if (UploadWizardConfig::getSetting('enableLicensePreference')) {
         $licenseConfig = UploadWizardConfig::getSetting('licenses');
         $licenses = array();
         $ownWork = UploadWizardConfig::getSetting('licensesOwnWork');
         foreach ($ownWork['licenses'] as $license) {
             $licenseMessage = self::getLicenseMessage($license, $licenseConfig);
             $licenses[wfMsgExt('mwe-upwiz-prefs-license-own', 'parsemag', $licenseMessage)] = 'ownwork-' . $license;
         }
         foreach (UploadWizardConfig::getThirdPartyLicenses() as $license) {
             if ($license !== 'custom') {
                 $licenseMessage = self::getLicenseMessage($license, $licenseConfig);
                 $licenses[wfMsgExt('mwe-upwiz-prefs-license-thirdparty', 'parsemag', $licenseMessage)] = 'thirdparty-' . $license;
             }
         }
         $licenses = array_merge(array(wfMsg('mwe-upwiz-prefs-def-license-def') => 'default'), $licenses);
         $preferences['upwiz_deflicense'] = array('type' => 'radio', 'label-message' => 'mwe-upwiz-prefs-def-license', 'section' => 'under-the-hood', 'options' => $licenses);
     }
     return true;
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $limit = $params['limit'];
     $this->addTables('uw_campaigns');
     $this->addWhereIf(array('campaign_enabled' => 1), $params['enabledonly']);
     $this->addOption('LIMIT', $limit + 1);
     $this->addOption('ORDER BY', 'campaign_id');
     // Not sure if required?
     $this->addFields(array('campaign_id', 'campaign_name', 'campaign_enabled'));
     if (!is_null($params['continue'])) {
         $from_id = (int) $params['continue'];
         $this->addWhere("campaign_id >= {$from_id}");
         // Not SQL Injection, since we already force this to be an integer
     }
     $res = $this->select(__METHOD__);
     $result = $this->getResult();
     $count = 0;
     foreach ($res as $row) {
         if (++$count > $limit) {
             // We have more results than $limit. Set continue
             $this->setContinueEnumParameter('continue', $row->campaign_id);
             break;
         }
         $campaign = UploadWizardCampaign::newFromName($row->campaign_name);
         $campaignPath = array('query', $this->getModuleName(), $row->campaign_id);
         $result->addValue($campaignPath, '*', json_encode($campaign->getParsedConfig()));
         $result->addValue($campaignPath, 'name', $campaign->getName());
         $result->addValue($campaignPath, 'trackingCategory', $campaign->getTrackingCategory()->getDBKey());
         $result->addValue($campaignPath, 'totalUploads', $campaign->getUploadedMediaCount());
         if (UploadWizardConfig::getSetting('campaignExpensiveStatsEnabled') === true) {
             $result->addValue($campaignPath, 'totalContributors', $campaign->getTotalContributorsCount());
         }
     }
     if (defined('ApiResult::META_CONTENT')) {
         $result->addIndexedTagName(array('query', $this->getModuleName()), 'campaign');
     } else {
         $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'campaign');
     }
 }
 /**
  * Constructs HTML for the tutorial (laboriously), including an imagemap for the clickable "Help desk" button.
  *
  * @param MediaTransformOutput $thumb
  * @param String|null $campaign Upload Wizard campaign for which the tutorial should be displayed.
  *
  * @return String HTML representing the image, with clickable helpdesk button
  */
 public static function getImageHtml(MediaTransformOutput $thumb, $campaign = null)
 {
     $helpDeskUrl = wfMessage('mwe-upwiz-help-desk-url')->text();
     // Per convention, we may be either using an absolute URL or a wiki page title in this UI message
     if (preg_match('/^(?:' . wfUrlProtocols() . ')/', $helpDeskUrl)) {
         $helpDeskHref = $helpDeskUrl;
     } else {
         $helpDeskTitle = Title::newFromText($helpDeskUrl);
         $helpDeskHref = $helpDeskTitle ? $helpDeskTitle->getLocalURL() : '#';
     }
     $buttonCoords = UploadWizardConfig::getSetting('tutorialHelpdeskCoords', $campaign);
     $useMap = $buttonCoords !== false && trim($buttonCoords) != '';
     $imgAttributes = array('src' => $thumb->getUrl(), 'width' => $thumb->getWidth(), 'height' => $thumb->getHeight());
     if ($useMap) {
         $imgAttributes['usemap'] = '#' . self::IMAGEMAP_ID;
     }
     // here we use the not-yet-forgotten HTML imagemap to add a clickable area to the tutorial image.
     // we could do more special effects with hovers and images and such, not to mention SVG scripting,
     // but we aren't sure what we want yet...
     $imgHtml = Html::element('img', $imgAttributes);
     if ($useMap) {
         $areaAltText = wfMessage('mwe-upwiz-help-desk')->text();
         $area = Html::element('area', array('shape' => 'rect', 'coords' => $buttonCoords, 'href' => $helpDeskHref, 'alt' => $areaAltText, 'title' => $areaAltText));
         $imgHtml = Html::rawElement('map', array('id' => self::IMAGEMAP_ID, 'name' => self::IMAGEMAP_ID), $area) . $imgHtml;
     }
     return $imgHtml;
 }
 public function getTotalContributorsCount()
 {
     global $wgMemc;
     wfProfileIn(__METHOD__);
     $key = wfMemcKey('uploadwizard', 'campaign', $this->getName(), 'contributors-count');
     $data = $wgMemc->get($key);
     if ($data === false) {
         wfDebug(__METHOD__ . ' cache miss for key ' . $key);
         $dbr = wfGetDB(DB_SLAVE);
         $result = $dbr->select(array('categorylinks', 'page', 'image'), array('count' => 'COUNT(DISTINCT img_user)'), array('cl_to' => $this->getTrackingCategory()->getDBKey(), 'cl_type' => 'file'), __METHOD__, array('USE INDEX' => array('categorylinks' => 'cl_timestamp')), array('page' => array('INNER JOIN', 'cl_from=page_id'), 'image' => array('INNER JOIN', 'page_title=img_name')));
         $data = $result->current()->count;
         $wgMemc->set($key, $data, UploadWizardConfig::getSetting('campaignStatsMaxAge'));
     }
     wfProfileOut(__METHOD__);
     return $data;
 }
 protected function checkApiSetup()
 {
     // this is needed to initialize the global $wgUploadWizardConfig
     $wgUploadWizardConfig = UploadWizardConfig::getConfig();
     if (!isset($wgUploadWizardConfig['flickrApiKey'])) {
         $this->markTestSkipped('This test needs a Flickr API key to work');
     }
     if (!isset($wgUploadWizardConfig['flickrApiUrl']) || Http::get($wgUploadWizardConfig['flickrApiUrl']) === false) {
         // Http::get returns false if the server is unreachable.
         // Sometimes unit tests may be run in places without network access.
         $this->markTestSkipped($wgUploadWizardConfig['flickrApiUrl'] . ' is unreachable.');
     }
 }
Example #11
0
 /**
  * Return the basic HTML structure for the entire page
  * Will be enhanced by the javascript to actually do stuff
  * @return {String} html
  */
 function getWizardHtml()
 {
     global $wgExtensionAssetsPath;
     $globalConf = UploadWizardConfig::getConfig($this->campaign);
     $headerContent = $this->getPageContent($globalConf['headerLabelPage']);
     if ($headerContent !== false) {
         $this->getOutput()->addWikiText($headerContent);
     }
     if (array_key_exists('fallbackToAltUploadForm', $globalConf) && array_key_exists('altUploadForm', $globalConf) && $globalConf['altUploadForm'] != '' && $globalConf['fallbackToAltUploadForm']) {
         $linkHtml = '';
         $altUploadForm = Title::newFromText($globalConf['altUploadForm']);
         if ($altUploadForm instanceof Title) {
             $linkHtml = Html::rawElement('p', array('style' => 'text-align: center;'), Html::rawElement('a', array('href' => $altUploadForm->getLocalURL()), $globalConf['altUploadForm']));
         }
         return Html::rawElement('div', array('id' => 'upload-wizard', 'class' => 'upload-section'), Html::rawElement('p', array('style' => 'text-align: center'), wfMsg('mwe-upwiz-extension-disabled')) . $linkHtml);
     }
     $tutorialHtml = '';
     // only load the tutorial HTML if we aren't skipping the first step
     // TODO should use user preference not a cookie ( so the user does not have to skip it for every browser )
     if (!isset($_COOKIE['skiptutorial']) && !$globalConf['skipTutorial']) {
         $tutorialHtml = UploadWizardTutorial::getHtml($this->campaign);
     }
     // TODO move this into UploadWizard.js or some other javascript resource so the upload wizard
     // can be dynamically included ( for example the add media wizard )
     return '<div id="upload-wizard" class="upload-section">' . '<div id="mwe-first-spinner" style="min-width:750px; max-width:900px; height:200px; line-height:200px; text-align:center;">' . '&nbsp;<img src="' . $wgExtensionAssetsPath . '/UploadWizard/resources/images/24px-spinner-0645ad.gif" width="24" height="24" />&nbsp;' . '</div>' . '<ul id="mwe-upwiz-steps" style="display:none;">' . '<li id="mwe-upwiz-step-tutorial"><div>' . wfMsg('mwe-upwiz-step-tutorial') . '</div></li>' . '<li id="mwe-upwiz-step-file"><div>' . wfMsg('mwe-upwiz-step-file') . '</div></li>' . '<li id="mwe-upwiz-step-deeds"><div>' . wfMsg('mwe-upwiz-step-deeds') . '</div></li>' . '<li id="mwe-upwiz-step-details"><div>' . wfMsg('mwe-upwiz-step-details') . '</div></li>' . '<li id="mwe-upwiz-step-thanks"><div>' . wfMsg('mwe-upwiz-step-thanks') . '</div></li>' . '</ul>' . '<div id="mwe-upwiz-content">' . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-tutorial" style="display:none;">' . '<div id="mwe-upwiz-tutorial">' . $tutorialHtml . '</div>' . '<div class="mwe-upwiz-buttons">' . '<input type="checkbox" id="mwe-upwiz-skip" value="1" name="skip">' . '<label for="mwe-upwiz-skip">' . wfMsg('mwe-upwiz-skip-tutorial-future') . '</label>' . '<button class="mwe-upwiz-button-next">' . wfMsg("mwe-upwiz-next") . '</button>' . '</div>' . '</div>' . '<div class="mwe-upwiz-stepdiv ui-helper-clearfix" id="mwe-upwiz-stepdiv-file" style="display:none;">' . '<div id="mwe-upwiz-files">' . '<div id="mwe-upwiz-filelist" class="ui-corner-all"></div>' . '<div id="mwe-upwiz-upload-ctrls" class="mwe-upwiz-file ui-helper-clearfix">' . '<div id="mwe-upwiz-add-file-container" class="mwe-upwiz-add-files-0">' . '<button id="mwe-upwiz-add-file">' . wfMsg("mwe-upwiz-add-file-0-free") . '</button>' . '</div>' . '<div id="mwe-upwiz-upload-ctrl-container">' . '<button id="mwe-upwiz-upload-ctrl">' . wfMsg("mwe-upwiz-upload") . '</button>' . '</div>' . '</div>' . '<div id="mwe-upwiz-progress" class="ui-helper-clearfix"></div>' . '<div id="mwe-upwiz-continue" class="ui-helper-clearfix"></div>' . '</div>' . '<div class="mwe-upwiz-buttons">' . '<div class="mwe-upwiz-file-next-all-ok mwe-upwiz-file-endchoice">' . wfMsg("mwe-upwiz-file-all-ok") . '<button class="mwe-upwiz-button-next">' . wfMsg("mwe-upwiz-next-file") . '</button>' . '</div>' . '<div class="mwe-upwiz-file-next-some-failed mwe-upwiz-file-endchoice">' . wfMsg("mwe-upwiz-file-some-failed") . '<button class="mwe-upwiz-button-retry">' . wfMsg("mwe-upwiz-file-retry") . '</button>' . '<button class="mwe-upwiz-button-next">' . wfMsg("mwe-upwiz-next-file-despite-failures") . '</button>' . '</div>' . '<div class="mwe-upwiz-file-next-all-failed mwe-upwiz-file-endchoice">' . wfMsg("mwe-upwiz-file-all-failed") . '<button class="mwe-upwiz-button-retry"> ' . wfMsg("mwe-upwiz-file-retry") . '</button>' . '</div>' . '</div>' . '</div>' . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-deeds" style="display:none;">' . '<div id="mwe-upwiz-deeds-thumbnails" class="ui-helper-clearfix"></div>' . '<div id="mwe-upwiz-deeds" class="ui-helper-clearfix"></div>' . '<div id="mwe-upwiz-deeds-custom" class="ui-helper-clearfix"></div>' . '<div class="mwe-upwiz-buttons">' . '<button class="mwe-upwiz-button-next">' . wfMsg("mwe-upwiz-next-deeds") . '</button>' . '</div>' . '</div>' . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-details" style="display:none;">' . '<div id="mwe-upwiz-macro-files" class="mwe-upwiz-filled-filelist ui-corner-all"></div>' . '<div class="mwe-upwiz-buttons">' . '<div id="mwe-upwiz-details-error-count" class="mwe-upwiz-file-endchoice mwe-error"></div>' . '<div class="mwe-upwiz-start-next mwe-upwiz-file-endchoice">' . '<button class="mwe-upwiz-button-next">' . wfMsg("mwe-upwiz-next-details") . '</button>' . '</div>' . '<div class="mwe-upwiz-file-next-some-failed mwe-upwiz-file-endchoice">' . wfMsg("mwe-upwiz-file-some-failed") . '<button class="mwe-upwiz-button-retry">' . wfMsg("mwe-upwiz-file-retry") . '</button>' . '<button class="mwe-upwiz-button-next-despite-failures">' . wfMsg("mwe-upwiz-next-file-despite-failures") . '</button>' . '</div>' . '<div class="mwe-upwiz-file-next-all-failed mwe-upwiz-file-endchoice">' . wfMsg("mwe-upwiz-file-all-failed") . '<button class="mwe-upwiz-button-retry"> ' . wfMsg("mwe-upwiz-file-retry") . '</button>' . '</div>' . '</div>' . '</div>' . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-thanks" style="display:none;">' . '<div id="mwe-upwiz-thanks"></div>' . '<div class="mwe-upwiz-buttons">' . '<button class="mwe-upwiz-button-home">' . wfMsg("mwe-upwiz-home") . '</button>' . '<button class="mwe-upwiz-button-begin">' . wfMsg("mwe-upwiz-upload-another") . '</button>' . '</div>' . '</div>' . '</div>' . '<div class="mwe-upwiz-clearing"></div>' . '</div>';
 }
 /**
  * Returns all config parameters, after parsing the wikitext based ones
  *
  * @since 1.3
  *
  * @return array
  */
 public function getParsedConfig($lang = null)
 {
     if ($lang === null) {
         $lang = $this->context->getLanguage();
     }
     // We check if the parsed config for this campaign is cached. If it is available in cache,
     // we then check to make sure that it is the latest version - by verifying that its
     // timestamp is greater than or equal to the timestamp of the last time an invalidate was
     // issued.
     $cache = ObjectCache::getMainWANInstance();
     $memKey = wfMemcKey('uploadwizard', 'campaign', $this->getName(), 'parsed-config', $lang->getCode());
     $depKeys = array($this->makeInvalidateTimestampKey());
     $curTTL = null;
     $memValue = $cache->get($memKey, $curTTL, $depKeys);
     if (is_array($memValue) && $curTTL > 0) {
         $this->parsedConfig = $memValue['config'];
     }
     if ($this->parsedConfig === null) {
         $parsedConfig = array();
         foreach ($this->config as $key => $value) {
             switch ($key) {
                 case "title":
                 case "description":
                     $parsedConfig[$key] = $this->parseValue($value, $lang);
                     break;
                 case "display":
                     foreach ($value as $option => $optionValue) {
                         if (is_array($optionValue)) {
                             $parsedConfig['display'][$option] = $this->parseArrayValues($optionValue, $lang, array('label'));
                         } else {
                             $parsedConfig['display'][$option] = $this->parseValue($optionValue, $lang);
                         }
                     }
                     break;
                 case "fields":
                     $parsedConfig['fields'] = array();
                     foreach ($value as $field) {
                         $parsedConfig['fields'][] = $this->parseArrayValues($field, $lang, array('label', 'options'));
                     }
                     break;
                 case "whileActive":
                 case "afterActive":
                 case "beforeActive":
                     if (array_key_exists('display', $value)) {
                         $value['display'] = $this->parseArrayValues($value['display'], $lang);
                     }
                     $parsedConfig[$key] = $value;
                     break;
                 default:
                     $parsedConfig[$key] = $value;
                     break;
             }
         }
         $this->parsedConfig = $parsedConfig;
         $cache->set($memKey, array('timestamp' => time(), 'config' => $parsedConfig));
     }
     $uwDefaults = UploadWizardConfig::getSetting('defaults');
     if (array_key_exists('objref', $uwDefaults)) {
         $this->applyObjectReferenceToButtons($uwDefaults['objref']);
     }
     $this->modifyIfNecessary();
     return $this->parsedConfig;
 }
 /**
  * Hook to blacklist flickr images by intercepting upload from url
  */
 public static function onIsUploadAllowedFromUrl($url, &$allowed)
 {
     if ($allowed) {
         $flickrBlacklist = new UploadWizardFlickrBlacklist(UploadWizardConfig::getConfig(), RequestContext::getMain());
         if ($flickrBlacklist->isBlacklisted($url)) {
             $allowed = false;
         }
     }
     return true;
 }
 /**
  * Adds the preferences of UploadWizard to the list of available ones.
  * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
  *
  * @since 1.2
  *
  * @param User $user
  * @param array $preferences
  *
  * @return true
  */
 public static function onGetPreferences(User $user, array &$preferences)
 {
     // User preference to skip the licensing tutorial, provided it's not globally disabled
     if (UploadWizardConfig::getSetting('skipTutorial') == false) {
         $preferences['upwiz_skiptutorial'] = array('type' => 'check', 'label-message' => 'mwe-upwiz-prefs-skiptutorial', 'section' => 'uploads/upwiz-interface');
     }
     if (UploadWizardConfig::getSetting('enableLicensePreference')) {
         $licenseConfig = UploadWizardConfig::getSetting('licenses');
         $licenses = array();
         $ownWork = UploadWizardConfig::getSetting('licensesOwnWork');
         foreach ($ownWork['licenses'] as $license) {
             $licenseMessage = self::getLicenseMessage($license, $licenseConfig);
             $licenses[wfMessage('mwe-upwiz-prefs-license-own', $licenseMessage)->text()] = 'ownwork-' . $license;
         }
         foreach (UploadWizardConfig::getThirdPartyLicenses() as $license) {
             if ($license !== 'custom') {
                 $licenseMessage = self::getLicenseMessage($license, $licenseConfig);
                 $licenses[wfMessage('mwe-upwiz-prefs-license-thirdparty', $licenseMessage)->text()] = 'thirdparty-' . $license;
             }
         }
         $licenses = array_merge(array(wfMessage('mwe-upwiz-prefs-def-license-def')->text() => 'default'), $licenses);
         $preferences['upwiz_deflicense'] = array('type' => 'radio', 'label-message' => 'mwe-upwiz-prefs-def-license', 'section' => 'uploads/upwiz-licensing', 'options' => $licenses);
         if (UploadWizardConfig::getSetting('enableChunked') === 'opt-in') {
             $preferences['upwiz-chunked'] = array('type' => 'check', 'label-message' => 'mwe-upwiz-prefs-chunked', 'section' => 'uploads/upwiz-experimental');
         }
     }
     return true;
 }
 /**
  * Returns the configuration, ready for merging with the
  * global configuration.
  *
  * @since 1.2
  *
  * @return arrayu
  */
 public function getConfigForGlobalMerge()
 {
     $config = $this->getConfig();
     foreach ($config as $settingName => &$settingValue) {
         switch ($settingName) {
             case 'licensesOwnWork':
                 $settingValue = array_merge(UploadWizardConfig::getSetting('licensesOwnWork'), array('licenses' => $settingValue));
                 break;
         }
     }
     foreach (self::getDefaultConfig() as $name => $data) {
         if (!array_key_exists($name, $config)) {
             $config[$name] = $data['default'];
         }
     }
     $config['licensesOwnWork']['defaults'] = array($config['defaultOwnWorkLicence']);
     unset($config['defaultOwnWorkLicence']);
     return $config;
 }
Example #16
0
<?php

return array("type" => "object", "id" => "#campaignnode", "required" => true, "properties" => array("title" => array("type" => "string"), "description" => array("type" => "string"), "enabled" => array("type" => "boolean", "required" => true), "start" => array("type" => "string"), "end" => array("type" => "string"), "autoAdd" => array("type" => "object", "properties" => array("categories" => array("type" => "array", "items" => array(array("type" => "string"))), "wikitext" => array("type" => "string"))), "fields" => array("type" => "array", "items" => array(array("type" => "object", "properties" => array("wikitext" => array("type" => "string"), "label" => array("type" => "string"), "maxLength" => array("type" => "integer"), "initialValue" => array("type" => "string"), "required" => array("type" => "boolean"), "type" => array("type" => "string"), "options" => array("type" => "object", "properties" => array(), "additionalProperties" => true))))), "defaults" => array("type" => "object", "properties" => array("alt" => array("type" => "number"), "categories" => array("type" => "array", "items" => array(array("type" => "string"))), "description" => array("type" => "string"), "lat" => array("type" => "number"), "lon" => array("type" => "number"))), "display" => array("type" => "object", "properties" => array("headerLabel" => array("type" => "string"), "thanksLabel" => array("type" => "string"), "homeButton" => array("type" => "object", "properties" => array("label" => array("type" => "string"), "target" => array("type" => "string"))), "beginButton" => array("type" => "object", "properties" => array("label" => array("type" => "string"), "target" => array("type" => "string"))), "labelPickImage" => array("type" => "string"), "noticeExistingImage" => array("type" => "string"), "noticeUpdateDelay" => array("type" => "string"))), "licensing" => array("type" => "object", "properties" => array("defaultType" => array("type" => "string"), "ownWorkDefault" => array("type" => "string"), "ownWork" => array("type" => "object", "properties" => array("default" => array("type" => "string", "enum" => array_keys(UploadWizardConfig::getSetting('licenses'))), "licenses" => array("type" => "array", "items" => array(array("type" => "string", "enum" => array_keys(UploadWizardConfig::getSetting('licenses'))))), "template" => array("type" => "string"), "type" => array("type" => "string"))), "thirdParty" => array("type" => "object", "properties" => array("defaults" => array("type" => "string", "enum" => array_keys(UploadWizardConfig::getSetting('licenses'))), "licenseGroups" => array("type" => "array", "items" => array(array("type" => "object", "properties" => array("head" => array("type" => "string"), "licenses" => array("type" => "array", "items" => array(array("type" => "string", "enum" => array_keys(UploadWizardConfig::getSetting('licenses'))))), "subhead" => array("type" => "string"))))), "type" => array("type" => "string"))))), "tutorial" => array("type" => "object", "properties" => array("skip" => array("type" => "boolean"), "helpdeskCoords" => array("type" => "string"), "template" => array("type" => "string"), "width" => array("type" => "number"))), "whileActive" => array("type" => "object", "properties" => array("display" => array("type" => "object", "properties" => array("headerLabel" => array("type" => "string"), "thanksLabel" => array("type" => "string"))), "autoAdd" => array("type" => "object", "properties" => array("categories" => array("type" => "array", "items" => array(array("type" => "string"))), "wikitext" => array("type" => "string"))))), "beforeActive" => array("type" => "object", "properties" => array("display" => array("type" => "object", "properties" => array("headerLabel" => array("type" => "string"), "thanksLabel" => array("type" => "string"))))), "afterActive" => array("type" => "object", "properties" => array("display" => array("type" => "object", "properties" => array("headerLabel" => array("type" => "string"), "thanksLabel" => array("type" => "string")))))));