Fix whitespace, braces
Fix return items
This commit is contained in:
parent
0c9fea9ad6
commit
d90b987ade
6 changed files with 43 additions and 22 deletions
37
img_auth.php
37
img_auth.php
|
|
@ -50,8 +50,7 @@ $whitelist = array();
|
|||
if ( $dotPos !== false ) {
|
||||
$whitelist[] = substr( $path, $dotPos + 1 );
|
||||
}
|
||||
if ( !$wgRequest->checkUrlExtension( $whitelist ) )
|
||||
{
|
||||
if ( !$wgRequest->checkUrlExtension( $whitelist ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -59,38 +58,44 @@ $filename = realpath( $wgUploadDirectory . $path );
|
|||
$realUpload = realpath( $wgUploadDirectory );
|
||||
|
||||
// Basic directory traversal check
|
||||
if( substr( $filename, 0, strlen( $realUpload ) ) != $realUpload )
|
||||
if( substr( $filename, 0, strlen( $realUpload ) ) != $realUpload ) {
|
||||
wfForbidden('img-auth-accessdenied','img-auth-notindir');
|
||||
}
|
||||
|
||||
// Extract the file name and chop off the size specifier
|
||||
// (e.g. 120px-Foo.png => Foo.png)
|
||||
$name = wfBaseName( $path );
|
||||
if( preg_match( '!\d+px-(.*)!i', $name, $m ) )
|
||||
if( preg_match( '!\d+px-(.*)!i', $name, $m ) ) {
|
||||
$name = $m[1];
|
||||
}
|
||||
|
||||
// Check to see if the file exists
|
||||
if( !file_exists( $filename ) )
|
||||
if( !file_exists( $filename ) ) {
|
||||
wfForbidden('img-auth-accessdenied','img-auth-nofile',$filename);
|
||||
}
|
||||
|
||||
// Check to see if tried to access a directory
|
||||
if( is_dir( $filename ) )
|
||||
if( is_dir( $filename ) ) {
|
||||
wfForbidden('img-auth-accessdenied','img-auth-isdir',$filename);
|
||||
|
||||
}
|
||||
|
||||
$title = Title::makeTitleSafe( NS_FILE, $name );
|
||||
|
||||
// See if could create the title object
|
||||
if( !$title instanceof Title )
|
||||
if( !$title instanceof Title ) {
|
||||
wfForbidden('img-auth-accessdenied','img-auth-badtitle',$name);
|
||||
}
|
||||
|
||||
// Run hook
|
||||
if (!wfRunHooks( 'ImgAuthBeforeStream', array( &$title, &$path, &$name, &$result ) ) )
|
||||
if (!wfRunHooks( 'ImgAuthBeforeStream', array( &$title, &$path, &$name, &$result ) ) ) {
|
||||
wfForbidden($result[0],$result[1],array_slice($result,2));
|
||||
}
|
||||
|
||||
// Check user authorization for this title
|
||||
// UserCanRead Checks Whitelist too
|
||||
if( !$title->userCanRead() )
|
||||
if( !$title->userCanRead() ) {
|
||||
wfForbidden('img-auth-accessdenied','img-auth-noread',$name);
|
||||
}
|
||||
|
||||
// Stream the requested file
|
||||
wfDebugLog( 'img_auth', "Streaming `".$filename."`." );
|
||||
|
|
@ -101,16 +106,18 @@ wfLogProfilingData();
|
|||
* Issue a standard HTTP 403 Forbidden header ($msg1-a message index, not a message) and an
|
||||
* error message ($msg2, also a message index), (both required) then end the script
|
||||
* subsequent arguments to $msg2 will be passed as parameters only for replacing in $msg2
|
||||
* @param $msg1
|
||||
* @param $msg2
|
||||
*/
|
||||
function wfForbidden($msg1,$msg2) {
|
||||
function wfForbidden( $msg1, $msg2 ) {
|
||||
global $wgImgAuthDetails;
|
||||
$args = func_get_args();
|
||||
array_shift( $args );
|
||||
array_shift( $args );
|
||||
$MsgHdr = htmlspecialchars(wfMsg($msg1));
|
||||
$detailMsg = (htmlspecialchars(wfMsg(($wgImgAuthDetails ? $msg2 : 'badaccess-group0'),$args)));
|
||||
wfDebugLog('img_auth', "wfForbidden Hdr:".wfMsgExt( $msg1, array('language' => 'en'))." Msg: ".
|
||||
wfMsgExt($msg2,array('language' => 'en'),$args));
|
||||
$MsgHdr = htmlspecialchars( wfMsg( $msg1 ) );
|
||||
$detailMsg = ( htmlspecialchars( wfMsg( ( $wgImgAuthDetails ? $msg2 : 'badaccess-group0' ), $args ) ) );
|
||||
wfDebugLog('img_auth', "wfForbidden Hdr:".wfMsgExt( $msg1, array( 'language' => 'en' ) )." Msg: ".
|
||||
wfMsgExt( $msg2, array('language' => 'en' ), $args ) );
|
||||
header( 'HTTP/1.0 403 Forbidden' );
|
||||
header( 'Cache-Control: no-cache' );
|
||||
header( 'Content-Type: text/html; charset=utf-8' );
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ function wfUrlencode( $s ) {
|
|||
static $needle;
|
||||
if ( is_null( $s ) ) {
|
||||
$needle = null;
|
||||
return;
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( is_null( $needle ) ) {
|
||||
|
|
@ -537,6 +537,7 @@ function wfUrlProtocols( $includeProtocolRelative = true ) {
|
|||
* Like wfUrlProtocols(), but excludes '//' from the protocol list. Use this if
|
||||
* you need a regex that matches all URL protocols but does not match protocol-
|
||||
* relative URLs
|
||||
* @return String
|
||||
*/
|
||||
function wfUrlProtocolsWithoutProtRel() {
|
||||
return wfUrlProtocols( false );
|
||||
|
|
@ -960,6 +961,9 @@ function wfReadOnly() {
|
|||
return (bool)$wgReadOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function wfReadOnlyReason() {
|
||||
global $wgReadOnly;
|
||||
wfReadOnly();
|
||||
|
|
@ -2888,6 +2892,7 @@ function wfRelativePath( $path, $from ) {
|
|||
*
|
||||
* @deprecated since 1.19
|
||||
* @see DeferredUpdates::doUpdate()
|
||||
* @param $commit string
|
||||
*/
|
||||
function wfDoUpdates( $commit = '' ) {
|
||||
DeferredUpdates::doUpdates( $commit );
|
||||
|
|
@ -2985,6 +2990,7 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1, $lowercase = t
|
|||
*
|
||||
* @param $name String
|
||||
* @param $p Array: parameters
|
||||
* @return object
|
||||
* @deprecated since 1.18, warnings in 1.18, removal in 1.20
|
||||
*/
|
||||
function wfCreateObject( $name, $p ) {
|
||||
|
|
@ -2992,6 +2998,9 @@ function wfCreateObject( $name, $p ) {
|
|||
return MWFunction::newObj( $name, $p );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function wfHttpOnlySafe() {
|
||||
global $wgHttpOnlyBlacklist;
|
||||
|
||||
|
|
@ -3122,7 +3131,6 @@ function wfWikiID() {
|
|||
* Split a wiki ID into DB name and table prefix
|
||||
*
|
||||
* @param $wiki String
|
||||
* @param $bits String
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -3382,7 +3390,6 @@ function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
|
|||
*
|
||||
* @param $maxLag Integer (deprecated)
|
||||
* @param $wiki mixed Wiki identifier accepted by wfGetLB
|
||||
* @return null
|
||||
*/
|
||||
function wfWaitForSlaves( $maxLag = false, $wiki = false ) {
|
||||
$lb = wfGetLB( $wiki );
|
||||
|
|
@ -3414,6 +3421,7 @@ function wfOut( $s ) {
|
|||
* Count down from $n to zero on the terminal, with a one-second pause
|
||||
* between showing each number. For use in command-line scripts.
|
||||
* @codeCoverageIgnore
|
||||
* @param $n int
|
||||
*/
|
||||
function wfCountDown( $n ) {
|
||||
for ( $i = $n; $i >= 0; $i-- ) {
|
||||
|
|
@ -3522,7 +3530,7 @@ function wfShorthandToInteger( $string = '' ) {
|
|||
* See unit test for examples.
|
||||
*
|
||||
* @param $code String: The language code.
|
||||
* @return $langCode String: The language code which complying with BCP 47 standards.
|
||||
* @return String: The language code which complying with BCP 47 standards.
|
||||
*/
|
||||
function wfBCP47( $code ) {
|
||||
$codeSegment = explode( '-', $code );
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ abstract class Page {}
|
|||
class WikiPage extends Page {
|
||||
/**
|
||||
* @var Title
|
||||
* @protected
|
||||
*/
|
||||
public $mTitle = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* A special page listing redirects tonon existent page. Those should be
|
||||
* A special page listing redirects to non existent page. Those should be
|
||||
* fixed to point to an existing page.
|
||||
*
|
||||
* @ingroup SpecialPage
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ function wfThumbMain() {
|
|||
// Check permissions if there are read restrictions
|
||||
if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) {
|
||||
if ( !$img->getTitle()->userCanRead() ) {
|
||||
wfThumbError( 403, 'Access denied. You do not have permission to access ' .
|
||||
wfThumbError( 403, 'Access denied. You do not have permission to access ' .
|
||||
'the source file.' );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return;
|
||||
|
|
@ -162,6 +162,10 @@ function wfThumbMain() {
|
|||
wfProfileOut( __METHOD__ );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $status
|
||||
* @param $msg
|
||||
*/
|
||||
function wfThumbError( $status, $msg ) {
|
||||
global $wgShowHostnames;
|
||||
header( 'Cache-Control: no-cache' );
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ XML;
|
|||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $err string
|
||||
*/
|
||||
private function XMLerror( $err = "Invalid request." ) {
|
||||
header( "HTTP/1.0 400 Bad Request" );
|
||||
header( "Content-Type: application/xml; charset=utf-8" );
|
||||
|
|
|
|||
Loading…
Reference in a new issue