Example #1
0
 /**
  * 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', '*', [], __METHOD__)) {
         $status->warning('config-install-interwiki-exists');
         return $status;
     }
     global $IP;
     MediaWiki\suppressWarnings();
     $rows = file("{$IP}/maintenance/interwiki.list", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
     MediaWiki\restoreWarnings();
     $interwikis = [];
     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(['iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid'], explode('|', $row));
     }
     $this->db->insert('interwiki', $interwikis, __METHOD__);
     return Status::newGood();
 }
 private function findReferenceByPropertyTable($proptable, $id)
 {
     $row = false;
     if ($proptable->usesIdSubject()) {
         $row = $this->connection->selectRow($proptable->getName(), array('s_id'), array('s_id' => $id), __METHOD__);
     }
     if ($row !== false) {
         return $row;
     }
     $fields = $proptable->getFields($this->store);
     // Check whether an object reference exists or not
     if (isset($fields['o_id'])) {
         // This next time someone ... I'm going to Alaska
         $field = strpos($proptable->getName(), 'redi') ? array('s_title', 's_namespace') : array('s_id');
         $row = $this->connection->selectRow($proptable->getName(), $field, array('o_id' => $id), __METHOD__);
         if ($row !== false && strpos($proptable->getName(), 'redi')) {
             $row->s_id = $this->store->getObjectIds()->findRedirectIdFor($row->s_title, $row->s_namespace);
         }
     }
     // If the property table is not a fixed table (== assigns a whole
     // table to a specific property with the p_id column being suppressed)
     // then check for the p_id field
     if ($row === false && !$proptable->isFixedPropertyTable()) {
         $row = $this->connection->selectRow($proptable->getName(), array('s_id'), array('p_id' => $id), __METHOD__);
     }
     // If the query table contains a reference then we keep the object (could
     // be a subject, property, or printrequest) where in case the query is
     // removed the object will also loose its reference
     if ($row === false) {
         $row = $this->connection->selectRow(SQLStore::QUERY_LINKS_TABLE, array('s_id'), array('o_id' => $id), __METHOD__);
     }
     return $row;
 }
Example #3
0
 function checkMissingImage($fullpath)
 {
     $filename = wfBaseName($fullpath);
     $row = $this->dbw->selectRow('image', ['img_name'], ['img_name' => $filename], __METHOD__);
     if (!$row) {
         // file not registered
         $this->addMissingImage($filename, $fullpath);
     }
 }
Example #4
0
 /**
  * May throw a database error if, say, the server dies during query.
  * @param Database $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;
 }
 private function canSuppressUpdateOnSkewFactorFor($sid, $subject)
 {
     if ($sid < 1) {
         return false;
     }
     $row = $this->connection->selectRow(SMWSQLStore3::QUERY_LINKS_TABLE, array('s_id'), array('s_id' => $sid), __METHOD__);
     $skewedTouchedTimesamp = $subject->getTitle()->getTouched() + $this->skewFactorForDepedencyUpdateInSeconds;
     // Check whether the query has already been registered and only then
     // check for a possible divergent time
     return $row !== false && $skewedTouchedTimesamp > wfTimestamp(TS_MW);
 }
Example #6
0
 /**
  * Check the site_stats table is not properly populated.
  */
 protected function checkStats()
 {
     $this->output("...site_stats is populated...");
     $row = $this->db->selectRow('site_stats', '*', ['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);
 }
Example #7
0
 /**
  * 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', ['old_text', 'old_flags'], ['old_id' => $id], __METHOD__);
     $text = Revision::getRevisionText($row);
     if ($text === false) {
         return false;
     }
     $stripped = str_replace("\r", "", $text);
     $normalized = $wgContLang->normalize($stripped);
     return $normalized;
 }
Example #8
0
 function selectRow($table, $vars, $conds, $fname = __METHOD__, $options = array(), $join_conds = array())
 {
     if (is_array($conds)) {
         $conds = $this->wrapConditionsForWhere($table, $conds);
     }
     return parent::selectRow($table, $vars, $conds, $fname, $options, $join_conds);
 }
 /**
  * @since 2.1
  *
  * @param string $jobName
  *
  * @return boolean
  */
 public function selectJobRowFor($jobName)
 {
     $row = $this->connection->selectRow($this->tablename, '*', array('job_cmd' => $jobName), __METHOD__);
     return $row;
 }
Example #10
0
 ***************************************************************/
$Core->setGlobals();
// Load language file
include 'lang/' . $GLOBALS["user_cur_lang"] . '/common.php';
/***************************************************************
 * Setup the Database class and Database connections
 ***************************************************************/
require 'core/class.database.php';
$DB = new Database($Config->getDbInfo('db_host'), $Config->getDbInfo('db_port'), $Config->getDbInfo('db_username'), $Config->getDbInfo('db_password'), $Config->getDbInfo('db_name'));
// Check the database status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
if ($DB->status() != 1) {
    echo "Cannot connect to the Realm database. Please make sure you have run the installer to properly set the DB info in the database.";
    die;
}
// Make an array from `dbinfo` column for the selected realm..
$DB_info = $DB->selectRow("SELECT * FROM realmlist WHERE id='" . $GLOBALS['cur_selected_realm'] . "'");
$dbinfo = explode(';', $DB_info['dbinfo']);
// DBinfo column: char_host;char_port;char_username;char_password;charDBname;
// world_host;world_port;world_username;world_pass;worldDBname
$Realm_DB_Info = array('char_db_host' => $dbinfo['0'], 'char_db_port' => $dbinfo['1'], 'char_db_username' => $dbinfo['2'], 'char_db_password' => $dbinfo['3'], 'char_db_name' => $dbinfo['4'], 'w_db_host' => $dbinfo['5'], 'w_db_port' => $dbinfo['6'], 'w_db_username' => $dbinfo['7'], 'w_db_password' => $dbinfo['8'], 'w_db_name' => $dbinfo['9']);
// Free up memory.
unset($dbinfo, $DB_info);
// === Establish the Character DB connection === //
$CDB = new Database($Realm_DB_Info['char_db_host'], $Realm_DB_Info['char_db_port'], $Realm_DB_Info['char_db_username'], $Realm_DB_Info['char_db_password'], $Realm_DB_Info['char_db_name']);
// Check the CDB status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
if ($CDB->status() != 1) {
    echo "Cannot connect to the Character database. Please make sure you have this realm setup successfully in the Admin Panel. \n\tDelete your cookies to reset realm selection back to default";
    die;
}
// === Establish the World DB connection === //
$WDB = new Database($Realm_DB_Info['w_db_host'], $Realm_DB_Info['w_db_port'], $Realm_DB_Info['w_db_username'], $Realm_DB_Info['w_db_password'], $Realm_DB_Info['w_db_name']);
Example #11
0
 /**
  * Get count of revisions per page...not very efficient
  * @param Database $db
  * @param int $id, page id
  */
 static function countByPageId($db, $id)
 {
     $row = $db->selectRow('revision', 'COUNT(*) AS revCount', array('rev_page' => $id), __METHOD__);
     if ($row) {
         return $row->revCount;
     }
     return 0;
 }
Example #12
0
 /**
  * If the given revision is newer than the currently set page_latest,
  * update the page record. Otherwise, do nothing.
  *
  * @param Database $dbw
  * @param Revision $revision
  */
 function updateIfNewerOn(&$dbw, $revision)
 {
     wfProfileIn(__METHOD__);
     $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()) {
             wfProfileOut(__METHOD__);
             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);
     wfProfileOut(__METHOD__);
     return $ret;
 }
Example #13
0
 /**
  * Create a new null-revision for insertion into a page's
  * history. This will not re-save the text, but simply refer
  * to the text from the previous version.
  *
  * Such revisions can for instance identify page rename
  * operations and other such meta-modifications.
  *
  * @param Database $dbw
  * @param int      $pageId ID number of the page to read from
  * @param string   $summary
  * @param bool     $minor
  * @return Revision
  */
 function newNullRevision(&$dbw, $pageId, $summary, $minor)
 {
     $fname = 'Revision::newNullRevision';
     wfProfileIn($fname);
     $current = $dbw->selectRow(array('page', 'revision'), array('page_latest', 'rev_text_id'), array('page_id' => $pageId, 'page_latest=rev_id'), $fname);
     if ($current) {
         $revision = new Revision(array('page' => $pageId, 'comment' => $summary, 'minor_edit' => $minor, 'text_id' => $current->rev_text_id));
     } else {
         $revision = null;
     }
     wfProfileOut($fname);
     return $revision;
 }
Example #14
0
 /**
  * If the given revision is newer than the currently set page_latest,
  * update the page record. Otherwise, do nothing.
  *
  * @param Database $dbw
  * @param Revision $revision
  */
 function updateIfNewerOn(&$dbw, $revision)
 {
     $fname = 'Article::updateIfNewerOn';
     wfProfileIn($fname);
     $row = $dbw->selectRow(array('revision', 'page'), array('rev_id', 'rev_timestamp'), array('page_id' => $this->getId(), 'page_latest=rev_id'), $fname);
     if ($row) {
         if ($row->rev_timestamp >= $revision->getTimestamp()) {
             wfProfileOut($fname);
             return false;
         }
         $prev = $row->rev_id;
     } else {
         # No or missing previous revision; mark the page as new
         $prev = 0;
     }
     $ret = $this->updateRevisionOn($dbw, $revision, $prev);
     wfProfileOut($fname);
     return $ret;
 }
Example #15
0
 protected static function check_exists($query)
 {
     return Database::selectRow($query) !== null;
 }
 private final function check_as_where()
 {
     $query = "\r\n\t\t\tSELECT\r\n\t\t\t\t1\r\n\t\t\tFROM\r\n\t\t\t\t`" . $this->getDatabase() . "`.`" . $this->getTable() . "`\r\n\t\t\tWHERE\r\n\t\t\t\t{$this->get_where_clause()}\r\n\t\t\tLIMIT 1";
     $result = Database::selectRow($query);
     return count(Database::select($query)) === 1;
 }