/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $ids = array_map('intval', $this->ids); $live = $db->select(array('revision', 'page', 'user'), array_merge(Revision::selectFields(), Revision::selectUserFields()), array('rev_page' => $this->title->getArticleID(), 'rev_id' => $ids), __METHOD__, array('ORDER BY' => 'rev_id DESC'), array('page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond())); if ($live->numRows() >= count($ids)) { // All requested revisions are live, keeps things simple! return $live; } // Check if any requested revisions are available fully deleted. $archived = $db->select(array('archive'), Revision::selectArchiveFields(), array('ar_rev_id' => $ids), __METHOD__, array('ORDER BY' => 'ar_rev_id DESC')); if ($archived->numRows() == 0) { return $live; } elseif ($live->numRows() == 0) { return $archived; } else { // Combine the two! Whee $rows = array(); foreach ($live as $row) { $rows[$row->rev_id] = $row; } foreach ($archived as $row) { $rows[$row->ar_rev_id] = $row; } krsort($rows); return new FakeResultWrapper(array_values($rows)); } }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $ids = array_map('intval', $this->ids); $queryInfo = ['tables' => ['revision', 'user'], 'fields' => array_merge(Revision::selectFields(), Revision::selectUserFields()), 'conds' => ['rev_page' => $this->title->getArticleID(), 'rev_id' => $ids], 'options' => ['ORDER BY' => 'rev_id DESC'], 'join_conds' => ['page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond()]]; ChangeTags::modifyDisplayQuery($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], $queryInfo['join_conds'], $queryInfo['options'], ''); $live = $db->select($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], __METHOD__, $queryInfo['options'], $queryInfo['join_conds']); if ($live->numRows() >= count($ids)) { // All requested revisions are live, keeps things simple! return $live; } $archiveQueryInfo = ['tables' => ['archive'], 'fields' => Revision::selectArchiveFields(), 'conds' => ['ar_rev_id' => $ids], 'options' => ['ORDER BY' => 'ar_rev_id DESC'], 'join_conds' => []]; ChangeTags::modifyDisplayQuery($archiveQueryInfo['tables'], $archiveQueryInfo['fields'], $archiveQueryInfo['conds'], $archiveQueryInfo['join_conds'], $archiveQueryInfo['options'], ''); // Check if any requested revisions are available fully deleted. $archived = $db->select($archiveQueryInfo['tables'], $archiveQueryInfo['fields'], $archiveQueryInfo['conds'], __METHOD__, $archiveQueryInfo['options'], $archiveQueryInfo['join_conds']); if ($archived->numRows() == 0) { return $live; } elseif ($live->numRows() == 0) { return $archived; } else { // Combine the two! Whee $rows = []; foreach ($live as $row) { $rows[$row->rev_id] = $row; } foreach ($archived as $row) { $rows[$row->ar_rev_id] = $row; } krsort($rows); return new FakeResultWrapper(array_values($rows)); } }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $ids = array_map('intval', $this->ids); $queryInfo = array('tables' => array('revision', 'user'), 'fields' => array_merge(Revision::selectFields(), Revision::selectUserFields()), 'conds' => array('rev_page' => $this->title->getArticleID(), 'rev_id' => $ids), 'options' => array('ORDER BY' => 'rev_id DESC'), 'join_conds' => array('page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond())); ChangeTags::modifyDisplayQuery($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], $queryInfo['join_conds'], $queryInfo['options'], ''); return $db->select($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], __METHOD__, $queryInfo['options'], $queryInfo['join_conds']); }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $archiveNames = array(); foreach ($this->ids as $timestamp) { $archiveNames[] = $timestamp . '!' . $this->title->getDBkey(); } return $db->select('oldimage', OldLocalFile::selectFields(), array('oi_name' => $this->title->getDBkey(), 'oi_archive_name' => $archiveNames), __METHOD__, array('ORDER BY' => 'oi_timestamp DESC')); }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $timestamps = array(); foreach ($this->ids as $id) { $timestamps[] = $db->timestamp($id); } return $db->select('archive', Revision::selectArchiveFields(), array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), 'ar_timestamp' => $timestamps), __METHOD__, array('ORDER BY' => 'ar_timestamp DESC')); }
/** * Fetch the next set of rows from the database. */ public function next() { $res = $this->db->select($this->table, $this->fetchColumns, $this->buildConditions(), __METHOD__, ['LIMIT' => $this->batchSize, 'ORDER BY' => $this->orderBy], $this->joinConditions); // The iterator is converted to an array because in addition to // returning it in self::current() we need to use the end value // in self::buildConditions() $this->current = iterator_to_array($res); $this->key++; }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $ids = array_map('intval', $this->ids); $queryInfo = DatabaseLogEntry::getSelectQueryData(); $queryInfo['conds'] += array('log_id' => $ids); $queryInfo['options'] += array('ORDER BY' => 'log_id DESC'); ChangeTags::modifyDisplayQuery($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], $queryInfo['join_conds'], $queryInfo['options'], ''); return $db->select($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], __METHOD__, $queryInfo['options'], $queryInfo['join_conds']); }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $timestamps = []; foreach ($this->ids as $id) { $timestamps[] = $db->timestamp($id); } $tables = ['archive']; $fields = Revision::selectArchiveFields(); $conds = ['ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), 'ar_timestamp' => $timestamps]; $join_conds = []; $options = ['ORDER BY' => 'ar_timestamp DESC']; ChangeTags::modifyDisplayQuery($tables, $fields, $conds, $join_conds, $options, ''); return $db->select($tables, $fields, $conds, __METHOD__, $options, $join_conds); }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $conds = ['rev_page' => $this->title->getArticleID()]; if ($this->ids !== null) { $conds['rev_id'] = array_map('intval', $this->ids); } return $db->select(['revision', 'page', 'user'], array_merge(Revision::selectFields(), Revision::selectUserFields()), $conds, __METHOD__, ['ORDER BY' => 'rev_id DESC'], ['page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond()]); }
/** * This function should *not* be called outside of JobQueueDB * * @param IDatabase $dbw * @param IJobSpecification[] $jobs * @param int $flags * @param string $method * @throws DBError * @return void */ public function doBatchPushInternal(IDatabase $dbw, array $jobs, $flags, $method) { if (!count($jobs)) { return; } $rowSet = array(); // (sha1 => job) map for jobs that are de-duplicated $rowList = array(); // list of jobs for jobs that are not de-duplicated foreach ($jobs as $job) { $row = $this->insertFields($job); if ($job->ignoreDuplicates()) { $rowSet[$row['job_sha1']] = $row; } else { $rowList[] = $row; } } if ($flags & self::QOS_ATOMIC) { $dbw->startAtomic($method); // wrap all the job additions in one transaction } try { // Strip out any duplicate jobs that are already in the queue... if (count($rowSet)) { $res = $dbw->select('job', 'job_sha1', array('job_sha1' => array_keys($rowSet), 'job_token' => ''), $method); foreach ($res as $row) { wfDebug("Job with hash '{$row->job_sha1}' is a duplicate.\n"); unset($rowSet[$row->job_sha1]); // already enqueued } } // Build the full list of job rows to insert $rows = array_merge($rowList, array_values($rowSet)); // Insert the job rows in chunks to avoid slave lag... foreach (array_chunk($rows, 50) as $rowBatch) { $dbw->insert('job', $rowBatch, $method); } JobQueue::incrStats('inserts', $this->type, count($rows)); JobQueue::incrStats('dupe_inserts', $this->type, count($rowSet) + count($rowList) - count($rows)); } catch (DBError $e) { if ($flags & self::QOS_ATOMIC) { $dbw->rollback($method); } throw $e; } if ($flags & self::QOS_ATOMIC) { $dbw->endAtomic($method); } return; }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $ids = array_map('intval', $this->ids); return $db->select('filearchive', ArchivedFile::selectFields(), array('fa_name' => $this->title->getDBkey(), 'fa_id' => $ids), __METHOD__, array('ORDER BY' => 'fa_id DESC')); }
/** * Add the old versions of the image to the batch * @return array List of archive names from old versions */ public function addOlds() { $archiveBase = 'archive'; $this->olds = []; $this->oldCount = 0; $archiveNames = []; $result = $this->db->select('oldimage', ['oi_archive_name', 'oi_deleted'], ['oi_name' => $this->oldName], __METHOD__, ['LOCK IN SHARE MODE']); foreach ($result as $row) { $archiveNames[] = $row->oi_archive_name; $oldName = $row->oi_archive_name; $bits = explode('!', $oldName, 2); if (count($bits) != 2) { wfDebug("Old file name missing !: '{$oldName}' \n"); continue; } list($timestamp, $filename) = $bits; if ($this->oldName != $filename) { wfDebug("Old file name doesn't match: '{$oldName}' \n"); continue; } $this->oldCount++; // Do we want to add those to oldCount? if ($row->oi_deleted & File::DELETED_FILE) { continue; } $this->olds[] = ["{$archiveBase}/{$this->oldHash}{$oldName}", "{$archiveBase}/{$this->newHash}{$timestamp}!{$this->newName}"]; } return $archiveNames; }
/** * @param IDatabase $dbr * @param string|array $condition * @return bool|ResultWrapper */ protected static function listPages($dbr, $condition) { return $dbr->select(['archive'], ['ar_namespace', 'ar_title', 'count' => 'COUNT(*)'], $condition, __METHOD__, ['GROUP BY' => ['ar_namespace', 'ar_title'], 'ORDER BY' => ['ar_namespace', 'ar_title'], 'LIMIT' => 100]); }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $ids = array_map('intval', $this->ids); return $db->select('logging', array('log_id', 'log_type', 'log_action', 'log_timestamp', 'log_user', 'log_user_text', 'log_namespace', 'log_title', 'log_page', 'log_comment', 'log_params', 'log_deleted'), array('log_id' => $ids), __METHOD__, array('ORDER BY' => 'log_id DESC')); }
/** * @param IDatabase $dbr * @param string|array $condition * @return bool|ResultWrapper */ protected static function listPages($dbr, $condition) { return $dbr->select(array('archive'), array('ar_namespace', 'ar_title', 'count' => 'COUNT(*)'), $condition, __METHOD__, array('GROUP BY' => array('ar_namespace', 'ar_title'), 'ORDER BY' => array('ar_namespace', 'ar_title'), 'LIMIT' => 100)); }
/** * Do a batched query to get the parent revision lengths * @param IDatabase $db * @param array $revIds * @return array */ public static function getParentLengths($db, array $revIds) { $revLens = array(); if (!$revIds) { return $revLens; // empty } $res = $db->select('revision', array('rev_id', 'rev_len'), array('rev_id' => $revIds), __METHOD__); foreach ($res as $row) { $revLens[$row->rev_id] = $row->rev_len; } return $revLens; }
/** * Count the number of items on a user's watchlist * * @param IDatabase $dbr A database connection * @return int */ protected function countItems($dbr) { # Fetch the raw count $rows = $dbr->select('watchlist', array('count' => 'COUNT(*)'), array('wl_user' => $this->getUser()->getId()), __METHOD__); $row = $dbr->fetchObject($rows); $count = $row->count; return floor($count / 2); }
protected static function fetchTitleInfo(IDatabase $db, array $pages, $fname = __METHOD__) { $titleInfo = []; $batch = new LinkBatch(); foreach ($pages as $titleText) { $title = Title::newFromText($titleText); if ($title) { // Page name may be invalid if user-provided (e.g. gadgets) $batch->addObj($title); } } if (!$batch->isEmpty()) { $res = $db->select('page', ['page_namespace', 'page_title', 'page_touched', 'page_len', 'page_latest'], $batch->constructSet('page', $db), $fname); foreach ($res as $row) { // Avoid including ids or timestamps of revision/page tables so // that versions are not wasted $title = Title::makeTitle($row->page_namespace, $row->page_title); $titleInfo[$title->getPrefixedText()] = ['page_len' => $row->page_len, 'page_latest' => $row->page_latest, 'page_touched' => $row->page_touched]; } } return $titleInfo; }