/**
  * @param $user
  * @param $result
  * @return bool
  */
 public function AutoAuthenticateOverSymfony($user, &$result)
 {
     $symfonyToken = $this->symfonyConatiner->get('security.token_storage')->getToken();
     if (!$symfonyToken || !is_object($symfonyToken)) {
         return false;
     }
     $symfonyUser = $symfonyToken->getUser();
     if (!$symfonyUser || !is_object($symfonyUser)) {
         return false;
     }
     $dbr =& wfGetDB(DB_SLAVE);
     $s = $dbr->selectRow('user', array('user_id'), array('user_name' => $symfonyUser->getUsername()), "UserAuthSymfony::AutoAuthenticateOverSymfony");
     if ($s === false) {
         $username = $symfonyUser->getUsername();
         $newUser = new \User();
         $newUser->loadDefaults($username);
         // Added as it's done this way in CentralAuth.
         $newUser->setEmail($symfonyUser->getEmail());
         $newUser->setName($username);
         $newUser->confirmEmail();
         $newUser->mTouched = wfTimestamp();
         $newUser->addToDatabase();
         $user =& $newUser;
     } else {
         $user->mId = $s->user_id;
     }
     $sfGroups = array();
     if (method_exists($symfonyUser, 'getGroups')) {
         $sfGroups = $symfonyUser->getGroups();
     }
     $oldGroups = $user->getGroups();
     // previous groups
     foreach ($oldGroups as $group) {
         //ignore wiki groups and remove only non wiki groups
         if (!in_array($group, array('sysop', 'bureaucrat'))) {
             $user->removeGroup($group);
             // remove it
         }
     }
     // readd current groups
     foreach ($sfGroups as $sfGroup) {
         $user->addGroup(GroupBridge::getGroupAlias($sfGroup));
     }
     if ($user->loadFromDatabase()) {
         $user->saveToCache();
     }
     $result = true;
     return true;
 }
 /**
  * Creates a new user with the given attributes in the database.
  * Additionally notification mails are sent if properly configured.
  * @param User $user the user object to process
  * @param array $attrs the user's attributes
  * @return boolean true on success, false otherwise
  */
 private function createUser(&$user, $attrs)
 {
     // setup mail
     if ($this->config['comm']['onUserCreation']['notifyMail']) {
         // prepare extra headers
         $headers = 'From: ' . $this->config['comm']['onUserCreation']['notifyMailFrom'] . "\r\n" . 'Reply-To: ' . $this->config['comm']['onUserCreation']['notifyMailFrom'] . "\r\n" . 'X-Mailer: PHP/' . phpversion();
         // prepare search/replace
         global $wgSitename;
         $search = array('{SITENAME}', '{USERNAME}');
         $replace = array($wgSitename, $attrs['username']);
     }
     // setup the user object
     $user->loadDefaults($attrs['username']);
     $this->initUser($user, true);
     // create database entry
     $user->addToDatabase();
     // see if it worked ...
     if ($user->mId > 0) {
         wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . "Added database entry for user '{$attrs['username']}' with ID " . $user->mId . ".");
         // set all attributes other than the Uid/Username
         $this->modifyUserIfNeeded($user, $attrs);
         if ($this->config['comm']['onUserCreation']['notifyMail']) {
             // send success email
             if (mail($this->config['comm']['onUserCreation']['notifyMailTo'], str_replace($search, $replace, $this->config['comm']['onUserCreation']['notifyMailSubjectSuccess']), str_replace($search, $replace, $this->config['comm']['onUserCreation']['notifyMailMessageSuccess']), $headers)) {
                 wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . "Notification mail accepted for delivery.");
             } else {
                 wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . "Notification mail rejected for delivery.");
             }
         }
         return true;
     } else {
         wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . "Error while adding a database entry for the user '{$attrs['username']}'.");
         if ($this->config['comm']['onUserCreation']['notifyMail']) {
             // send error email
             if (mail($this->config['comm']['onUserCreation']['notifyMailTo'], str_replace($search, $replace, $this->config['comm']['onUserCreation']['notifyMailSubjectError']), str_replace($search, $replace, $this->config['comm']['onUserCreation']['notifyMailMessageError']), $headers)) {
                 wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . "Notification mail accepted for delivery.");
             } else {
                 wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . "Notification mail rejected.");
             }
         }
         return false;
     }
 }