/** * Common function for databases that don't understand the MySQLish syntax of interwiki.sql. * * @return Status */ public function populateInterwikiTable() { $status = $this->getConnection(); if (!$status->isOK()) { return $status; } $this->db->selectDB($this->getVar('wgDBname')); if ($this->db->selectRow('interwiki', '*', array(), __METHOD__)) { $status->warning('config-install-interwiki-exists'); return $status; } global $IP; wfSuppressWarnings(); $rows = file("{$IP}/maintenance/interwiki.list", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); wfRestoreWarnings(); $interwikis = array(); if (!$rows) { return Status::newFatal('config-install-interwiki-list'); } foreach ($rows as $row) { $row = preg_replace('/^\\s*([^#]*?)\\s*(#.*)?$/', '\\1', $row); // strip comments - whee if ($row == "") { continue; } $row .= "||"; $interwikis[] = array_combine(array('iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid'), explode('|', $row)); } $this->db->insert('interwiki', $interwikis, __METHOD__); return Status::newGood(); }
/** * fixTemplate * * This code ensures that the version of the Template that was in existence * at the same time as the Memento gets loaded and displayed with the * Memento. * * @fixme make this compatible with parser cache * @param Title $title * @param Parser $parser * @param integer $id * * @return array containing the text, finalTitle, and deps */ public function fixTemplate(Title $title, Parser $parser, &$id) { // stopgap measure until we can find a better way // to work with parser cache $parser->disableCache(); $request = $parser->getUser()->getRequest(); if ($request->getHeader('ACCEPT-DATETIME')) { $requestDatetime = $request->getHeader('ACCEPT-DATETIME'); $mwMementoTimestamp = $this->parseRequestDateTime($requestDatetime); $firstRev = $title->getFirstRevision(); // if the template no longer exists, return gracefully if ($firstRev != null) { if ($firstRev->getTimestamp() < $mwMementoTimestamp) { $pgID = $title->getArticleID(); $this->db->begin(); $res = $this->db->selectRow('revision', array('rev_id'), array('rev_page' => $pgID, 'rev_timestamp <=' . $this->db->addQuotes($mwMementoTimestamp)), __METHOD__, array('ORDER BY' => 'rev_id DESC', 'LIMIT' => '1')); $id = $res->rev_id; } else { // if we get something prior to the first memento, just // go with the first one $id = $firstRev->getId(); } } } }
/** * @since 2.2 * * @param integer $propertyId * * @return integer */ public function getUsageCount($propertyId) { if (!is_int($propertyId)) { return 0; } $row = $this->dbConnection->selectRow($this->table, array('usage_count'), array('p_id' => $propertyId), __METHOD__); return $row !== false ? (int) $row->usage_count : 0; }
function checkMissingImage($fullpath) { $filename = wfBaseName($fullpath); $row = $this->dbw->selectRow('image', array('img_name'), array('img_name' => $filename), __METHOD__); if (!$row) { // file not registered $this->addMissingImage($filename, $fullpath); } }
/** * May throw a database error if, say, the server dies during query. * @param DatabaseBase $db * @param int $id The old_id * @return string */ private function doGetText($db, $id) { $id = intval($id); $row = $db->selectRow('text', ['old_text', 'old_flags'], ['old_id' => $id], __METHOD__); $text = Revision::getRevisionText($row); if ($text === false) { return false; } return $text; }
/** * @param $cond array * @return bool */ private function initFromCond($cond) { global $wgExternalAuthConf; $this->mDb = DatabaseBase::factory($wgExternalAuthConf['DBtype'], array('host' => $wgExternalAuthConf['DBserver'], 'user' => $wgExternalAuthConf['DBuser'], 'password' => $wgExternalAuthConf['DBpassword'], 'dbname' => $wgExternalAuthConf['DBname'], 'tablePrefix' => $wgExternalAuthConf['DBprefix'])); $row = $this->mDb->selectRow('user', array('user_name', 'user_id', 'user_password', 'user_email', 'user_email_authenticated'), $cond, __METHOD__); if (!$row) { return false; } $this->mRow = $row; return true; }
/** * May throw a database error if, say, the server dies during query. * @param $id * @return bool|string */ private function getTextDb($id) { global $wgContLang; $row = $this->db->selectRow('text', array('old_text', 'old_flags'), array('old_id' => $id), __METHOD__); $text = Revision::getRevisionText($row); if ($text === false) { return false; } $stripped = str_replace("\r", "", $text); $normalized = $wgContLang->normalize($stripped); return $normalized; }
/** * Check the site_stats table is not properly populated. */ protected function checkStats() { $this->output("...site_stats is populated..."); $row = $this->db->selectRow('site_stats', '*', array('ss_row_id' => 1), __METHOD__); if ($row === false) { $this->output("data is missing! rebuilding...\n"); } elseif (isset($row->site_stats) && $row->ss_total_pages == -1) { $this->output("missing ss_total_pages, rebuilding...\n"); } else { $this->output("done.\n"); return; } SiteStatsInit::doAllAndCommit($this->db); }
/** * May throw a database error if, say, the server dies during query. * @param int $id * @return bool|string * @throws MWException */ private function getTextDb($id) { global $wgContLang; if (!isset($this->db)) { throw new MWException(__METHOD__ . "No database available"); } $row = $this->db->selectRow('text', array('old_text', 'old_flags'), array('old_id' => $id), __METHOD__); $text = Revision::getRevisionText($row); if ($text === false) { return false; } $stripped = str_replace("\r", "", $text); $normalized = $wgContLang->normalize($stripped); return $normalized; }
function checkMissingImage($fullpath) { $filename = wfBaseName($fullpath); if (is_dir($fullpath)) { return; } if (is_link($fullpath)) { $this->output("skipping symlink at {$fullpath}\n"); return; } $row = $this->dbw->selectRow('image', array('img_name'), array('img_name' => $filename), __METHOD__); if ($row) { // already known, move on return; } else { $this->addMissingImage($filename, $fullpath); } }
/** * Updates an existing unit. If the unit already had a version for the current number, * it will be updated, otherwise a new one will be created. * * @since 0.1 * * @param $unit * @param $unitValues Array * @param $versionValues Array * @param $dbr DatabaseBase */ protected static function updateUnit($unit, array $unitValues, array $versionValues, DatabaseBase $dbr) { $dbw = wfGetDB(DB_MASTER); $versionValues['version_unit_id'] = $unit->unit_id; // Query for existing versions of this unit with the same version number. $version = $dbr->selectRow('distribution_unit_versions', array('version_id'), array('unit_id' => $unit->unit_id, 'version_nr' => $unitValues['current_version_nr'])); // If this version does not exist yet, create it. if ($version == false) { $versionValues['version_nr'] = $unitValues['current_version_nr']; $dbw->insert('distribution_unit_versions', $versionValues); $unitValues['unit_current'] = $dbw->insertId(); } else { // If the version already exists, update it. $dbw->update('distribution_unit_versions', $versionValues, array('version_id' => $version->version_id)); $unitValues['unit_current'] = $version->version_id; } // Update the unit so it points to the correct version. $dbw->update('distribution_units', $unitValues, array('unit_id' => $unit->unit_id)); }
function selectRow($table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array()) { if (is_array($conds)) { $conds = $this->wrapConditionsForWhere($table, $conds); } return parent::selectRow($table, $vars, $conds, $fname, $options, $join_conds); }
/** * @brief auxiliary method for getting hidden pages/wikis from db * * @param DatabaseBase $dbHandler * * @author ADi * @return array */ private function getHiddenFromDb($dbHandler) { wfProfileIn(__METHOD__); $result = false; if (!$this->user->isAnon()) { $row = $dbHandler->selectRow(array('page_wikia_props'), array('props'), array('page_id' => $this->user->getId(), 'propname' => self::PAGE_WIKIA_PROPS_PROPNAME), __METHOD__, array()); if (!empty($row)) { $result = unserialize($row->props); } $result = empty($result) ? array() : $result; } wfProfileOut(__METHOD__); return $result; }
/** * Add cache information to concept data and make sure that there is * exactly one value for the concept table. * * @note This code will vanish when concepts have a more standard * handling. So not point in optimizing this much now. * * @since 1.8 * @param integer $sid * @param &array $insertData * @param DatabaseBase $dbr used for reading only */ private function prepareConceptTableInserts($sid, &$insertData, DatabaseBase $dbr) { // Make sure that there is exactly one row to be written: if (array_key_exists('smw_fpt_conc', $insertData) && !empty($insertData['smw_fpt_conc'])) { $insertValues = end($insertData['smw_fpt_conc']); } else { $insertValues = array('concept_txt' => '', 'concept_docu' => '', 'concept_features' => 0, 'concept_size' => -1, 'concept_depth' => -1); } // Add existing cache status data to this row: $row = $dbr->selectRow('smw_fpt_conc', array('cache_date', 'cache_count'), array('s_id' => $sid), 'SMWSQLStoreQueries::updateConcData'); if ($row === false) { $insertValues['cache_date'] = null; $insertValues['cache_count'] = null; } else { $insertValues['cache_date'] = $row->cache_date; $insertValues['cache_count'] = $row->cache_count; } $insertValueKey = self::makeDatabaseRowKey($insertValues); $insertData['smw_fpt_conc'] = array($insertValueKey => $insertValues); }
protected function getCurrentRenameCount(DatabaseBase $dbw) { $row = $dbw->selectRow(array('renameuser_status'), array('COUNT(*) as count'), array(), __METHOD__); return (int) $row->count; }
/** * If the given revision is newer than the currently set page_latest, * update the page record. Otherwise, do nothing. * * @deprecated since 1.24, use updateRevisionOn instead * * @param DatabaseBase $dbw * @param Revision $revision * @return bool */ public function updateIfNewerOn($dbw, $revision) { $row = $dbw->selectRow(array('revision', 'page'), array('rev_id', 'rev_timestamp', 'page_is_redirect'), array('page_id' => $this->getId(), 'page_latest=rev_id'), __METHOD__); if ($row) { if (wfTimestamp(TS_MW, $row->rev_timestamp) >= $revision->getTimestamp()) { return false; } $prev = $row->rev_id; $lastRevIsRedirect = (bool) $row->page_is_redirect; } else { // No or missing previous revision; mark the page as new $prev = 0; $lastRevIsRedirect = null; } $ret = $this->updateRevisionOn($dbw, $revision, $prev, $lastRevIsRedirect); return $ret; }
function selectRow($table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array()) { global $wgContLang; if ($conds != null) { $conds2 = array(); $conds = !is_array($conds) ? array($conds) : $conds; foreach ($conds as $col => $val) { $col_info = $this->fieldInfoMulti($table, $col); $col_type = $col_info != false ? $col_info->type() : 'CONSTANT'; if ($col_type == 'CLOB') { $conds2['TO_CHAR(' . $col . ')'] = $wgContLang->checkTitleEncoding($val); } elseif ($col_type == 'VARCHAR2' && !mb_check_encoding($val)) { $conds2[$col] = $wgContLang->checkTitleEncoding($val); } else { $conds2[$col] = $val; } } return parent::selectRow($table, $vars, $conds2, $fname, $options, $join_conds); } else { return parent::selectRow($table, $vars, $conds, $fname, $options, $join_conds); } }
/** * Get count of revisions per page...not very efficient * * @param DatabaseBase $db * @param int $id Page id * @return int */ static function countByPageId($db, $id) { $row = $db->selectRow('revision', array('revCount' => 'COUNT(*)'), array('rev_page' => $id), __METHOD__); if ($row) { return $row->revCount; } return 0; }
/** * @param DatabaseBase $db * @return bool|ResultWrapper */ static function doLoad($db) { return $db->selectRow('site_stats', array('ss_row_id', 'ss_total_views', 'ss_total_edits', 'ss_good_articles', 'ss_total_pages', 'ss_users', 'ss_active_users', 'ss_images'), false, __METHOD__); }
/** * Update the usage count in the property statistics table for all * properties. This function also initialises the required entry for * all properties that have IDs in the SMW IDs table. * * @since 1.8 * @param boolean $verbose * @param DatabaseBase $dbw used for writing */ protected function refreshPropertyStatistics($verbose, $dbw) { $this->reportProgress("Updating property statistics. This may take a while.\n", $verbose); $res = $dbw->select(SMWSql3SmwIds::tableName, array('smw_id', 'smw_title'), array('smw_namespace' => SMW_NS_PROPERTY), __METHOD__); $propertyTables = SMWSQLStore3::getPropertyTables(); foreach ($res as $row) { $this->reportProgress('.', $verbose); $usageCount = 0; foreach ($propertyTables as $propertyTable) { if ($propertyTable->isFixedPropertyTable() && $propertyTable->getFixedProperty() != $row->smw_title) { // This table cannot store values for this property continue; } $propRow = $dbw->selectRow($propertyTable->getName(), 'Count(*) as count', $propertyTable->isFixedPropertyTable() ? array() : array('p_id' => $row->smw_id), __METHOD__); $usageCount += $propRow->count; } $dbw->replace(SMWSQLStore3::PROPERTY_STATISTICS_TABLE, 'p_id', array('p_id' => $row->smw_id, 'usage_count' => $usageCount), __METHOD__); } $this->reportProgress("\nUpdated statistics for {$res->numRows()} Properties.\n", $verbose); $dbw->freeResult($res); }
/** * @param DatabaseBase $dbr * @param string $fname * @return array|bool */ private function loadFieldsWithTimestamp($dbr, $fname) { $fieldMap = false; $row = $dbr->selectRow('image', $this->getLazyCacheFields('img_'), array('img_name' => $this->getName(), 'img_timestamp' => $this->getTimestamp()), $fname); if ($row) { $fieldMap = $this->unprefixRow($row, 'img_'); } else { # File may have been uploaded over in the meantime; check the old versions $row = $dbr->selectRow('oldimage', $this->getLazyCacheFields('oi_'), array('oi_name' => $this->getName(), 'oi_timestamp' => $this->getTimestamp()), $fname); if ($row) { $fieldMap = $this->unprefixRow($row, 'oi_'); } } return $fieldMap; }
function selectRow($table, $vars, $conds, $fname = __METHOD__, $options = [], $join_conds = []) { if (is_array($conds)) { $conds = $this->wrapConditionsForWhere($table, $conds); } return parent::selectRow($table, $vars, $conds, $fname, $options, $join_conds); }