public function maintenance($server)
 {
     global $wgCityId, $IP;
     $cmd = sprintf("SERVER_ID={$wgCityId} php {$IP}/maintenance/update.php --server={$server} --quick --nopurge");
     $output = wfShellExec($cmd, $exitStatus);
     $this->info('run update.php', ['exitStatus' => $exitStatus, 'output' => $output]);
     $cmd = sprintf("SERVER_ID={$wgCityId} php {$IP}/maintenance/initStats.php --server={$server}");
     $output = wfShellExec($cmd, $exitStatus);
     $this->info('run initStats.php', ['exitStatus' => $exitStatus, 'output' => $output]);
     $cmd = sprintf("SERVER_ID={$wgCityId} php {$IP}/maintenance/refreshLinks.php --server={$server} --new-only");
     $output = wfShellExec($cmd, $exitStatus);
     $this->info('run refreshLinks.php', ['exitStatus' => $exitStatus, 'output' => $output]);
     $this->info("Remove edit lock");
     $variable = \WikiFactory::getVarByName('wgReadOnly', $wgCityId);
     if (isset($variable->cv_variable_id)) {
         \WikiFactory::removeVarById($variable->cv_variable_id, $wgCityId);
         \WikiFactory::clearCache($wgCityId);
     }
     $dbname = \WikiFactory::IDtoDB($wgCityId);
     $founder = $this->founder->getId();
     $cmd = sprintf("perl /usr/wikia/backend/bin/scribe/events_local_users.pl --usedb={$dbname} --user={$founder} ");
     $output = wfShellExec($cmd, $exitStatus);
     $this->info('run events_local_users.pl', ['exitStatus' => $exitStatus, 'output' => $output]);
     $wgMemc = wfGetMainCache();
     $wgMemc->delete(\WikiFactory::getVarsKey($wgCityId));
     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;
 }
 /**
  * Look for videos that are blacklisted in the wgVideosModuleBlackList variable on community central
  */
 protected function initializeBlacklist()
 {
     $communityBlacklist = \WikiFactory::getVarByName("wgVideosModuleBlackList", \WikiFactory::COMMUNITY_CENTRAL);
     if (is_object($communityBlacklist) && !empty($communityBlacklist->cv_value)) {
         $this->blacklist = unserialize($communityBlacklist->cv_value);
     }
 }
/**
 * axWFactoryGetVariable
 *
 * Method for getting variable form via AJAX request.
 *
 * @author Krzysztof Krzyżaniak <*****@*****.**>
 * @access public
 *
 * @return HTML code with variable data
 */
function axWFactoryGetVariable()
{
    global $wgRequest, $wgUser, $wgOut, $wgPreWikiFactoryValues;
    if (!$wgUser->isAllowed('wikifactory')) {
        $wgOut->readOnlyPage();
        #--- FIXME: later change to something reasonable
        return;
    }
    $cv_id = $wgRequest->getVal("varid");
    $city_id = $wgRequest->getVal("wiki");
    $variable = WikiFactory::getVarById($cv_id, $city_id);
    // BugId:3054
    if (empty($variable)) {
        return json_encode(array('error' => true, 'message' => 'No such variable.'));
    }
    $related = array();
    $r_pages = array();
    if (preg_match("/Related variables:(.*)\$/", $variable->cv_description, $matches)) {
        $names = preg_split("/[\\s,;.()]+/", $matches[1], null, PREG_SPLIT_NO_EMPTY);
        foreach ($names as $name) {
            $rel_var = WikiFactory::getVarByName($name, $city_id);
            if (!empty($rel_var)) {
                $related[] = $rel_var;
            } else {
                if (preg_match("/^MediaWiki:.*\$/", $name, $matches2)) {
                    $r_pages[] = array("url" => GlobalTitle::newFromText($name, 0, $city_id)->getFullURL());
                }
            }
        }
    }
    $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/");
    $oTmpl->set_vars(array("cityid" => $city_id, "variable" => $variable, "groups" => WikiFactory::getGroups(), "accesslevels" => WikiFactory::$levels, "related" => $related, "related_pages" => $r_pages, "preWFValues" => $wgPreWikiFactoryValues, 'wikiFactoryUrl' => Title::makeTitle(NS_SPECIAL, 'WikiFactory')->getFullUrl()));
    return json_encode(array("div-body" => $oTmpl->render("variable"), "div-name" => "wk-variable-form"));
}
 public function getWikisList()
 {
     $this->wf->profileIn(__METHOD__);
     $cacheKey = $this->getGlobalCacheKey(self::MEMCACHE_GLOBAL_KEY_TOKEN);
     $ret = $this->loadFromCache($cacheKey);
     if (empty($ret)) {
         $ret = array();
         $wikiFactoryRecommendVar = WikiFactory::getVarByName(self::WF_SWITCH_NAME, null);
         if (!empty($wikiFactoryRecommendVar)) {
             $gamesIds = WikiFactory::getCityIDsFromVarValue($wikiFactoryRecommendVar->cv_variable_id, true, '=');
             foreach ($gamesIds as $wikiId) {
                 $game = $this->getSettings($wikiId);
                 if (!empty($game)) {
                     $wikiName = WikiFactory::getVarValueByName('wgSitename', $wikiId);
                     $wikiThemeSettings = WikiFactory::getVarValueByName('wgOasisThemeSettings', $wikiId);
                     $game->name = !empty($wikiThemeSettings['wordmark-text']) ? $wikiThemeSettings['wordmark-text'] : $wikiName;
                     $game->id = WikiFactory::IDtoDB($wikiId);
                     $game->domain = str_replace('http://', '', WikiFactory::getVarValueByName('wgServer', $wikiId));
                     $ret[$game->id] = $game;
                 }
             }
         } else {
             $this->wf->profileOut(__METHOD__);
             throw new WikiaException('WikiFactory variable \'' . self::WF_SWITCH_NAME . '\' not found');
         }
         $this->storeInCache($cacheKey, $ret);
     }
     $this->app->wf->profileOut(__METHOD__);
     return $ret;
 }
示例#6
0
 protected function getWfWikiTopics($wikiId)
 {
     $topics = unserialize(WikiFactory::getVarByName(self::WF_VARIABLE_NAME, $wikiId)->cv_value);
     if (!is_array($topics) || $topics == false || empty($topics)) {
         $topics = array();
     }
     return $topics;
 }
function isVESet($id)
{
    $out = WikiFactory::getVarByName('wgEnableVisualEditorExt', $id);
    if (!is_object($out) || empty($out->cv_value)) {
        return false;
    } else {
        return true;
    }
}
function getBrokenThemeSettings($id)
{
    $themeSettings = WikiFactory::getVarByName('wgOasisThemeSettings', $id);
    if (!is_object($themeSettings) || empty($themeSettings->cv_value)) {
        return null;
    }
    $themeSettingsArray = unserialize($themeSettings->cv_value);
    $backgroundImage = $themeSettingsArray['background-image'];
    return getType($backgroundImage) !== 'string' || $backgroundImage === 'false' ? $themeSettingsArray : null;
}
 public static function loadData($forceRefresh = false, $forceLanguage = null)
 {
     global $wgMemc, $wgStatsDB, $wgContLang, $wgExternalSharedDB, $wgStatsDBEnabled;
     wfProfileIn(__METHOD__);
     self::$mLanguage = !empty($forceLanguage) ? $forceLanguage : $wgContLang->getCode();
     $cacheKey = self::CACHE_KEY_TOKEN . ':' . strtoupper(self::$mLanguage);
     self::$mData = $wgMemc->get($cacheKey);
     if (empty(self::$mData) || $forceRefresh) {
         self::$mData = array();
         $wikisIDs = array();
         // get all the active wikis selected by the sales team
         $wikiFactoryRecommended = WikiFactory::getVarByName(self::WF_VAR_NAME, null);
         self::$mData['recommended'] = array();
         if (!empty($wikiFactoryRecommended) && !empty($wikiFactoryRecommended->cv_variable_id)) {
             $dbr = WikiFactory::db(DB_SLAVE);
             $res = $dbr->select(array('city_list', 'city_variables'), 'city_id', array('city_id = cv_city_id', 'city_public' => 1, 'city_lang' => self::$mLanguage, 'cv_variable_id' => $wikiFactoryRecommended->cv_variable_id, 'cv_value' => serialize(true)));
             while ($row = $dbr->fetchObject($res)) {
                 self::$mData['recommended'][] = $row->city_id;
             }
             $dbr->freeResult($res);
         }
         $counter = 0;
         self::$mData['hubs'] = array();
         if (!empty($wgStatsDBEnabled)) {
             $langs = array(self::$mLanguage);
             $wikis = DataMartService::getTopWikisByPageviews(DataMartService::PERIOD_ID_MONTHLY, 200, $langs, null, 1);
             $minPageViews = isset(self::$pageviewsLimits[self::$mLanguage]) ? self::$pageviewsLimits[self::$mLanguage] : self::$pageviewsLimits['default'];
             foreach ($wikis as $wikiID => $pvCount) {
                 if ($pvCount >= $minPageViews) {
                     $hub = WikiFactoryHub::getInstance();
                     $cat_id = $hub->getCategoryId($wikiID);
                     if (!$cat_id) {
                         continue;
                     }
                     if (!isset(self::$mData['hubs'][$cat_id])) {
                         self::$mData['hubs'][$cat_id] = array();
                     }
                     self::$mData['hubs'][$cat_id][] = $wikiID;
                     $counter++;
                 }
             }
         }
         // removing entries from hubs that have a match in recommended
         if (!empty(self::$mData['recommended']) && !empty(self::$mData['hubs'])) {
             $counter = 0;
             foreach (self::$mData['hubs'] as $hubID => &$item) {
                 $item = array_diff($item, self::$mData['recommended']);
                 $counter += count($item);
             }
         }
         self::$mData['total'] = $counter;
         $wgMemc->set($cacheKey, self::$mData, 3600 * self::CACHE_EXPIRY);
     }
     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 getWamPageUrl()
 {
     try {
         $wikiId = (new WikiaCorporateModel())->getCorporateWikiIdByLang($this->langCode);
     } catch (Exception $e) {
         $wikiId = WikiService::WIKIAGLOBAL_CITY_ID;
     }
     $wamPageConfig = WikiFactory::getVarByName('wgWAMPageConfig', $wikiId)->cv_value;
     $pageName = !empty($wamPageConfig['pageName']) ? $wamPageConfig['pageName'] : 'WAM';
     $url = GlobalTitle::newFromText($pageName, NS_MAIN, $wikiId)->getFullURL();
     return $url;
 }
示例#12
0
 /**
  * execute
  *
  * entry point for TaskExecutor
  *
  * @access public
  * @author eloy@wikia
  *
  * @param mixed $params default null - task data from wikia_tasks table
  *
  * @return boolean - status of operation
  */
 public function execute($params = null)
 {
     global $IP, $wgWikiaLocalSettingsPath, $wgWikiaAdminSettingsPath, $wgExtensionMessagesFiles;
     $this->mTaskID = $params->task_id;
     $this->mParams = unserialize($params->task_arguments);
     $city_id = $this->mParams["city_id"];
     $command = $this->mParams["command"];
     $type = $this->mParams["type"];
     $server = $this->mParams["server"];
     $this->addLog("wgServer for this site is: {$server}");
     if ($city_id && $command) {
         $this->mWikiId = $city_id;
         /**
          * execute maintenance script
          */
         $cmd = sprintf("SERVER_ID={$city_id} php {$IP}/{$command} --server={$server} --conf {$wgWikiaLocalSettingsPath} --aconf {$wgWikiaAdminSettingsPath}");
         $this->addLog("Running {$cmd}");
         $retval = wfShellExec($cmd, $status);
         $this->addLog($retval);
         if ($type == "ACWLocal" || $type == "CWLocal") {
             $cmd = sprintf("SERVER_ID={$city_id} php {$IP}/maintenance/update.php --server={$server} --quick --nopurge --conf {$wgWikiaLocalSettingsPath} --aconf {$wgWikiaAdminSettingsPath}");
             $this->addLog("Running {$cmd}");
             $retval = wfShellExec($cmd, $status);
             $this->addLog($retval);
             $cmd = sprintf("SERVER_ID={$city_id} php {$IP}/maintenance/initStats.php --server={$server} --conf {$wgWikiaLocalSettingsPath} --aconf {$wgWikiaAdminSettingsPath}");
             $this->addLog("Running {$cmd}");
             $retval = wfShellExec($cmd, $status);
             $this->addLog($retval);
             $cmd = sprintf("SERVER_ID={$city_id} php {$IP}/maintenance/refreshLinks.php --server={$server} --new-only --conf {$wgWikiaLocalSettingsPath} --aconf {$wgWikiaAdminSettingsPath}");
             $this->addLog("Running {$cmd}");
             $retval = wfShellExec($cmd, $status);
             $this->addLog($retval);
             $this->addLog("Remove edit lock");
             $oVariable = WikiFactory::getVarByName('wgReadOnly', $city_id);
             if (isset($oVariable->cv_variable_id)) {
                 WikiFactory::removeVarById($oVariable->cv_variable_id, $city_id);
                 WikiFactory::clearCache($city_id);
             }
         }
         $dbname = WikiFactory::IDtoDB($city_id);
         $cmd = sprintf("perl /usr/wikia/backend/bin/scribe/events_local_users.pl --usedb={$dbname} ");
         $this->addLog("Running {$cmd}");
         $retval = wfShellExec($cmd, $status);
         $this->addLog($retval);
         /**
          * once again clear cache at the very end
          */
         $wgMemc = wfGetMainCache();
         $wgMemc->delete(WikiFactory::getVarsKey($city_id));
     }
     return true;
 }
示例#13
0
 /**
  * @access public
  * @static
  */
 public static function customSpecialStatistics(&$specialpage, &$text)
 {
     global $wgOut, $wgDBname, $wgLang, $wgRequest, $wgTitle, $wgUser, $wgCityId, $wgHTTPProxy;
     $tmpl = new EasyTemplate(dirname(__FILE__) . "/templates/");
     /**
      * get last dump request timestamp
      */
     $wiki = WikiFactory::getWikiByID($wgCityId);
     if (strtotime(wfTimestampNow()) - strtotime($wiki->city_lastdump_timestamp) > 7 * 24 * 60 * 60) {
         $tmpl->set("available", true);
     } else {
         $tmpl->set("available", false);
     }
     $tmpl->set("title", $wgTitle);
     $tmpl->set("isAnon", $wgUser->isAnon());
     $dumpInfo = self::getLatestDumpInfo($wgCityId);
     $sTimestamp = $dumpInfo ? $dumpInfo['timestamp'] : false;
     $sDumpExtension = self::getExtensionFromCompression($dumpInfo ? $dumpInfo['compression'] : false);
     $tmpl->set('nolink', false);
     if (empty($sTimestamp)) {
         $sTimestamp = wfMessage('dump-database-last-unknown')->escaped();
         $tmpl->set('nolink', true);
     }
     $tmpl->set("curr", array("url" => 'http://s3.amazonaws.com/wikia_xml_dumps/' . self::getPath("{$wgDBname}_pages_current.xml{$sDumpExtension}"), "timestamp" => $sTimestamp));
     $tmpl->set("full", array("url" => 'http://s3.amazonaws.com/wikia_xml_dumps/' . self::getPath("{$wgDBname}_pages_full.xml{$sDumpExtension}"), "timestamp" => $sTimestamp));
     // The Community Central's value of the wgDumpRequestBlacklist variable contains an array of users who are not allowed to request dumps with this special page.
     $aDumpRequestBlacklist = (array) unserialize(WikiFactory::getVarByName('wgDumpRequestBlacklist', WikiFactory::COMMUNITY_CENTRAL)->cv_value);
     $bIsAllowed = $wgUser->isAllowed('dumpsondemand') && !in_array($wgUser->getName(), $aDumpRequestBlacklist);
     $tmpl->set('bIsAllowed', $bIsAllowed);
     $text .= $tmpl->render("dod");
     if ($wgRequest->wasPosted() && $bIsAllowed) {
         self::queueDump($wgCityId);
         wfDebug(__METHOD__, ": request for database dump was posted\n");
         $text = Wikia::successbox(wfMsg("dump-database-request-requested")) . $text;
     }
     return true;
 }
 /**
  * @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');
 }
 protected function getWhitelistedWikisFromWF()
 {
     $this->wf->ProfileIn(__METHOD__);
     $key = wfMemcKey(__CLASS__, __METHOD__);
     $data = $this->wg->memc->get($key, null);
     if (!empty($data)) {
         $this->wf->ProfileOut(__METHOD__);
         return $data;
     }
     $oVariable = WikiFactory::getVarByName('wgImageReviewWhitelisted', 177);
     $fromWf = WikiFactory::getListOfWikisWithVar($oVariable->cv_variable_id, 'bool', '=', true);
     $this->wg->memc->set($key, $fromWf, 60 * 10);
     $this->wf->ProfileOut(__METHOD__);
     return $fromWf;
 }
示例#16
0
 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";
                 }
             }
         }
     }
 }
function isVEenabled($id)
{
    $out = WikiFactory::getVarByName('wgEnableVisualEditorExt', $id);
    return $out ? unserialize($out->cv_value) : false;
}
示例#18
0
    }
    return null;
}
foreach ($list as $wiki) {
    echo "\n";
    $wiki = sanitizeUrl($wiki);
    // get wiki ID
    $id = WikiFactory::DomainToID($wiki);
    if (empty($id)) {
        echo "{$wiki}: ERROR (not found in WikiFactory)\n";
        continue;
    }
    // get URL, in case the one given is not the main one
    $oUrl = WikiFactory::getVarByName('wgServer', $id);
    $oLang = WikiFactory::getVarByName('wgLanguageCode', $id);
    $oSkin = WikiFactory::getVarByName('wgDefaultSkin', $id);
    if (empty($oUrl) || empty($oLang)) {
        // should never happen, but...
        echo "{$wiki}: ERROR (failed to get URL for ID {$id} or language; something's wrong)\n";
        continue;
    }
    $domain = sanitizeUrl(unserialize($oUrl->cv_value));
    $lang = unserialize($oLang->cv_value);
    $currentSkin = $oSkin ? unserialize($oLang->cv_value) : null;
    // handle exceptions
    if (in_array($currentSkin, array('monobook', 'uncyclopedia', 'oasis'))) {
        echo "{$wiki}: SKIPPING! Current skin is {$currentSkin}! Will NOT process.\n";
        continue;
    }
    if (in_array($domain, $exceptions)) {
        echo "{$wiki}: SKIPPING! This wiki is listed as an exception in the Rallout Plan!\n";
示例#19
0
echo( "Check migration for $wgCityId\n" );

$dbr = wfGetDB( DB_SLAVE );
$dbw_dataware = wfGetDB( DB_MASTER, array(), $wgExternalDatawareDB );

$rows = $dbr->select('image',
	array( 'img_name' ),
	array( "img_name LIKE ':%'" ),
	__METHOD__
);

$rowCount = $rows->numRows();

$dbr->freeResult($rows);

$v = WikiFactory::getVarByName('wgVideoHandlersVideosMigrated', $wgCityId);
$ve = $v->cv_value;
echo(": {$rowCount} old videos found ($ve)\n");

if($rowCount > 0 && $ve != True) {
//if(true) {
	$dbw_dataware->insert(
		'video_notmigrated2',
		array(
			'wiki_id' => $wgCityId,
			'wiki_name' => WikiFactory::getWikiByID($wgCityId)->city_url,
			'video_count' => $rowCount
		)
	);
	echo("$wgCityId has videos but was not migrated!\n");
}
 public function execute()
 {
     $this->dryRun = $this->hasOption('dry-run');
     $this->verbose = $this->hasOption('verbose');
     $this->varName = $this->getOption('varName', '');
     $set = $this->hasOption('set');
     $varValue = $this->getOption('set', '');
     $remove = $this->hasOption('remove');
     $wikiId = $this->getOption('wikiId', '');
     $file = $this->getOption('file', '');
     if (empty($this->varName)) {
         die("Error: Empty variable name.\n");
     }
     if ($set && $remove) {
         die("Error: Cannot set and remove the variable at the same time\n");
     }
     if ($set && $varValue == '') {
         die("Error: Empty variable value.\n");
     }
     $varData = (array) WikiFactory::getVarByName($this->varName, false, true);
     if (empty($varData['cv_id'])) {
         die("Error: {$this->varName} not found.\n");
     }
     echo "Variable: {$this->varName} (Id: {$varData['cv_id']})\n";
     $this->debug("Variable data: " . json_encode($varData) . "\n");
     if (!empty($wikiId)) {
         $wikiIds = [$wikiId];
     } else {
         if (!empty($file)) {
             $wikiIds = file($file);
         } else {
             die("Error: wiki id is empty or the file is invalid.\n");
         }
     }
     // get valid value
     if ($set) {
         if ($varValue == 'true') {
             $varValue = true;
         } else {
             if ($varValue == 'false') {
                 $varValue = false;
             } else {
                 if (is_numeric($varValue)) {
                     $varValue = intval($varValue);
                 }
             }
         }
     }
     $wg = F::app()->wg;
     $wg->User = User::newFromName('WikiaBot');
     $wg->User->load();
     $cnt = 0;
     $total = count($wikiIds);
     foreach ($wikiIds as $id) {
         $cnt++;
         $id = trim($id);
         echo "Wiki {$id} [{$cnt} of {$total}]: ";
         $status = true;
         if ($set) {
             echo "Set {$this->varName} to " . var_export($varValue, true);
             $status = $this->setVariable($id, $varValue);
         } else {
             if ($remove) {
                 echo "Remove {$this->varName}";
                 $status = $this->removeVariableFromWiki($id, $varData);
             } else {
                 echo $this->varName . " = " . var_export(WikiFactory::getVarValueByName($this->varName, $id), true);
             }
         }
         if ($this->dryRun || $status) {
             echo " ... DONE.\n";
             $this->success++;
         } else {
             echo " ... FAILED.\n";
         }
     }
     echo "\nTotal wikis: {$total}, Success: {$this->success}, Failed: " . ($total - $this->success) . "\n\n";
 }
示例#21
0
 private static function allowResultsForEditedArticles($row, $from_db = false)
 {
     global $wgTTCache;
     wfProfileIn(__METHOD__);
     $result = array();
     $memkey = wfMemcKey(__METHOD__, 'oWikia', intval($row['wikia']));
     $oWikia = $wgTTCache->get($memkey);
     if (!isset($oWikia)) {
         $allowed = true;
         /*
          * check city list
          */
         $oWikia = WikiFactory::getWikiByID($row['wikia']);
         if (!$oWikia) {
             $allowed = false;
         }
         /*
          * check city lang
          */
         if ($allowed && !in_array($oWikia->city_lang, self::$allowedLanguages)) {
             $allowed = false;
         }
         /*
          * check sitename
          */
         if ($allowed) {
             $siteName = WikiFactory::getVarByName('wgSitename', $row['wikia']);
             if (!$siteName) {
                 $allowed = false;
             }
         }
         /*
          * check wikiname
          */
         $oWikia->city_sitename = "";
         if ($allowed) {
             $oWikia->city_sitename = unserialize($siteName->cv_value);
             if (!$oWikia->city_sitename) {
                 $allowed = false;
             } else {
                 foreach (self::$excludeNames as $search) {
                     $pos = stripos($oWikia->city_sitename, $search);
                     if ($pos !== false) {
                         $allowed = false;
                     }
                 }
             }
         }
         if (!$allowed) {
             $oWikia = 'ERROR';
         }
         # set in memc
         if ($oWikia != 'ERROR') {
             $wgTTCache->set($memkey, $oWikia, 60 * 60);
         }
     }
     if ($oWikia == 'ERROR') {
         wfProfileOut(__METHOD__);
         return false;
     }
     /* check article */
     $memkey = wfMemcKey(__METHOD__, 'article', intval($row['wikia']), intval($row['page']), $oWikia->city_dbname);
     $result = $from_db === true ? null : $wgTTCache->get($memkey);
     if (!isset($result)) {
         $allowedPage = true;
         /*
          * check Title && Wiki domain
          */
         $oGTitle = GlobalTitle::newFromId($row['page'], $row['wikia'], $oWikia->city_dbname);
         if (!is_object($oGTitle)) {
             $allowedPage = false;
         }
         if ($allowedPage) {
             $wikiaUrl = $oGTitle->getServer();
             $pageUrl = $oGTitle->getFullURL();
             $articleName = $oGTitle->getArticleName();
             $oRegexCore = new TextRegexCore(self::$excludeWikiDomainsKey, 0);
             if (is_object($oRegexCore)) {
                 $allowed = $oRegexCore->isAllowedText($wikiaUrl, "", false);
                 if (!$allowed) {
                     $allowedPage = false;
                 }
             }
         }
         /*
          * check hub name
          */
         if ($allowedPage) {
             $hubName = WikiFactoryHub::getInstance()->getCategoryName($row['wikia']);
             if (in_array($hubName, self::$excludeWikiHubs)) {
                 $allowedPage = false;
             }
         }
         /*
          * check article name
          */
         if ($allowedPage) {
             $oRegexArticles = new TextRegexCore(self::$excludeWikiArticles, 0);
             if (is_object($oRegexArticles)) {
                 $filterText = sprintf("%s:%s", $oWikia->city_dbname, $articleName);
                 $allowed = $oRegexArticles->isAllowedText($filterText, "", false);
                 if (!$allowed) {
                     $allowedPage = false;
                 }
             }
         }
         if (!$allowedPage) {
             $result = 'ERROR';
         } else {
             /*
              * ok
              */
             $result = array('wikia' => $oWikia->city_sitename, 'db' => $oWikia->city_dbname, 'hub' => $hubName, 'page_name' => $articleName, 'wikia_url' => $wikiaUrl, 'page_url' => $pageUrl, 'count' => $row['count']);
             # set in memc
             $wgTTCache->set($memkey, $result, 60 * 30);
         }
     }
     if ($result == 'ERROR') {
         $result = false;
     }
     wfProfileOut(__METHOD__);
     return $result;
 }
示例#22
0
 /**
  * Finds wikis which name, domain or topic match a string optionally filtering by vertical (hub) and/or language
  *
  * @param string $string search term
  * @param mixed $hub [OPTIONAL] The name of the vertical as a string(e.g. Gaming, Entertainment,
  * Lifestyle, etc.) or it's related numeric ID 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
  * @param bool [OPTIONAL] Include the domain name in the search, defaults to false
  *
  * @return array A collection of results with id, name, hub, language, topic, domain
  */
 public function getByString($string, array $langs = null, $hub = null, $includeDomain = false)
 {
     wfProfileIn(__METHOD__);
     $wikis = [];
     if (!empty($string)) {
         $hubId = null;
         if (!empty($hub)) {
             if (is_string($hub)) {
                 //this has it's own memcache layer (24h)
                 $hubData = WikiFactoryHub::getInstance()->getCategoryByName($hub);
                 if (is_array($hubData)) {
                     $hubId = $hubData['id'];
                 }
             } elseif (is_integer($hub)) {
                 $hubId = $hub;
             }
         }
         if (empty($hub) || !empty($hub) && is_integer($hubId)) {
             $cacheKey = wfSharedMemcKey(__METHOD__, self::CACHE_VERSION, md5(strtolower($string)), $hubId, implode(',', $langs), !empty($includeDomain) ? 'includeDomain' : null);
             $wikis = $this->app->wg->Memc->get($cacheKey);
             if (!is_array($wikis)) {
                 $wikis = [];
                 $db = $this->getSharedDB();
                 $string = $db->addQuotes("%{$string}%");
                 $varId = (int) WikiFactory::getVarByName('wgWikiTopics', null)->cv_variable_id;
                 $tables = array('city_list', 'city_variables');
                 $clause = array("city_list.city_title LIKE {$string}");
                 if (!empty($includeDomain)) {
                     $clause[] = "city_list.city_url LIKE {$string}";
                 }
                 $clause[] = "city_variables.cv_value LIKE {$string}";
                 $where = array('city_list.city_public' => 1, '(' . implode(' OR ', $clause) . ')');
                 $join = array('city_variables' => array('LEFT JOIN', "city_list.city_id = city_variables.cv_city_id AND city_variables.cv_variable_id = {$varId}"));
                 if (!empty($langs)) {
                     $langs = $db->makeList($langs);
                     $where[] = 'city_list.city_lang IN (' . $langs . ')';
                 }
                 if (is_integer($hubId)) {
                     $tables[] = 'city_cat_mapping';
                     $where['city_cat_mapping.cat_id'] = $hubId;
                     $join['city_cat_mapping'] = array('LEFT JOIN', 'city_list.city_id = city_cat_mapping.city_id');
                 }
                 $rows = $db->select($tables, array('city_list.city_id', 'city_list.city_lang', 'city_list.city_title', 'city_variables.cv_value'), $where, __METHOD__, array('LIMIT' => self::MAX_WIKI_RESULTS), $join);
                 while ($row = $db->fetchObject($rows)) {
                     $wikis[] = array('id' => $row->city_id, 'name' => $row->city_title, 'hub' => !empty($hub) && is_string($hub) ? $hub : $this->getVerticalByWikiId($row->city_id), 'language' => $row->city_lang, 'topic' => !empty($row->cv_value) ? unserialize($row->cv_value) : null, 'domain' => $this->getDomainByWikiId($row->city_id));
                 }
                 $this->wg->Memc->set($cacheKey, $wikis, 43200);
             }
         }
     }
     wfProfileOut(__METHOD__);
     return $wikis;
 }
function getVEForcedValue($wikiId)
{
    $wikiFactoryVar = WikiFactory::getVarByName('wgForceVisualEditor', $wikiId);
    return is_object($wikiFactoryVar) && $wikiFactoryVar->cv_value ? unserialize($wikiFactoryVar->cv_value) : false;
}
ini_set('include_path', dirname(__FILE__) . "/../");
ini_set('display_errors', 1);
require_once "commandLine.inc";
if (isset($options['help'])) {
    die("Usage: php updateWikiFactoryVariable.php [--help] [--name=wgXyz] [--dry-run] [--remove] [--removeFromWF] [--wikiId=123] [--limit=10]\n\t--name             WikiFactory variable name\n\t--remove           remove the variable from the Wiki\n\t--removeFromWF     remove the variable from WikiFactory (delete from city_variables_pool table)\n\t--wikiId           Wiki Id\n\t--limit            limit\n\t--dry-run          dry run\n\t--help             you are reading it right now\n\n");
}
$dryRun = isset($options['dry-run']);
$varName = isset($options['name']) ? $options['name'] : '';
$wikiId = isset($options['wikiId']) ? $options['wikiId'] : '';
$remove = isset($options['remove']);
$removeFromWF = isset($options['removeFromWF']);
$limit = empty($options['limit']) ? 1000 : $options['limit'];
if (empty($varName)) {
    die("Error: Empty variable name.\n");
}
$varData = (array) WikiFactory::getVarByName($varName, false, true);
if (empty($varData['cv_id'])) {
    die("Error: {$varName} not found.\n");
}
echo "Variable: {$varName} (Id: {$varData['cv_id']})\n";
// for debugging
//echo "Variable data: ".json_encode( $varData )."\n";
$wgUser = User::newFromName('WikiaBot');
$wgUser->load();
if ($removeFromWF) {
    $wikiIds = getWikiIds($varData['cv_id'], 1);
    if (empty($wikiIds)) {
        echo "\tRemove {$varName} from WikiFactory";
        if ($dryRun) {
            $status = Status::newGood();
        } else {
 public static function isAnswersWiki($wikiId = null)
 {
     // If the current wiki, just return the global where its already loaded
     if (empty($wikiId) || $wikiId == F::app()->wg->CityId) {
         return !empty(F::app()->wg->EnableAnswers);
     }
     // Otherwise, pull the value from the DB for the wiki given
     $var = WikiFactory::getVarByName('wgEnableAnswers', $wikiId);
     if (empty($var)) {
         return false;
     }
     return unserialize($var->cv_value);
 }
    /**
     * Figure out what articles include this file from any wiki
     */
    public function getGlobalUsage()
    {
        wfProfileIn(__METHOD__);
        if (empty($this->wg->EnableGlobalUsageExt)) {
            $this->summary = array();
            wfProfileOut(__METHOD__);
            return;
        }
        $fileTitle = $this->getVal('fileTitle', '');
        $titleObj = empty($fileTitle) ? $this->wg->Title : Title::newFromText($fileTitle);
        $memcKey = $this->getMemcKeyGlobalUsage($titleObj->getDBkey());
        $globalUsage = $this->wg->Memc->get($memcKey);
        if (!is_array($globalUsage)) {
            // Query the global usage table to see where the current File title is used
            $db = wfGetDB(DB_SLAVE, array(), $this->wg->GlobalUsageDatabase);
            $gilTo = $db->addQuotes($titleObj->getDBkey());
            $wiki = $db->addQuotes($this->wg->DBname);
            // The 'limit' parameter is used by both usage methods we forward to as a way to limit
            // the number of rows returned.  This is a safeguard against extreme cases
            $limit = self::LIMIT_GLOBAL_USAGE;
            $sql = <<<SQL
\t\t\t\tSELECT *
\t\t\t\tFROM (
\t\t\t\t\tSELECT  *
\t\t\t\t\tFROM `globalimagelinks`
\t\t\t\t\tWHERE gil_to = {$gilTo} AND gil_wiki != {$wiki}
\t\t\t\t\tORDER BY gil_wiki, gil_page_namespace_id
\t\t\t\t\tLIMIT 1000
\t\t\t\t) s
\t\t\t\tGROUP BY gil_wiki
\t\t\t\tLIMIT {$limit}
SQL;
            $result = $db->query(trim($sql), __METHOD__);
            // We need to make sure $globalUsage is an array. If the query below returns no rows, $globalUsage
            // ends up being null due to it's initial assignment of $globalUsage = $this->wg->Memc->get( $memcKey );
            $globalUsage = array();
            while ($row = $db->fetchObject($result)) {
                // Don't show private wikis in the list of global usage for a video
                $wikiId = WikiFactory::DBtoID($row->gil_wiki);
                $isPrivate = WikiFactory::getVarByName('wgIsPrivateWiki', $wikiId)->cv_value;
                // getVarByName returns a serialized value, eg 'b:1'
                $isPrivate = unserialize($isPrivate);
                if ($isPrivate) {
                    continue;
                }
                $globalUsage[$row->gil_wiki][] = ['image' => $row->gil_page_title, 'id' => $row->gil_page, 'namespace_id' => $row->gil_page_namespace_id, 'title' => $row->gil_to, 'wiki' => $row->gil_wiki];
            }
            $this->wg->Memc->set($memcKey, $globalUsage, 60 * 60);
        }
        $this->summary = $globalUsage;
        wfProfileOut(__METHOD__);
    }
 /**
  * @param int $id WikiId
  * @return string
  */
 protected function getWikiWordmarkImage($id)
 {
     $settings = WikiFactory::getVarByName(ThemeSettings::WikiFactorySettings, $id);
     $values = unserialize($settings->cv_value);
     return isset($values[self::WORDMARK_URL_SETTING]) ? $values[self::WORDMARK_URL_SETTING] : '';
 }