Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public function getDBName()
 {
     if (empty($this->dbName) and !empty($this->cityId)) {
         $this->dbName = WikiFactory::IDtoDB($this->cityId);
     }
     return $this->dbName;
 }
Exemplo n.º 3
0
 public function __construct($id = null)
 {
     parent::__construct();
     if (is_null($id)) {
         $id = $this->wg->CityId;
     }
     $this->id = $id;
     if ($this->wg->CityId == $id) {
         $this->db = wfGetDB(DB_SLAVE);
         $this->dbname = $this->wg->DBname;
     } else {
         // find db name
         $dbname = WikiFactory::IDtoDB($this->id);
         if (empty($dbname)) {
             throw new Exception("Could not find wiki with ID {$this->id}");
         }
         // open db connection (and check if db really exists)
         $db = wfGetDB(DB_SLAVE, array(), $dbname);
         if (!is_object($db)) {
             throw new Exception("Could not connect to wiki database {$dbname}");
         }
         $this->db = $db;
         $this->dbname = $dbname;
     }
 }
Exemplo n.º 4
0
 public function execute()
 {
     $this->test = $this->hasOption('test') ? true : false;
     $this->verbose = $this->hasOption('verbose') ? true : false;
     $this->clear = $this->hasOption('clear') ? true : false;
     $this->refresh = $this->hasOption('refresh') ? true : false;
     if ($this->test) {
         echo "== TEST MODE ==\n";
     }
     $this->debug("(debugging output enabled)\n");
     $startTime = time();
     // Clear existing suggestions if we are forcing a rebuild
     if ($this->clear) {
         $this->clearSuggestions();
     }
     $this->processVideoList();
     $delta = $this->formatDuration(time() - $startTime);
     $stats = $this->usageStats();
     $wgDBName = WikiFactory::IDtoDB($_ENV['SERVER_ID']);
     echo "[{$wgDBName}] Finished in {$delta}.\n";
     echo "[{$wgDBName}] Usage Stats: Total videos before swapping videos=" . ($stats['totalVids'] + $stats['swapTypes'][2] + $stats['swapTypes'][3]) . ", ";
     echo "Total videos=" . $stats['totalVids'] . " (Videos with suggestions=" . $stats['vidsWithSuggestions'] . "), ";
     echo "Total suggestions=" . $stats['numSuggestions'] . ", Avg per video=" . sprintf("%.1f", $stats['avgSuggestions']) . ", ";
     echo "Total kept videos=" . $stats['swapTypes'][1] . ", Total swapped videos=" . ($stats['swapTypes'][2] + $stats['swapTypes'][3]) . " (Exact title=" . $stats['swapTypes'][3] . ")\n";
 }
Exemplo n.º 5
0
 /**
  * @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;
 }
Exemplo n.º 6
0
 /**
  * Lazy-loads file meta data from another wiki
  */
 private function loadData()
 {
     if (!isset($this->mData)) {
         $dbname = WikiFactory::IDtoDB($this->mTitle->mCityId);
         $dbr = wfGetDB(DB_SLAVE, array(), $dbname);
         $this->mData = $dbr->selectRow('image', ['img_width', 'img_height', 'img_timestamp', 'img_major_mime', 'img_minor_mime'], ['img_name' => $this->mTitle->getDBkey()], __METHOD__);
     }
 }
 /**
  * Clears the local watchlist tables for a given user.
  * @param int $userID
  */
 public function clearLocalWatchlists($userID)
 {
     $wikiIDs = $this->getWikisWithWatchedPagesForUser($userID);
     foreach ($wikiIDs as $wikiID) {
         $db = wfGetDB(DB_MASTER, [], WikiFactory::IDtoDB($wikiID));
         (new WikiaSQL())->UPDATE('watchlist')->SET('wl_notificationtimestamp', null)->WHERE('wl_user')->EQUAL_TO($userID)->run($db);
     }
 }
Exemplo n.º 8
0
 public static function getImageOriginalUrl($wikiId, $pageId)
 {
     $app = F::app();
     $app->wf->ProfileIn(__METHOD__);
     $dbname = WikiFactory::IDtoDB($wikiId);
     $title = GlobalTitle::newFromId($pageId, $wikiId);
     $param = array('action' => 'query', 'prop' => 'imageinfo', 'iiprop' => 'url', 'titles' => $title->getPrefixedText());
     $response = ApiService::foreignCall($dbname, $param);
     $app->wf->ProfileOut(__METHOD__);
     return array('src' => $imageSrc, 'page' => $imagePage);
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
0
 public function execute()
 {
     $this->dryRun = $this->hasOption('dry-run');
     $this->verbose = $this->hasOption('verbose');
     $wikiId = $this->getOption('wikiId', '');
     if (empty($wikiId)) {
         die("Error: Empty wiki id.\n");
     }
     $dbname = WikiFactory::IDtoDB($wikiId);
     if (empty($dbname)) {
         die("Error: Cannot find dbname.\n");
     }
     $pageLimit = 20000;
     $totalLimit = $this->getOption('limit', $pageLimit);
     if (empty($totalLimit) || $totalLimit < -1) {
         die("Error: invalid limit.\n");
     }
     if ($totalLimit == -1) {
         $totalLimit = $this->getTotalPages($dbname);
     }
     $maxSet = ceil($totalLimit / $pageLimit);
     $limit = $totalLimit > $pageLimit ? $pageLimit : $totalLimit;
     $totalPages = 0;
     for ($set = 1; $set <= $maxSet; $set++) {
         $cnt = 0;
         if ($set == $maxSet) {
             $limit = $totalLimit - $pageLimit * ($set - 1);
         }
         $offset = ($set - 1) * $pageLimit;
         $pages = $this->getAllPages($dbname, $limit, $offset);
         $total = count($pages);
         foreach ($pages as $page) {
             $cnt++;
             echo "Wiki {$wikiId} - Page {$page['id']} [{$cnt} of {$total}, set {$set} of {$maxSet}]: ";
             $title = GlobalTitle::newFromId($page['id'], $wikiId);
             if ($title instanceof GlobalTitle) {
                 $url = $title->getFullURL();
                 echo "{$url}\n";
                 if (!$this->dryRun) {
                     SquidUpdate::purge([$url]);
                 }
                 $this->success++;
             } else {
                 echo "ERROR: Cannot find global title for {$page['title']}\n";
             }
         }
         $totalPages = $totalPages + $total;
     }
     echo "\nWiki {$wikiId}: Total pages: {$totalPages}, Success: {$this->success}, Failed: " . ($totalPages - $this->success) . "\n\n";
 }
 public static function getCityLink($cityId)
 {
     global $wgCityId, $wgSitename;
     $domains = WikiFactory::getDomains($cityId);
     if ($wgCityId == $cityId) {
         // Hack based on the fact we should only ask for current wiki's sitename
         $text = $wgSitename;
     } else {
         // The fallback to return anything
         $text = "[" . WikiFactory::IDtoDB($cityId) . ":{$cityId}]";
     }
     if (!empty($domains)) {
         $text = Xml::tags('a', array("href" => "http://" . $domains[0]), $text);
     }
     return $text;
 }
Exemplo n.º 12
0
 public function emailFollowNotifications($initiatingUser, $aWatchers, $iUserId, $iNamespace, $sMessage, $sAction)
 {
     $wg = F::app()->wg;
     $wg->DBname = WikiFactory::IDtoDB($this->getWikiId());
     $wg->Server = trim(WikiFactory::DBtoUrl(F::app()->wg->DBname), '/');
     if (!empty($wg->DevelEnvironment)) {
         $wg->Server = WikiFactory::getLocalEnvURL($wg->Server);
     }
     $wg->User = User::newFromId($initiatingUser);
     $targetUser = User::newFromId($iUserId);
     $this->logWatchers($aWatchers, $sAction);
     foreach ($aWatchers as $sKey => $sValue) {
         $oTitle = Title::makeTitle($iNamespace, $sKey);
         $oEmailNotification = new EmailNotification($targetUser, $oTitle, wfTimestampNow(), $sMessage, false, $currentRevId = 0, $previousRevId = 0, $sAction, ['notisnull' => 1, 'childTitle' => $this->title]);
         $oEmailNotification->notifyOnPageChange();
     }
 }
Exemplo n.º 13
0
 public function getArticleDetails($wikiId, $articleId, $url)
 {
     $domain = WikiFactory::DBtoUrl(WikiFactory::IDtoDB($wikiId));
     //TODO: REFACTOR THE HACK
     if ($domain) {
         $callUrl = sprintf('%sapi/v1/Articles/Details?ids=%u', $domain, $articleId);
         $details = Http::get($callUrl);
         if (empty($details)) {
             $details = file_get_contents($callUrl);
         }
         $data = json_decode($details);
         if ($data) {
             return $data;
         }
         return false;
     }
     return false;
 }
Exemplo n.º 14
0
 public static function getImageOriginalUrl($wikiId, $pageId)
 {
     wfProfileIn(__METHOD__);
     $dbname = WikiFactory::IDtoDB($wikiId);
     $title = GlobalTitle::newFromId($pageId, $wikiId);
     $param = array('action' => 'query', 'prop' => 'imageinfo', 'iiprop' => 'url', 'titles' => $title->getPrefixedText());
     $imagePage = $title->getFullUrl();
     $response = ApiService::foreignCall($dbname, $param, ApiService::API, true);
     if (!empty($response['query']['pages'])) {
         $imagePageData = array_shift($response['query']['pages']);
         $imageInfo = array_shift($imagePageData['imageinfo']);
         $imageSrc = empty($imageInfo['url']) ? '' : $imageInfo['url'];
     } else {
         $imageSrc = '';
     }
     wfProfileOut(__METHOD__);
     return array('src' => $imageSrc, 'page' => $imagePage);
 }
 function getRecentAdminEdits($fromWikiId = null, $toWikiId = null)
 {
     global $wgStatsDB, $wgStatsDBEnabled;
     $recentAdminEdit = array();
     if (!empty($wgStatsDBEnabled) && !empty($fromWikiId) && !empty($toWikiId)) {
         $dbrStats = wfGetDB(DB_SLAVE, array(), $wgStatsDB);
         //get wikis with edits < 1000 and admins not active in last 45 days
         //260000 = ID of wiki created on 2011-05-01 so it will work for wikis created after this project has been deployed
         $res = $dbrStats->query('select e1.wiki_id, sum(e1.edits) as sum_edits from specials.events_local_users e1 ' . 'where e1.wiki_id > ' . $fromWikiId . ' and e1.wiki_id <= ' . $toWikiId . ' ' . 'group by e1.wiki_id ' . 'having sum_edits < 1000 and (' . 'select count(0) from specials.events_local_users e2 ' . 'where e1.wiki_id = e2.wiki_id and ' . 'all_groups like "%sysop%" and ' . 'editdate > now() - interval 45 day ' . ') = 0', __METHOD__);
         while ($row = $dbrStats->fetchObject($res)) {
             $wikiDbname = WikiFactory::IDtoDB($row->wiki_id);
             if ($wikiDbname === false) {
                 //check if wiki exists in city_list
                 continue;
             }
             if (WikiFactory::isPublic($row->wiki_id) === false) {
                 //check if wiki is closed
                 continue;
             }
             if (self::isFlagSet($row->wiki_id, WikiFactory::FLAG_ADOPTABLE)) {
                 // check if adoptable flag is set
                 continue;
             }
             $res2 = $dbrStats->query("select user_id, max(editdate) as lastedit from specials.events_local_users where wiki_id = {$row->wiki_id} and all_groups like '%sysop%' group by 1 order by null;", __METHOD__);
             $recentAdminEdit[$row->wiki_id] = array('recentEdit' => time(), 'admins' => array());
             while ($row2 = $dbrStats->fetchObject($res2)) {
                 if (($lastedit = wfTimestamp(TS_UNIX, $row2->lastedit)) < $recentAdminEdit[$row->wiki_id]['recentEdit']) {
                     $recentAdminEdit[$row->wiki_id]['recentEdit'] = $lastedit;
                 } else {
                     if ($row2->lastedit == '0000-00-00 00:00:00') {
                         // use city_created if no lastedit
                         $wiki = WikiFactory::getWikiByID($row->wiki_id);
                         if (!empty($wiki)) {
                             $recentAdminEdit[$row->wiki_id]['recentEdit'] = wfTimestamp(TS_UNIX, $wiki->city_created);
                         }
                     }
                 }
                 $recentAdminEdit[$row->wiki_id]['admins'][] = $row2->user_id;
             }
         }
     }
     return $recentAdminEdit;
 }
Exemplo n.º 16
0
 /**
  * Main code block
  */
 public function execute()
 {
     $this->test = $this->hasOption('test');
     $this->verbose = $this->hasOption('verbose');
     $start = time();
     if ($this->test) {
         echo "*** TEST MODE ***\n";
     }
     $dbname = WikiFactory::IDtoDB(F::app()->wg->CityId);
     echo "Checking wiki: {$dbname}\n";
     // Set the user to WikiaBot for methods that need $wgUser
     global $wgUser;
     $wgUser = User::newFromName('WikiaBot');
     $pages = $this->getPages();
     foreach ($pages as $pageId) {
         $this->updatePage($pageId);
     }
     $elapsed = time() - $start;
     echo "Done: {$elapsed} s\n";
 }
Exemplo n.º 17
0
 protected function evaluate()
 {
     $this->messages = array();
     $this->status = false;
     // find db name
     $dbname = WikiFactory::IDtoDB($this->id);
     if (empty($dbname)) {
         $this->messages[] = "Wiki could not be found by ID: {$this->id}";
         return;
     }
     // open db connection (and check if db really exists)
     $db = wfGetDB(DB_SLAVE, array(), $dbname);
     if (!is_object($db)) {
         $this->messages[] = "Wiki db could not be opened: {$dbname}";
         return;
     }
     $this->db = $db;
     $this->doEvaluate();
     $this->status = empty($this->messages);
 }
Exemplo n.º 18
0
 public function execute()
 {
     global $top100WikisBySize;
     $wikis = $this->getOption("wikiIds", $top100WikisBySize);
     if (is_string($wikis)) {
         $wikis = explode(',', $wikis);
     }
     $linkSuggestVersions = $this->getVersionsToTest();
     foreach ($wikis as $wikiId) {
         $db = WikiFactory::IDtoDB($wikiId);
         if (empty($db)) {
             continue;
         }
         foreach ($this->getQueriesToTest() as $query) {
             foreach ($linkSuggestVersions as $linkSuggestVersion) {
                 $time = $linkSuggestVersion->performQueryTest($wikiId, $query);
                 echo implode(";", [$db, $linkSuggestVersion->getKey(), $query, $time]) . "\n";
                 usleep(300000);
             }
         }
     }
 }
Exemplo n.º 19
0
 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;
 }
Exemplo n.º 20
0
 protected function getContentUrl($wikiId, $articleId)
 {
     return $this->getEpisodeService()->replaceHostUrl(WikiFactory::DBtoUrl(WikiFactory::IDtoDB($wikiId)) . EpisodeEntitySearchService::API_URL . $articleId);
 }
Exemplo n.º 21
0
function SharedHelpWantedPagesSql(&$page, &$sql)
{
    global $wgHelpWikiId, $wgMemc;
    wfProfileIn(__METHOD__);
    $helpPages = "";
    $helpdb = WikiFactory::IDtoDB($wgHelpWikiId);
    if ($helpdb) {
        $helpPagesKey = wfSharedMemcKey('helppages', $helpdb);
        $helpArticles = $wgMemc->get($helpPagesKey);
        if (empty($helpArticles)) {
            $dbr = wfGetDB(DB_SLAVE, array(), $helpdb);
            $oRes = $dbr->select('page', 'page_title, page_namespace', array('page_namespace' => NS_HELP), __METHOD__);
            $helpArticles = array();
            while ($oRow = $dbr->fetchObject($oRes)) {
                $helpArticles[] = $oRow->page_title;
            }
            $helpPages = $dbr->makeList($helpArticles);
            $wgMemc->set($helpPagesKey, $helpPages, 12 * 60 * 60);
        } else {
            $helpPages = $helpArticles;
        }
    }
    $notInHelpPages = '';
    if (!empty($helpPages)) {
        $notInHelpPages = " OR pl_title NOT IN (" . $helpPages . ") ";
    }
    $excludedNamespaces = array(NS_MEDIAWIKI);
    if (defined('NS_BLOG_ARTICLE')) {
        $excludedNamespaces[] = NS_BLOG_ARTICLE;
        $excludedNamespaces[] = NS_BLOG_ARTICLE_TALK;
    }
    if (!empty($excludedNamespaces)) {
        $sql['conds'][] = ' pl_namespace NOT IN ( ' . implode(',', $excludedNamespaces) . ' ) ';
    }
    $sql['conds'][] = " ( pl_namespace != 12 {$notInHelpPages} ) ";
    wfProfileOut(__METHOD__);
    return true;
}
                $val = '<abbr class="cant_print" title="cant display, use edit link">' . $var->cv_variable_type . '</abbr>';
                $combined[$item->cv_id]['_'] = false;
        }
        if ($val === null) {
            $val = '<abbr title="===null"><i>null</i></abbr>';
        }
        $combined[$item->cv_id][$side] = $val;
    }
}
ksort($combined);
print "<table class='WikiaTable'>\n";
print "<tr>\n";
print "<th colspan=2>name</th>\n";
print "<th colspan=2>" . WikiFactory::IDtoDB($wiki->city_id) . "</th>\n";
if ($to) {
    print "<th colspan=2>" . WikiFactory::IDtoDB($to) . "</th>\n";
}
print "</tr>\n";
global $wgServer;
$WF_base = Title::newFromText('WikiFactory', NS_SPECIAL)->getLocalURL();
$wfURL_L = $WF_base . "/{$vars['L']['city']}/variables/";
if ($to) {
    $wfURL_R = $WF_base . "/{$vars['R']['city']}/variables/";
}
$blankImg = wfBlankImgUrl();
$editSprite = "<img src='{$blankImg}' class='sprite edit-pencil' alt='Edit'>";
$findSprite = "<img src='{$blankImg}' class='sprite details' alt='Find more'>";
$WF_find = Title::newFromText('WikiFactoryReporter', NS_SPECIAL)->getLocalURL();
foreach ($combined as $var_id => $var) {
    /* var has:
    		* => the name
Exemplo n.º 23
0
 /**
  * Processes specific local wiki database and makes all needed changes for an IP address
  *
  * Important: should only be run within maintenace script (bound to specified wiki)
  */
 public function updateLocalIP()
 {
     global $wgCityId, $wgUser;
     wfProfileIn(__METHOD__);
     if ($this->mUserId !== 0 || !IP::isIPAddress($this->mOldUsername) || !IP::isIPAddress($this->mNewUsername)) {
         $this->addError(wfMessage('userrenametool-error-invalid-ip')->escaped());
         wfProfileOut(__METHOD__);
         return;
     }
     $wgOldUser = $wgUser;
     $wgUser = User::newFromName('Wikia');
     $cityDb = WikiFactory::IDtoDB($wgCityId);
     $this->addLog("Processing wiki database: {$cityDb}.");
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     $tasks = self::$mLocalIpDefaults;
     $hookName = 'UserRename::LocalIP';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, [$dbw, $this->mUserId, $this->mOldUsername, $this->mNewUsername, $this, $wgCityId, &$tasks]);
     foreach ($tasks as $task) {
         $this->addLog("Updating wiki \"{$cityDb}\": {$task['table']}:{$task['username_column']}");
         $this->renameInTable($dbw, $task['table'], $this->mUserId, $this->mOldUsername, $this->mNewUsername, $task);
     }
     $hookName = 'UserRename::AfterLocalIP';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, [$dbw, $this->mUserId, $this->mOldUsername, $this->mNewUsername, $this, $wgCityId, &$tasks]);
     $dbw->commit();
     $this->addLog("Finished updating wiki database: {$cityDb}");
     $this->addMainLog("log", RenameUserLogFormatter::wiki($this->mRequestorName, $this->mOldUsername, $this->mNewUsername, $wgCityId, $this->mReason, !empty($this->warnings) || !empty($this->errors)));
     $wgUser = $wgOldUser;
     wfProfileOut(__METHOD__);
 }
Exemplo n.º 24
0
function SharedHelpWantedPagesSql($page, $sql)
{
    global $wgWantedPagesThreshold;
    global $wgHelpWikiId, $wgMemc;
    wfProfileIn(__METHOD__);
    $count = $wgWantedPagesThreshold - 1;
    $type = 'Wantedpages';
    $helpPages = "";
    $helpdb = WikiFactory::IDtoDB($wgHelpWikiId);
    if ($helpdb) {
        $helpPagesKey = "helppages:{$helpdb}";
        $helpArticles = $wgMemc->get($helpPagesKey);
        if (empty($helpArticles)) {
            $dbr = wfGetDB(DB_SLAVE, array(), $helpdb);
            $oRes = $dbr->select('page', 'page_title, page_namespace', array('page_namespace' => NS_HELP, 'page_is_redirect' => 0), __METHOD__);
            $helpArticles = array();
            while ($oRow = $dbr->fetchObject($oRes)) {
                $helpArticles[] = $oRow->page_title;
            }
            $helpPages = $dbr->makeList($helpArticles);
            $wgMemc->set($helpPagesKey, $helpPages, 12 * 60 * 60);
        } else {
            $helpPages = $helpArticles;
        }
    }
    $notInHelpPages = "";
    if (!empty($helpPages)) {
        $notInHelpPages = " OR pl_title NOT IN (" . $helpPages . ") ";
    }
    $blogNamespaces = "";
    if (defined('NS_BLOG_ARTICLE')) {
        $blogNamespaces = implode(",", array(NS_BLOG_ARTICLE, NS_BLOG_ARTICLE_TALK));
        $sql['conds'][] = " pl_namespace NOT IN ( {$blogNamespaces} ) ";
    }
    $sql['conds'][] = " ( pl_namespace != 12 {$notInHelpPages} ) ";
    wfProfileOut(__METHOD__);
    return true;
}
Exemplo n.º 25
0
    return $result;
}
if ($help) {
    echo <<<TEXT
Usage:
    php testArchiveData.php --help
    php testArchiveData.php [--limit=N]

    --help         : This help message
    --limit=N      : Number of records to check
TEXT;
    exit(0);
} else {
    $start = time();
    $wikia = $wgCityId;
    $records = getEventsRecords($wikia, $limit);
    $res = array('ok' => 0, 'error' => 0);
    echo "Found " . count($records) . " \n";
    foreach ($records as $id => $oRow) {
        $dbname = WikiFactory::IDtoDB($oRow->wiki_id);
        if ($dbname) {
            $result = compareEventRecordWithRevision($dbname, $oRow, $debug);
            $key = $result === false ? 'error' : 'ok';
            $res[$key]++;
        }
    }
    $end = time();
    echo "\n\nScript finished after: " . time_duration($end - $start) . " \n";
    echo "Result: ok:" . $res['ok'] . ", err:" . $res['error'] . " \n";
}
echo "end \n";
 public static function onAbuseFilterEnabled($varName, $wikiId, $value)
 {
     wfProfileIn(__METHOD__);
     if ($varName == 'wgEnableAbuseFilterExtension' && $value == true) {
         global $wgDBtype;
         $dir = dirname(__FILE__) . '/../../AbuseFilter';
         $dbName = WikiFactory::IDtoDB($wikiId);
         $dbw = wfGetDB(DB_MASTER, 'wikifactory', $dbName);
         //not really interested in the Postgres variant, add the case if needed (take a look at onLoadExtensionSchemaUpdates)
         if ($wgDBtype == 'mysql') {
             $sqlSources = array("{$dir}/abusefilter.tables.sql", "{$dir}/db_patches/patch-abuse_filter_history.sql", "{$dir}/db_patches/patch-afh_changed_fields.sql", "{$dir}/db_patches/patch-af_deleted.sql", "{$dir}/db_patches/patch-af_actions.sql");
             foreach ($sqlSources as $path) {
                 Wikia::log(__METHOD__, null, "Running {$path} on {$dbName} database", true);
                 try {
                     $error = $dbw->sourceFile($path);
                     if ($error !== true) {
                         Wikia::log(__METHOD__, null, "Error running {$path}: {$error}", true);
                     }
                     $dbw->commit();
                 } catch (Exception $e) {
                     Wikia::log(__METHOD__, null, "Error running {$path}: {$e->getMessage()}", true);
                 }
             }
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
Exemplo n.º 27
0
 /**
  * check if page exists
  *
  * @return int 0/1
  */
 public function exists()
 {
     $this->loadAll();
     if (!is_null($this->mExists)) {
         return $this->mExists;
     }
     if (WikiFactory::isPublic($this->mCityId)) {
         $dbName = WikiFactory::IDtoDB($this->mCityId);
         $dbr = wfGetDB(DB_SLAVE, array(), $dbName);
         $oRow = $dbr->selectRow(array('page'), array('page_id'), array('page_title' => $this->mText, 'page_namespace' => $this->mNamespace), __METHOD__);
         $this->mExists = intval($oRow ? $oRow->page_id > 0 : 0);
     } else {
         $this->mExists = 0;
     }
     return $this->mExists;
 }
Exemplo n.º 28
0
 public function getUserEdits($cityID, $day = null)
 {
     wfProfileIn(__METHOD__);
     $userEdits = array();
     $today = empty($day) ? date('Ymd', strtotime('-1 day')) : str_replace("-", "", $day);
     $dbname = WikiFactory::IDtoDB($cityID);
     if (empty($dbname)) {
         wfProfileOut(__METHOD__);
         return 0;
     }
     $db = wfGetDB(DB_SLAVE, 'vslow', $dbname);
     $oRes = $db->select(array('revision'), array('rev_user', 'min(rev_timestamp) as min_ts'), array('rev_user > 0'), __METHOD__, array('GROUP BY' => 'rev_user', 'HAVING' => "min(rev_timestamp)" . $db->buildLike($today, $db->anyString())));
     while ($oRow = $db->fetchObject($oRes)) {
         $userEdits[$oRow->rev_user] = $oRow->min_ts;
     }
     $db->freeResult($oRes);
     wfProfileOut(__METHOD__);
     return $userEdits;
 }
Exemplo n.º 29
0
 /**
  * Get timestamp of last (most recent) user's contribution on specified wiki.
  * @since Nov 2013
  * @author Kamil Koterba
  *
  * @param $wikiId Integer Id of wiki - specifies wiki from which to get editcount, 0 for current wiki
  * @return String Timestamp in format YmdHis e.g. 20131107192200 or null
  */
 private function getLastContributionTimestamp($wikiId = 0)
 {
     wfProfileIn(__METHOD__);
     $dbName = $wikiId == 0 ? false : WikiFactory::IDtoDB($wikiId);
     /* Get lastContributionTimestamp from database */
     $dbr = $this->getWikiDB(DB_SLAVE, $dbName);
     $res = $dbr->selectRow('revision', array('max(rev_timestamp) AS lastContributionTimestamp'), array('rev_user' => $this->userId), __METHOD__);
     $lastContributionTimestamp = null;
     if (!empty($res)) {
         $lastContributionTimestamp = $res->lastContributionTimestamp;
     }
     wfProfileOut(__METHOD__);
     return $lastContributionTimestamp;
 }
Exemplo n.º 30
0
 /**
  * dumpSQL
  *
  * dump database as SQL file
  *
  * @access private
  * @author eloy@wikia
  *
  * @return void
  */
 private function dumpSQL()
 {
     global $wgWikiaLocalSettingsPath;
     $iWikiID = $this->mParams["source_wikia_id"];
     $sDBName = WikiFactory::IDtoDB($iWikiID);
     $sTaskDirectory = $this->getTaskDirectory();
     $sDumpFile = sprintf("%s/dump.sql.bz2", $sTaskDirectory);
 }