Пример #1
0
 private function addCoreDBData()
 {
     # disabled for performance
     #$this->tablesUsed[] = 'page';
     #$this->tablesUsed[] = 'revision';
     if ($this->db->getType() == 'oracle') {
         # Insert 0 user to prevent FK violations
         # Anonymous user
         $this->db->insert('user', array('user_id' => 0, 'user_name' => 'Anonymous'), __METHOD__, array('IGNORE'));
         # Insert 0 page to prevent FK violations
         # Blank page
         $this->db->insert('page', array('page_id' => 0, 'page_namespace' => 0, 'page_title' => ' ', 'page_restrictions' => NULL, 'page_counter' => 0, 'page_is_redirect' => 0, 'page_is_new' => 0, 'page_random' => 0, 'page_touched' => $this->db->timestamp(), 'page_latest' => 0, 'page_len' => 0), __METHOD__, array('IGNORE'));
     }
     User::resetIdByNameCache();
     //Make sysop user
     $user = User::newFromName('UTSysop');
     if ($user->idForName() == 0) {
         $user->addToDatabase();
         $user->setPassword('UTSysopPassword');
         $user->addGroup('sysop');
         $user->addGroup('bureaucrat');
         $user->saveSettings();
     }
     //Make 1 page with 1 revision
     $page = WikiPage::factory(Title::newFromText('UTPage'));
     if (!$page->getId() == 0) {
         $page->doEdit('UTContent', 'UTPageSummary', EDIT_NEW, false, User::newFromName('UTSysop'));
     }
 }
Пример #2
0
 function addMissingImage($filename, $fullpath)
 {
     global $wgContLang;
     $timestamp = $this->dbw->timestamp($this->getRepo()->getFileTimestamp($fullpath));
     $altname = $wgContLang->checkTitleEncoding($filename);
     if ($altname != $filename) {
         if ($this->dryrun) {
             $filename = $altname;
             $this->output("Estimating transcoding... {$altname}\n");
         } else {
             # @todo FIXME: create renameFile()
             $filename = $this->renameFile($filename);
         }
     }
     if ($filename == '') {
         $this->output("Empty filename for {$fullpath}\n");
         return;
     }
     if (!$this->dryrun) {
         $file = wfLocalFile($filename);
         if (!$file->recordUpload('', '(recovered file, missing upload log entry)', '', '', '', false, $timestamp)) {
             $this->output("Error uploading file {$fullpath}\n");
             return;
         }
     }
     $this->output($fullpath . "\n");
 }
Пример #3
0
 private function addCoreDBData()
 {
     if ($this->db->getType() == 'oracle') {
         # Insert 0 user to prevent FK violations
         # Anonymous user
         $this->db->insert('user', array('user_id' => 0, 'user_name' => 'Anonymous'), __METHOD__, array('IGNORE'));
         # Insert 0 page to prevent FK violations
         # Blank page
         $this->db->insert('page', array('page_id' => 0, 'page_namespace' => 0, 'page_title' => ' ', 'page_restrictions' => null, 'page_is_redirect' => 0, 'page_is_new' => 0, 'page_random' => 0, 'page_touched' => $this->db->timestamp(), 'page_latest' => 0, 'page_len' => 0), __METHOD__, array('IGNORE'));
     }
     User::resetIdByNameCache();
     // Make sysop user
     $user = User::newFromName('UTSysop');
     if ($user->idForName() == 0) {
         $user->addToDatabase();
         TestUser::setPasswordForUser($user, 'UTSysopPassword');
     }
     // Always set groups, because $this->resetDB() wipes them out
     $user->addGroup('sysop');
     $user->addGroup('bureaucrat');
     // Make 1 page with 1 revision
     $page = WikiPage::factory(Title::newFromText('UTPage'));
     if ($page->getId() == 0) {
         $page->doEditContent(new WikitextContent('UTContent'), 'UTPageSummary', EDIT_NEW, false, $user);
         // doEditContent() probably started the session via
         // User::loadFromSession(). Close it now.
         if (session_id() !== '') {
             session_write_close();
             session_id('');
         }
     }
 }
Пример #4
0
 private function addCoreDBData()
 {
     if ($this->db->getType() == 'oracle') {
         # Insert 0 user to prevent FK violations
         # Anonymous user
         if (!$this->db->selectField('user', '1', ['user_id' => 0])) {
             $this->db->insert('user', ['user_id' => 0, 'user_name' => 'Anonymous'], __METHOD__, ['IGNORE']);
         }
         # Insert 0 page to prevent FK violations
         # Blank page
         if (!$this->db->selectField('page', '1', ['page_id' => 0])) {
             $this->db->insert('page', ['page_id' => 0, 'page_namespace' => 0, 'page_title' => ' ', 'page_restrictions' => null, 'page_is_redirect' => 0, 'page_is_new' => 0, 'page_random' => 0, 'page_touched' => $this->db->timestamp(), 'page_latest' => 0, 'page_len' => 0], __METHOD__, ['IGNORE']);
         }
     }
     User::resetIdByNameCache();
     // Make sysop user
     $user = static::getTestSysop()->getUser();
     // Make 1 page with 1 revision
     $page = WikiPage::factory(Title::newFromText('UTPage'));
     if ($page->getId() == 0) {
         $page->doEditContent(new WikitextContent('UTContent'), 'UTPageSummary', EDIT_NEW, false, $user);
         // doEditContent() probably started the session via
         // User::loadFromSession(). Close it now.
         if (session_id() !== '') {
             session_write_close();
             session_id('');
         }
     }
 }
Пример #5
0
 /**
  * @param DatabaseBase $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'));
 }
Пример #6
0
 /**
  * Update the page record to point to a newly saved revision.
  *
  * @param DatabaseBase $dbw
  * @param Revision $revision For ID number, and text used to set
  *   length and redirect status fields
  * @param int $lastRevision If given, will not overwrite the page field
  *   when different from the currently set value.
  *   Giving 0 indicates the new page flag should be set on.
  * @param bool $lastRevIsRedirect If given, will optimize adding and
  *   removing rows in redirect table.
  * @return bool True on success, false on failure
  */
 public function updateRevisionOn($dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null)
 {
     global $wgContentHandlerUseDB;
     // Assertion to try to catch T92046
     if ((int) $revision->getId() === 0) {
         throw new InvalidArgumentException(__METHOD__ . ': Revision has ID ' . var_export($revision->getId(), 1));
     }
     $content = $revision->getContent();
     $len = $content ? $content->getSize() : 0;
     $rt = $content ? $content->getUltimateRedirectTarget() : null;
     $conditions = array('page_id' => $this->getId());
     if (!is_null($lastRevision)) {
         // An extra check against threads stepping on each other
         $conditions['page_latest'] = $lastRevision;
     }
     $row = array('page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp($revision->getTimestamp()), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => $rt !== null ? 1 : 0, 'page_len' => $len);
     if ($wgContentHandlerUseDB) {
         $row['page_content_model'] = $revision->getContentModel();
     }
     $dbw->update('page', $row, $conditions, __METHOD__);
     $result = $dbw->affectedRows() > 0;
     if ($result) {
         $this->updateRedirectOn($dbw, $rt, $lastRevIsRedirect);
         $this->setLastEdit($revision);
         $this->mLatest = $revision->getId();
         $this->mIsRedirect = (bool) $rt;
         // Update the LinkCache.
         LinkCache::singleton()->addGoodLinkObj($this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest, $revision->getContentModel());
     }
     return $result;
 }
Пример #7
0
 /**
  * @param DatabaseBase $db
  * @return string
  */
 protected function getMaxDateTime($db)
 {
     if (time() > 0x7fffffff) {
         return $db->timestamp(1 << 62);
     } else {
         return $db->timestamp(0x7fffffff);
     }
 }
 /**
  * Update the query cache as needed
  *
  * @param DatabaseBase $dbw
  * @param int $days How many days user must be idle before he is considered inactive
  * @param int $window Maximum time range of new data to scan (in seconds)
  * @return int|bool UNIX timestamp the cache is now up-to-date as of (false on error)
  */
 protected static function doQueryCacheUpdate(DatabaseBase $dbw, $days, $window)
 {
     $lockKey = wfWikiID() . '-activeusers';
     if (!$dbw->lock($lockKey, __METHOD__, 1)) {
         return false;
         // exclusive update (avoids duplicate entries)
     }
     $now = time();
     $cTime = $dbw->selectField('querycache_info', 'qci_timestamp', array('qci_type' => 'activeusers'));
     $cTimeUnix = $cTime ? wfTimestamp(TS_UNIX, $cTime) : 1;
     // Pick the date range to fetch from. This is normally from the last
     // update to till the present time, but has a limited window for sanity.
     // If the window is limited, multiple runs are need to fully populate it.
     $sTimestamp = max($cTimeUnix, $now - $days * 86400);
     $eTimestamp = min($sTimestamp + $window, $now);
     // Get all the users active since the last update
     $res = $dbw->select(array('recentchanges'), array('rc_user_text', 'lastedittime' => 'MAX(rc_timestamp)'), array('rc_user > 0', 'rc_type != ' . $dbw->addQuotes(RC_EXTERNAL), 'rc_log_type IS NULL OR rc_log_type != ' . $dbw->addQuotes('newusers'), 'rc_timestamp >= ' . $dbw->addQuotes($dbw->timestamp($sTimestamp)), 'rc_timestamp <= ' . $dbw->addQuotes($dbw->timestamp($eTimestamp))), __METHOD__, array('GROUP BY' => array('rc_user_text'), 'ORDER BY' => 'NULL'));
     $names = array();
     foreach ($res as $row) {
         $names[$row->rc_user_text] = $row->lastedittime;
     }
     // Rotate out users that have not edited in too long (according to old data set)
     $dbw->delete('querycachetwo', array('qcc_type' => 'activeusers', 'qcc_value < ' . $dbw->addQuotes($now - $days * 86400)), __METHOD__);
     // Find which of the recently active users are already accounted for
     if (count($names)) {
         $res = $dbw->select('querycachetwo', array('user_name' => 'qcc_title'), array('qcc_type' => 'activeusers', 'qcc_namespace' => NS_USER, 'qcc_title' => array_keys($names)), __METHOD__);
         foreach ($res as $row) {
             unset($names[$row->user_name]);
         }
     }
     // Insert the users that need to be added to the list (which their last edit time
     if (count($names)) {
         $newRows = array();
         foreach ($names as $name => $lastEditTime) {
             $newRows[] = array('qcc_type' => 'activeusers', 'qcc_namespace' => NS_USER, 'qcc_title' => $name, 'qcc_value' => wfTimestamp(TS_UNIX, $lastEditTime), 'qcc_namespacetwo' => 0, 'qcc_titletwo' => '');
         }
         foreach (array_chunk($newRows, 500) as $rowBatch) {
             $dbw->insert('querycachetwo', $rowBatch, __METHOD__);
             if (!$dbw->trxLevel()) {
                 wfWaitForSlaves();
             }
         }
     }
     // Touch the data freshness timestamp
     $dbw->replace('querycache_info', array('qci_type'), array('qci_type' => 'activeusers', 'qci_timestamp' => $dbw->timestamp($eTimestamp)), __METHOD__);
     $dbw->unlock($lockKey, __METHOD__);
     return $eTimestamp;
 }
Пример #9
0
 /**
  * Insert a new revision into the database, returning the new revision ID
  * number on success and dies horribly on failure.
  *
  * @param DatabaseBase $dbw (master connection)
  * @throws MWException
  * @return int
  */
 public function insertOn($dbw)
 {
     global $wgDefaultExternalStore, $wgContentHandlerUseDB;
     $this->checkContentModel();
     $data = $this->mText;
     $flags = self::compressRevisionText($data);
     # Write to external storage if required
     if ($wgDefaultExternalStore) {
         // Store and get the URL
         $data = ExternalStore::insertToDefault($data);
         if (!$data) {
             throw new MWException("Unable to store text to external storage");
         }
         if ($flags) {
             $flags .= ',';
         }
         $flags .= 'external';
     }
     # Record the text (or external storage URL) to the text table
     if ($this->mTextId === null) {
         $old_id = $dbw->nextSequenceValue('text_old_id_seq');
         $dbw->insert('text', array('old_id' => $old_id, 'old_text' => $data, 'old_flags' => $flags), __METHOD__);
         $this->mTextId = $dbw->insertId();
     }
     if ($this->mComment === null) {
         $this->mComment = "";
     }
     # Record the edit in revisions
     $rev_id = $this->mId !== null ? $this->mId : $dbw->nextSequenceValue('revision_rev_id_seq');
     $row = array('rev_id' => $rev_id, 'rev_page' => $this->mPage, 'rev_text_id' => $this->mTextId, 'rev_comment' => $this->mComment, 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0, 'rev_user' => $this->mUser, 'rev_user_text' => $this->mUserText, 'rev_timestamp' => $dbw->timestamp($this->mTimestamp), 'rev_deleted' => $this->mDeleted, 'rev_len' => $this->mSize, 'rev_parent_id' => $this->mParentId === null ? $this->getPreviousRevisionId($dbw) : $this->mParentId, 'rev_sha1' => $this->mSha1 === null ? Revision::base36Sha1($this->mText) : $this->mSha1);
     if ($wgContentHandlerUseDB) {
         // NOTE: Store null for the default model and format, to save space.
         // XXX: Makes the DB sensitive to changed defaults.
         // Make this behavior optional? Only in miser mode?
         $model = $this->getContentModel();
         $format = $this->getContentFormat();
         $title = $this->getTitle();
         if ($title === null) {
             throw new MWException("Insufficient information to determine the title of the " . "revision's page!");
         }
         $defaultModel = ContentHandler::getDefaultModelFor($title);
         $defaultFormat = ContentHandler::getForModelID($defaultModel)->getDefaultFormat();
         $row['rev_content_model'] = $model === $defaultModel ? null : $model;
         $row['rev_content_format'] = $format === $defaultFormat ? null : $format;
     }
     $dbw->insert('revision', $row, __METHOD__);
     $this->mId = $rev_id !== null ? $rev_id : $dbw->insertId();
     // Assertion to try to catch T92046
     if ((int) $this->mId === 0) {
         throw new UnexpectedValueException('After insert, Revision mId is ' . var_export($this->mId, 1) . ': ' . var_export($row, 1));
     }
     Hooks::run('RevisionInsertComplete', array(&$this, $data, $flags));
     return $this->mId;
 }
Пример #10
0
 /**
  * Update the page record to point to a newly saved revision.
  *
  * @param DatabaseBase $dbw
  * @param Revision $revision For ID number, and text used to set
  *   length and redirect status fields
  * @param int $lastRevision If given, will not overwrite the page field
  *   when different from the currently set value.
  *   Giving 0 indicates the new page flag should be set on.
  * @param bool $lastRevIsRedirect If given, will optimize adding and
  *   removing rows in redirect table.
  * @return bool True on success, false on failure
  */
 public function updateRevisionOn($dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null)
 {
     global $wgContentHandlerUseDB;
     wfProfileIn(__METHOD__);
     $content = $revision->getContent();
     $len = $content ? $content->getSize() : 0;
     $rt = $content ? $content->getUltimateRedirectTarget() : null;
     $conditions = array('page_id' => $this->getId());
     if (!is_null($lastRevision)) {
         // An extra check against threads stepping on each other
         $conditions['page_latest'] = $lastRevision;
     }
     $now = wfTimestampNow();
     $row = array('page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp($now), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => $rt !== null ? 1 : 0, 'page_len' => $len);
     if ($wgContentHandlerUseDB) {
         $row['page_content_model'] = $revision->getContentModel();
     }
     $dbw->update('page', $row, $conditions, __METHOD__);
     $result = $dbw->affectedRows() > 0;
     if ($result) {
         $this->updateRedirectOn($dbw, $rt, $lastRevIsRedirect);
         $this->setLastEdit($revision);
         $this->setCachedLastEditTime($now);
         $this->mLatest = $revision->getId();
         $this->mIsRedirect = (bool) $rt;
         // Update the LinkCache.
         LinkCache::singleton()->addGoodLinkObj($this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest, $revision->getContentModel());
     }
     wfProfileOut(__METHOD__);
     return $result;
 }
Пример #11
0
 /**
  * Builds update conditions. Additional conditions may be added to $conditions to
  * protected against race conditions using a compare-and-set (CAS) mechanism
  * based on comparing $this->mTouched with the user_touched field.
  *
  * @param DatabaseBase $db
  * @param array $conditions WHERE conditions for use with DatabaseBase::update
  * @return array WHERE conditions for use with DatabaseBase::update
  */
 protected function makeUpdateConditions(DatabaseBase $db, array $conditions)
 {
     if ($this->mTouched) {
         // CAS check: only update if the row wasn't changed sicne it was loaded.
         $conditions['user_touched'] = $db->timestamp($this->mTouched);
     }
     return $conditions;
 }