* @see $wgAutopromoteOnce
*/
public function addAutopromoteOnceGroups( $event ) {
- global $wgAutopromoteOnceLogInRC;
+ global $wgAutopromoteOnceLogInRC, $wgAuth;
$toPromote = array();
if ( $this->getId() ) {
$toPromote = Autopromote::getAutopromoteOnceGroups( $this, $event );
if ( count( $toPromote ) ) {
$oldGroups = $this->getGroups(); // previous groups
+
foreach ( $toPromote as $group ) {
$this->addGroup( $group );
}
+ // update groups in external authentication database
+ $wgAuth->updateExternalDBGroups( $this, $toPromote );
+
$newGroups = array_merge( $oldGroups, $toPromote ); // all groups
$logEntry = new ManualLogEntry( 'rights', 'autopromote' );
}
/**
- * Return the revision and link for the oldest new talk page message for
- * this user.
+ * Return the data needed to construct links for new talk page message
+ * alerts. If there are new messages, this will return an associative array
+ * with the following data:
+ * wiki: The database name of the wiki
+ * link: Root-relative link to the user's talk page
+ * rev: The last talk page revision that the user has seen or null. This
+ * is useful for building diff links.
+ * If there are no new messages, it returns an empty array.
* @note This function was designed to accomodate multiple talk pages, but
* currently only returns a single link and revision.
* @return Array
}
/**
- * Get the revision ID for the oldest new talk page message for this user
- * @return int|null Revision id or null if there are no new messages
+ * Get the revision ID for the last talk page revision viewed by the talk
+ * page owner.
+ * @return int|null Revision ID or null
*/
public function getNewMessageRevisionId() {
$newMessageRevisionId = null;
# set it, and then it was disabled removing their ability to change it). But
# we don't want to erase the preferences in the database in case the preference
# is re-enabled again. So don't touch $mOptions, just override the returned value
- if ( in_array( $oname, $wgHiddenPrefs ) && !$ignoreHidden ) {
+ if ( !$ignoreHidden && in_array( $oname, $wgHiddenPrefs ) ) {
return self::getDefaultOption( $oname );
}
}
/**
- * Get the user's current setting for a given option, as a boolean value.
+ * Get the user's current setting for a given option, as an integer value.
*
* @param string $oname The option to check
* @param int $defaultOverride A default value returned if the option does not exist
$this->mOptions[$oname] = $val;
}
+ /**
+ * Get a token stored in the preferences (like the watchlist one),
+ * resetting it if it's empty (and saving changes).
+ *
+ * @param string $oname The option name to retrieve the token from
+ * @return string|bool User's current value for the option, or false if this option is disabled.
+ * @see resetTokenFromOption()
+ * @see getOption()
+ */
+ public function getTokenFromOption( $oname ) {
+ global $wgHiddenPrefs;
+ if ( in_array( $oname, $wgHiddenPrefs ) ) {
+ return false;
+ }
+
+ $token = $this->getOption( $oname );
+ if ( !$token ) {
+ $token = $this->resetTokenFromOption( $oname );
+ $this->saveSettings();
+ }
+ return $token;
+ }
+
+ /**
+ * Reset a token stored in the preferences (like the watchlist one).
+ * *Does not* save user's preferences (similarly to setOption()).
+ *
+ * @param string $oname The option name to reset the token in
+ * @return string|bool New token value, or false if this option is disabled.
+ * @see getTokenFromOption()
+ * @see setOption()
+ */
+ public function resetTokenFromOption( $oname ) {
+ global $wgHiddenPrefs;
+ if ( in_array( $oname, $wgHiddenPrefs ) ) {
+ return false;
+ }
+
+ $token = MWCryptRand::generateHex( 40 );
+ $this->setOption( $oname, $token );
+ return $token;
+ }
+
/**
* Return a list of the types of user options currently returned by
* User::getOptionKinds().
/**
* Get the user's edit count.
- * @return int
+ * @return int, null for anonymous users
*/
public function getEditCount() {
if ( !$this->getId() ) {
// it has not been initialized. do so.
$count = $this->initEditCount();
}
- $this->mEditCount = intval( $count );
+ $this->mEditCount = $count;
wfProfileOut( __METHOD__ );
}
- return $this->mEditCount;
+ return (int) $this->mEditCount;
}
/**
// In case loadGroups was not called before, we now have the right twice.
// Get rid of the duplicate.
$this->mGroups = array_unique( $this->mGroups );
- $this->mRights = User::getGroupPermissions( $this->getEffectiveGroups( true ) );
+
+ // Refresh the groups caches, and clear the rights cache so it will be
+ // refreshed on the next call to $this->getRights().
+ $this->getEffectiveGroups( true );
+ $this->mRights = null;
$this->invalidateCache();
}
}
$this->loadGroups();
$this->mGroups = array_diff( $this->mGroups, array( $group ) );
- $this->mRights = User::getGroupPermissions( $this->getEffectiveGroups( true ) );
+
+ // Refresh the groups caches, and clear the rights cache so it will be
+ // refreshed on the next call to $this->getRights().
+ $this->getEffectiveGroups( true );
+ $this->mRights = null;
$this->invalidateCache();
}
* null (default): Use the default ($wgCookieSecure) to set the secure attribute
*/
protected function setCookie( $name, $value, $exp = 0, $secure = null ) {
- $this->getRequest()->response()->setcookie( $name, $value, $exp, null, null, $secure );
+ $this->getRequest()->response()->setcookie( $name, $value, $exp, array(
+ 'secure' => $secure,
+ ) );
}
/**
$this->clearCookie( 'forceHTTPS' );
// Remember when user logged out, to prevent seeing cached pages
- $this->setCookie( 'LoggedOut', wfTimestampNow(), time() + 86400 );
+ $this->setCookie( 'LoggedOut', time(), time() + 86400 );
}
/**
/**
* Check, if the given group has the given permission
*
+ * If you're wanting to check whether all users have a permission, use
+ * User::isEveryoneAllowed() instead. That properly checks if it's revoked
+ * from anyone.
+ *
* @since 1.21
* @param string $group Group to check
* @param string $role Role to check
&& !( isset( $wgRevokePermissions[$group][$role] ) && $wgRevokePermissions[$group][$role] );
}
+ /**
+ * Check if all users have the given permission
+ *
+ * @since 1.22
+ * @param string $right Right to check
+ * @return bool
+ */
+ public static function isEveryoneAllowed( $right ) {
+ global $wgGroupPermissions, $wgRevokePermissions;
+ static $cache = array();
+
+ // Use the cached results, except in unit tests which rely on
+ // being able change the permission mid-request
+ if ( isset( $cache[$right] ) && !defined( 'MW_PHPUNIT_TEST' ) ) {
+ return $cache[$right];
+ }
+
+ if ( !isset( $wgGroupPermissions['*'][$right] ) || !$wgGroupPermissions['*'][$right] ) {
+ $cache[$right] = false;
+ return false;
+ }
+
+ // If it's revoked anywhere, then everyone doesn't have it
+ foreach ( $wgRevokePermissions as $rights ) {
+ if ( isset( $rights[$right] ) && $rights[$right] ) {
+ $cache[$right] = false;
+ return false;
+ }
+ }
+
+ // Allow extensions (e.g. OAuth) to say false
+ if ( !wfRunHooks( 'UserIsEveryoneAllowed', array( $right ) ) ) {
+ $cache[$right] = false;
+ return false;
+ }
+
+ $cache[$right] = true;
+ return true;
+ }
+
/**
* Get the localized descriptive name for a group, if it exists
*