Example #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'));
     }
 }
 /**
  * Deletes a sandboxed user without doing much validation.
  *
  * @param User $user
  * @param string $force If set to 'force' will skip the little validation we have.
  * @throws MWException
  */
 public static function deleteUser(User $user, $force = '')
 {
     $uid = $user->getId();
     if ($force !== 'force' && !self::isSandboxed($user)) {
         throw new MWException("Not a sandboxed user");
     }
     // Delete from database
     $dbw = wfGetDB(DB_MASTER);
     $dbw->delete('user', array('user_id' => $uid), __METHOD__);
     $dbw->delete('user_groups', array('ug_user' => $uid), __METHOD__);
     // If someone tries to access still object still, they will get anon user
     // data.
     $user->clearInstanceCache('defaults');
     // Nobody should access the user by id anymore, but in case they do, purge
     // the cache so they wont get stale data
     $user->invalidateCache();
     // In case we create an user with same name as was deleted during the same
     // request, we must also reset this cache or the User class will try to load
     // stuff for the old id, which is no longer present since we just deleted
     // the cache above. But it would have the side effect or overwriting all
     // member variables with null data. This used to manifest as a bug where
     // inserting a new user fails because the mName properpty is set to null,
     // which is then converted as the ip of the current user, and trying to
     // add that twice results in a name conflict. It was fun to debug.
     User::resetIdByNameCache();
 }
 private function addCoreDBData()
 {
     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
     $article = new Article(Title::newFromText('UTPage'));
     $article->doEdit('UTContent', 'UTPageSummary', EDIT_NEW, false, User::newFromName('UTSysop'));
 }
Example #4
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('');
         }
     }
 }
Example #5
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('');
         }
     }
 }