function getPathPrefix() { $wikiDbName = $this->repo->getDBName(); $wikiId = WikiFactory::DBtoID($wikiDbName); $wikiUploadPath = WikiFactory::getVarValueByName('wgUploadPath', $wikiId); return VignetteRequest::parsePathPrefix($wikiUploadPath); }
public function index() { if (!$this->wg->User->isAllowed('gameguidescontent')) { $this->displayRestrictionError(); return false; // skip rendering } $title = $this->wf->Msg('wikiagameguides-content-title'); $this->wg->Out->setPageTitle($title); $this->wg->Out->setHTMLTitle($title); $this->wg->Out->addModules('jquery.autocomplete'); $assetManager = AssetsManager::getInstance(); $styles = $assetManager->getUrl('extensions/wikia/GameGuides/css/GameGuidesContentManagmentTool.scss'); foreach ($styles as $s) { $this->wg->Out->addStyle($s); } $scripts = $assetManager->getURL('extensions/wikia/GameGuides/js/GameGuidesContentManagmentTool.js'); foreach ($scripts as $s) { $this->wg->Out->addScriptFile($s); } F::build('JSMessages')->enqueuePackage('GameGuidesContentMsg', JSMessages::INLINE); $tags = WikiFactory::getVarValueByName('wgWikiaGameGuidesContent', $this->wg->CityId); $this->response->setVal('tags', $tags); return true; }
/** * Get variables values * * @return object key / value list variables */ private function getVariablesValues() { global $wgInstantGlobalsOverride; if (!empty($wgInstantGlobalsOverride) && is_array($wgInstantGlobalsOverride)) { $override = $wgInstantGlobalsOverride; } else { $override = []; } $ret = []; $variables = []; wfRunHooks('InstantGlobalsGetVariables', [&$variables]); foreach ($variables as $name) { // Use the value on community but override with the $wgInstantGlobalsOverride if (array_key_exists($name, $override)) { $value = $override[$name]; } else { $value = WikiFactory::getVarValueByName($name, Wikia::COMMUNITY_WIKI_ID); } // don't emit "falsy" values if (!empty($value)) { $ret[$name] = $value; } } return (object) $ret; }
/** * Get the top wikis by weekly pageviews optionally filtering by vertical (hub) and/or language * * @param string $hub [OPTIONAL] The name of the vertical (e.g. Gaming, Entertainment, * Lifestyle, etc.) to use as a filter * @param string $lang [OPTIONAL] The language code (e.g. en, de, fr, es, it, etc.) to use as a filter * * @return array A collection of results with id, name, hub, language, topic and domain */ public function getTop($lang = null, $hub = null) { $this->wf->profileIn(__METHOD__); $cacheKey = $this->wf->SharedMemcKey(__METHOD__, self::CACHE_VERSION, $lang, $hub); $results = $this->wg->Memc->get($cacheKey); if (!is_array($results)) { $results = array(); $wikis = DataMartService::getTopWikisByPageviews(DataMartService::PERIOD_ID_WEEKLY, self::MAX_RESULTS, $lang, $hub, 1); foreach ($wikis as $wikiId => $wiki) { //fetching data from WikiFactory //the table is indexed and values cached separately //so making one query for all of them or a few small //separate ones doesn't make any big difference while //this respects WF's data abstraction layer //also: WF data is heavily cached $name = WikiFactory::getVarValueByName('wgSitename', $wikiId); $hubName = !empty($hub) ? $hub : $this->getVerticalByWikiId($wikiId); $langCode = WikiFactory::getVarValueByName('wgLanguageCode', $wikiId); $topic = WikiFactory::getVarValueByName('wgWikiTopics', $wikiId); $domain = $this->getDomainByWikiId($wikiId); $results[] = array('id' => $wikiId, 'name' => !empty($name) ? $name : null, 'hub' => $hubName, 'language' => !empty($langCode) ? $langCode : null, 'topic' => !empty($topic) ? $topic : null, 'domain' => $domain); } $this->wg->Memc->set($cacheKey, $results, 86400); } $this->wf->profileOut(__METHOD__); return $results; }
/** * Get storage instance to access uploaded files for a given wiki * * @param $cityId number|string city ID or wiki name * @param $dataCenter string|null name of data center (res, iowa ... ) * @return SwiftStorage storage instance */ public static function newFromWiki($cityId, $dataCenter = null) { $wgUploadPath = \WikiFactory::getVarValueByName('wgUploadPath', $cityId); $path = trim(parse_url($wgUploadPath, PHP_URL_PATH), '/'); list($containerName, $prefix) = explode('/', $path, 2); return new self($containerName, '/' . $prefix, $dataCenter); }
private function getUploadDir() { if (!isset($this->uploadDir)) { $this->uploadDir = WikiFactory::getVarValueByName('wgUploadPath', $this->mTitle->mCityId); } return $this->uploadDir; }
function execute($params = null) { global $IP, $wgWikiaLocalSettingsPath; $this->mTaskID = $params->task_id; $oUser = User::newFromId($params->task_user_id); $oUser->load(); $this->mUser = $oUser->getName(); $data = unserialize($params->task_arguments); $articles = $data["articles"]; $username = escapeshellarg($data["username"]); $this->addLog("Starting task."); $this->addLog("List of restored articles (by " . $this->mUser . ' as ' . $username . "):"); for ($i = 0; $i < count($articles); $i++) { $titleobj = Title::makeTitle($articles[$i]["namespace"], $articles[$i]["title"]); $article_to_do = $titleobj->getText(); $namespace = intval($articles[$i]["namespace"]); $reason = $articles[$i]['reason'] ? ' -r ' . escapeshellarg($articles[$i]['reason']) : ''; $sCommand = "SERVER_ID=" . $articles[$i]["wikiid"] . " php {$IP}/maintenance/wikia/restoreOn.php -u " . $username . " -t " . escapeshellarg($article_to_do) . " -n " . $namespace . $reason . " --conf " . escapeshellarg($wgWikiaLocalSettingsPath); $city_url = WikiFactory::getVarValueByName("wgServer", $articles[$i]["wikiid"]); if (empty($city_url)) { $city_url = 'wiki id in WikiFactory: ' . $articles[$i]["wikiid"]; } $city_path = WikiFactory::getVarValueByName("wgScript", $articles[$i]["wikiid"]); $actual_title = wfShellExec($sCommand, $retval); if ($retval) { $this->addLog('Article undeleting error! (' . $city_url . '). Error code returned: ' . $retval . ' Error was: ' . $actual_title); } else { $this->addLog('<a href="' . $city_url . $city_path . '?title=' . $actual_title . '">' . $city_url . $city_path . '?title=' . $actual_title . '</a>'); } } return true; }
public function getWikisList($limit = null, $batch = 1) { wfProfileIn(__METHOD__); $cacheKey = $this->generateCacheKey(__METHOD__); $games = $this->loadFromCache($cacheKey); if (empty($games)) { $games = array(); $wikiFactoryRecommendVar = WikiFactory::getVarByName(self::WF_WIKI_RECOMMEND_VAR, null); if (!empty($wikiFactoryRecommendVar)) { $recommendedIds = WikiFactory::getCityIDsFromVarValue($wikiFactoryRecommendVar->cv_variable_id, true, '='); foreach ($recommendedIds as $wikiId) { $wikiName = WikiFactory::getVarValueByName('wgSitename', $wikiId); $wikiGames = WikiFactory::getVarValueByName('wgWikiTopics', $wikiId); $wikiDomain = str_replace('http://', '', WikiFactory::getVarValueByName('wgServer', $wikiId)); $wikiThemeSettings = WikiFactory::getVarValueByName('wgOasisThemeSettings', $wikiId); $wordmarkUrl = $wikiThemeSettings['wordmark-image-url']; $wordmarkType = $wikiThemeSettings['wordmark-type']; //$wikiLogo = WikiFactory::getVarValueByName( "wgLogo", $wikiId ); $games[] = array('name' => !empty($wikiThemeSettings['wordmark-text']) ? $wikiThemeSettings['wordmark-text'] : $wikiName, 'games' => !empty($wikiGames) ? $wikiGames : '', 'color' => !empty($wikiThemeSettings['wordmark-color']) ? $wikiThemeSettings['wordmark-color'] : '#0049C6', 'backgroundColor' => !empty($wikiThemeSettings['color-page']) ? $wikiThemeSettings['color-page'] : '#FFFFFF', 'domain' => $wikiDomain, 'wordmarkUrl' => $wordmarkType == 'graphic' && !empty($wordmarkUrl) ? $wordmarkUrl : ''); } } else { wfProfileOut(__METHOD__); throw new WikiaException('WikiFactory variable \'' . self::WF_WIKI_RECOMMEND_VAR . '\' not found'); } $this->storeInCache($cacheKey, $games); } $ret = wfPaginateArray($games, $limit, $batch); wfProfileOut(__METHOD__); return $ret; }
/** * @param $wikiId * @param $query * @return float */ public function performQueryTest($wikiId, $query) { $wgLinkSuggestLimit = 6; $dbName = WikiFactory::IDtoDB($wikiId); $db = wfGetDB(DB_SLAVE, [], $dbName); $namespaces = WikiFactory::getVarValueByName("wgContentNamespaces", $wikiId); $namespaces = $namespaces ? $namespaces : [0]; $query = addslashes($query); $queryLower = strtolower($query); if (count($namespaces) > 0) { $commaJoinedNamespaces = count($namespaces) > 1 ? array_shift($namespaces) . ', ' . implode(', ', $namespaces) : $namespaces[0]; } $pageNamespaceClause = isset($commaJoinedNamespaces) ? 'page_namespace IN (' . $commaJoinedNamespaces . ') AND ' : ''; $pageTitlePrefilter = ""; if (strlen($queryLower) >= 2) { $pageTitlePrefilter = "(\n\t\t\t\t\t\t\t( page_title " . $db->buildLike(strtoupper($queryLower[0]) . strtolower($queryLower[1]), $db->anyString()) . " ) OR\n\t\t\t\t\t\t\t( page_title " . $db->buildLike(strtoupper($queryLower[0]) . strtoupper($queryLower[1]), $db->anyString()) . " ) ) AND "; } else { if (strlen($queryLower) >= 1) { $pageTitlePrefilter = "( page_title " . $db->buildLike(strtoupper($queryLower[0]), $db->anyString()) . " ) AND "; } } $sql = "SELECT page_len, page_id, page_title, rd_title, page_namespace, page_is_redirect\n\t\t\t\t\t\tFROM page\n\t\t\t\t\t\tLEFT JOIN redirect ON page_is_redirect = 1 AND page_id = rd_from\n\t\t\t\t\t\tLEFT JOIN querycache ON qc_title = page_title AND qc_type = 'BrokenRedirects'\n\t\t\t\t\t\tWHERE {$pageTitlePrefilter} {$pageNamespaceClause} (LOWER(page_title) LIKE '{$queryLower}%')\n\t\t\t\t\t\t\tAND qc_type IS NULL\n\t\t\t\t\t\tORDER BY page_id\n\t\t\t\t\t\tLIMIT " . $wgLinkSuggestLimit * 3; // we fetch 3 times more results to leave out redirects to the same page $start = microtime(true); $res = $db->query($sql, __METHOD__); while ($res->fetchRow()) { } return microtime(true) - $start; }
function execute($par) { global $wgOut, $wgCityId, $wgSuppressWikiHeader, $wgSuppressPageHeader, $wgShowMyToolsOnly, $wgExtensionsPath, $wgBlankImgUrl, $wgJsMimeType, $wgTitle, $wgUser, $wgRequest; wfProfileIn(__METHOD__); // redirect to www.wikia.com if ($wgCityId == 177) { $destServer = WikiFactory::getVarValueByName('wgServer', $this->destCityId); $destArticlePath = WikiFactory::getVarValueByName('wgArticlePath', $this->destCityId); $wgOut->redirect($destServer . str_replace('$1', 'Special:LandingPage', $destArticlePath)); return; } $this->setHeaders(); $wgOut->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/wikia/LandingPage/css/LandingPage.scss')); // hide wiki and page header $wgSuppressWikiHeader = true; $wgSuppressPageHeader = true; // only shown "My Tools" on floating toolbar $wgShowMyToolsOnly = true; // parse language links (RT #71622) $languageLinks = array(); $parsedMsg = wfStringToArray(wfMsg('landingpage-language-links'), '*', 10); foreach ($parsedMsg as $item) { if ($item != '') { list($text, $lang) = explode('|', $item); $languageLinks[] = array('text' => $text, 'href' => $wgTitle->getLocalUrl("uselang={$lang}")); } } // fetching the landingpage sites $landingPageLinks = CorporatePageHelper::parseMsgImg('landingpage-sites', false, false); // render HTML $template = new EasyTemplate(dirname(__FILE__) . '/templates'); $template->set_vars(array('imagesPath' => $wgExtensionsPath . '/wikia/LandingPage/images/', 'languageLinks' => $languageLinks, 'wgBlankImgUrl' => $wgBlankImgUrl, 'wgTitle' => $wgTitle, 'landingPageLinks' => $landingPageLinks, 'landingPageSearch' => F::app()->getView("SearchController", "Index", array("placeholder" => "Search Wikia", "fulltext" => "0", "wgBlankImgUrl" => $wgBlankImgUrl, "wgTitle" => $wgTitle)))); $wgOut->addHTML($template->render('main')); wfProfileOut(__METHOD__); }
public static function getRtpCountries() { static $countries; if ($countries) { return $countries; } return $countries = WikiFactory::getVarValueByName(self::RTP_COUNTRIES, WikiFactory::COMMUNITY_CENTRAL); }
function execute($params = null) { global $IP, $wgWikiaLocalSettingsPath; /* go with each supplied wiki and delete the supplied article load all configs for particular wikis before doing so (from wikifactory, not by _obsolete_ maintenance scripts and from LocalSettings as worked on fps) */ $this->mTaskID = $params->task_id; $oUser = User::newFromId($params->task_user_id); if ($oUser instanceof User) { $oUser->load(); $this->mUser = $oUser->getName(); } else { $this->log("Invalid user - id: " . $params->task_user_id); return true; } $data = unserialize($params->task_arguments); foreach ($data['page_list'] as $imageData) { $retval = ""; list($wikiId, $imageId) = $imageData; $dbname = WikiFactory::getWikiByID($wikiId); if (!$dbname) { continue; } $title = GlobalTitle::newFromId($imageId, $wikiId); if (!is_object($title)) { $this->log('Apparently the article does not exist anymore'); continue; } $city_url = WikiFactory::getVarValueByName("wgServer", $wikiId); if (empty($city_url)) { continue; } $city_path = WikiFactory::getVarValueByName("wgScript", $wikiId); $city_lang = WikiFactory::getVarValueByName("wgLanguageCode", $wikiId); $reason = wfMsgExt('imagereview-reason', array('language' => $city_lang)); $sCommand = "perl /usr/wikia/backend/bin/run_maintenance --id={$wikiId} --script=wikia/deleteOn.php "; $sCommand .= "-- "; $sCommand .= "-u " . escapeshellarg($this->mUser) . " "; $sCommand .= "-t " . escapeshellarg($title->getPrefixedText()) . " "; if ($reason) { $sCommand .= "-r " . escapeshellarg($reason) . " "; } $actual_title = wfShellExec($sCommand, $retval); if ($retval) { $this->addLog('Article deleting error! (' . $city_url . '). Error code returned: ' . $retval . ' Error was: ' . $actual_title); } else { $this->addLog('Removed: <a href="' . $city_url . $city_path . '?title=' . wfEscapeWikiText($actual_title) . '">' . $city_url . $city_path . '?title=' . $actual_title . '</a>'); } $this->flagUser($imageId, $wikiId); $this->flagWiki($wikiId); } return true; }
function wfAdEngineSetupJSVars(array &$vars) { wfProfileIn(__METHOD__); global $wgRequest, $wgNoExternals, $wgEnableAdsInContent, $wgEnableOpenXSPC, $wgAdDriverCookieLifetime, $wgHighValueCountries, $wgDartCustomKeyValues, $wgUser, $wgEnableWikiAnswers, $wgAdDriverUseCookie, $wgAdDriverUseExpiryStorage, $wgEnableAdMeldAPIClient, $wgEnableAdMeldAPIClientPixels, $wgLoadAdDriverOnLiftiumInit; $wgNoExternals = $wgRequest->getBool('noexternals', $wgNoExternals); if (!empty($wgNoExternals)) { $vars["wgNoExternals"] = $wgNoExternals; } if (!empty($wgEnableAdsInContent)) { $vars["wgEnableAdsInContent"] = $wgEnableAdsInContent; } if (!empty($wgEnableAdMeldAPIClient)) { $vars["wgEnableAdMeldAPIClient"] = $wgEnableAdMeldAPIClient; } if (!empty($wgEnableAdMeldAPIClientPixels)) { $vars["wgEnableAdMeldAPIClientPixels"] = $wgEnableAdMeldAPIClientPixels; } // OpenX SPC (init in AdProviderOpenX.js) if (!empty($wgEnableOpenXSPC)) { $vars["wgEnableOpenXSPC"] = $wgEnableOpenXSPC; } // AdDriver $vars['wgAdDriverCookieLifetime'] = $wgAdDriverCookieLifetime; $highValueCountries = WikiFactory::getVarValueByName('wgHighValueCountries', 177); // community central if (empty($highValueCountries)) { $highValueCountries = $wgHighValueCountries; } $vars['wgHighValueCountries'] = $highValueCountries; if (!empty($wgAdDriverUseExpiryStorage)) { $vars["wgAdDriverUseExpiryStorage"] = $wgAdDriverUseExpiryStorage; } if (!empty($wgAdDriverUseCookie)) { $vars["wgAdDriverUseCookie"] = $wgAdDriverUseCookie; } if (!empty($wgLoadAdDriverOnLiftiumInit)) { $vars['wgLoadAdDriverOnLiftiumInit'] = $wgLoadAdDriverOnLiftiumInit; } if ($wgUser->getOption('showAds')) { $vars['wgUserShowAds'] = true; } // Answers sites if (!empty($wgEnableWikiAnswers)) { $vars['wgEnableWikiAnswers'] = $wgEnableWikiAnswers; } /* // Krux if (!empty($wgEnableKruxTargeting) && empty($wgNoExternals)) { $vars['wgEnableKruxTargeting'] = $wgEnableKruxTargeting; $vars['wgKruxCategoryId'] = WikiFactoryHub::getInstance()->getKruxId($cat['id']); } */ wfProfileOut(__METHOD__); return true; }
/** * Get domain for a wiki using given database name * * @param string database name * @return string HTTP domain */ private static function getHostByDbName($dbname) { global $wgDevelEnvironment, $wgDevelEnvironmentName; if (!empty($wgDevelEnvironment)) { $hostName = "http://{$dbname}.{$wgDevelEnvironmentName}.wikia-dev.com"; } else { $cityId = WikiFactory::DBtoID($dbname); $hostName = WikiFactory::getVarValueByName('wgServer', $cityId); } return rtrim($hostName, '/'); }
public function getFiltered() { $filtered = $this->filter->getFiltered(); foreach ($filtered as $key => $wikiData) { $wikiId = (int) $wikiData['id']; if (WikiFactory::getVarValueByName('wgIsPrivateWiki', $wikiId)) { unset($filtered[$key]); } } return $filtered; }
public function getData() { $this->wf->profileIn(__METHOD__); $wikiaBarConfigMessage = WikiFactory::getVarValueByName('wgWikiaBarConfig', self::WIKIA_BAR_CONFIG_WIKI_ID, true); if (!empty($wikiaBarConfigMessage) && !empty($wikiaBarConfigMessage[$this->getVertical()]) && !empty($wikiaBarConfigMessage[$this->getVertical()][$this->getLang()])) { $data = trim($wikiaBarConfigMessage[$this->getVertical()][$this->getLang()]); } else { $data = false; } $this->wf->profileOut(__METHOD__); return $data; }
/** * main entry point * * @access public */ public function run() { global $wgUser, $wgErrorLog, $wgExtensionMessagesFiles, $wgInternalServer, $wgServer; wfProfileIn(__METHOD__); /** * @see SquidUpdate::expand */ $wgInternalServer = $wgServer; $wgExtensionMessagesFiles["AutoCreateWiki"] = dirname(__FILE__) . "/AutoCreateWiki.i18n.php"; $wgErrorLog = false; /** * setup founder user */ if ($this->mParams["founder"]) { $this->mFounder = User::newFromId($this->mParams["founder"]); $this->mFounder->load(); } if (!$this->mFounder) { Wikia::log(__METHOD__, "user", "Cannot load user with user_id = {$this->mParams["founder"]}"); if (!empty($this->mParams["founder-name"])) { $this->mFounder = User::newFromName($this->mParams["founder-name"]); $this->mFounder->load(); } } $wgUser = User::newFromName("CreateWiki script"); /** * main page should be move in first stage of create wiki, but sometimes * is too early for that. This is fallback function */ $this->wikiaName = isset($this->mParams["title"]) ? $this->mParams["title"] : WikiFactory::getVarValueByName("wgSitename", $this->mParams["city_id"], true); $this->wikiaLang = isset($this->mParams["language"]) ? $this->mParams["language"] : WikiFactory::getVarValueByName("wgLanguageCode", $this->mParams["city_id"]); $this->moveMainPage(); $this->changeStarterContributions(); $this->setWelcomeTalkPage(); $this->sendWelcomeMail(); $this->populateCheckUserTables(); $this->protectKeyPages(); $this->queueReminderMail(); $this->sendRevisionToScribe(); $this->addStarterImagesToUploadLog(); /** * different things for different types */ switch ($this->mParams["type"]) { case "answers": $this->copyDefaultAvatars(); break; } wfRunHooks('CreateWikiLocalJob-complete', array(&$this->mParams)); wfProfileOut(__METHOD__); return true; }
/** * Get domain for a wiki using given database name * * @param string $dbName database name * * @return string HTTP domain */ private static function getHostByDbName($dbName) { global $wgDevelEnvironment, $wgDevelEnvironmentName; $cityId = WikiFactory::DBtoID($dbName); $hostName = WikiFactory::getVarValueByName('wgServer', $cityId); if (!empty($wgDevelEnvironment)) { if (strpos($hostName, "wikia.com")) { $hostName = str_replace("wikia.com", "{$wgDevelEnvironmentName}.wikia-dev.com", $hostName); } else { $hostName = WikiFactory::getLocalEnvURL($hostName); } } return rtrim($hostName, '/'); }
function getSectionForWiki($wiki = false) { global $wgDBname, $wgDBcluster, $smwgUseExternalDB; if ($this->lastWiki === $wiki) { return $this->lastSection; } list($dbName, $prefix) = $this->getDBNameAndPrefix($wiki); /** * actually we should not have any fallback because it will end with * fatal anyway. * * But it makes PHP happy */ $section = 'central'; $this->isSMWClusterActive = false; if ($smwgUseExternalDB) { /** * set flag, strip database name */ if (substr($dbName, 0, 4) == "smw+" && isset($this->sectionsByDB["smw+"])) { $this->isSMWClusterActive = true; $dbName = substr($dbName, 4); wfDebugLog("connect", __METHOD__ . ": smw+ cluster is active, dbname changed to {$dbName}\n", true); } } if (isset($this->sectionsByDB[$dbName])) { // this is a db that has a cluster defined in the config file (DB.php) $section = $this->sectionsByDB[$dbName]; } elseif ($this->isSMWClusterActive) { // use smw+ entry $section = $this->sectionsByDB["smw+"]; wfDebugLog("connect", __METHOD__ . "-smw: section {$section} choosen for {$wiki}\n"); } elseif ($dbName == $wgDBname) { // this is a local db so use global variables if (isset($wgDBcluster)) { $section = $wgDBcluster; } } else { // this is a foreign db that either has a cluster defined in WikiFactory... $section = WikiFactory::getVarValueByName('wgDBcluster', WikiFactory::DBtoID($wiki)); if (empty($section)) { $section = 'central'; } } $this->lastSection = $section; $this->lastWiki = $wiki; wfDebugLog("connect", __METHOD__ . ": section {$this->lastSection}, wiki {$this->lastWiki}\n"); return $section; }
public function delete($pageList, $suppress = false) { global $IP; $user = \User::newFromId($this->createdBy); $userName = $user->getName(); $articlesDeleted = 0; foreach ($pageList as $imageData) { list($wikiId, $imageId) = $imageData; if (!\WikiFactory::isPublic($wikiId)) { $this->notice('wiki has been disabled', ['wiki_id' => $wikiId]); continue; } $dbname = \WikiFactory::getWikiByID($wikiId); if (!$dbname) { $this->warning('did not find database', ['wiki_id' => $wikiId]); continue; } $cityUrl = \WikiFactory::getVarValueByName('wgServer', $wikiId); if (empty($cityUrl)) { $this->warning('could not determine city url', ['wiki_id' => $wikiId]); continue; } $cityLang = \WikiFactory::getVarValueByName('wgLanguageCode', $wikiId); $reason = wfMsgExt('imagereview-reason', ['language' => $cityLang]); $command = "SERVER_ID={$wikiId} php {$IP}/maintenance/wikia/deleteOn.php" . ' -u ' . escapeshellarg($userName) . ' --id ' . $imageId; if ($reason) { $command .= ' -r ' . escapeshellarg($reason); } if ($suppress) { $command .= ' -s'; } $title = wfShellExec($command, $exitStatus); if ($exitStatus !== 0) { $this->error('article deletion error', ['city_url' => $cityUrl, 'exit_status' => $exitStatus, 'error' => $title]); continue; } $cityPath = \WikiFactory::getVarValueByName('wgScript', $wikiId); $escapedTitle = wfEscapeWikiText($title); $this->info('removed image', ['link' => "{$cityUrl}{$cityPath}?title={$escapedTitle}", 'title' => $escapedTitle]); ++$articlesDeleted; } $success = $articlesDeleted == count($pageList); if (!$success) { $this->sendNotification(); } return $success; }
public function postCreationSetup($params) { global $wgErrorLog, $wgServer, $wgInternalServer, $wgStatsDBEnabled; $wgServer = rtrim($params['url'], '/'); $wgInternalServer = $wgServer; $wgStatsDBEnabled = false; // disable any DW queries/hooks during wiki creation $wgErrorLog = false; if ($params['founderId']) { $this->info('loading founding user', ['founder_id' => $params['founderId']]); $this->founder = \User::newFromId($params['founderId']); $this->founder->load(); } if (!$this->founder || $this->founder->isAnon()) { $this->warning('cannot load founding user', ['founder_id' => $params['founderId']]); if (!empty($params['founderName'])) { $this->founder = \User::newFromName($params['founderName']); $this->founder->load(); } } if (!$this->founder || $this->founder->isAnon()) { global $wgExternalAuthType; if ($wgExternalAuthType) { $extUser = \ExternalUser::newFromName($params['founderName']); if (is_object($extUser)) { $extUser->linkToLocal($extUser->getId()); } } } $this->wikiName = isset($params['sitename']) ? $params['sitename'] : \WikiFactory::getVarValueByName('wgSitename', $params['city_id'], true); $this->wikiLang = isset($params['language']) ? $params['language'] : \WikiFactory::getVarValueByName('wgLanguageCode', $params['city_id']); $this->moveMainPage(); $this->changeStarterContributions($params); $this->setWelcomeTalkPage(); $this->populateCheckUserTables(); $this->protectKeyPages(); $this->sendRevisionToScribe(); $hookParams = ['title' => $params['sitename'], 'url' => $params['url'], 'city_id' => $params['city_id']]; if (empty($params['disableCompleteHook'])) { wfRunHooks('CreateWikiLocalJob-complete', array($hookParams)); } return true; }
static function getHubsFeedsVariable($tagname) { global $wgMemc, $wgCityId; wfProfileIn(__METHOD__); $key = wfMemcKey('autohubs', $tagname, 'feeds_displayed'); $data = $wgMemc->get($key); if (!$data) { $feeds = WikiFactory::getVarValueByName('wgWikiaAutoHubsFeedsDisplayed', $wgCityId); if (!empty($feeds[$tagname]) && is_array($feeds[$tagname])) { $tag = $feeds; } else { $tag[$tagname] = self::getDefaultHubsFeeds(); } $wgMemc->set($key, $tag); } else { $tag = $data; } wfProfileOut(__METHOD__); return $tag; }
/** * @author Federico "Lox" Lucignano * @param $wikiCityID int the city_id for the wiki * @return string the name of the cluster the wiki DB belongs to * * Retrieves the name of the cluster in which the local DB for the specified wiki is stored */ public static function getCityCluster($wikiCityID) { wfProfileIn(__METHOD__); //check for non admitted values if (empty($wikiCityID) || !is_int($wikiCityID)) { wfProfileOut(__METHOD__); return false; } wfDebugLog(__CLASS__ . '::' . __METHOD__, "Looking up cluster for wiki with ID {$wikiCityID}"); //WikiFactory implementation $value = WikiFactory::getVarValueByName('wgDBcluster', $wikiCityID); //if not found fall back to city_list implementation if (empty($value)) { $dbr = WikiFactory::db(DB_SLAVE); $res = $dbr->selectField('city_list', 'city_cluster', array('city_id' => $wikiCityID)); $value = $res; } wfDebugLog(__CLASS__ . '::' . __METHOD__, "Cluster for wiki with ID {$wikiCityID} is '{$value}'" . (empty($value) ? ' (main shared DB)' : null)); wfProfileOut(__METHOD__); return empty($value) ? self::CLUSTER_DEFAULT : $value; }
/** * checkImageDirectory * * check if target directory exists. if not create it. if not possible * signalize it. We have to have id of target wiki * * @access public * @author eloy@wikia * * @return boolean: status of operation */ public function checkImageDirectory() { $mRetVal = false; if (empty($this->mTargetID)) { return $mRetVal; } wfProfileIn(__METHOD__); $UploadDirectory = WikiFactory::getVarValueByName("wgUploadDirectory", $this->mTargetID); if (file_exists($UploadDirectory)) { if (is_dir($UploadDirectory)) { $this->addLog("Target {$UploadDirectory} exists and is directory."); $mRetVal = true; } else { $this->addLog("Target {$UploadDirectory} exists but is not directory"); $mRetVal = false; } } else { $mRetVal = wfMkdirParents($UploadDirectory); } wfProfileOut(__METHOD__); return $mRetVal; }
public function getActive($pageNo = 1) { $db = $this->getDb(); $activeWikis = array(); $is_enabled = $this->app->getGlobal('wgStatsDBEnabled'); if (empty($is_enabled)) { return array('wikisNum' => 0, 'pageNo' => $pageNo, 'wikis' => array()); } $row = $db->selectRow(array('wikia_monthly_stats'), array('unix_timestamp(ts) as lastdate'), array('wiki_id' => $this->app->getGlobal('wgCityId')), __METHOD__, array('ORDER BY' => 'ts DESC')); $statsDate = date('Ym', $row->lastdate); //select group_concat(wiki_id) from wikia_monthly_stats where stats_date = 201104 and articles > 10 and articles_edits > 50 and wiki_id in ( select city_id from wikicities.city_list where city_created > now() - interval 2 week ); $res = $db->query("\n\t\t SELECT group_concat(wiki_id) AS wikis\n\t\t FROM wikia_monthly_stats\n\t\t WHERE\n\t\t stats_date='" . $statsDate . "' AND\n\t\t articles>'" . self::MAX_PAGES . "' AND\n\t\t articles_edits>'" . self::MAX_EDITS . "' AND\n\t\t wiki_id IN ( SELECT city_id FROM wikicities.city_list WHERE city_created>NOW() - INTERVAL " . self::MAX_WEEKS . " WEEK )"); $row = $db->fetchObject($res); //select pv_city_id, sum(pv_views) from page_views_wikia where pv_city_id in ( 249526,249598,249611,249645,249756,249771,249836,249839,249841,249948,250124,250179,250276,250427,250549,250747 ) group by 1 $res = $db->query("\n\t\t SELECT pv_city_id, sum(pv_views) AS pviews\n\t\t FROM page_views_wikia\n\t\t WHERE pv_city_id IN ( " . $row->wikis . " ) AND\n\t\t 2 < " . self::MAX_PV . "\n\t\t GROUP BY 1\n\t\t ORDER BY 2 DESC\n\t\t LIMIT " . self::MAX_WIKIS); while ($row = $db->fetchObject($res)) { // won't work on devboxes for fresh city IDs $activeWikis[] = array('wikiId' => $row->pv_city_id, 'wikiName' => WikiFactory::getVarValueByName('wgSitename', $row->pv_city_id), 'wikiUrl' => WikiFactory::getVarValueByName('wgServer', $row->pv_city_id), 'pv' => $row->pviews); } $result = array('wikisNum' => $db->numRows($res), 'pageNo' => $pageNo, 'wikis' => array_slice($activeWikis, $pageNo * self::MAX_WIKIS_PER_PAGE - 1, self::MAX_WIKIS_PER_PAGE)); return $result; }
/** * Send confirmation reminder emails for users that signed up on current wiki 7 days ago */ function sendReminder() { global $wgCityId, $wgServer; wfProfileIn(__METHOD__); // update url $wgServer = WikiFactory::getVarValueByName('wgServer', $wgCityId); $users = getRecipientsForCurrentWiki(); $cnt = 0; $userLoginHelper = new UserLoginHelper(); foreach ($users as $user) { // send reminder email $result = $userLoginHelper->sendConfirmationReminderEmail($user); if (!$result->isGood()) { echo "Error: Cannot send reminder to user (id=" . $user->getId() . ", email=" . $user->getEmail() . "): " . $result->getMessage() . "\n"; } else { $cnt++; echo "Sent reminder to user (id=" . $user->getId() . ", email=" . $user->getEmail() . ").\n"; } } echo "WikiId {$wgCityId}: " . sizeof($users) . " of total {$cnt} confirmation reminder emails sent.\n"; wfProfileOut(__METHOD__); }
function execute($params = null) { global $IP, $wgWikiaLocalSettingsPath; /* go with each supplied wiki and delete the supplied article load all configs for particular wikis before doing so (from wikifactory, not by _obsolete_ maintenance scripts and from LocalSettings as worked on fps) */ $this->mTaskID = $params->task_id; $oUser = User::newFromId($params->task_user_id); $oUser->load(); $this->mUser = $oUser->getName(); $data = unserialize($params->task_arguments); $articlesData = $data['articles']; $username = escapeshellarg($data['username']); $this->addLog('Starting task.'); $this->addLog('List of deleted articles (by ' . $this->mUser . ' as ' . $username . '):'); foreach ($articlesData as $wikiId => $articles) { foreach ($articles as $article) { $namespace = $article['namespace']; $reason = $article['reason'] ? '-r ' . escapeshellarg($article['reason']) : ''; $sCommand = "SERVER_ID={$wikiId} php {$IP}/maintenance/wikia/deleteOn.php -u {$username} -t " . escapeshellarg($article['title']) . " {$reason} --conf " . escapeshellarg($wgWikiaLocalSettingsPath); $city_url = WikiFactory::getVarValueByName('wgServer', $wikiId); if (empty($city_url)) { $city_url = "wiki id in WikiFactory: {$wikiId}"; } $city_path = WikiFactory::getVarValueByName('wgScript', $wikiId); $actual_title = wfShellExec($sCommand, $retval); if ($retval) { $this->addLog('Article deleting error! (' . $city_url . '). Error code returned: ' . $retval . ' Error was: ' . $actual_title); } else { $this->addLog('<a href="' . $city_url . $city_path . '?title=' . $actual_title . '">' . $city_url . $city_path . '?title=' . $actual_title . '</a>'); } } } return true; }
public static function getInterWikiaURL(Title &$title, &$url, $query) { global $wgArticlePath, $wgScriptPath; if (in_array($title->mInterwiki, array('w', 'wikia', 'wikicities'))) { $aLinkParts = explode(':', $title->getFullText()); if ($aLinkParts[1] == 'c') { $iCityId = self::isWikiExists($aLinkParts[2]); if ($iCityId) { $sArticlePath = WikiFactory::getVarValueByName('wgArticlePath', $iCityId); //I've replaced wgArticlePath to hardcoded value in order to fix FogBug:3066 //This is a persistent issue with getting default value of variable that is not set in WikiFactory //Similar problem exists when displaying "default value" in WikiFactory - it's not the real default (taken from file) //it's value for current wiki (community for WikiFactory, www.wikia.com for 3066 bug) //anyway - current value in CommonSettings.php for wgArticlePath is '/wiki/$1' that's why this hardcoded //fix will work.. for now.. it would be nice to introduce some function to get REAL DEFAULT VALUE for any variable //Marooned $sArticlePath = !empty($sArticlePath) ? $sArticlePath : '/wiki/$1'; //$wgArticlePath; /* $wgScriptPath is already included in city_url $sScriptPath = WikiFactory::getVarValueByName('wgScriptPath', $iCityId); $sScriptPath = !empty($sScriptPath) ? $sScriptPath : $wgScriptPath; */ if (!empty($sArticlePath)) { $sArticleTitle = ''; for ($i = 3; $i < count($aLinkParts); $i++) { $sArticleTitle .= (!empty($sArticleTitle) ? ':' : '') . $aLinkParts[$i]; } //RT#54264,#41254 $sArticleTitle = str_replace(' ', '_', $sArticleTitle); $sArticleTitle = urlencode($sArticleTitle); $sCityUrl = self::getCityUrl($iCityId); if (!empty($sCityUrl)) { $url = str_replace('$1', $sArticleTitle, $sArticlePath); $url = $sCityUrl . $url; } } } } } return true; }
public function execute($wikiID) { global $wgOut, $wgRequest, $wgCityId, $wgUser; wfProfileIn(__METHOD__); $this->setHeaders(); $firstVisit = true; $wikiID = !empty($wikiID) ? (int) $wikiID : $wgCityId; if (isset($_COOKIE[$this->mCookieName])) { $this->mCookie = json_decode($_COOKIE[$this->mCookieName]); $firstVisit = false; } else { $this->mCookie = new stdClass(); $this->mCookie->origHub = null; $this->mCookie->langCode = null; $this->mCookie->history = array(); if (!empty($wikiID)) { $hub = WikiFactory::getCategory($wikiID); if (is_object($hub)) { $this->mCookie->origHub = $hub->cat_id; $this->mCookie->langCode = WikiFactory::getWikiByID($wikiID)->city_lang; $this->mCookie->history[] = $wikiID; } } } $this->loadData(); $historyCount = count($this->mCookie->history); // reset the history if the user visited all the possible targets if ($historyCount >= $this->mData['total']) { $this->mCookie->history = array($wikiID); } // if language other than English and list of targets exhausted fall back to english if (($historyCount >= $this->mData['total'] || $this->mData['total'] == 0 && (count($this->mData['recommended']) == 0 || !$firstVisit)) && $this->mCookie->langCode != 'en') { $this->mCookie->langCode = 'en'; $this->loadData(); } $destinationID = null; $from = null; srand(time()); // pick a recommended wiki the first time if ($firstVisit && !empty($this->mData['recommended'])) { $destinationID = $this->mData['recommended'][array_rand($this->mData['recommended'])]; $from = 'recommended'; } elseif (!empty($this->mCookie->origHub) && !empty($this->mData['hubs'][$this->mCookie->origHub])) { $currentHub = array_diff($this->mData['hubs'][$this->mCookie->origHub], $this->mCookie->history); if (count($currentHub) && count($this->mCookie->history) < RandomWikiHelper::TRACK_LIMIT) { $destinationID = $currentHub[array_rand($currentHub)]; $from = 'origHub'; } } // in case no wiki has been selected in the previous block pick a wiki from a random hub if (empty($destinationID)) { $hubsCount = count($this->mData['hubs']); $hub = array_rand($this->mData['hubs'], $hubsCount); if (!is_array($hub)) { $hub = array($hub); } foreach ($hub as $key) { $tmpHub = array_diff($this->mData['hubs'][$key], $this->mCookie->history); if (!count($tmpHub)) { continue; } $itemKey = array_rand($tmpHub); $destinationID = $tmpHub[$itemKey]; $from = "hub {$itemKey}"; } } $this->mCookie->history[] = $destinationID; $cookieValue = json_encode($this->mCookie); $wgRequest->response()->setcookie(self::COOKIE_NAME_TOKEN, $cookieValue, time() + 3600 * self::COOKIE_EXPIRY); $url = WikiFactory::getVarValueByName('wgServer', $destinationID); //FB#1033: avoid being sent to Special:WikiActivity when logged-in, see MyHomw::getInitialMainPage if ($wgUser->isLoggedIn()) { $url .= '?redirect=no'; } // Redirect the user to a randomly-chosen wiki (or not if profiling requested) $profiling = $wgRequest->getInt('forceprofile', 0); if ($profiling !== 1) { $wgOut->redirect($url); } wfProfileOut(__METHOD__); }
/** * @brief Hook on WikiFactory change and update wikis's visibility if the wgGroupPermissionsLocal is changed * * @param String $cv_name * @param Integer $city_id * @param String $value * * @return Boolean * * @author Evgeniy (aquilax) */ public static function onWikiFactoryChanged($cv_name, $city_id, $value) { global $wgExternalDatawareDB; if (empty($wgExternalDatawareDB)) { // Exit if there is no Dataware DB return true; } if ($cv_name === 'wgGroupPermissionsLocal') { $is_restricted = false; $permissions = WikiFactory::getVarValueByName('wgGroupPermissionsLocal', $city_id); if (!empty($value)) { $permissions = WikiFactoryLoader::parsePermissionsSettings($value); } if (isset($permissions['*']) && is_array($permissions['*']) && isset($permissions['*']['read']) && $permissions['*']['read'] === false) { $is_restricted = true; } UserProfilePageHelper::updateRestrictedWikis((int) $city_id, $is_restricted); } return true; }