I am working on an extension for Mediawiki. The extension is to give permissions to user the ability to upload video files. Not sure why I keep getting this error but all docs I am reading says I needed not to use global wgUser and specify it as parameter in the function.
Error Message:
<code>TypeError: Argument 2 passed to VideoPermissionsHooks::onUploadVerifyFile() must be an instance of User, string given
</code>
<code>TypeError: Argument 2 passed to VideoPermissionsHooks::onUploadVerifyFile() must be an instance of User, string given
</code>
TypeError: Argument 2 passed to VideoPermissionsHooks::onUploadVerifyFile() must be an instance of User, string given
VideoPermissionsHooks.php
<code><?php
class VideoPermissionsHooks {
/**
* Hook: BeforePageDisplay
* @param OutputPage $out
* @param Skin $skin
*/
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
// Check if the user has permission to view videos
if ( !$out->getUser()->isAllowed( 'view_video' ) ) {
$out->addModules( 'ext.VideoPermissions.noVideo' );
}
}
/**
* Hook: UploadVerifyFile
* @param UploadBase $upload
* @param User $user
* @param string $mime
* @param bool $error
* @param string[] &$warnings
* @return bool
*/
public static function onUploadVerifyFile( $upload, User $user, $mime, &$error, array &$warnings ) {
global $wgVideoPermissionEnable;
// Check if video permissions feature is enabled
if ( !$wgVideoPermissionEnable ) {
return true; // Bypass checks if the feature is disabled
}
$fileName = $upload->getLocalFile()->getName();
$fileExtension = strtolower( pathinfo( $fileName, PATHINFO_EXTENSION ) );
// Verify if the user has permission to upload video files
if ( $fileExtension === 'mp4' ) {
if ( !$user->isAllowed( 'upload_video' ) ) {
$error = 'You do not have permission to upload video files.';
return false;
}
}
return true;
}
}
</code>
<code><?php
class VideoPermissionsHooks {
/**
* Hook: BeforePageDisplay
* @param OutputPage $out
* @param Skin $skin
*/
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
// Check if the user has permission to view videos
if ( !$out->getUser()->isAllowed( 'view_video' ) ) {
$out->addModules( 'ext.VideoPermissions.noVideo' );
}
}
/**
* Hook: UploadVerifyFile
* @param UploadBase $upload
* @param User $user
* @param string $mime
* @param bool $error
* @param string[] &$warnings
* @return bool
*/
public static function onUploadVerifyFile( $upload, User $user, $mime, &$error, array &$warnings ) {
global $wgVideoPermissionEnable;
// Check if video permissions feature is enabled
if ( !$wgVideoPermissionEnable ) {
return true; // Bypass checks if the feature is disabled
}
$fileName = $upload->getLocalFile()->getName();
$fileExtension = strtolower( pathinfo( $fileName, PATHINFO_EXTENSION ) );
// Verify if the user has permission to upload video files
if ( $fileExtension === 'mp4' ) {
if ( !$user->isAllowed( 'upload_video' ) ) {
$error = 'You do not have permission to upload video files.';
return false;
}
}
return true;
}
}
</code>
<?php
class VideoPermissionsHooks {
/**
* Hook: BeforePageDisplay
* @param OutputPage $out
* @param Skin $skin
*/
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
// Check if the user has permission to view videos
if ( !$out->getUser()->isAllowed( 'view_video' ) ) {
$out->addModules( 'ext.VideoPermissions.noVideo' );
}
}
/**
* Hook: UploadVerifyFile
* @param UploadBase $upload
* @param User $user
* @param string $mime
* @param bool $error
* @param string[] &$warnings
* @return bool
*/
public static function onUploadVerifyFile( $upload, User $user, $mime, &$error, array &$warnings ) {
global $wgVideoPermissionEnable;
// Check if video permissions feature is enabled
if ( !$wgVideoPermissionEnable ) {
return true; // Bypass checks if the feature is disabled
}
$fileName = $upload->getLocalFile()->getName();
$fileExtension = strtolower( pathinfo( $fileName, PATHINFO_EXTENSION ) );
// Verify if the user has permission to upload video files
if ( $fileExtension === 'mp4' ) {
if ( !$user->isAllowed( 'upload_video' ) ) {
$error = 'You do not have permission to upload video files.';
return false;
}
}
return true;
}
}