/** * @desc get a list of labs features * @return array $list */ public function getFeatureLabs() { $list = array(); if (isset($this->wg->WikiFeatures['labs']) && is_array($this->wg->WikiFeatures['labs'])) { //allow adding features in runtime wfrunHooks('WikiFeatures::onGetFeatureLabs'); foreach ($this->wg->WikiFeatures['labs'] as $feature) { $list[] = array('name' => $feature, 'enabled' => $this->getFeatureEnabled($feature), 'new' => self::isNew($feature), 'active' => $this->wg->Lang->formatNum($this->getNumActiveWikis($feature)), 'imageExtension' => '.png'); } } return $list; }
/** * @desc enable/disable feature * @requestParam string enabled [true/false] * @requestParam string feature (extension variable) * @responseParam string result [OK/error] * @responseParam string error (error message) */ public function toggleFeature() { $enabled = $this->getVal('enabled', null); $feature = $this->getVal('feature', null); wfrunHooks('WikiFeatures::onToggleFeature', ['name' => $feature, 'enabled' => $enabled]); // check user permission if (!$this->wg->User->isAllowed('wikifeatures')) { $this->setVal('result', 'error'); $this->setVal('error', wfMsg('wikifeatures-error-permission')); return; } // check if feature given is actually something we allow setting if (!in_array($feature, $this->wg->WikiFeatures['normal']) && !in_array($feature, $this->wg->WikiFeatures['labs'])) { $this->setVal('result', 'error'); $this->setVal('error', wfMsg('wikifeatures-error-invalid-parameter', $feature)); return; } // validate feature: valid value ($enabled and $feature), check if Feature exists ($wg_value) $wg_value = WikiFactory::getVarByName($feature, $this->wg->CityId); if ($enabled != 'true' && $enabled != 'false' || empty($feature) || empty($wg_value)) { $this->setVal('result', 'error'); $this->setVal('error', wfMsg('wikifeatures-error-invalid-parameter', $feature)); return; } $enabled = $enabled == 'true'; $logMsg = "set extension option: {$feature} = " . var_export($enabled, TRUE); $log = new LogPage('wikifeatures'); $log->addEntry('wikifeatures', SpecialPage::getTitleFor('WikiFeatures'), $logMsg, array()); WikiFactory::setVarByName($feature, $this->wg->CityId, $enabled, "WikiFeatures"); if ($feature == 'wgShowTopListsInCreatePage') { WikiFactory::setVarByName('wgEnableTopListsExt', $this->wg->CityId, $enabled, "WikiFeatures"); } // clear cache for active wikis WikiFactory::clearCache($this->wg->CityId); $this->wg->Memc->delete(WikiFeaturesHelper::getInstance()->getMemcKeyNumActiveWikis($feature)); wfRunHooks('WikiFeatures::afterToggleFeature', [$feature, $enabled]); $this->setVal('result', 'ok'); }