/**
  * Bug 37963
  * Make sure defaults are loaded when setOption is called.
  * @covers User::loadOptions
  */
 public function testAnonOptions()
 {
     global $wgDefaultUserOptions;
     $this->user->setOption('userjs-someoption', 'test');
     $this->assertEquals($wgDefaultUserOptions['cols'], $this->user->getOption('cols'));
     $this->assertEquals('test', $this->user->getOption('userjs-someoption'));
 }
 static function createTemporaryUser($real_name, $email)
 {
     $user = new User();
     $maxid = User::getMaxID();
     $anonid = $maxid + 1;
     $username = "******";
     $user->setName($username);
     $real_name = strip_tags($real_name);
     // make sure this hasn't already been created
     while ($user->idForName() > 0) {
         $anonid = rand(0, 100000);
         $username = "******";
         $user->setName($username);
     }
     if ($real_name) {
         $user->setRealName($real_name);
     } else {
         $user->setRealName("Anonymous");
     }
     if ($email) {
         $user->setEmail($email);
     }
     $user->setPassword(WH_ANON_USER_PASSWORD);
     $user->setOption("disablemail", 1);
     $user->addToDatabase();
     return $user;
 }
 function testGetPreferredVariantUserOption()
 {
     global $wgUser;
     $wgUser = new User();
     $wgUser->setId(1);
     $wgUser->setOption('variant', 'tg-latn');
     $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
     $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
     $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
     $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
 }
 function testGetPreferredVariantUserOption()
 {
     global $wgUser;
     $wgUser = new User();
     $wgUser->load();
     // from 'defaults'
     $wgUser->mId = 1;
     $wgUser->mDataLoaded = true;
     $wgUser->mOptionsLoaded = true;
     $wgUser->setOption('variant', 'tg-latn');
     $this->assertEquals('tg-latn', $this->lc->getPreferredVariant());
 }
 /**
  * Keeps track of recently used message groups per user.
  */
 public static function trackGroup(MessageGroup $group, User $user)
 {
     if ($user->isAnon()) {
         return true;
     }
     $groups = $user->getOption('translate-recent-groups', '');
     if ($groups === '') {
         $groups = array();
     } else {
         $groups = explode('|', $groups);
     }
     if (isset($groups[0]) && $groups[0] === $group->getId()) {
         return true;
     }
     array_unshift($groups, $group->getId());
     $groups = array_unique($groups);
     $groups = array_slice($groups, 0, 5);
     $user->setOption('translate-recent-groups', implode('|', $groups));
     // Promise to persist the data post-send
     DeferredUpdates::addCallableUpdate(function () use($user) {
         $user->saveSettings();
     });
     return true;
 }
 /**
  * @covers LanguageConverter::getPreferredVariant
  * @covers LanguageConverter::getUserVariant
  */
 public function testGetPreferredVariantUserOptionForForeignLanguage()
 {
     global $wgContLang, $wgUser;
     $wgContLang = Language::factory('en');
     $wgUser = new User();
     $wgUser->load();
     // from 'defaults'
     $wgUser->mId = 1;
     $wgUser->mDataLoaded = true;
     $wgUser->mOptionsLoaded = true;
     $wgUser->setOption('variant-tg', 'tg-latn');
     $this->assertEquals('tg-latn', $this->lc->getPreferredVariant());
 }
 /**
  * send reminder email
  * @param User $user
  * @return Status object
  */
 public function sendConfirmationReminderEmail(&$user)
 {
     if ($user->getOption("cr_mailed", 0) == 1) {
         return false;
     }
     $emailTextTemplate = $this->app->renderView("UserLogin", "GeneralMail", array('language' => $user->getOption('language'), 'type' => 'confirmation-reminder-email'));
     $user->setOption("cr_mailed", "1");
     return $user->sendConfirmationMail(false, 'ConfirmationReminderMail', 'usersignup-confirmation-reminder-email', true, $emailTextTemplate);
 }
Example #8
0
 /**
  * Do any required setup which is dependent on test options.
  *
  * @see staticSetup() for more information about setup/teardown
  *
  * @param array $test Test info supplied by TestFileReader
  * @param callable|null $nextTeardown
  * @return ScopedCallback
  */
 public function perTestSetup($test, $nextTeardown = null)
 {
     $teardown = [];
     $this->checkSetupDone('setupDatabase', 'setDatabase');
     $teardown[] = $this->markSetupDone('perTestSetup');
     $opts = $this->parseOptions($test['options']);
     $config = $test['config'];
     // Find out values for some special options.
     $langCode = self::getOptionValue('language', $opts, 'en');
     $variant = self::getOptionValue('variant', $opts, false);
     $maxtoclevel = self::getOptionValue('wgMaxTocLevel', $opts, 999);
     $linkHolderBatchSize = self::getOptionValue('wgLinkHolderBatchSize', $opts, 1000);
     $setup = ['wgEnableUploads' => self::getOptionValue('wgEnableUploads', $opts, true), 'wgLanguageCode' => $langCode, 'wgRawHtml' => self::getOptionValue('wgRawHtml', $opts, false), 'wgNamespacesWithSubpages' => [0 => isset($opts['subpage'])], 'wgMaxTocLevel' => $maxtoclevel, 'wgAllowExternalImages' => self::getOptionValue('wgAllowExternalImages', $opts, true), 'wgThumbLimits' => [self::getOptionValue('thumbsize', $opts, 180)], 'wgDefaultLanguageVariant' => $variant, 'wgLinkHolderBatchSize' => $linkHolderBatchSize, 'wgEnableMagicLinks' => self::getOptionValue('wgEnableMagicLinks', $opts, []) + ['ISBN' => true, 'PMID' => true, 'RFC' => true]];
     if ($config) {
         $configLines = explode("\n", $config);
         foreach ($configLines as $line) {
             list($var, $value) = explode('=', $line, 2);
             $setup[$var] = eval("return {$value};");
         }
     }
     /** @since 1.20 */
     Hooks::run('ParserTestGlobals', [&$setup]);
     // Create tidy driver
     if (isset($opts['tidy'])) {
         // Cache a driver instance
         if ($this->tidyDriver === null) {
             $this->tidyDriver = MWTidy::factory($this->tidySupport->getConfig());
         }
         $tidy = $this->tidyDriver;
     } else {
         $tidy = false;
     }
     MWTidy::setInstance($tidy);
     $teardown[] = function () {
         MWTidy::destroySingleton();
     };
     // Set content language. This invalidates the magic word cache and title services
     $lang = Language::factory($langCode);
     $setup['wgContLang'] = $lang;
     $reset = function () {
         MagicWord::clearCache();
         $this->resetTitleServices();
     };
     $setup[] = $reset;
     $teardown[] = $reset;
     // Make a user object with the same language
     $user = new User();
     $user->setOption('language', $langCode);
     $setup['wgLang'] = $lang;
     // We (re)set $wgThumbLimits to a single-element array above.
     $user->setOption('thumbsize', 0);
     $setup['wgUser'] = $user;
     // And put both user and language into the context
     $context = RequestContext::getMain();
     $context->setUser($user);
     $context->setLanguage($lang);
     $teardown[] = function () use($context) {
         // Reset context to the restored globals
         $context->setUser($GLOBALS['wgUser']);
         $context->setLanguage($GLOBALS['wgContLang']);
     };
     $teardown[] = $this->executeSetupSnippets($setup);
     return $this->createTeardownObject($teardown, $nextTeardown);
 }
	/**
	 * Register the user viewed the watchlist,
	 * so we know that following chnages should
	 * result into notification emails is desired.
	 * 
	 * @since 0.1
	 * 
	 * @param User $user
	 */
	protected function registerUserView( User $user ) {
		$this->lastViewed = $user->getOption( 'swl_last_view' );
		
		if ( is_null( $this->lastViewed ) ) {
			$this->lastViewed = wfTimestampNow();
		}
		
		$user->setOption( 'swl_last_view', wfTimestampNow() );
		$user->setOption( 'swl_mail_count',0 );
		$user->saveSettings();		
	}
Example #10
0
 /**
  * When creating a user account, initialize user with information from LDAP.
  *
  * @param User $user
  * @access public
  */
 function initUser(&$user)
 {
     global $LDAPUseLDAPGroups;
     $this->printDebug("Entering initUser", 1);
     if ('local' == $_SESSION['LDAPDomain']) {
         $this->printDebug("User is using a local domain", 1);
         return;
     }
     //We are creating an LDAP user, it is very important that we do
     //NOT set a local password because it could compromise the
     //security of our domain.
     $user->mPassword = '';
     if (isset($LDAPRetrievePrefs[$_SESSION['LDAPDomain']]) && $LDAPRetrievePrefs[$_SESSION['LDAPDomain']]) {
         if ('' != $this->lang) {
             $user->setOption('language', $this->lang);
         }
         if ('' != $this->nickname) {
             $user->setOption('nickname', $this->nickname);
         }
         if ('' != $this->realname) {
             $user->setRealName($this->realname);
         }
         if ('' != $this->email) {
             $user->setEmail($this->email);
         }
     }
     if (isset($LDAPUseLDAPGroups[$_SESSION['LDAPDomain']]) && $LDAPUseLDAPGroups[$_SESSION['LDAPDomain']]) {
         $this->setGroups($user);
     }
     $user->saveSettings();
 }
 /**
  * Clears a user's UserImage setting
  * @param User $oUser
  */
 public static function unsetUserImage($oUser)
 {
     if ($oUser->getOption('MW::UserImage')) {
         $oUser->setOption('MW::UserImage', null);
         $oUser->saveSettings();
     }
     return;
 }
 /**
  * When creating a user account, optionally fill in preferences and such.
  * For instance, you might pull the email address or real name from the
  * external user database.
  *
  * The User object is passed by reference so it can be modified; don't
  * forget the & on your function declaration.
  *
  * @param User $user
  * @access public
  */
 function initUser(&$user)
 {
     global $G_SESSION;
     //unless you want the person to be nameless, you should probably populate
     // info about this user here
     if (isset($G_SESSION)) {
         $user->setRealName($G_SESSION->getRealName());
         $user->setEmail($G_SESSION->getEmail());
     }
     $user->mEmailAuthenticated = wfTimestampNow();
     $user->setToken();
     //turn on e-mail notifications by default
     $user->setOption('enotifwatchlistpages', 1);
     $user->setOption('enotifusertalkpages', 1);
     $user->setOption('enotifminoredits', 1);
     $user->setOption('enotifrevealaddr', 1);
 }
 /**
  * When a user logs in, update user with information from LDAP.
  *
  * @param User $user
  * @access public
  * TODO: fix the setExternalID stuff
  */
 function updateUser(&$user)
 {
     global $wgLDAPRetrievePrefs, $wgLDAPPreferences;
     global $wgLDAPUseLDAPGroups;
     global $wgLDAPUniqueBlockLogin, $wgLDAPUniqueRenameUser;
     $this->printDebug("Entering updateUser", NONSENSITIVE);
     if ($this->authFailed) {
         $this->printDebug("User didn't successfully authenticate, exiting.", NONSENSITIVE);
         return;
     }
     $saveSettings = false;
     //If we aren't pulling preferences, we don't want to accidentally
     //overwrite anything.
     if (isset($wgLDAPRetrievePrefs[$_SESSION['wsDomain']]) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] || isset($wgLDAPPreferences[$_SESSION['wsDomain']])) {
         $this->printDebug("Setting user preferences.", NONSENSITIVE);
         if ('' != $this->lang) {
             $this->printDebug("Setting language.", NONSENSITIVE);
             $user->setOption('language', $this->lang);
         }
         if ('' != $this->nickname) {
             $this->printDebug("Setting nickname.", NONSENSITIVE);
             $user->setOption('nickname', $this->nickname);
         }
         if ('' != $this->realname) {
             $this->printDebug("Setting realname.", NONSENSITIVE);
             $user->setRealName($this->realname);
         }
         if ('' != $this->email) {
             $this->printDebug("Setting email.", NONSENSITIVE);
             $user->setEmail($this->email);
             $user->confirmEmail();
         }
         if (isset($wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']]) && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] || isset($wgLDAPUniqueRenameUser[$_SESSION['wsDomain']]) && $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']]) {
             if ('' != $this->externalid) {
                 $user->setExternalID($this->externalid);
             }
         }
         $saveSettings = true;
     }
     if (isset($wgLDAPUseLDAPGroups[$_SESSION['wsDomain']]) && $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']]) {
         $this->printDebug("Setting user groups.", NONSENSITIVE);
         $this->setGroups($user);
         $saveSettings = true;
     }
     if ($saveSettings) {
         $this->printDebug("Saving user settings.", NONSENSITIVE);
         $user->saveSettings();
     }
 }
	protected function showPermissions( $step ) {
		global $wgLang, $wgRequest;
		$header = new HtmlTag( 'h2' );
		$step_message = 'translate-fs-permissions-title';
		$header->content( wfMsg( $step_message ) )->style( 'opacity', 0.4 );

		if ( $step ) {
			$this->out->addHtml( $header );
			return $step;
		}

		if ( $wgRequest->wasPosted() &&
			$this->user->matchEditToken( $wgRequest->getVal( 'token' ) ) &&
			$wgRequest->getText( 'step' ) === 'permissions' )
		{
			// This is ridiculous
			global $wgCaptchaTriggers;
			$captcha = $wgCaptchaTriggers;
			$wgCaptchaTriggers = null;

			$language = $wgRequest->getVal( 'primary-language' );
			$message = $wgRequest->getText( 'message', '...' );
			$params = array(
				'action' => 'threadaction',
				'threadaction' => 'newthread',
				'token' => $this->user->editToken(),
				'talkpage' => 'Project:Translator',
				'subject' => "{{LanguageHeader|$language}}",
				'reason' => 'Using Special:FirstSteps',
				'text' => $message,
			);
			$request = new FauxRequest( $params, true, $_SESSION );
			$api = new ApiMain( $request, true );
			$api->execute();
			$result = $api->getResultData();
			$wgCaptchaTriggers = $captcha;
			$page = $result['threadaction']['thread']['thread-title'];
			$this->user->setOption( 'translate-firststeps-request', $page );
			$this->user->saveSettings();
		}

		$page = $this->user->getOption( 'translate-firststeps-request' );
		if ( $this->user->isAllowed( 'translate' ) ) {
			$header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
			$this->out->addHtml( $header );
			return $step;
		} elseif ( $page ) {
			$header->content( $header->content . wfMsg( 'translate-fs-pagetitle-pending' ) );
			$this->out->addHtml( $header->style( 'opacity', false ) );
			$this->out->addWikiMsg( 'translate-fs-permissions-pending', $page );
			return $step_message;
		}

		$this->out->addHtml( $header->style( 'opacity', false ) );
		$this->out->addWikiMsg( 'translate-fs-permissions-help' );

		$output = Html::openElement( 'form', array( 'method' => 'post' ) );
		$output .= Html::hidden( 'step', 'permissions' );
		$output .= Html::hidden( 'token', $this->user->editToken() );
		$output .= Html::hidden( 'title', $this->getTitle() );
		$name = $id = 'primary-language';
		$selector = new XmlSelect();
		$selector->addOptions( $this->languages( $wgLang->getCode() ) );
		$selector->setAttribute( 'id', $id );
		$selector->setAttribute( 'name', $name );
		$selector->setDefault( $wgLang->getCode() );
		$text = wfMessage( 'translate-fs-permissions-planguage' )->text();
		$output .= Xml::label( $text, $id ) . "&#160;" . $selector->getHtml() . '<br />';
		$output .= Html::element( 'textarea', array( 'rows' => 5, 'name' => 'message' ), '' );
		$output .= Xml::submitButton( wfMsg( 'translate-fs-permissions-submit' ) );
		$output .= Html::closeElement( 'form' );

		$this->out->addHtml( $output );
		return $step_message;
	}
 /**
  * @param User $user
  * @param $options
  */
 protected function setUserOptionByNameAndValue($user, $options)
 {
     foreach ($options as $optionName => $optionValue) {
         if (!is_array($optionValue)) {
             $user->setOption($optionName, $optionValue);
         }
     }
 }
 /**
  * When creating a user account, optionally fill in preferences and such.
  * For instance, you might pull the email address or real name from the
  * external user database.
  *
  * The User object is passed by reference so it can be modified; don't
  * forget the & on your function declaration.
  *
  * @param User $user
  * @access public
  */
 function initUser(&$user)
 {
     //We are creating an LDAP user, it is very important that we do
     //NOT set a local password because it could compromise the
     //security of our domain.
     if ('local' == $_SESSION['wsDomain']) {
         return;
     }
     $user->setPassword('');
     if ('' != $this->lang) {
         $user->setOption('language', $this->lang);
     }
     if ('' != $this->nickname) {
         $user->setOption('nickname', $this->nickname);
     }
     if ('' != $this->realname) {
         $user->setRealName($this->realname);
     }
     if ('' != $this->email) {
         $user->setEmail($this->email);
     }
 }
 /**
  * Implements the PreferencesFormPreSave hook, to remove the 'autodisable' flag
  * when the user it was set on explicitly enables VE.
  * @param array $data User-submitted data
  * @param PreferencesForm $form A ContextSource
  * @param User $user User with new preferences already set
  * @param bool &$result Success or failure
  */
 public static function onPreferencesFormPreSave($data, $form, $user, &$result)
 {
     $veConfig = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor');
     // On a wiki where enable is hidden and set to 1, if user sets betatempdisable=0
     // then set autodisable=0
     // On a wiki where betatempdisable is hidden and set to 0, if user sets enable=1
     // then set autodisable=0
     if ($user->getOption('visualeditor-autodisable') && $user->getOption('visualeditor-enable') && !$user->getOption('visualeditor-betatempdisable')) {
         $user->setOption('visualeditor-autodisable', false);
     } elseif ($veConfig->get('VisualEditorTransitionDefault') && !$user->getOption('visualeditor-betatempdisable') && !$user->getOption('visualeditor-enable') && !$user->getOption('visualeditor-autodisable')) {
         $user->setOption('visualeditor-autodisable', true);
     }
 }