if ( $dotPos !== false ) {
$whitelist[] = substr( $path, $dotPos + 1 );
}
-if ( !$wgRequest->checkUrlExtension( $whitelist ) )
-{
+if ( !$wgRequest->checkUrlExtension( $whitelist ) ) {
return;
}
$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."`." );
* 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' );
static $needle;
if ( is_null( $s ) ) {
$needle = null;
- return;
+ return '';
}
if ( is_null( $needle ) ) {
* 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 );
return (bool)$wgReadOnly;
}
+/**
+ * @return bool
+ */
function wfReadOnlyReason() {
global $wgReadOnly;
wfReadOnly();
*
* @deprecated since 1.19
* @see DeferredUpdates::doUpdate()
+ * @param $commit string
*/
function wfDoUpdates( $commit = '' ) {
DeferredUpdates::doUpdates( $commit );
*
* @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 ) {
return MWFunction::newObj( $name, $p );
}
+/**
+ * @return bool
+ */
function wfHttpOnlySafe() {
global $wgHttpOnlyBlacklist;
* Split a wiki ID into DB name and table prefix
*
* @param $wiki String
- * @param $bits String
*
* @return array
*/
*
* @param $maxLag Integer (deprecated)
* @param $wiki mixed Wiki identifier accepted by wfGetLB
- * @return null
*/
function wfWaitForSlaves( $maxLag = false, $wiki = false ) {
$lb = wfGetLB( $wiki );
* 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-- ) {
* 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 );