本文整理汇总了PHP中WikiFactory::getVarById方法的典型用法代码示例。如果您正苦于以下问题:PHP WikiFactory::getVarById方法的具体用法?PHP WikiFactory::getVarById怎么用?PHP WikiFactory::getVarById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WikiFactory
的用法示例。
在下文中一共展示了WikiFactory::getVarById方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: axWFactorySaveVariable
/**
* axWFactorySaveVariable
*
* ajax method, save variable from form
*
* @author Krzysztof Krzyżaniak (eloy) <eloy@wikia-inc.com>
* @access public
*
* @return string encoded in JSON format
*/
function axWFactorySaveVariable()
{
global $wgUser, $wgRequest;
$error = 0;
$return = "";
if (!$wgUser->isAllowed('wikifactory')) {
$error++;
$return = Wikia::errormsg("You are not allowed to change variable value");
} else {
$cv_id = $wgRequest->getVal('varId');
$city_id = $wgRequest->getVal('cityid');
$cv_name = $wgRequest->getVal('varName');
$cv_value = $wgRequest->getVal('varValue');
$cv_variable_type = $wgRequest->getVal('varType');
$reason = $wgRequest->getVal('reason', null);
$tag_name = $wgRequest->getVal('tagName');
$tag_wiki_count = 0;
$form_id = $wgRequest->getVal("formId", null);
#--- check if variable is valid
switch ($cv_variable_type) {
case "boolean":
if ((bool) $cv_value != $cv_value) {
$error++;
$return = Wikia::errormsg("Syntax error: value is not boolean. Variable not saved.");
} else {
$return = Wikia::successmsg("Parse OK, variable saved");
$cv_value = (bool) $cv_value;
}
break;
case "integer":
if ((int) $cv_value != $cv_value) {
$error++;
$return = Wikia::errormsg("Syntax error: value is not integer. Variable not saved.");
} else {
$return = Wikia::successmsg("Parse OK, variable saved.");
$cv_value = (int) $cv_value;
}
break;
case "string":
$return = Wikia::successmsg("Parse OK, variable saved.");
break;
default:
$tEval = "\$__var_value = {$cv_value};";
/**
* catch parse errors
*/
ob_start();
if (eval($tEval) === FALSE) {
$error++;
$return = Wikia::errormsg("Syntax error, value is not valid PHP structure. Variable not saved.");
} else {
$cv_value = $__var_value;
/**
* now check if it's actually array when we want array)
*/
if (in_array($cv_variable_type, array("array", "struct", "hash"))) {
if (is_array($cv_value)) {
$return = Wikia::successmsg("Syntax OK (array), variable saved.");
} else {
$error++;
$return = Wikia::errormsg("Syntax error: value is not array. Variable not saved.");
}
} else {
$return = Wikia::successmsg("Parse OK, variable saved.");
}
}
ob_end_clean();
#--- puts parse error to /dev/null
}
if (empty($error)) {
$varInfo = WikiFactory::getVarById($cv_id, $city_id);
if ($varInfo->cv_is_unique) {
$wikis = WikiFactory::getCityIDsFromVarValue($cv_id, $cv_value, '=');
$count = count($wikis);
if ($count == 1 && $wikis[0] != $city_id || $count > 1) {
$return = Wikia::errormsg("Value of this variable need to be unique.");
$error++;
}
}
}
wfRunHooks('WikiFactoryVarSave::AfterErrorDetection', array($cv_id, $city_id, $cv_name, $cv_value, &$return, &$error));
# Save to DB, but only if no errors occurred
if (empty($error)) {
if (!WikiFactory::setVarByID($cv_id, $city_id, $cv_value, $reason)) {
$error++;
$return = Wikia::errormsg("Variable not saved because of problems with database. Try again.");
} else {
/* the one "set" that used this is now disabled, so disabling the call until needed again
$tied = WikiFactory::getTiedVariables( $cv_name );
if( $tied ) {
//.........这里部分代码省略.........
示例2: array
}
#do we still have a R side?
if ($to) {
/****************************************************/
/*
get right stuff
*/
/****************************************************/
$vars['R']['city'] = $to;
$vars['R']['*'] = WikiFactory::getVariables("cv_id", $vars['R']['city'], 0, true);
}
$combined = array();
foreach ($vars as $side => $data) {
foreach ($data['*'] as $item) {
$combined[$item->cv_id]['*'] = $item->cv_name;
$var = WikiFactory::getVarById($item->cv_id, $data['city']);
$combined[$item->cv_id]['type'] = $var->cv_variable_type;
$combined[$item->cv_id]['_'] = true;
$val = unserialize($var->cv_value);
switch ($var->cv_variable_type) {
case "string":
/*use as is*/
break;
case "integer":
/*use as is*/
break;
case "boolean":
$val = $val ? 'true' : 'false';
$val = "<abbr title='boolean'><i>{$val}</i></abbr>";
break;
default:
示例3: getHomePageContents
private function getHomePageContents($wikiId)
{
$url = unserialize(WikiFactory::getVarById(5, $wikiId)->cv_value);
echo "Loading {$wikiId} - {$url}";
$htmlContents = file_get_contents($url);
if (!empty($htmlContents)) {
echo " - success\n";
} else {
echo " - failed\n";
$htmlContents = '';
}
return $htmlContents;
}
示例4: getCustomSettings
function getCustomSettings()
{
global $wgExternalSharedDB;
$city_list = 'city_list';
$cv = 'city_variables';
$cv_pool = 'city_variables_pool';
$dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
$res = $dbr->select(array($city_list, $cv, $cv_pool), array('cv_value', 'city_url', 'city_id'), array("{$city_list}.city_id = {$cv}.cv_city_id", "{$cv}.cv_variable_id = {$cv_pool}.cv_id", "{$cv_pool}.cv_id = '{$this->varid}'"), __METHOD__);
$variable = WikiFactory::getVarById($this->varid, 0);
$data = array();
$values = array();
$row_count = $dbr->numRows($res);
if ($row_count == 0) {
$dbr->freeResult($res);
$out = "no settings found in WikiFactory\n";
return $out;
}
$this->over_limit = false;
if ($row_count > 1000) {
$this->over_limit = true;
}
if ($this->disable_limit) {
$this->over_limit = false;
}
while ($row = $dbr->fetchObject($res)) {
$city_id = $row->city_id;
$cv_value = unserialize($row->cv_value);
$nom_value = $cv_value;
if (is_array($cv_value)) {
asort($cv_value);
$cv_value = join(', ', $cv_value);
$nom_value = 'array';
} elseif (is_bool($cv_value)) {
$cv_value = $cv_value ? 'true' : 'false';
$nom_value = $cv_value;
} else {
#$cv_value = 'Error. Not an array?!?';
}
if (preg_match('/http:\\/\\/([\\w\\.\\-]+)\\//', $row->city_url, $matches)) {
$city_url = str_ireplace('.wikia.com', '', $matches[1]);
} else {
$city_url = 'Error. Unknown wiki?!?';
}
if (!empty($cv_value)) {
if (count($data) <= 1000 || $this->disable_limit) {
$data[] = array('value' => $cv_value, 'url' => $city_url, 'city' => $city_id);
}
$values[] = $nom_value;
}
}
$dbr->freeResult($res);
$acv = array_count_values($values);
asort($acv);
unset($values);
global $wgCityId;
if ($wgCityId == 177) {
#we're on central (or are faking it), so link locallly
$WF_title = SpecialPage::getTitleFor('WikiFactory');
$wie_title = SpecialPage::getTitleFor('WhereIsExtension');
} else {
#we're away from home, so make sure the links link back right
$WF_title = GlobalTitle::newFromText('WikiFactory', NS_SPECIAL, 177);
$wie_title = GlobalTitle::newFromText('WhereIsExtension', NS_SPECIAL, 177);
}
$wie_query = array('var' => $variable->cv_variable_id, 'searchType' => 'full', 'val' => 0);
#likeValue is appended manually inside the template;
$wie_base = $wie_title->getFullURL(http_build_query($wie_query));
unset($wie_query);
unset($wie_title);
$limit_message = '';
if ($this->over_limit) {
$limit_message = Wikia::errorbox("Warning, this variable has {$row_count} entries. Only first 1000 shown");
$QS = http_build_query(array('varid' => $variable->cv_variable_id, 'nolimit' => 1));
$limit_message .= "<a href='/index.php?title=Special:WikiFactoryReporter&{$QS}'>Click here to load all results</a>\n";
}
$groups = WikiFactory::getGroups();
$variable->var_group = $groups[$variable->cv_variable_group];
unset($groups);
$sprites = array('search' => "<img src='" . wfBlankImgUrl() . "' class='sprite search' alt='search' height='16' width='22'>", 'edit' => "<img src='" . wfBlankImgUrl() . "' class='sprite edit-pencil' alt='edit'>");
$tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
$tmpl->set_vars(array('th' => array($variable->cv_name, 'wiki', 'city_id'), 'data' => $data, 'variable' => $variable, 'acv' => $acv, 'wf_base' => $WF_title->getFullUrl(), 'limit_message' => $limit_message, 'sprites' => $sprites, 'wie_base' => $wie_base));
$out = $tmpl->render('reporter');
return $out;
}
示例5: isValidCity
protected function isValidCity($cityId)
{
return WikiaDataAccess::cache('hubsapi_is_valid_cityid_' . $cityId, 6 * 60 * 60, function () use($cityId) {
$varId = WikiFactory::getVarIdByName(self::HUBS_V3_VARIABLE_NAME);
$varData = WikiFactory::getVarById($varId, $cityId);
return !empty($varData) && !empty($varData->cv_value) && unserialize($varData->cv_value);
});
}