コード例 #1
0
ファイル: LocalIdLookup.php プロジェクト: paladox/mediawiki
 public function lookupUserNames(array $nameToId, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL)
 {
     if (!$nameToId) {
         return [];
     }
     $audience = $this->checkAudience($audience);
     list($index, $options) = DBAccessObjectUtils::getDBOptions($flags);
     $db = wfGetDB($index);
     $tables = ['user'];
     $fields = ['user_id', 'user_name'];
     $where = ['user_name' => array_map('strval', array_keys($nameToId))];
     $join = [];
     if ($audience && !$audience->isAllowed('hideuser')) {
         $tables[] = 'ipblocks';
         $join['ipblocks'] = ['LEFT JOIN', 'ipb_user=user_id'];
         $where[] = 'ipb_deleted = 0 OR ipb_deleted IS NULL';
     }
     $res = $db->select($tables, $fields, $where, __METHOD__, $options, $join);
     foreach ($res as $row) {
         $nameToId[$row->user_name] = (int) $row->user_id;
     }
     return $nameToId;
 }
コード例 #2
0
ファイル: WikiPage.php プロジェクト: paladox/mediawiki
 /**
  * Load the object from a given source by title
  *
  * @param object|string|int $from One of the following:
  *   - A DB query result object.
  *   - "fromdb" or WikiPage::READ_NORMAL to get from a replica DB.
  *   - "fromdbmaster" or WikiPage::READ_LATEST to get from the master DB.
  *   - "forupdate"  or WikiPage::READ_LOCKING to get from the master DB
  *     using SELECT FOR UPDATE.
  *
  * @return void
  */
 public function loadPageData($from = 'fromdb')
 {
     $from = self::convertSelectType($from);
     if (is_int($from) && $from <= $this->mDataLoadedFrom) {
         // We already have the data from the correct location, no need to load it twice.
         return;
     }
     if (is_int($from)) {
         list($index, $opts) = DBAccessObjectUtils::getDBOptions($from);
         $data = $this->pageDataFromTitle(wfGetDB($index), $this->mTitle, $opts);
         if (!$data && $index == DB_REPLICA && wfGetLB()->getServerCount() > 1 && wfGetLB()->hasOrMadeRecentMasterChanges()) {
             $from = self::READ_LATEST;
             list($index, $opts) = DBAccessObjectUtils::getDBOptions($from);
             $data = $this->pageDataFromTitle(wfGetDB($index), $this->mTitle, $opts);
         }
     } else {
         // No idea from where the caller got this data, assume replica DB.
         $data = $from;
         $from = self::READ_NORMAL;
     }
     $this->loadFromRow($data, $from);
 }
コード例 #3
0
ファイル: User.php プロジェクト: Acidburn0zzz/mediawiki
 /**
  * Load user and user_group data from the database.
  * $this->mId must be set, this is how the user is identified.
  *
  * @param integer $flags User::READ_* constant bitfield
  * @return bool True if the user exists, false if the user is anonymous
  */
 public function loadFromDatabase($flags = self::READ_LATEST)
 {
     // Paranoia
     $this->mId = intval($this->mId);
     // Anonymous user
     if (!$this->mId) {
         $this->loadDefaults();
         return false;
     }
     list($index, $options) = DBAccessObjectUtils::getDBOptions($flags);
     $db = wfGetDB($index);
     $s = $db->selectRow('user', self::selectFields(), array('user_id' => $this->mId), __METHOD__, $options);
     $this->queryFlagsUsed = $flags;
     Hooks::run('UserLoadFromDatabase', array($this, &$s));
     if ($s !== false) {
         // Initialise user table data
         $this->loadFromRow($s);
         $this->mGroups = null;
         // deferred
         $this->getEditCount();
         // revalidation for nulls
         return true;
     } else {
         // Invalid user_id
         $this->mId = 0;
         $this->loadDefaults();
         return false;
     }
 }
 public function testUserExists($username, $flags = User::READ_NORMAL)
 {
     $username = User::getCanonicalName($username, 'usable');
     if ($username === false) {
         return false;
     }
     list($db, $options) = \DBAccessObjectUtils::getDBOptions($flags);
     return (bool) wfGetDB($db)->selectField(['user'], ['user_id'], ['user_name' => $username], __METHOD__, $options);
 }
コード例 #5
0
ファイル: Revision.php プロジェクト: OrBin/mediawiki
 /**
  * Get the RC object belonging to the current revision, if there's one
  *
  * @param int $flags (optional) $flags include:
  *      Revision::READ_LATEST  : Select the data from the master
  *
  * @since 1.22
  * @return RecentChange|null
  */
 public function getRecentChange($flags = 0)
 {
     $dbr = wfGetDB(DB_SLAVE);
     list($dbType, ) = DBAccessObjectUtils::getDBOptions($flags);
     return RecentChange::newFromConds(array('rc_user_text' => $this->getUserText(Revision::RAW), 'rc_timestamp' => $dbr->timestamp($this->getTimestamp()), 'rc_this_oldid' => $this->getId()), __METHOD__, $dbType);
 }
コード例 #6
0
ファイル: BotPassword.php プロジェクト: OrBin/mediawiki
 /**
  * Get the password
  * @return Password
  */
 protected function getPassword()
 {
     list($index, $options) = DBAccessObjectUtils::getDBOptions($this->flags);
     $db = self::getDB($index);
     $password = $db->selectField('bot_passwords', 'bp_password', array('bp_user' => $this->centralId, 'bp_app_id' => $this->appId), __METHOD__, $options);
     if ($password === false) {
         return PasswordFactory::newInvalidPassword();
     }
     $passwordFactory = new \PasswordFactory();
     $passwordFactory->init(\RequestContext::getMain()->getConfig());
     try {
         return $passwordFactory->newFromCiphertext($password);
     } catch (PasswordError $ex) {
         return PasswordFactory::newInvalidPassword();
     }
 }
コード例 #7
0
ファイル: Revision.php プロジェクト: paladox/mediawiki
 private function fetchText()
 {
     $textId = $this->getTextId();
     // If we kept data for lazy extraction, use it now...
     if ($this->mTextRow !== null) {
         $row = $this->mTextRow;
         $this->mTextRow = null;
     } else {
         $row = null;
     }
     // Callers doing updates will pass in READ_LATEST as usual. Since the text/blob tables
     // do not normally get rows changed around, set READ_LATEST_IMMUTABLE in those cases.
     $flags = $this->mQueryFlags;
     $flags |= DBAccessObjectUtils::hasFlags($flags, self::READ_LATEST) ? self::READ_LATEST_IMMUTABLE : 0;
     list($index, $options, $fallbackIndex, $fallbackOptions) = DBAccessObjectUtils::getDBOptions($flags);
     if (!$row) {
         // Text data is immutable; check replica DBs first.
         $row = wfGetDB($index)->selectRow('text', ['old_text', 'old_flags'], ['old_id' => $textId], __METHOD__, $options);
     }
     // Fallback to DB_MASTER in some cases if the row was not found
     if (!$row && $fallbackIndex !== null) {
         // Use FOR UPDATE if it was used to fetch this revision. This avoids missing the row
         // due to REPEATABLE-READ. Also fallback to the master if READ_LATEST is provided.
         $row = wfGetDB($fallbackIndex)->selectRow('text', ['old_text', 'old_flags'], ['old_id' => $textId], __METHOD__, $fallbackOptions);
     }
     if (!$row) {
         wfDebugLog('Revision', "No text row with ID '{$textId}' (revision {$this->getId()}).");
     }
     $text = self::getRevisionText($row);
     if ($row && $text === false) {
         wfDebugLog('Revision', "No blob for text row '{$textId}' (revision {$this->getId()}).");
     }
     return is_string($text) ? $text : false;
 }
 /**
  * Get all projects associated with a given page (as project IDs)
  * @param int $pageId Page ID
  * @param int $flags IDBAccessObject::READ_* constant. This can be used to
  *     force reading from the master database. See docs at IDBAccessObject.php.
  * @return array $results All projects associated with given page
  */
 public static function getAllProjects($pageId, $flags = self::READ_NORMAL)
 {
     list($index, $options) = DBAccessObjectUtils::getDBOptions($flags);
     $db = wfGetDB($index);
     $res = $db->select('page_assessments', 'pa_project_id', array('pa_page_id' => $pageId), __METHOD__, $options);
     $results = array();
     if ($res) {
         foreach ($res as $row) {
             $results[] = $row->pa_project_id;
         }
     }
     return $results;
 }