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; }
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__); }
/** * 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"; } }
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; }
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'); } }
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); } }
/** * 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; }
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'])) { if ($history[$i]['settings']['background-image-name'] == self::BackgroundImageName) { $history[$i]['settings']['background-image-name'] = $oldBackgroundFile['name']; } } } } WikiFactory::setVarByName(self::WikiFactoryHistory, $cityId, $history, $reason); }
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";
function fixBGImage($id, $themeSettingsArray) { $themeSettingsArray['background-image'] = ''; WikiFactory::setVarByName('wgOasisThemeSettings', $id, $themeSettingsArray); WikiFactory::clearCache($id); }
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 f**k 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"); $res = $dbr->select('filearchive', ['fa_name AS name', 'fa_storage_key AS storage_key', 'fa_size AS size', 'fa_major_mime AS major_mime', 'fa_minor_mime AS minor_mime']); while ($row = $res->fetchRow()) { $path = $this->getRemovedImagePath($row); $this->queueFile($path, $row); } $this->processQueue(); echo count($this->allFiles) . PHP_EOL; // stats per DC $statsPerDC = []; foreach ($this->timePerDC as $dc => $time) { $statsPerDC[] = sprintf("%s took %s", $dc, Wikia::timeDuration(round($time))); } // summary $totalTime = time() - $this->time; $report = sprintf('Migrated %d files with %d fails in %s', $this->migratedImagesCnt, $this->migratedImagesFailedCnt, Wikia::timeDuration($totalTime)); $this->output("\n{$report}\n"); self::logWikia(__CLASS__, 'migration completed - ' . $report, self::LOG_MIGRATION_PROGRESS); // if running in --dry-run, leave now if ($isDryRun) { $this->output("\nDry run completed!\n"); return; } // unlock the wiki $dbw->ping(); $dbw->replace('city_image_migrate', ['city_id'], ['city_id' => $wgCityId, 'locked' => 0], __CLASS__); $dbr = $this->getDB(DB_MASTER, array(), $wgExternalSharedDB); $dbr->ping(); // update wiki configuration // enable Swift storage via WikiFactory WikiFactory::setVarByName('wgEnableSwiftFileBackend', $wgCityId, true, sprintf('%s - migration took %s', self::REASON, Wikia::timeDuration($totalTime))); $this->output("\nNew storage enabled\n"); // too short bucket name fix if ($this->shortBucketNameFixed) { global $wgUploadPath, $wgUploadDirectory, $wgUploadDirectoryNFS; WikiFactory::setVarByName('wgUploadPath', $wgCityId, $wgUploadPath, self::REASON); WikiFactory::setVarByName('wgUploadDirectory', $wgCityId, $wgUploadDirectory, self::REASON); WikiFactory::setVarByName('wgUploadDirectoryNFS', $wgCityId, $wgUploadDirectoryNFS, self::REASON); $this->output("\nNew upload directory set up\n"); } // enable uploads via WikiFactory // wgEnableUploads = true / wgUploadMaintenance = false (remove values from WF to give them the default value) WikiFactory::removeVarByName('wgEnableUploads', $wgCityId, self::REASON); WikiFactory::removeVarByName('wgUploadMaintenance', $wgCityId, self::REASON); $this->areUploadsDisabled = false; $this->output("\nUploads and image operations enabled\n"); $this->output("\nDone!\n"); }
$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);
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; }
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"; } } } } }
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); } }
foreach ($commentList as $comment) { $cnt++; echo "{$cnt} [{$fromId}-{$toId}]: ID {$comment->page_id}(NS {$comment->page_namespace}): {$comment->page_title}"; $title = F::build('Title', array($comment), 'newFromRow'); $articleComment = F::build('ArticleComment', array($title), 'newFromTitle'); $articleComment->load(); // parent page id $parentPageId = getParentPage($articleComment); if (empty($parentPageId)) { echo ".....Parent page NOT found.\n"; $failed++; continue; } // get parent comment id $parentCommentObj = $articleComment->getTopParentObj(); if ($parentCommentObj instanceof ArticleComment) { // posts/replies $parentCommentId = $parentCommentObj->getTitle()->getArticleID(); $lastChildCommentId = 0; } else { // main comments $parentCommentId = 0; $lastChildCommentId = getLastChildCommentId($articleComment); } // insert main comment insertIntoCommentsIndex($parentPageId, $articleComment, $parentCommentId, $lastChildCommentId); echo ".....DONE.\n"; } WikiFactory::setVarByName("wgWallIndexed", $wgCityId, true); echo "TOTAL: " . $cnt . ", SUCCESS: " . ($cnt - $failed) . ", FAILED: {$failed}\n\n"; echo "#DONE !!!\n";
/** * @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); // check user permission if (!$this->wg->User->isAllowed('wikifeatures')) { $this->setVal('result', 'error'); $this->setVal('error', $this->wf->Msg('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', $this->wf->Msg('wikifeatures-error-invalid-parameter')); 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', $this->wf->Msg('wikifeatures-error-invalid-parameter')); return; } $enabled = $enabled == 'true'; $logMsg = "set extension option: {$feature} = " . var_export($enabled, TRUE); $log = WF::build('LogPage', array('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)); $this->setVal('result', 'ok'); }
<?php /** * Enables CuratedContent on wikias where GameGuides was enabled * https://wikia-inc.atlassian.net/browse/DAT-2264 * * Get familiar with "How_to_run_maintenance_script" article on internal to figure out how to run it. * */ ini_set("include_path", dirname(__FILE__) . "/.."); require_once 'commandLine.inc'; $app = F::app(); $cityId = $app->wg->CityId; if (empty($cityId)) { die("Error: Invalid wiki id."); } $statusEnabled = WikiFactory::setVarByName('wgEnableCuratedContentExt', $cityId, true); if ($statusEnabled == 0) { die("Error: Cannot Set EnableCuratedContentExt Variable"); } echo "enabled Curated Content on wikiId: " . $cityId . "\n";
function enableVEUI($id) { WikiFactory::setVarByName('wgEnableVisualEditorUI', $id, true); WikiFactory::clearCache($id); }
public static function setWikiaStatsInWF($statsValues) { WikiFactory::setVarByName('wgCorpMainPageStats', Wikia::COMMUNITY_WIKI_ID, $statsValues); $corpWikisLangs = array_keys((new CityVisualization())->getVisualizationWikisData()); $wikiaHubsHelper = new WikiaHubsServicesHelper(); foreach ($corpWikisLangs as $lang) { $wikiaHubsHelper->purgeHomePageVarnish($lang); } }
/** * setmainDomain * * sets domain as main (wgServer) * * @param integer $city_id: wiki identifier in city_list * @param string $domain: domain name (on null) * * @return boolean: true - set, false otherwise */ public static function setmainDomain($city_id, $domain = null, $reason = null) { if (!self::isUsed()) { Wikia::log(__METHOD__, "", "WikiFactory is not used."); return false; } if ('http://' != strpos($domain, 0, 7)) { $domain = 'http://' . $domain; } $retVal = WikiFactory::setVarByName("wgServer", $city_id, $domain, $reason); self::clearDomainCache($city_id); return $retVal; }
/** * Save data about hub slots displayed on wikia homepage in hubs section. * After save memcache is purged to get fresh data on wikia homepage. * * @param $hubSlotsValues data containing hub wiki id, description and links * @param $corporateId corporate wiki id * @param $lang language code */ public function saveHubSlotsToWF($hubSlotsValues, $corporateId, $lang, $varName = 'wgWikiaHomePageHubsSlots') { $status = WikiFactory::setVarByName($varName, $corporateId, $hubSlotsValues); if ($status) { WikiaDataAccess::cachePurge($this->getHubSlotsMemcacheKey($lang)); } return $status; }
/** * @param null $code * @return GWTSiteSyncStatus */ public function verify_site($code = null) { if (!$code) { $info = $this->site_info(); $code = $info->getPageVerificationCode(); } // Update the wgGoogleSiteVerification variable with this code WikiFactory::setVarByName('wgGoogleSiteVerification', $this->mWiki->city_id, $code); // Send the verification request to google $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/"); $oTmpl->set_vars(array("site_id" => $this->make_site_id())); $xml = $oTmpl->render("wt-verify-request"); return $this->put_verify($xml); }
public function saveSettings($wikiId, $categoryName, $iconUrl, $watermarkUrl) { $this->app->wf->profileIn(__METHOD__); $values = array(); $ret = false; if (!empty($categoryName)) { $values[] = "category={$categoryName}"; } if (!empty($iconUrl)) { $values[] = "thumbnail={$iconUrl}"; } if (!empty($watermarkUrl)) { $values[] = "watermark={$watermarkUrl}"; } if (!empty($values)) { $ret = WikiFactory::setVarByName(self::WF_SETTINGS_NAME, $wikiId, implode('|', $values), "Updating PhotoPop settings"); //force the list of wikis' cache to be rebuilt next time $this->wg->memc->delete($this->getGlobalCacheKey(self::MEMCACHE_GLOBAL_KEY_TOKEN)); } $this->app->wf->profileOut(__METHOD__); return $ret; }
<?php /** * @package MediaWiki * @addtopackage maintenance * @author tomek@wikia * @author tor@wikia * copy blog data from page_props to page_wikia_props * * */ ini_set("include_path", dirname(__FILE__) . "/.."); require_once "commandLine.inc"; if (!empty($wgBlogsInWikiaProps)) { echo "Already done"; exit; } $list = BlogArticle::getPropsList(); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(array("page_props"), array("*"), array("pp_propname" => array_keys($list), "pp_value" => 1, "pp_page in (select page_id from page where page_namespace = " . NS_BLOG_ARTICLE . ") "), __METHOD__); $dbr = wfGetDB(DB_MASTER); while ($row = $dbr->fetchObject($res)) { wfSetWikiaPageProp($list[$row->pp_propname], $row->pp_page, $row->pp_value); } $dbr->commit(); WikiFactory::setVarByName("wgBlogsInWikiaProps", $wgCityId, true);
public function execute() { global $wgCityId, $wgExternalSharedDB; // 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'); // 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::log(__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) { WikiFactory::setVarByName('wgEnableUploads', $wgCityId, false, self::REASON); WikiFactory::setVarByName('wgUploadMaintenance', $wgCityId, true, self::REASON); $this->output("Uploads and image operations disabled\n\n"); } 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->copyFile($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->copyFile($path, $row); } // (c) deleted images // @see http://www.mediawiki.org/wiki/Filearchive_table $this->output("\nC) Deleted images - /deleted\n"); $res = $dbr->select('filearchive', ['fa_name AS name', 'fa_storage_key AS storage_key', 'fa_size AS size', 'fa_major_mime AS major_mime', 'fa_minor_mime AS minor_mime']); while ($row = $res->fetchRow()) { $path = $this->getRemovedImagePath($row); $this->copyFile($path, $row); } // stats per DC $statsPerDC = []; foreach ($this->timePerDC as $dc => $time) { $statsPerDC[] = sprintf("%s took %s", $dc, Wikia::timeDuration(round($time))); } // summary $totalTime = time() - $this->time; $report = sprintf('Migrated %d files (%d MB) with %d fails in %s (%.2f files/sec, %.2f kB/s) - DCs: %s', $this->migratedImagesCnt, round($this->migratedImagesSize / 1024 / 1024), $this->migratedImagesFailedCnt, Wikia::timeDuration($totalTime), floor($this->imagesCnt) / (time() - $this->time), $this->migratedImagesSize / 1024 / (time() - $this->time), join(', ', $statsPerDC)); $this->output("\n{$report}\n"); self::log(__CLASS__, 'migration completed - ' . $report, self::LOG_MIGRATION_PROGRESS); // if running in --dry-run, leave now if ($isDryRun) { $this->output("\nDry run completed!\n"); return; } // unlock the wiki $dbw->ping(); $dbw->replace('city_image_migrate', ['city_id'], ['city_id' => $wgCityId, 'locked' => 0], __CLASS__); // update wiki configuration // enable Swift storage via WikiFactory WikiFactory::setVarByName('wgEnableSwiftFileBackend', $wgCityId, true, sprintf('%s - migration took %s', self::REASON, Wikia::timeDuration($totalTime))); $this->output("\nNew storage enabled\n"); // too short bucket name fix if ($this->shortBucketNameFixed) { global $wgUploadPath, $wgUploadDirectory, $wgUploadDirectoryNFS; WikiFactory::setVarByName('wgUploadPath', $wgCityId, $wgUploadPath, self::REASON); WikiFactory::setVarByName('wgUploadDirectory', $wgCityId, $wgUploadDirectory, self::REASON); WikiFactory::setVarByName('wgUploadDirectoryNFS', $wgCityId, $wgUploadDirectoryNFS, self::REASON); $this->output("\nNew upload directory set up\n"); } // enable uploads via WikiFactory // wgEnableUploads = true / wgUploadMaintenance = false (remove values from WF to give them the default value) WikiFactory::removeVarByName('wgEnableUploads', $wgCityId, self::REASON); WikiFactory::removeVarByName('wgUploadMaintenance', $wgCityId, self::REASON); $this->output("\nUploads and image operations enabled\n"); $this->output("\nDone!\n"); }
private static function setServerBasket($basket) { WikiFactory::setVarByName(self::$serversBasket, self::$CentralCityId, $basket); }
continue; } if (!in_array($lang, $allowedLanguages)) { echo "{$wiki}: SKIPPING! Wiki's language ({$lang}) is not on the allowed languaes list.\n"; continue; } if (!isset($options['yes'])) { $response = null; // repeat until we get a valid response while (is_null($response)) { echo "{$wiki}: Are you sure you want to switch to Oasis? [yes/no] "; $input = fgets(STDIN); $response = parseInput($input); } if (!$response) { // user answered no echo "{$wiki}: SKIPPING (because you said so)\n"; continue; } else { echo "{$wiki}: PROCEEDING\n"; } } WikiFactory::setVarByName('wgDefaultSkin', $id, 'oasis'); WikiFactory::clearCache($id); // purge varnishes if (!isset($options['nopurge'])) { $cmd = "pdsh -g all_varnish varnishadm -T :6082 'purge req.http.host == \"" . $domain . "\"'"; passthru($cmd); } echo "{$wiki}: PROCESSING COMPLETED\n"; }
$table = $row->entry_table; $id = $row->entry_id; $idField = $row->entry_id_field; $nsField = $row->entry_ns_field; echo " Undo on\t$table\tid:\t$id\n"; $dbw->update($table, array( $nsField => 400 ), array( $idField => $id ), __METHOD__ ); $dbw_dataware->delete( 'video_postmigrate_undo', array('id' => $row->id), __METHOD__ ); } $dbw->freeResult($rows); echo "Done updating tables\n"; echo "Flipping the switch\n"; WikiFactory::setVarByName('wgVideoHandlersVideosMigrated', $wgCityId, false); echo "Done\n"; ?>
* */ ini_set("include_path", dirname(__FILE__) . "/.."); require_once 'commandLine.inc'; /** * connect to WF db */ $variable = "wgUploadDirectory"; $dbw = Wikifactory::db(DB_MASTER); $sth = $dbw->select(array("city_variables"), array("*"), array("cv_variable_id = (SELECT cv_id FROM city_variables_pool WHERE cv_name = '{$variable}')"), __METHOD__, array("FOR UPDATE")); while ($row = $dbw->fetchObject($sth)) { $value = ltrim(unserialize($row->cv_value), "/"); #print "{$value}\n"; $parts = explode("/", $value); /** * first part is not interesting */ $prefix = array_shift($parts); if (strlen($parts[0]) > 1) { /* * it's not converted yet */ $letter = strtolower(substr($parts[0], 0, 1)); $path = sprintf("/%s/%s/%s", $prefix, $letter, implode("/", $parts)); print "{$value} => {$path}\n"; /** * now update value through WF to get logs */ WikiFactory::setVarByName($variable, $row->cv_city_id, $path); } }