$a = $wgScript;
} else {
$a = "{$wgScript}?{$q}";
- }
+ }
} else if ( '' == $q ) {
$a = str_replace( "$1", $a, $wgArticlePath );
} else if ($wgScript != '' ) {
- $a = "{$wgScript}?title={$a}&{$q}";
+ $a = "{$wgScript}?title={$a}&{$q}";
} else { //XXX hackish solution for toplevel wikis
- $a = "/{$a}?{$q}";
+ $a = "/{$a}?{$q}";
}
return $a;
}
} else {
$length = 1;
}
-
+
if ( $length != strlen( $char ) ) {
return '';
}
if ( isset( $_GET['action'] ) && $_GET['action'] == 'raw' && !$wgDebugRawPage ) {
return;
}
-
+
if ( isset( $wgOut ) && $wgDebugComments && !$logonly ) {
$wgOut->debug( $text );
}
# Get a message from anywhere
function wfMsg( $key ) {
+ global $wgRequest;
+ if ( $wgRequest->getVal( 'debugmsg' ) )
+ return $key;
$args = func_get_args();
if ( count( $args ) ) {
array_shift( $args );
$line = $bt[$i]['line'];
wfDebug("WARNING: Abrupt exit in $file at line $line\n");
}
- } else {
+ } else {
wfDebug('WARNING: Abrupt exit\n');
}
if ( !$error ) {
}
if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
$msg .= $call['function'] . "()";
-
+
if ( $wgCommandLineMode ) {
$msg .= "\n";
} else {
if ( -1 != $wgNumberOfArticles ) return;
$dbr =& wfGetDB( DB_SLAVE );
- $s = $dbr->getArray( 'site_stats',
+ $s = $dbr->getArray( 'site_stats',
array( 'ss_total_views', 'ss_total_edits', 'ss_good_articles' ),
array( 'ss_row_id' => 1 ), $fname
);
- if ( $s === false ) {
- return;
+ if ( $s === false ) {
+ return;
} else {
$wgTotalViews = $s->ss_total_views;
$wgTotalEdits = $s->ss_total_edits;
if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
$dest .= '/' . substr( $hash, 0, 2 );
if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
-
+
umask( $oldumask );
return $dest;
}
$hash = md5( $fname );
$oldumask = umask(0);
-
+
# Suppress warning messages here; if the file itself can't
# be written we'll worry about it then.
$archive = "{$wgUploadDirectory}/{$subdir}";
function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source = "" )
{
global $wgUser, $wgLang, $wgTitle, $wgOut, $wgDeferredUpdateList;
- global $wgUseCopyrightUpload;
-
+ global $wgUseCopyrightUpload;
+
$fname = 'wfRecordUpload';
$dbw =& wfGetDB( DB_MASTER );
-
+
# img_name must be unique
if ( !$dbw->indexUnique( 'image', 'img_name' ) ) {
wfDebugDieBacktrace( 'Database schema not up to date, please run maintenance/archives/patch-image_name_unique.sql' );
}
-
+
$now = wfTimestampNow();
$won = wfInvertTimestamp( $now );
$size = IntVal( $size );
-
+
if ( $wgUseCopyrightUpload )
{
$textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" .
$won = wfInvertTimestamp( $now );
# Test to see if the row exists using INSERT IGNORE
- # This avoids race conditions by locking the row until the commit, and also
+ # This avoids race conditions by locking the row until the commit, and also
# doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
- $dbw->insert( 'image',
+ $dbw->insert( 'image',
array(
'img_name' => $name,
'img_size'=> $size,
if ( $dbw->affectedRows() ) {
# Successfully inserted, this is a new image
$id = $descTitle->getArticleID();
-
+
if ( $id == 0 ) {
$seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
- $dbw->insertArray( 'cur',
- array(
+ $dbw->insertArray( 'cur',
+ array(
'cur_id' => $seqVal,
'cur_namespace' => NS_IMAGE,
'cur_title' => $name,
), $fname
);
$id = $dbw->insertId() or 0; # We should throw an error instead
-
+
RecentChange::notifyNew( $now, $descTitle, 0, $wgUser, $desc );
-
+
$u = new SearchUpdate( $id, $name, $desc );
$u->doUpdate();
}
'oi_user_text' => $s->img_user_text
), $fname
);
-
+
# Update the current image row
- $dbw->updateArray( 'image',
+ $dbw->updateArray( 'image',
array( /* SET */
'img_size' => $size,
'img_timestamp' => wfTimestampNow(),
'img_name' => $name
), $fname
);
-
+
# Invalidate the cache for the description page
$descTitle->invalidateCache();
}
# Yay, more global functions!
function wfCheckLimits( $deflimit = 50, $optionname = 'rclimit' ) {
global $wgUser, $wgRequest;
-
+
$limit = $wgRequest->getInt( 'limit', 0 );
if( $limit < 0 ) $limit = 0;
if( ( $limit == 0 ) && ( $optionname != '' ) ) {
}
if( $limit <= 0 ) $limit = $deflimit;
if( $limit > 5000 ) $limit = 5000; # We have *some* limits...
-
+
$offset = $wgRequest->getInt( 'offset', 0 );
if( $offset < 0 ) $offset = 0;
return array( $limit, $offset );
}
-# Escapes the given text so that it may be output using addWikiText()
-# without any linking, formatting, etc. making its way through. This
+# Escapes the given text so that it may be output using addWikiText()
+# without any linking, formatting, etc. making its way through. This
# is achieved by substituting certain characters with HTML entities.
# As required by the callers, <nowiki> is not used. It currently does
# not filter out characters which have special meaning only at the
# start of a line, such as "*".
function wfEscapeWikiText( $text )
{
- $text = str_replace(
+ $text = str_replace(
array( '[', '|', "'", 'ISBN ' , '://' , "\n=" ),
array( '[', '|', ''', 'ISBN ', '://' , "\n=" ),
htmlspecialchars($text) );
return $text;
}
-function wfQuotedPrintable( $string, $charset = '' )
+function wfQuotedPrintable( $string, $charset = '' )
{
# Probably incomplete; see RFC 2045
if( empty( $charset ) ) {
# This function takes two arrays as input, and returns a CGI-style string, e.g.
# "days=7&limit=100". Options in the first array override options in the second.
# Options set to "" will not be output.
-function wfArrayToCGI( $array1, $array2 = NULL )
+function wfArrayToCGI( $array1, $array2 = NULL )
{
if ( !is_null( $array2 ) ) {
$array1 = $array1 + $array2;
$first = true;
$retVal = '';
foreach ( $args as $arg ) {
- if ( !$first ) {
+ if ( !$first ) {
$retVal .= ' ';
} else {
$first = false;
return $retVal;
}
-# wfMerge attempts to merge differences between three texts.
+# wfMerge attempts to merge differences between three texts.
# Returns true for a clean merge and false for failure or a conflict.
function wfMerge( $old, $mine, $yours, &$result ){
global $wgDiff3;
- # This check may also protect against code injection in
+ # This check may also protect against code injection in
# case of broken installations.
- if(! file_exists( $wgDiff3 ) ){
+ if(! file_exists( $wgDiff3 ) ){
return false;
}
$oldtextFile = fopen( $oldtextName = tempnam( $td, 'merge-old-' ), 'w' );
$mytextFile = fopen( $mytextName = tempnam( $td, 'merge-mine-' ), 'w' );
$yourtextFile = fopen( $yourtextName = tempnam( $td, 'merge-your-' ), 'w' );
-
- fwrite( $oldtextFile, $old ); fclose( $oldtextFile );
- fwrite( $mytextFile, $mine ); fclose( $mytextFile );
+
+ fwrite( $oldtextFile, $old ); fclose( $oldtextFile );
+ fwrite( $mytextFile, $mine ); fclose( $mytextFile );
fwrite( $yourtextFile, $yours ); fclose( $yourtextFile );
# Check for a conflict
pclose( $handle );
# Merge differences
- $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a -e --merge ' .
+ $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a -e --merge ' .
wfEscapeShellArg( $mytextName, $oldtextName, $yourtextName );
$handle = popen( $cmd, 'r' );
$result = '';
header( "HTTP/1.0 $code $label" );
header( "Status: $code $label" );
$wgOut->sendCacheControl();
-
+
# Don't send content if it's a HEAD request.
if( $_SERVER['REQUEST_METHOD'] == 'HEAD' ) {
header( 'Content-type: text/plain' );
if( !$accept ) {
return array( $def => 1 );
}
-
+
$prefs = array();
-
+
$parts = explode( ',', $accept );
-
+
foreach( $parts as $part ) {
# FIXME: doesn't deal with params like 'text/html; level=1'
@list( $value, $qpart ) = explode( ';', $part );
$prefs[$value] = $match[1];
}
}
-
+
return $prefs;
}
# XXX: generalize to negotiate other stuff
function wfNegotiateType( $cprefs, $sprefs ) {
$combine = array();
-
+
foreach( array_keys($sprefs) as $type ) {
$parts = explode( '/', $type );
if( $parts[1] != '*' ) {
}
}
}
-
+
foreach( array_keys( $cprefs ) as $type ) {
$parts = explode( '/', $type );
if( $parts[1] != '*' && !array_key_exists( $type, $sprefs ) ) {
}
}
}
-
+
$bestq = 0;
$besttype = NULL;
-
+
foreach( array_keys( $combine ) as $type ) {
if( $combine[$type] > $bestq ) {
$besttype = $type;
$bestq = $combine[$type];
}
}
-
+
return $besttype;
}
# Array lookup
-# Returns an array where the values in the first array are replaced by the
+# Returns an array where the values in the first array are replaced by the
# values in the second array with the corresponding keys
function wfArrayLookup( $a, $b )
{
- return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) );
+ return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) );
}
# Since Windows is so different to any of the other popular OSes, it seems appropriate
break;
default:
return;
- }
+ }
}
?>