* @file
*/
+use IPSet\IPSet;
use MediaWiki\MediaWikiServices;
use MediaWiki\Session\SessionManager;
use MediaWiki\Session\Token;
use MediaWiki\Auth\AuthenticationResponse;
use MediaWiki\Auth\AuthenticationRequest;
use Wikimedia\ScopedCallback;
+use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\DBExpectedError;
/**
* String Some punctuation to prevent editing from broken text-mangling proxies.
$ttl = $cache->adaptiveTTL( wfTimestamp( TS_UNIX, $this->mTouched ), $ttl );
- return $data;
+ // if a user group membership is about to expire, the cache needs to
+ // expire at that time (T163691)
+ foreach ( $this->mGroupMemberships as $ugm ) {
+ if ( $ugm->getExpiry() ) {
+ $secondsUntilExpiry = wfTimestamp( TS_UNIX, $ugm->getExpiry() ) - time();
+ if ( $secondsUntilExpiry > 0 && $secondsUntilExpiry < $ttl ) {
+ $ttl = $secondsUntilExpiry;
+ }
+ }
+ }
+ return $data;
},
[ 'pcTTL' => $cache::TTL_PROC_LONG, 'version' => self::VERSION ]
);
$wgProxyList = array_map( 'trim', file( $wgProxyList ) );
}
- if ( is_array( $wgProxyList ) ) {
- if (
- // Look for IP as value
- array_search( $ip, $wgProxyList ) !== false ||
- // Look for IP as key (for backwards-compatility)
- array_key_exists( $ip, $wgProxyList )
- ) {
- return true;
+ $resultProxyList = [];
+ $deprecatedIPEntries = [];
+
+ // backward compatibility: move all ip addresses in keys to values
+ foreach ( $wgProxyList as $key => $value ) {
+ $keyIsIP = IP::isIPAddress( $key );
+ $valueIsIP = IP::isIPAddress( $value );
+ if ( $keyIsIP && !$valueIsIP ) {
+ $deprecatedIPEntries[] = $key;
+ $resultProxyList[] = $key;
+ } elseif ( $keyIsIP && $valueIsIP ) {
+ $deprecatedIPEntries[] = $key;
+ $resultProxyList[] = $key;
+ $resultProxyList[] = $value;
+ } else {
+ $resultProxyList[] = $value;
}
}
- return false;
+ if ( $deprecatedIPEntries ) {
+ wfDeprecated(
+ 'IP addresses in the keys of $wgProxyList (found the following IP addresses in keys: ' .
+ implode( ', ', $deprecatedIPEntries ) . ', please move them to values)', '1.30' );
+ }
+
+ $proxyListIPSet = new IPSet( $resultProxyList );
+ return $proxyListIPSet->match( $ip );
}
/**
/**
* Deferred version of incEditCountImmediate()
+ *
+ * This function, rather than incEditCountImmediate(), should be used for
+ * most cases as it avoids potential deadlocks caused by concurrent editing.
*/
public function incEditCount() {
wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle(