/* public*/ var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry;
/* private */ var $mNetworkBits, $mIntegerAddr;
- function Block( $address = "", $user = "", $by = 0, $reason = "",
- $timestamp = "" , $auto = 0, $expiry = "" )
+ function Block( $address = '', $user = '', $by = 0, $reason = '',
+ $timestamp = '' , $auto = 0, $expiry = '' )
{
$this->mAddress = $address;
$this->mUser = $user;
function clear()
{
- $mAddress = $mReason = $mTimestamp = "";
+ $mAddress = $mReason = $mTimestamp = '';
$mUser = $mBy = 0;
}
# Get a ban from the DB, with either the given address or the given username
function load( $address, $user = 0, $killExpired = true )
{
- $fname = "Block::load";
+ $fname = 'Block::load';
$ret = false;
$killed = false;
function initialiseRange()
{
if ( $this->mUser == 0 ) {
- $rangeParts = explode( "/", $this->mAddress );
+ $rangeParts = explode( '/', $this->mAddress );
if ( count( $rangeParts ) == 2 ) {
$this->mNetworkBits = $rangeParts[1];
} else {
# Callback with a Block object for every block
/*static*/ function enumBlocks( $callback, $tag, $killExpired = true )
{
- $sql = "SELECT * FROM ipblocks ORDER BY ipb_timestamp DESC";
- $res = wfQuery( $sql, DB_READ, "Block::enumBans" );
+ $sql = 'SELECT * FROM ipblocks ORDER BY ipb_timestamp DESC';
+ $res = wfQuery( $sql, DB_READ, 'Block::enumBans' );
$block = new Block();
while ( $row = wfFetchObject( $res ) ) {
function delete()
{
- $fname = "Block::delete";
+ $fname = 'Block::delete';
if ( $this->mAddress == "" ) {
$sql = "DELETE FROM ipblocks WHERE ipb_id={$this->mId}";
} else {
$sql = "DELETE FROM ipblocks WHERE ipb_address='" .
wfStrencode( $this->mAddress ) . "'";
}
- wfQuery( $sql, DB_WRITE, "Block::delete" );
+ wfQuery( $sql, DB_WRITE, 'Block::delete' );
$this->clearCache();
}
function insert()
{
- $sql = "INSERT INTO ipblocks
- (ipb_address, ipb_user, ipb_by, ipb_reason, ipb_timestamp, ipb_auto, ipb_expiry )
- VALUES ('" . wfStrencode( $this->mAddress ) . "', {$this->mUser}, {$this->mBy}, '" .
+ $sql = 'INSERT INTO ipblocks ' .
+ '(ipb_address, ipb_user, ipb_by, ipb_reason, ipb_timestamp, ipb_auto, ipb_expiry )' .
+ "VALUES ('" . wfStrencode( $this->mAddress ) . "', {$this->mUser}, {$this->mBy}, '" .
wfStrencode( $this->mReason ) . "','{$this->mTimestamp}', {$this->mAuto}, '{$this->mExpiry}')";
- wfQuery( $sql, DB_WRITE, "Block::insert" );
+ wfQuery( $sql, DB_WRITE, 'Block::insert' );
$this->clearCache();
}
function isValid()
{
- return $this->mAddress != "";
+ return $this->mAddress != '';
}
function updateTimestamp()
$this->mTimestamp = wfTimestampNow();
$this->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
- wfQuery( "UPDATE ipblocks SET " .
+ wfQuery( 'UPDATE ipblocks SET ' .
"ipb_timestamp='" . $this->mTimestamp . "', " .
"ipb_expiry='" . $this->mExpiry . "' " .
- "WHERE ipb_address='" . wfStrencode( $this->mAddress ) . "'", DB_WRITE, "Block::updateTimestamp" );
+ "WHERE ipb_address='" . wfStrencode( $this->mAddress ) . "'", DB_WRITE, 'Block::updateTimestamp' );
$this->clearCache();
}
/* static */ function normaliseRange( $range )
{
- $parts = explode( "/", $range );
+ $parts = explode( '/', $range );
if ( count( $parts ) == 2 ) {
$shift = 32 - $parts[1];
$ipint = ip2long( $parts[0] );
{
var $mData = false, $mMemcKey;
- function BlockCache( $deferLoad = false, $dbName = "" )
+ function BlockCache( $deferLoad = false, $dbName = '' )
{
global $wgDBname;
- if ( $dbName == "" ) {
+ if ( $dbName == '' ) {
$dbName = $wgDBname;
}
- $this->mMemcKey = "$dbName:ipblocks";
+ $this->mMemcKey = $dbName.':ipblocks';
if ( !$deferLoad ) {
$this->load();
if ( !is_array( $this->mData ) ) {
# Load from DB
$this->mData = array();
- Block::enumBlocks( "wfBlockCacheInsert", "" ); # Calls $this->insert()
+ Block::enumBlocks( 'wfBlockCacheInsert', '' ); # Calls $this->insert()
}
if ( $saveMemc ) {
if ( $blocked ) {
# Clear low order bits
if ( $networkBits != 32 ) {
- $ip .= "/$networkBits";
+ $ip .= '/'.$networkBits;
$ip = Block::normaliseRange( $ip );
}
$block = new Block();
# $wgFileCacheDirectory
# $wgUseGzip
-require_once( "Title.php" );
+require_once( 'Title.php' );
class CacheManager {
var $mTitle, $mFileCache;
function CacheManager( &$title ) {
$this->mTitle =& $title;
- $this->mFileCache = "";
+ $this->mFileCache = '';
}
function fileCacheName() {
$hash = md5( $key = $this->mTitle->getDbkey() );
if( $this->mTitle->getNamespace() )
$key = $wgLang->getNsText( $this->mTitle->getNamespace() ) . ":" . $key;
- $key = str_replace( ".", "%2E", urlencode( $key ) );
+ $key = str_replace( '.', '%2E', urlencode( $key ) );
$hash1 = substr( $hash, 0, 1 );
$hash2 = substr( $hash, 0, 2 );
$this->mFileCache = "{$wgFileCacheDirectory}/{$hash1}/{$hash2}/{$key}.html";
if($this->useGzip())
- $this->mFileCache .= ".gz";
+ $this->mFileCache .= '.gz';
wfDebug( " fileCacheName() - {$this->mFileCache}\n" );
}
function fetchPageText() {
if( $this->useGzip() ) {
/* Why is there no gzfile_get_contents() or gzdecode()? */
- return implode( "", gzfile( $this->fileCacheName() ) );
+ return implode( '', gzfile( $this->fileCacheName() ) );
} else {
return $this->fetchRawText();
}
if( $this->useGzip() ) {
if( wfClientAcceptsGzip() ) {
- header( "Content-Encoding: gzip" );
+ header( 'Content-Encoding: gzip' );
} else {
/* Send uncompressed */
readgzfile( $filename );
function checkCacheDirs() {
$filename = $this->fileCacheName();
- $mydir2=substr($filename,0,strrpos($filename,"/")); # subdirectory level 2
- $mydir1=substr($mydir2,0,strrpos($mydir2,"/")); # subdirectory level 1
+ $mydir2=substr($filename,0,strrpos($filename,'/')); # subdirectory level 2
+ $mydir1=substr($mydir2,0,strrpos($mydir2,'/')); # subdirectory level 1
if(!file_exists($mydir1)) { mkdir($mydir1,0775); } # create if necessary
if(!file_exists($mydir2)) { mkdir($mydir2,0775); }
}
function saveToFileCache( $text ) {
- if(strcmp($text,"") == 0) return "";
+ if(strcmp($text,'') == 0) return '';
wfDebug(" saveToFileCache()\n", false);
$this->checkCacheDirs();
- $f = fopen( $this->fileCacheName(), "w" );
+ $f = fopen( $this->fileCacheName(), 'w' );
if($f) {
$now = wfTimestampNow();
if( $this->useGzip() ) {
- $rawtext = str_replace( "</html>",
- "<!-- Cached/compressed $now -->\n</html>",
+ $rawtext = str_replace( '</html>',
+ '<!-- Cached/compressed '.$now." -->\n</html>",
$text );
$text = gzencode( $rawtext );
} else {
- $text = str_replace( "</html>",
- "<!-- Cached $now -->\n</html>",
+ $text = str_replace( '</html>',
+ '<!-- Cached '.$now." -->\n</html>",
$text );
}
fwrite( $f, $text );
fclose( $f );
if( $this->useGzip() ) {
if( wfClientAcceptsGzip() ) {
- header( "Content-Encoding: gzip" );
+ header( 'Content-Encoding: gzip' );
return $text;
} else {
return $rawtext;
class DateFormatter
{
var $mSource, $mTarget;
- var $monthNames = "", $rxDM, $rxMD, $rxDMY, $rxYDM, $rxMDY, $rxYMD;
+ var $monthNames = '', $rxDM, $rxMD, $rxDMY, $rxYDM, $rxMDY, $rxYMD;
var $regexes, $pDays, $pMonths, $pYears;
var $rules, $xMonths;
# Extraction keys
# See the comments in replace() for the meaning of the letters
- $this->keys[DF_DMY] = "jFY";
- $this->keys[DF_YDM] = "Y jF";
- $this->keys[DF_MDY] = "FjY";
- $this->keys[DF_YMD] = "Y Fj";
- $this->keys[DF_DM] = "jF";
- $this->keys[DF_MD] = "Fj";
- $this->keys[DF_ISO1] = "ymd"; # y means ISO year
- $this->keys[DF_ISO2] = "ymd";
+ $this->keys[DF_DMY] = 'jFY';
+ $this->keys[DF_YDM] = 'Y jF';
+ $this->keys[DF_MDY] = 'FjY';
+ $this->keys[DF_YMD] = 'Y Fj';
+ $this->keys[DF_DM] = 'jF';
+ $this->keys[DF_MD] = 'Fj';
+ $this->keys[DF_ISO1] = 'ymd'; # y means ISO year
+ $this->keys[DF_ISO2] = 'ymd';
# Target date formats
- $this->targets[DF_DMY] = "[[F j|j F]] [[Y]]";
- $this->targets[DF_YDM] = "[[Y]], [[F j|j F]]";
- $this->targets[DF_MDY] = "[[F j]], [[Y]]";
- $this->targets[DF_YMD] = "[[Y]] [[F j]]";
- $this->targets[DF_DM] = "[[F j|j F]]";
- $this->targets[DF_MD] = "[[F j]]";
- $this->targets[DF_ISO1] = "[[Y|y]]-[[F j|m-d]]";
- $this->targets[DF_ISO2] = "[[y-m-d]]";
+ $this->targets[DF_DMY] = '[[F j|j F]] [[Y]]';
+ $this->targets[DF_YDM] = '[[Y]], [[F j|j F]]';
+ $this->targets[DF_MDY] = '[[F j]], [[Y]]';
+ $this->targets[DF_YMD] = '[[Y]] [[F j]]';
+ $this->targets[DF_DM] = '[[F j|j F]]';
+ $this->targets[DF_MD] = '[[F j]]';
+ $this->targets[DF_ISO1] = '[[Y|y]]-[[F j|m-d]]';
+ $this->targets[DF_ISO2] = '[[y-m-d]]';
# Rules
# pref source target
# Default
$this->mTarget = $i;
}
- $text = preg_replace_callback( $this->regexes[$i], "wfMainDateReplace", $text );
+ $text = preg_replace_callback( $this->regexes[$i], 'wfMainDateReplace', $text );
}
return $text;
}
$format = $this->targets[$this->mTarget];
# Construct new date
- $text = "";
+ $text = '';
$fail = false;
for ( $p=0; $p < strlen( $format ); $p++ ) {
switch ( $char ) {
case 'd': # ISO day of month
if ( is_null($bits['d']) ) {
- $text .= sprintf( "%02d", $bits['j'] );
+ $text .= sprintf( '%02d', $bits['j'] );
} else {
$text .= $bits['d'];
}
case 'm': # ISO month
if ( is_null($bits['m']) ) {
$m = $this->makeIsoMonth( $bits['F'] );
- if ( !$m || $m == "00" ) {
+ if ( !$m || $m == '00' ) {
$fail = true;
} else {
$text .= $m;
function getMonthRegex()
{
global $wgMonthNamesEn;
- return implode( "|", $wgMonthNamesEn );
+ return implode( '|', $wgMonthNamesEn );
}
# Makes an ISO month, e.g. 02, from a month name
function makeIsoMonth( $monthName )
{
$n = $this->xMonths[strtolower( $monthName )];
- return sprintf( "%02d", $n );
+ return sprintf( '%02d', $n );
}
function makeIsoYear( $year )
if ( substr( $year, -2 ) == 'BC' ) {
$num = IntVal(substr( $year, 0, -3 )) - 1;
# PHP bug note: sprintf( "%04d", -1 ) fails poorly
- $text = sprintf( "-%04d", $num );
+ $text = sprintf( '-%04d', $num );
} else {
- $text = sprintf( "%04d", $year );
+ $text = sprintf( '%04d', $year );
}
return $text;
}
function makeNormalYear( $iso )
{
if ( $iso{0} == '-' ) {
- $text = (IntVal( substr( $iso, 1 ) ) - 1) . " BC";
+ $text = (IntVal( substr( $iso, 1 ) ) - 1) . ' BC';
} else {
$text = IntVal( $iso );
}