/** * Execute special page. Only available to wikihow staff. */ public function execute($par) { global $wgRequest, $wgOut, $wgUser, $wgLang; if (strtolower($par) == 'url') { $style = 'url'; } else { $style = ''; } $userGroups = $wgUser->getGroups(); if ($wgUser->isBlocked() || !in_array('staff', $userGroups)) { $wgOut->setRobotpolicy('noindex,nofollow'); $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext'); return; } if ($wgRequest->wasPosted()) { $action = $wgRequest->getVal('action'); $wgOut->setArticleBodyOnly(true); if ('load-config' == $action) { $key = $wgRequest->getVal('config-key', ''); $val = ConfigStorage::dbGetConfig($key); $style = $wgRequest->getVal('style', ''); if ($style == 'url') { //translate ids to readable urls $val = $this->translateValues($val, $style); } $result = array('result' => $val); } elseif ('save-config' == $action) { $errors = ''; $key = $wgRequest->getVal('config-key', ''); $val = $wgRequest->getVal('config-val', ''); $style = $wgRequest->getVal('style', ''); if ($style == 'url') { //validate for errors $errors = self::validateInput($key, $val); //grab the existing values from the db $val_db = ConfigStorage::dbGetConfig($key); //translate the good urls back to ids for storage purposes $val = $this->translateValues($val, 'id'); //add the new and old values together $val = $val_db . "\r\n" . $val; } ConfigStorage::dbStoreConfig($key, $val); $errors .= self::validateInput($key, $val); $output = 'saved and checked input<br/><br/>'; if ($errors) { $output .= 'ERRORS:<br/>' . str_replace("\n", "<br/>\n", $errors); } else { $output .= "no errors."; } if ($style == 'url') { // ** commentting out because it times out if the input was too big //translate back to urls for updated display //$val = $this->translateValues($val,'url'); $val = ''; } $result = array('result' => $output, 'val' => $val); } elseif ('remove-line' == $action) { $key = $wgRequest->getVal('config-key', ''); $id = $wgRequest->getVal('id', ''); $result = $this->removeLine($key, $id); $result = array('result' => $result['result'], 'error' => $result['error']); } else { $result = array('error' => 'bad action'); } print json_encode($result); return; } $wgOut->setHTMLTitle(wfMsg('pagetitle', 'Admin - Generalized Config Editor')); $listConfigs = ConfigStorage::dbListConfigKeys(); $tmpl = self::getGuts($listConfigs, $style); $wgOut->addHTML($tmpl); }
function enableTPCoach() { if (self::isTPCoachEnabled()) { return; } ConfigStorage::dbStoreConfig(self::TPCOACH_ENABLED, 1); }