本文整理汇总了PHP中WikiFactory::setVarByName方法的典型用法代码示例。如果您正苦于以下问题:PHP WikiFactory::setVarByName方法的具体用法?PHP WikiFactory::setVarByName怎么用?PHP WikiFactory::setVarByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WikiFactory
的用法示例。
在下文中一共展示了WikiFactory::setVarByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setHubsFeedsVariable
static function setHubsFeedsVariable()
{
global $wgRequest, $wgCityId, $wgMemc, $wgUser;
wfProfileIn(__METHOD__);
if (!$wgUser->isAllowed('corporatepagemanager')) {
$result['response'] = 'error';
} else {
$result = array('response' => 'ok');
$tagname = $wgRequest->getVal('tag');
$feedname = strtolower($wgRequest->getVal('feed'));
$key = wfMemcKey('autohubs', $tagname, 'feeds_displayed');
$oldtags = self::getHubsFeedsVariable($tagname);
$oldtags[$tagname][$feedname] = !$oldtags[$tagname][$feedname];
$result['disabled'] = $oldtags[$tagname][$feedname];
if (!WikiFactory::setVarByName('wgWikiaAutoHubsFeedsDisplayed', $wgCityId, $oldtags)) {
$result['response'] = 'error';
} else {
$wgMemc->delete($key);
}
}
$json = json_encode($result);
$response = new AjaxResponse($json);
$response->setCacheDuration(0);
$response->setContentType('text/plain; charset=utf-8');
wfProfileOut(__METHOD__);
return $response;
}
示例2: execute
public function execute($subpage)
{
global $wgOut, $wgRequest, $wgUser, $wgCacheEpoch, $wgCityId;
wfProfileIn(__METHOD__);
$this->setHeaders();
$this->mTitle = SpecialPage::getTitleFor('cacheepoch');
if ($this->isRestricted() && !$this->userCanExecute($wgUser)) {
$this->displayRestrictionError();
wfProfileOut(__METHOD__);
return;
}
//no WikiFactory (internal wikis)
if (empty($wgCityId)) {
$wgOut->addHTML(wfMsg('cacheepoch-no-wf'));
wfProfileOut(__METHOD__);
return;
}
if ($wgRequest->wasPosted()) {
$wgCacheEpoch = wfTimestampNow();
$status = WikiFactory::setVarByName('wgCacheEpoch', $wgCityId, $wgCacheEpoch, wfMsg('cacheepoch-wf-reason'));
if ($status) {
$wgOut->addHTML('<h2>' . wfMsg('cacheepoch-updated', $wgCacheEpoch) . '</h2>');
} else {
$wgOut->addHTML('<h2>' . wfMsg('cacheepoch-not-updated') . '</h2>');
}
} else {
$wgOut->addHTML('<h2>' . wfMsg('cacheepoch-header') . '</h2>');
}
$wgOut->addHTML(Xml::openElement('form', array('action' => $this->mTitle->getFullURL(), 'method' => 'post')));
$wgOut->addHTML(wfMsg('cacheepoch-value', $wgCacheEpoch) . '<br>');
$wgOut->addHTML(Xml::submitButton(wfMsg('cacheepoch-submit')));
$wgOut->addHTML(Xml::closeElement('form'));
wfProfileOut(__METHOD__);
}
示例3: enableSpecialVideosExt
/**
* enable Special Video Ext
* @param integer $wikiId
*/
function enableSpecialVideosExt( $wikiId ) {
echo "Enable Special Videos Ext:\n";
$feature = 'wgEnableSpecialVideosExt';
$wgValue = WikiFactory::getVarByName( $feature, $wikiId );
if ( empty($wgValue) ) {
echo "\tError invalid params. \n";
} else {
WikiFactory::setVarByName( $feature, $wikiId, true, "enable Special Videos Ext for wikis that enable Related Videos" );
WikiFactory::clearCache( $wikiId );
echo "\tUpdate $feature from ".var_export( unserialize($wgValue->cv_value), true )." to true. \n";
}
}
示例4: save
public function save()
{
if (!$this->wg->User->isAllowed('gameguidescontent')) {
$this->displayRestrictionError();
return false;
// skip rendering
}
$this->response->setFormat('json');
$categories = $this->getVal('categories');
$err = array();
$tags = array();
if (!empty($categories)) {
//check if categories exists
foreach ($categories as $categoryName => $values) {
$category = Category::newFromName($categoryName);
if (!$category instanceof Category || $category->getPageCount() === 0) {
$err[] = $categoryName;
} else {
if (empty($err)) {
if (array_key_exists($values['tag'], $tags)) {
$tags[$values['tag']]['categories'][] = array('category' => $categoryName, 'name' => $values['name']);
} else {
$tags[$values['tag']] = array('name' => $values['tag'], 'categories' => array(array('category' => $categoryName, 'name' => $values['name'])));
}
}
}
}
if (!empty($err)) {
$this->response->setVal('error', $err);
return true;
}
}
$status = WikiFactory::setVarByName('wgWikiaGameGuidesContent', $this->wg->CityId, array_values($tags));
$this->response->setVal('status', $status);
if ($status) {
$this->wf->RunHooks('GameGuidesContentSave');
}
return true;
}
示例5: onSubmit
public function onSubmit(array $data)
{
global $wgCityId;
$res = true;
if (!$data['Confirm']) {
return Status::newFatal('locknoconfirm');
}
wfSuppressWarnings();
if (!WikiFactory::setVarByName('wgReadOnly', $wgCityId, '')) {
wfDebug(__METHOD__ . ": cannot set wgReadOnly for Wikia: {$wgCityId} \n");
$res = false;
}
if (!WikiFactory::clearCache($wgCityId)) {
wfDebug(__METHOD__ . ": cannot clear cache for Wikia: {$wgCityId} \n");
$res = false;
}
wfRestoreWarnings();
if ($res) {
return Status::newGood();
} else {
return Status::newFatal('unlockdb-wikifactory-error');
}
}
示例6: storeInWikiFactory
private function storeInWikiFactory()
{
$this->output(sprintf("\nSaving %d restored values in WikiFactory:\n", count($this->variables)));
foreach ($this->variables as $name => $value) {
$this->output(sprintf(" * %s = %s\n", $name, json_encode($value)));
WikiFactory::setVarByName($name, $this->cityId, $value, self::REASON);
}
}
示例7: setVariable
/**
* Set the variable
* @param integer $wikiId
* @param mixed $varValue
* @return boolean
*/
protected function setVariable($wikiId, $varValue)
{
$status = false;
if (!$this->dryRun) {
$status = WikiFactory::setVarByName($this->varName, $wikiId, $varValue);
if ($status) {
WikiFactory::clearCache($wikiId);
}
}
return $status;
}
示例8: saveSettings
public function saveSettings($settings, $cityId = null)
{
global $wgCityId, $wgUser;
$cityId = empty($cityId) ? $wgCityId : $cityId;
// Verify wordmark length ( CONN-116 )
if (!empty($settings['wordmark-text'])) {
$settings['wordmark-text'] = trim($settings['wordmark-text']);
}
if (empty($settings['wordmark-text'])) {
// Do not save wordmark if its empty.
unset($settings['wordmark-text']);
} else {
if (mb_strlen($settings['wordmark-text']) > 50) {
$settings['wordmark-text'] = mb_substr($settings['wordmark-text'], 0, 50);
}
}
if (isset($settings['favicon-image-name']) && strpos($settings['favicon-image-name'], 'Temp_file_') === 0) {
$temp_file = new LocalFile(Title::newFromText($settings['favicon-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile(Title::newFromText(self::FaviconImageName, 6), RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), '', '');
$temp_file->delete('');
Wikia::invalidateFavicon();
$settings['favicon-image-url'] = $file->getURL();
$settings['favicon-image-name'] = $file->getName();
$file->repo->forceMaster();
$history = $file->getHistory(1);
if (count($history) == 1) {
$oldFaviconFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
}
}
if (isset($settings['wordmark-image-name']) && strpos($settings['wordmark-image-name'], 'Temp_file_') === 0) {
$temp_file = new LocalFile(Title::newFromText($settings['wordmark-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile(Title::newFromText(self::WordmarkImageName, 6), RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), '', '');
$temp_file->delete('');
$settings['wordmark-image-url'] = $file->getURL();
$settings['wordmark-image-name'] = $file->getName();
$file->repo->forceMaster();
$history = $file->getHistory(1);
if (count($history) == 1) {
$oldFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
}
}
if (isset($settings['background-image-name']) && strpos($settings['background-image-name'], 'Temp_file_') === 0) {
$temp_file = new LocalFile(Title::newFromText($settings['background-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile(Title::newFromText(self::BackgroundImageName, 6), RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), '', '');
$temp_file->delete('');
$settings['background-image'] = $file->getURL();
$settings['background-image-name'] = $file->getName();
$settings['background-image-width'] = $file->getWidth();
$settings['background-image-height'] = $file->getHeight();
$imageServing = new ImageServing(null, 120, array("w" => "120", "h" => "65"));
$settings['user-background-image'] = $file->getURL();
$settings['user-background-image-thumb'] = wfReplaceImageServer($file->getThumbUrl($imageServing->getCut($file->getWidth(), $file->getHeight(), "origin") . "-" . $file->getName()));
$file->repo->forceMaster();
$history = $file->getHistory(1);
if (count($history) == 1) {
$oldBackgroundFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
}
}
$reason = wfMsg('themedesigner-reason', $wgUser->getName());
// update history
if (!empty($GLOBALS[self::WikiFactoryHistory])) {
$history = $GLOBALS[self::WikiFactoryHistory];
$lastItem = end($history);
$revisionId = intval($lastItem['revision']) + 1;
} else {
$history = array();
$revisionId = 1;
}
// #140758 - Jakub
// validation
// default color values
foreach (ThemeDesignerHelper::getColorVars() as $sColorVar => $sDefaultValue) {
if (!isset($settings[$sColorVar]) || !ThemeDesignerHelper::isValidColor($settings[$sColorVar])) {
$settings[$sColorVar] = $sDefaultValue;
}
}
// update WF variable with current theme settings
WikiFactory::setVarByName(self::WikiFactorySettings, $cityId, $settings, $reason);
// add entry
$history[] = array('settings' => $settings, 'author' => $wgUser->getName(), 'timestamp' => wfTimestampNow(), 'revision' => $revisionId);
// limit history size to last 10 changes
$history = array_slice($history, -self::HistoryItemsLimit);
if (count($history) > 1) {
for ($i = 0; $i < count($history) - 1; $i++) {
if (isset($oldFaviconFile) && isset($history[$i]['settings']['favicon-image-name'])) {
if ($history[$i]['settings']['favicon-image-name'] == self::FaviconImageName) {
$history[$i]['settings']['favicon-image-name'] = $oldFaviconFile['name'];
$history[$i]['settings']['favicon-image-url'] = $oldFaviconFile['url'];
}
}
if (isset($oldFile) && isset($history[$i]['settings']['wordmark-image-name'])) {
if ($history[$i]['settings']['wordmark-image-name'] == self::WordmarkImageName) {
$history[$i]['settings']['wordmark-image-name'] = $oldFile['name'];
$history[$i]['settings']['wordmark-image-url'] = $oldFile['url'];
}
}
if (isset($oldBackgroundFile) && isset($history[$i]['settings']['background-image-name'])) {
//.........这里部分代码省略.........
示例9: ini_set
ini_set( "include_path", dirname(__FILE__)."/../" );
require( "commandLine.inc" );
if (isset($options['help'])) {
die( "migrating the ban status from old system to new system" );
}
if ( WikiFactory::getVarValueByName("wgChatBanMigrated", $wgCityId ) ) {
// die( "migrating the ban status from old system to new system" );
}
$db = wfGetDB(DB_SLAVE, array());
/*
* first time it run only count on pages and then it run this script with param -do and list
* it is hack for problem with memory leak from parser
*/
$res = $db->query("select ug_user, ug_group from user_groups where ug_group = 'bannedfromchat'");
$admin = User::newFromName("WikiaBot");
while ($row = $db->fetchRow($res)) {
$userToBan = User::newFromID($row['ug_user']);
Chat::banUser($userToBan->getName(), $admin, 60*60*24*30*6, "Auto migration script for new version of chat");
$userToBan->removeGroup('chatmoderator');
}
WikiFactory::setVarByName("wgChatBanMigrated", $wgCityId, true );
echo "List of pages\n";
示例10: fixBGImage
function fixBGImage($id, $themeSettingsArray)
{
$themeSettingsArray['background-image'] = '';
WikiFactory::setVarByName('wgOasisThemeSettings', $id, $themeSettingsArray);
WikiFactory::clearCache($id);
}
示例11: execute
public function execute()
{
global $wgDBname, $wgCityId, $wgExternalSharedDB, $wgUploadDirectory, $wgUploadDirectoryNFS;
$this->debug = $this->hasOption('debug');
$this->logger = new \Wikia\Swift\Logger\Logger($this->debug ? 10 : 10, -1, 10);
$this->logger->setFile('/var/log/migration/' . $wgDBname . '.log');
$this->logger = $this->logger->prefix($wgDBname);
// force migration of wikis with read-only mode
if (wfReadOnly()) {
global $wgReadOnly;
$wgReadOnly = false;
}
$this->init();
$dbr = $this->getDB(DB_SLAVE);
$isForced = $this->hasOption('force');
$isDryRun = $this->hasOption('dry-run');
$this->useDiff = $this->getOption('diff', false);
$this->useLocalFiles = $this->getOption('local', false);
$this->useDeletes = !$this->hasOption('no-deletes');
$this->threads = intval($this->getOption('threads', self::THREADS_DEFAULT));
$this->threads = min(self::THREADS_MAX, max(1, $this->threads));
$this->hammer = $this->getOption('hammer', null);
$uploadDir = !empty($wgUploadDirectoryNFS) ? $wgUploadDirectoryNFS : $wgUploadDirectory;
$uploadDir = $this->rewriteLocalPath($uploadDir);
if (!is_dir($uploadDir)) {
$this->fatal(__CLASS__, "Could not read the source directory: {$uploadDir}", self::LOG_MIGRATION_ERRORS);
}
// just don't fuck everything!
if ($this->useLocalFiles && !$isDryRun) {
if (gethostname() !== 'file-s4') {
$this->fatal(__CLASS__, "Incremental upload requires access to master file system (don't use --local)", self::LOG_MIGRATION_ERRORS);
}
}
if (!empty($this->hammer) && !$isDryRun) {
$this->fatal(__CLASS__, "Hammer option not supported when not using --dry-run", self::LOG_MIGRATION_ERRORS);
}
// one migration is enough
global $wgEnableSwiftFileBackend, $wgEnableUploads, $wgDBname;
if (!empty($wgEnableSwiftFileBackend) && !$isForced) {
$this->error("\$wgEnableSwiftFileBackend = true - new files storage already enabled on {$wgDBname} wiki!", 1);
}
if (empty($wgEnableUploads) && !$isForced) {
$this->error("\$wgEnableUploads = false - migration is already running on {$wgDBname} wiki!", 1);
}
// get images count
$tables = ['filearchive' => 'fa_size', 'image' => 'img_size', 'oldimage' => 'oi_size'];
foreach ($tables as $table => $sizeField) {
$row = $dbr->selectRow($table, ['count(*) AS cnt', "SUM({$sizeField}) AS size"], [], __METHOD__);
$this->output(sprintf("* %s:\t%d images (%d MB)\n", $table, $row->cnt, round($row->size / 1024 / 1024)));
$this->imagesCnt += $row->cnt;
$this->imagesSize += $row->size;
}
$this->output(sprintf("\n%d image(s) (%d MB) will be migrated (should take ~ %s with %d kB/s / ~ %s with %d files/sec)...\n", $this->imagesCnt, round($this->imagesSize / 1024 / 1024), Wikia::timeDuration($this->imagesSize / 1024 / self::KB_PER_SEC), self::KB_PER_SEC, Wikia::timeDuration($this->imagesCnt / self::FILES_PER_SEC), self::FILES_PER_SEC));
if ($this->hasOption('stats-only')) {
return;
}
// ok, so let's start...
$this->time = time();
self::logWikia(__CLASS__, 'migration started', self::LOG_MIGRATION_PROGRESS);
// wait a bit to prevent deadlocks (from 0 to 2 sec)
usleep(mt_rand(0, 2000) * 1000);
// lock the wiki
$dbw = $this->getDB(DB_MASTER, array(), $wgExternalSharedDB);
if (!$isDryRun) {
$dbw->replace('city_image_migrate', ['city_id'], ['city_id' => $wgCityId, 'locked' => 1], __CLASS__);
}
// block uploads via WikiFactory
if (!$isDryRun) {
register_shutdown_function(array($this, 'unlockWiki'));
$this->areUploadsDisabled = true;
WikiFactory::setVarByName('wgEnableUploads', $wgCityId, false, self::REASON);
WikiFactory::setVarByName('wgUploadMaintenance', $wgCityId, true, self::REASON);
$this->output("Uploads and image operations disabled\n\n");
if ($this->hasOption('wait')) {
$this->output("Sleeping for 180 seconds to let Apache finish uploads...\n");
sleep(180);
}
} else {
$this->output("Performing dry run...\n\n");
}
// prepare the list of files to migrate to new storage
// (a) current revisions of images
// @see http://www.mediawiki.org/wiki/Image_table
$this->output("\nA) Current revisions of images - /images\n");
$res = $dbr->select('image', ['img_name AS name', 'img_size AS size', 'img_sha1 AS hash', 'img_major_mime AS major_mime', 'img_minor_mime AS minor_mime']);
while ($row = $res->fetchRow()) {
$path = $this->getImagePath($row);
$this->queueFile($path, $row);
}
// (b) old revisions of images
// @see http://www.mediawiki.org/wiki/Oldimage_table
$this->output("\nB) Old revisions of images - /archive\n");
$res = $dbr->select('oldimage', ['oi_name AS name', 'oi_archive_name AS archived_name', 'oi_size AS size', 'oi_sha1 AS hash', 'oi_major_mime AS major_mime', 'oi_minor_mime AS minor_mime']);
while ($row = $res->fetchRow()) {
$path = $this->getOldImagePath($row);
$this->queueFile($path, $row);
}
// (c) deleted images
// @see http://www.mediawiki.org/wiki/Filearchive_table
$this->output("\nC) Deleted images - /deleted\n");
//.........这里部分代码省略.........
示例12: array
$usersWithData = array();
while( $row = $result->fetchRow() ) {
$usersWithData[$row['user_id']] = true;
}
$dbr_wikicities->freeResult( $result );
$num = count($usersWithData);
echo "Processing for $num users\n";
foreach( $usersWithData as $user=>$nnn ) {
$result = $dbr_wikicities->select( 'ach_user_counters', '*', array( 'user_id' => $user ) );
while( $row = $result->fetchRow() ) {
$data = unserialize( $row['data'] );
if(!isset($data[$wgCityId])) {
echo "WARNING: for user $user there is a reference but no data for wiki_id $wgCityId \n";
continue;
}
$data_for_wiki = $data[$wgCityId];
$ins = array(
'user_id' => $user,
'data' => serialize(array( $wgCityId => $data_for_wiki ))
);
$dbw->insert( 'ach_user_counters', $ins );
}
}
echo "Flipping the switch\n";
WikiFactory::setVarByName('wgEnableAchievementsStoreLocalData', $wgCityId, 1);
wfWaitForSlaves(2);
示例13: save
public function save()
{
if (!$this->wg->User->isAllowed('curatedcontent')) {
$this->displayRestrictionError();
return false;
// skip rendering
}
$this->response->setFormat('json');
$sections = $this->request->getArray('sections');
list($sections, $err) = $this->processSaveLogic($sections);
if (!empty($err)) {
$this->response->setVal('error', $err);
return true;
}
$status = WikiFactory::setVarByName('wgWikiaCuratedContent', $this->wg->CityId, $sections);
$this->response->setVal('status', $status);
if ($status) {
wfRunHooks('CuratedContentSave', [$sections]);
}
return true;
}
示例14: execute
public function execute()
{
$this->test = $this->hasOption('test');
$this->verbose = $this->hasOption('verbose');
$this->file = $this->getOption('file', '');
$this->dbname = $this->getOption('dbname', '');
$this->set = $this->hasOption('set');
$this->get = $this->hasOption('get');
if ($this->hasOption('enable')) {
$this->enabled = true;
}
if ($this->hasOption('disable')) {
$this->enabled = false;
}
if ($this->test) {
echo "\n=== TEST MODE ===\n";
}
// Shouldn't happen ... paranoid programming
if (!$this->set && !$this->get) {
$this->get = true;
}
if ($this->file) {
echo "Reading from " . $this->file . " ...\n";
$dbnames = file($this->file);
} else {
if ($this->dbname) {
$dbnames = [$this->dbname];
} else {
echo "ERROR: List file empty or not readable. Please provide a line-by-line list of wikis.\n";
echo "USAGE: php EnableVideosModule.php /path/to/file\n";
exit;
}
}
foreach ($dbnames as $db) {
$db = trim($db);
echo "Running on {$db} ...\n";
// get wiki ID
$id = WikiFactory::DBtoID($db);
if (empty($id)) {
echo "\t{$db}: ERROR (not found in WikiFactory)\n";
continue;
} else {
$this->debug("\tWiki ID ({$db}): {$id}");
}
if ($id == 177) {
echo "\tDefaulted to community, not likely a valid wiki, skipping...\n";
continue;
}
if ($this->set) {
if (!$this->test) {
$this->debug("\tSetting ... wgEnableVideosModuleExt");
WikiFactory::setVarByName('wgEnableVideosModuleExt', $id, $this->enabled);
WikiFactory::clearCache($id);
$this->debug("\tdone");
}
} else {
if ($this->get) {
$enabled = WikiFactory::getVarByName('wgEnableVideosModuleExt', $id);
$enabled = $enabled->cv_value;
$enabled = $enabled ? unserialize($enabled) : false;
if ($enabled) {
echo "\tEnabled\n";
} else {
echo "\tDisabled\n";
}
}
}
}
}
示例15: appendTopicsToWF
protected function appendTopicsToWF($phrases, $wikiId)
{
if ($this->mode == "add") {
$wfWikiTopics = $this->getWfWikiTopics($wikiId);
foreach ($phrases as $phrase) {
if (!in_array($phrase, $wfWikiTopics)) {
$wfWikiTopics[] = $phrase;
}
}
WikiFactory::setVarByName(self::WF_VARIABLE_NAME, $wikiId, $wfWikiTopics, 'PageClassification');
}
if ($this->mode == "overwrite") {
WikiFactory::setVarByName(self::WF_VARIABLE_NAME, $wikiId, $phrases);
}
}