function getPathPrefix() { $wikiDbName = $this->repo->getDBName(); $wikiId = WikiFactory::DBtoID($wikiDbName); $wikiUploadPath = WikiFactory::getVarValueByName('wgUploadPath', $wikiId); return VignetteRequest::parsePathPrefix($wikiUploadPath); }
public function getCityId() { if (empty($this->cityId) and !empty($this->dbName)) { $this->cityId = WikiFactory::DBtoID($this->dbName); } return $this->cityId; }
public function setDBname($dbname = '') { if ($dbname) { $this->mDBname = $this->__getDBname($dbname); $this->mWikiID = WikiFactory::DBtoID($this->mDBname); $this->mWikia = WikiFactory::getWikiByID($this->mWikiID); } }
/** * Get wiki ID by its db name * * @param $dbName string Database name * @return int Wiki ID (or null) */ protected function getCityIdByDbName($dbName) { $id = null; if ($dbName === 'c') { $id = self::COMMUNITY_WIKI_ID; } if ($id === null) { $id = WikiFactory::DBtoID($dbName); } return $id; }
/** * 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, '/'); }
/** * Get wiki ID by its db name * * @param $dbName string Database name * @return int Wiki ID (or null) */ protected static function getCityIdByDbName($dbName) { wfProfileIn(__METHOD__); $id = null; if ($dbName === 'c') { $id = self::COMMUNITY_WIKI_ID; } if ($id === null) { $id = WikiFactory::DBtoID($dbName); } wfProfileOut(__METHOD__); return $id; }
/** * 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; }
/** * Returns given blog post data * * @param string $dbname database name * @param string $title page title * @param boolean $getSnippet include blog post snippet in the data * @return mixed blog post data */ private function getBlogPostData($dbname, $title, $getSnippet = false) { wfProfileIn(__METHOD__); wfDebug(__METHOD__ . ": '{$title}' ({$dbname})\n"); $cityId = WikiFactory::DBtoID($dbname); // get blog info $data = ApiService::foreignCall($dbname, array('action' => 'query', 'prop' => 'revisions', 'titles' => $title, 'rvprop' => 'timestamp|user|content')); $blogPostData = reset($data['query']['pages']); $revisionData = array_shift($blogPostData['revisions']); // page ID $pageId = intval($blogPostData['pageid']); // parse blog post wikitext and get summary if ($getSnippet === true) { $data = ApiService::foreignCall($dbname, array('action' => 'parse', 'text' => $revisionData['*'], 'title' => $title)); $snippet = $this->getSnippet($data['parse']['text']['*']); } // generate full URL to blog post $blogPostTitle = F::build('GlobalTitle', array($pageId, $cityId), 'newFromId'); if (empty($blogPostTitle)) { wfProfileOut(__METHOD__); return false; } $blogPostUrl = $blogPostTitle->getFullURL(); // get blog post title $title = end(explode('/', $blogPostTitle->getText(), 2)); // get creator real name $creator = F::build('User', array($revisionData['user']), 'newFromName'); if (!empty($creator)) { $creatorName = $creator->getRealName(); if ($creatorName == '') { $creatorName = $creator->getName(); } } else { $creatorName = $revisionData['user']; } // get creator user page URL $blogCreatorPageTitle = F::build('GlobalTitle', array($revisionData['user'], NS_USER, $cityId), 'newFromText'); // get 220x140 image $imageData = ApiService::foreignCall($dbname, array('action' => 'imagecrop', 'imgId' => $pageId, 'imgSize' => 220, 'imgHeight' => 140)); // data $res = array('pageId' => $pageId, 'cityId' => $cityId, 'wikiname' => WikiFactory::getVarValueByName('wgSitename', $cityId), 'wikiUrl' => 'http://' . parse_url($blogPostUrl, PHP_URL_HOST), 'title' => $title, 'url' => $blogPostUrl, 'created' => $revisionData['timestamp'], 'creator' => $creatorName, 'creatorUrl' => $blogCreatorPageTitle->getFullURL(), 'snippet' => !empty($snippet) ? $snippet : false, 'image' => $imageData['image']['imagecrop']); wfProfileOut(__METHOD__); return $res; }
/** * constructor * If email and password are empty, will use the default preferred account from ' * * @access public */ public function __construct($email, $pass, $wiki = null) { global $wgGoogleWebToolsAccts; // If email and password weren't specified, use the preferred account. if (empty($email) && empty($pass)) { if (is_array($wgGoogleWebToolsAccts)) { foreach ($wgGoogleWebToolsAccts as $acctEmail => $acctData) { if (isset($acctData['preferred']) && $acctData['preferred'] == 1) { $email = $acctEmail; $pass = $acctData['pass']; break; } } // If no preferred email/pass was found, just grab the first one if (empty($email) && empty($pass) && count($wgGoogleWebToolsAccts) > 0) { $keys = array_keys($wgGoogleWebToolsAccts); $email = $keys[0]; $pass = isset($wgGoogleWebToolsAccts[$email]['pass']) ? $wgGoogleWebToolsAccts[$email]['pass'] : ""; } } } $this->mEmail = $email; $this->mPass = $pass; $this->mType = 'GOOGLE'; $this->mSource = 'WIKIA'; $this->mService = 'sitemaps'; if ($wiki != null) { if (!is_object($wiki)) { if (is_string($wiki)) { $wiki = WikiFactory::DBtoID($wiki); } $wikiId = WikiFactory::getWikiByID($wiki); if (!$wikiId) { throw new Exception("Could not find wiki by ID (id=" . $wiki . ")."); } $wiki = $wikiId; } $this->mWiki = $wiki; $this->mSiteURI = $this->make_site_uri(); } $this->mAuth = $this->getAuthToken(); }
foreach ($dbl as $dbname) { $DB[] = $dbname; } } }; $invalidDB = array(); $loop = 0; $flags = array(WikiFactory::FLAG_DELETE_DB_IMAGES, WikiFactory::FLAG_FREE_WIKI_URL, WikiFactory::FLAG_HIDE_DB_IMAGES); if ( !empty($DB) ) { $city_flags = 0; foreach ($flags as $flag) { $city_flags |= $flag; } foreach ($DB as $dbname) { $db = wfGetDB(DB_SLAVE, array(), $dbname); if (!$db->tableExists('revision')) { $city_id = WikiFactory::DBtoID($dbname); $sql = "update city_list set city_public = ". WikiFactory::HIDE_ACTION .", city_flags = {$city_flags} where city_id = {$city_id}"; if ( isset($options['dryrun'])) { echo $sql . ";\n"; } else { # $db_wiki->query($sql); } $loop++; } } } echo "Found $loop invalid wikis\n";
/** * get starter data for current parameters * * @access private * @author Krzysztof Krzyżaniak (eloy) * * @return mixed -- array if there's starter, false otherwise */ private function getStarter() { wfProfileIn(__METHOD__); $result = false; /** * determine database name, set default match */ $dbStarter = $this->mStarters["*"]["*"]; switch ($this->mType) { case "answers": $dbStarter = $this->mStarters["answers"]["*"]; if (isset($this->mStarters["answers"][$this->mWikiData["language"]])) { $dbStarter = $this->mStarters["answers"][$this->mWikiData["language"]]; } break; default: if (isset($this->mStarters["*"][$this->mWikiData["language"]])) { $dbStarter = $this->mStarters["*"][$this->mWikiData["language"]]; } } /** * determine if exists */ try { $dbr = wfGetDB(DB_SLAVE, array(), $dbStarter); /** * read info about connection */ $result = $dbr->getLBInfo(); /** * get UploadDirectory */ $result["dbStarter"] = $dbStarter; $result["uploadDir"] = WikiFactory::getVarValueByName("wgUploadDirectory", WikiFactory::DBtoID($dbStarter)); $this->log("starter {$dbStarter} exists"); } catch (DBConnectionError $e) { /** * well, it means that starter doesn't exists */ $this->log("starter {$dbStarter} does not exists"); } wfProfileOut(__METHOD__); return $result; }
function getExclusionList() { global $wgLookupContribsExcluded; wfProfileIn(__METHOD__); $result = array(); /* grumble grumble _precautions_ cough */ if (!isset($wgLookupContribsExcluded) || !is_array($wgLookupContribsExcluded) || empty($wgLookupContribsExcluded)) { wfProfileOut(__METHOD__); return array(); } $result[] = 0; foreach ($wgLookupContribsExcluded as $excluded) { $result[] = intval(WikiFactory::DBtoID($excluded)); } wfProfileOut(__METHOD__); return $result; }
<?php $to = null; global $wgRequest; $byid = $wgRequest->getInt('id', ''); $bydb = $wgRequest->getText('db', ''); $byurl = $wgRequest->getText('url', ''); Wikia::log('WikiFactory', 'compare', 'byid=' . $byid); Wikia::log('WikiFactory', 'compare', 'bydb=' . $bydb); Wikia::log('WikiFactory', 'compare', 'byurl=' . $byurl); if (!empty($byid) && $byid > 0) { Wikia::log('WikiFactory', 'compare', 'detected a byid, using it'); $to = (int) $byid; } elseif (!empty($bydb)) { Wikia::log('WikiFactory', 'compare', 'detected a bydb, using it'); $to = WikiFactory::DBtoID($bydb); Wikia::log('WikiFactory', 'compare', 'DBtoID says:' . $to); if ($to == false) { Wikia::log('WikiFactory', 'compare', 'found false, failing'); $to = null; } } elseif (!empty($byurl)) { Wikia::log('WikiFactory', 'compare', 'detected a byurl, using it'); if (strpos($byurl, '.') == false) { Wikia::log('WikiFactory', 'compare', 'no . found in input, adding .wikia.com'); #no $byurl .= '.wikia.com'; } $to = WikiFactory::DomainToID($byurl); Wikia::log('WikiFactory', 'compare', 'DomainToID says:' . $to); if ($to == false) {
/** * @desc Returns an array with correct elements from given api results * * @param array $postData results from API call with request of posts (articles) list in a category * * @return array */ private function prepareCssUpdateData($postData) { $cssUpdatePost = []; $communityWikiId = WikiFactory::DBtoID($this->getCommunityDbName()); $blogTitle = GlobalTitle::newFromText($postData['title'], NS_MAIN, $communityWikiId); $blogTitleText = $blogTitle->getText(); $lastRevisionUser = isset($postData['revisions'][0]['user']) ? $postData['revisions'][0]['user'] : null; $timestamp = isset($postData['revisions'][0]['timestamp']) ? $postData['revisions'][0]['timestamp'] : null; $blogUser = $this->getUserFromTitleText($blogTitleText, $lastRevisionUser); $userPage = GlobalTitle::newFromText($blogUser, NS_USER, $communityWikiId); if (!is_null($lastRevisionUser) && !is_null($timestamp) && $blogTitle instanceof GlobalTitle && $userPage instanceof GlobalTitle) { // $postData['revisions'][0]['*'] is being checked in SpecialCssModel::filterRevisionsData() // which is called before this method $sectionText = $postData['revisions'][0]['*']; $cssUpdateText = $this->truncateAndParseLinks($this->getCssUpdateSection($sectionText)); $cssUpdatePost = ['title' => $this->getAfterLastSlashText($blogTitleText), 'url' => $this->appendHeadlineAnchor($blogTitle->getFullURL()), 'userAvatar' => AvatarService::renderAvatar($blogUser, 25), 'userUrl' => $userPage->getFullUrl(), 'userName' => $blogUser, 'timestamp' => $timestamp, 'text' => $cssUpdateText]; } return $cssUpdatePost; }
/** * doMassTag * * data is stored in: * $this->mMassTag * $this->mMassTagWikis * * @access private * @author uberfuzzy@wikia-inc.com * @note yes, i know this is HORRIBLY ineffecient, but I was going for RAD, not clean. */ private function doMassTag() { wfProfileIn(__METHOD__); $this->mMassTagWikis = explode("\n", $this->mMassTagWikis); global $wgOut; $msg = false; $added = 0; foreach ($this->mMassTagWikis as $dart_string) { if (empty($dart_string)) { continue; } $dart_parts = explode("/", $dart_string); if (count($dart_parts) < 2) { continue; } $db = ltrim($dart_parts[1], '_'); $wkid = WikiFactory::DBtoID($db); // $wgOut->addHTML("id={$wkid}<br/>"); #debug $added++; $oTag = new WikiFactoryTags($wkid); $oTag->addTagsByName($this->mMassTag); #$oTag->clearCache(); } $oTQ = new WikiFactoryTagsQuery(''); // no tag, because we're just using it to uncache $oTQ->clearCache(); $msg = "Added '{$this->mMassTag}' to {$added} wikis"; wfProfileOut(__METHOD__); return Wikia::successbox($msg); }
/** * Get full url from dbname * @param string $fileTitle * @param string $dbName * @return string $fullUrl */ public static function getFullUrlFromDBName($fileTitle, $dbName) { $wikiId = WikiFactory::DBtoID($dbName); $globalTitle = GlobalTitle::newFromText($fileTitle, NS_FILE, $wikiId); $fullUrl = $globalTitle->getFullURL(); return $fullUrl; }
/** * @method load * * load and setup configuration before actual moving * and checking * * @author eloy@wikia * @access public * * @return nothing */ public function load() { global $wgContLang; if ($this->mDataLoaded) { return; } wfProfileIn(__METHOD__); $this->mDataLoaded = true; switch ($this->mFrom) { case "id": $this->mSourceName = WikiFactory::IDtoDB($this->mSourceID, true); $this->mTargetName = WikiFactory::IDtoDB($this->mTargetID, true); break; case "name": if ($this->mType === "external") { #--- # mType === external means that we move from temporary # database, it's external import, we don't have id # for that database in city_list $this->mSourceID = WikiFactory::DBtoID($this->mSourceName); } #--- but target wiki have to be created before task anyway $this->mTargetID = WikiFactory::DBtoID($this->mTargetName); break; } /** * get some configurations data from source and target database * NOTE: this should be handled in another way in WikiMover External * because it use temporary database and doesn't have configuration * stored in wikicities database. So you have to provide proper values * in constructor params */ if ($this->mType === "external") { $this->mSourceMetaSpace = $this->mParams("wgMetaNamespace"); $this->mSourceUploadDirectory = $this->mParams("wgUploadDirectory"); } else { #--- source wgMetaNamespace $this->mSourceMetaSpace = WikiFactory::getVarValueByName("wgMetaNamespace", $this->mSourceID); if (empty($this->mSourceMetaSpace)) { $this->mSourceMetaSpace = str_replace(' ', '_', WikiFactory::getVarValueByName("wgSitename", $this->mSourceID)); } if (empty($this->mSourceMetaSpace)) { $this->mSourceMetaSpace = $wgContLang->ucfirst($this->mSourceName); } #--- source path for images $this->mSourceUploadDirectory = WikiFactory::getVarValueByName("wgUploadDirectory", $this->mSourceID); } #--- target path for images $this->mTargetUploadDirectory = WikiFactory::getVarValueByName("wgUploadDirectory", $this->mTargetID); /** * table "text" could be in old format (three fields instead eleven) */ $dbTarget = wfGetDB(DB_MASTER, array(), $this->mTargetName); $oRes = $dbTarget->query(sprintf("SHOW COLUMNS FROM %s", $this->targetTable("text"))); while ($oRow = $dbTarget->fetchObject($oRes)) { $this->mTargetTextFields[] = $oRow->Field; } $dbTarget->freeResult($oRes); wfProfileOut(__METHOD__); }
/** * importStarter * * get starter data for current parameters * * @author Krzysztof Krzyzaniak <*****@*****.**> * @author Piotr Molski <*****@*****.**> * @access private * */ private function importStarter() { global $wgDBadminuser, $wgDBadminpassword, $wgWikiaLocalSettingsPath; if ($this->mType && isset($this->mStarters[$this->mType])) { $dbStarter = isset($this->mStarters[$this->mType][$this->mNewWiki->language]) ? $this->mStarters[$this->mType][$this->mNewWiki->language] : $this->mStarters[$this->mType]["*"]; } else { $dbStarter = isset($this->mStarters["*"][$this->mNewWiki->language]) ? $this->mStarters["*"][$this->mNewWiki->language] : $this->mStarters["*"]["*"]; } /** * determine if exists */ $starter = null; try { $dbr = wfGetDB(DB_SLAVE, array(), $dbStarter); /** * read info about connection */ $starter = $dbr->getLBInfo(); /** * get UploadDirectory */ $starter["dbStarter"] = $dbStarter; $starter["uploadDir"] = WikiFactory::getVarValueByName("wgUploadDirectory", WikiFactory::DBtoID($dbStarter)); // BugId:15644 - I need to pass this to CreateWikiLocalJob::changeStarterContributions $this->sDbStarter = $dbStarter; wfDebugLog("createwiki", __METHOD__ . ": starter {$dbStarter} exists\n", true); } catch (DBConnectionError $e) { /** * well, it means that starter doesn't exists */ wfDebugLog("createwiki", __METHOD__ . ": starter {$dbStarter} doesn't exist\n", true); } if ($starter) { $tables = $this->mStarterTables["*"]; if ($this->mType && isset($this->mStarterTables[$this->mType])) { $tables = array_merge($tables, $this->mStarterTables[$this->mType]); } $cmd = sprintf("%s -h%s -u%s -p%s %s %s | %s -h%s -u%s -p%s %s", $this->mMYSQLdump, $starter["host"], $starter["user"], $starter["password"], $starter["dbStarter"], implode(" ", $tables), $this->mMYSQLbin, $this->mNewWiki->dbw->getLBInfo('host'), $wgDBadminuser, $wgDBadminpassword, $this->mNewWiki->dbname); wfShellExec($cmd); wfDebugLog("createwiki", __METHOD__ . ": Import {$this->mIP}/maintenance/cleanupStarter.sql \n", true); $error = $this->mNewWiki->dbw->sourceFile("{$this->mIP}/maintenance/cleanupStarter.sql"); if ($error !== true) { wfDebugLog("createwiki", __METHOD__ . ": Import starter failed\n", true); return false; } /** * @todo move copying images from local database changes section * use wikifactory variable to determine proper path to images */ $startupImages = $starter["uploadDir"]; if (file_exists($startupImages) && is_dir($startupImages)) { wfShellExec("/bin/cp -af {$startupImages}/* {$this->mNewWiki->images_dir}/"); wfDebugLog("createwiki", __METHOD__ . ": /bin/cp -af {$startupImages}/* {$this->mNewWiki->images_dir}/ \n", true); } $cmd = sprintf("SERVER_ID=%d %s %s/maintenance/updateArticleCount.php --update --conf %s", $this->mNewWiki->city_id, $this->mPHPbin, $this->mIP, $wgWikiaLocalSettingsPath); wfShellExec($cmd); wfDebugLog("createwiki", __METHOD__ . ": Starter database copied \n", true); } return true; }
public function execute() { $this->test = $this->hasOption('test'); $this->verbose = $this->hasOption('verbose'); $this->file = $this->getOption('file', ''); $this->dbname = $this->getOption('dbname', ''); $this->set = $this->hasOption('set'); $this->get = $this->hasOption('get'); if ($this->hasOption('enable')) { $this->enabled = true; } if ($this->hasOption('disable')) { $this->enabled = false; } if ($this->test) { echo "\n=== TEST MODE ===\n"; } // Shouldn't happen ... paranoid programming if (!$this->set && !$this->get) { $this->get = true; } if ($this->file) { echo "Reading from " . $this->file . " ...\n"; $dbnames = file($this->file); } else { if ($this->dbname) { $dbnames = [$this->dbname]; } else { echo "ERROR: List file empty or not readable. Please provide a line-by-line list of wikis.\n"; echo "USAGE: php EnableVideosModule.php /path/to/file\n"; exit; } } foreach ($dbnames as $db) { $db = trim($db); echo "Running on {$db} ...\n"; // get wiki ID $id = WikiFactory::DBtoID($db); if (empty($id)) { echo "\t{$db}: ERROR (not found in WikiFactory)\n"; continue; } else { $this->debug("\tWiki ID ({$db}): {$id}"); } if ($id == 177) { echo "\tDefaulted to community, not likely a valid wiki, skipping...\n"; continue; } if ($this->set) { if (!$this->test) { $this->debug("\tSetting ... wgEnableVideosModuleExt"); WikiFactory::setVarByName('wgEnableVideosModuleExt', $id, $this->enabled); WikiFactory::clearCache($id); $this->debug("\tdone"); } } else { if ($this->get) { $enabled = WikiFactory::getVarByName('wgEnableVideosModuleExt', $id); $enabled = $enabled->cv_value; $enabled = $enabled ? unserialize($enabled) : false; if ($enabled) { echo "\tEnabled\n"; } else { echo "\tDisabled\n"; } } } } }
private function getTopEditUsers() { global $wgDBname, $wgCityId, $wgStatsDBEnabled; if (empty($wgStatsDBEnabled)) { return false; } #--- blank variables $nspace = $user = null; #--- initial parameters (dbname, limit, offset ...) extract($this->getInitialParams()); #--- request parameters () extract($this->extractRequestParams()); $this->initCacheKey($lcache_key, __METHOD__); try { #--- database instance $db = $this->getDB(); if (is_null($db)) { throw new WikiaApiQueryError(0); } $cid = empty($wgCityId) ? WikiFactory::DBtoID($wgDBname) : $wgCityId; $this->addTables(array("events_local_users")); $this->addFields(array('user_id', 'user_name', 'edits')); $this->addWhere("user_id > 0 and user_is_blocked = 0 and user_is_closed = 0"); if (!empty($cid)) { $this->addWhere("wiki_id = {$cid}"); } #--- user if (!is_null($user)) { if (!$this->isInt($user)) { throw new WikiaApiQueryError(1); } $this->setCacheKey($lcache_key, 'U', $user); $this->addWhere("user_id = '" . intval($user) . "'"); } #--- if (!empty($ctime)) { if (!$this->isInt($ctime)) { throw new WikiaApiQueryError(1); } } #--- limit if (!empty($limit)) { //WikiaApiQuery::DEF_LIMIT if (!$this->isInt($limit)) { throw new WikiaApiQueryError(1); } $this->addOption("LIMIT", $limit); $this->setCacheKey($lcache_key, 'L', $limit); } #--- offset if (!empty($offset)) { //WikiaApiQuery::DEF_LIMIT_COUNT if (!$this->isInt($offset)) { throw new WikiaApiQueryError(1); } $this->addOption("OFFSET", $offset); $this->setCacheKey($lcache_key, 'LO', $limit); } #--- order by $this->addOption("ORDER BY", "edits DESC"); $data = array(); // check data from cache ... $cached = $this->getDataFromCache($lcache_key); if (!is_array($cached)) { $res = $this->select(__METHOD__); while ($row = $db->fetchObject($res)) { $data[$row->user_id] = array("user_id" => $row->user_id, "cnt" => $row->edits, "user_name" => $row->user_name); ApiResult::setContent($data[$row->user_id], $row->user_name); } $db->freeResult($res); $this->saveCacheData($lcache_key, $data, $ctime); } else { // ... cached $data = $cached; } } catch (WikiaApiQueryError $e) { // getText(); } catch (DBQueryError $e) { $e = new WikiaApiQueryError(0, 'Query error: ' . $e->getText()); } catch (DBConnectionError $e) { $e = new WikiaApiQueryError(0, 'DB connection error: ' . $e->getText()); } catch (DBError $e) { $e = new WikiaApiQueryError(0, 'Error in database: ' . $e->getLogMessage()); } // is exception if (isset($e)) { $data = $e->getText(); $this->getResult()->setIndexedTagName($data, 'fault'); } else { $this->getResult()->setIndexedTagName($data, 'item'); } $this->getResult()->addValue('query', $this->getModuleName(), $data); }
/** * run backup for range of wikis */ function runBackups($from, $to, $full, $options) { global $IP, $wgWikiaLocalSettingsPath, $wgWikiaAdminSettingsPath, $wgMaxShellTime, $wgMaxShellFileSize, $wgDumpsDisabledWikis; $range = array(); /** * shortcut for full & current together */ $both = isset($options["both"]); /** * store backup in another folder, not available for users */ $hide = isset($options["hide"]); /** * store backup in the system tmp dir */ $use_temp = isset($options['tmp']); /** * send backup to Amazon S3 and delete the local copy */ $s3 = isset($options['s3']); /** * silly trick, if we have id defined we are defining $from & $to from it * if we have db param defined we first resolve which id is connected to this * database */ if (isset($options["db"]) && is_string($options["db"])) { $city_id = WikiFactory::DBtoID($options["db"]); if ($city_id) { $from = $to = $city_id; $to++; } } elseif (isset($options["id"]) && is_numeric($options["id"])) { $from = $to = $options["id"]; $to++; } elseif (isset($options["even"])) { $range[] = "city_id % 2 = 0"; $range[] = "city_public = 1"; } elseif (isset($options["odd"])) { $range[] = "city_id % 2 <> 0"; $range[] = "city_public = 1"; } else { /** * if all only for active */ $range[] = "city_public = 1"; } /** * exclude wikis with dumps disabled */ if (!empty($wgDumpsDisabledWikis) && is_array($wgDumpsDisabledWikis)) { $range[] = 'city_id NOT IN (' . implode(',', $wgDumpsDisabledWikis) . ')'; } /** * switch off limits for dumps */ $wgMaxShellTime = 0; $wgMaxShellFileSize = 0; if ($from !== false && $to !== false) { $range[] = sprintf("city_id >= %d AND city_id < %d", $from, $to); Wikia::log(__METHOD__, "info", "Running from {$from} to {$to}", true, true); } else { Wikia::log(__METHOD__, "info", "Running for all wikis", true, true); } $dbw = Wikifactory::db(DB_MASTER); $sth = $dbw->select(array("city_list"), array("city_id", "city_dbname"), $range, __METHOD__, array("ORDER BY" => "city_id")); while ($row = $dbw->fetchObject($sth)) { /** * get cluster for this wiki */ $cluster = WikiFactory::getVarValueByName("wgDBcluster", $row->city_id); $server = wfGetDB(DB_SLAVE, 'dumps', $row->city_dbname)->getProperty("mServer"); /** * build command */ $status = false; $basedir = getDirectory($row->city_dbname, $hide, $use_temp); if ($full || $both) { $path = sprintf("%s/%s_pages_full.xml.7z", $basedir, $row->city_dbname); $time = wfTime(); Wikia::log(__METHOD__, "info", "{$row->city_id} {$row->city_dbname} {$path}", true, true); $cmd = array("SERVER_ID={$row->city_id}", "php", "{$IP}/maintenance/dumpBackup.php", "--conf {$wgWikiaLocalSettingsPath}", "--aconf {$wgWikiaAdminSettingsPath}", "--full", "--xml", "--quiet", "--server={$server}", "--output=" . DumpsOnDemand::DEFAULT_COMPRESSION_FORMAT . ":{$path}"); wfShellExec(implode(" ", $cmd), $status); $time = Wikia::timeDuration(wfTime() - $time); Wikia::log(__METHOD__, "info", "{$row->city_id} {$row->city_dbname} status: {$status}, time: {$time}", true, true); if ($s3 && 0 == DumpsOnDemand::putToAmazonS3($path, !$hide, MimeMagic::singleton()->guessMimeType($path))) { unlink($path); } } if (!$full || $both) { $path = sprintf("%s/%s_pages_current.xml.7z", $basedir, $row->city_dbname); $time = wfTime(); Wikia::log(__METHOD__, "info", "{$row->city_id} {$row->city_dbname} {$path}", true, true); $cmd = array("SERVER_ID={$row->city_id}", "php", "{$IP}/maintenance/dumpBackup.php", "--conf {$wgWikiaLocalSettingsPath}", "--aconf {$wgWikiaAdminSettingsPath}", "--current", "--xml", "--quiet", "--server={$server}", "--output=" . DumpsOnDemand::DEFAULT_COMPRESSION_FORMAT . ":{$path}"); wfShellExec(implode(" ", $cmd), $status); $time = Wikia::timeDuration(wfTime() - $time); Wikia::log(__METHOD__, "info", "{$row->city_id} {$row->city_dbname} status: {$status}, time: {$time}", true, true); if ($s3 && 0 == DumpsOnDemand::putToAmazonS3($path, !$hide, MimeMagic::singleton()->guessMimeType($path))) { unlink($path); } } } }
/** * 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__); }
/** * run backup for range of wikis */ function runBackups($from, $to, $full, $options) { global $IP, $wgWikiaLocalSettingsPath, $wgWikiaAdminSettingsPath, $wgMaxShellTime, $wgMaxShellFileSize, $wgDumpsDisabledWikis; $range = array(); /** * shortcut for full & current together */ $both = isset($options["both"]) ? true : false; /** * store backup in another folder, not available for users */ $hide = isset($options["hide"]) ? true : false; /** * silly trick, if we have id defined we are defining $from & $to from it * if we have db param defined we first resolve which id is connected to this * database */ if (isset($options["db"]) && is_string($options["db"])) { $city_id = WikiFactory::DBtoID($options["db"]); if ($city_id) { $from = $to = $city_id; $to++; } } elseif (isset($options["id"]) && is_numeric($options["id"])) { $from = $to = $options["id"]; $to++; } elseif (isset($options["even"])) { $range[] = "city_id % 2 = 0"; $range[] = "city_public = 1"; } elseif (isset($options["odd"])) { $range[] = "city_id % 2 <> 0"; $range[] = "city_public = 1"; } else { /** * if all only for active */ $range[] = "city_public = 1"; } /** * exclude wikis with dumps disabled */ if (!empty($wgDumpsDisabledWikis) && is_array($wgDumpsDisabledWikis)) { $range[] = 'city_id NOT IN (' . implode(',', $wgDumpsDisabledWikis) . ')'; } /** * switch off limits for dumps */ $wgMaxShellTime = 0; $wgMaxShellFileSize = 0; if ($from !== false && $to !== false) { $range[] = sprintf("city_id >= %d AND city_id < %d", $from, $to); Wikia::log(__METHOD__, "info", "Running from {$from} to {$to}", true, true); } else { Wikia::log(__METHOD__, "info", "Running for all wikis", true, true); } $dbw = Wikifactory::db(DB_MASTER); $sth = $dbw->select(array("city_list"), array("city_id", "city_dbname"), $range, __METHOD__, array("ORDER BY" => "city_id")); while ($row = $dbw->fetchObject($sth)) { /** * get cluster for this wiki */ $cluster = WikiFactory::getVarValueByName("wgDBcluster", $row->city_id); $server = wfGetDB(DB_SLAVE, 'dumps', $row->city_dbname)->getProperty("mServer"); /** * build command */ $status = false; $basedir = getDirectory($row->city_dbname, $hide); if ($full || $both) { $path = sprintf("%s/pages_full.xml.gz", $basedir); $time = wfTime(); Wikia::log(__METHOD__, "info", "{$row->city_id} {$row->city_dbname} {$path}", true, true); $cmd = array("SERVER_ID={$row->city_id}", "php", "{$IP}/maintenance/dumpBackup.php", "--conf {$wgWikiaLocalSettingsPath}", "--aconf {$wgWikiaAdminSettingsPath}", "--full", "--xml", "--quiet", "--server={$server}", "--output=gzip:{$path}"); wfShellExec(implode(" ", $cmd), $status); $time = Wikia::timeDuration(wfTime() - $time); Wikia::log(__METHOD__, "info", "{$row->city_id} {$row->city_dbname} status: {$status}, time: {$time}", true, true); } if (!$full || $both) { $path = sprintf("%s/pages_current.xml.gz", $basedir); $time = wfTime(); Wikia::log(__METHOD__, "info", "{$row->city_id} {$row->city_dbname} {$path}", true, true); $cmd = array("SERVER_ID={$row->city_id}", "php", "{$IP}/maintenance/dumpBackup.php", "--conf {$wgWikiaLocalSettingsPath}", "--aconf {$wgWikiaAdminSettingsPath}", "--current", "--xml", "--quiet", "--server={$server}", "--output=gzip:{$path}"); wfShellExec(implode(" ", $cmd), $status); $time = Wikia::timeDuration(wfTime() - $time); Wikia::log(__METHOD__, "info", "{$row->city_id} {$row->city_dbname} status: {$status}, time: {$time}", true, true); } /** * generate index.json */ $jsonfile = sprintf("%s/index.json", $basedir); $json = array(); /** * open dir and read info about files */ if (is_dir($basedir)) { $dh = opendir($basedir); while (($file = readdir($dh)) !== false) { $fullpath = $basedir . "/" . $file; if (is_file($fullpath)) { $json[$file] = array("name" => $file, "timestamp" => filectime($fullpath), "mwtimestamp" => wfTimestamp(TS_MW, filectime($fullpath))); } } closedir($dh); } if (count($json)) { file_put_contents($jsonfile, json_encode($json)); } } }
function isClosed($dbname) { wfProfileIn(__METHOD__); $res = false; $cityId = WikiFactory::DBtoID($dbname, true); if (!empty($cityId)) { $oRow = WikiFactory::getWikiByID($cityId); if ($oRow->city_public == 0) { $this->closedWiki = $oRow; $res = true; } } wfProfileOut(__METHOD__); return $res; }