Manual:Hooks/ImgAuthBeforeStream
ImgAuthBeforeStream | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> executed before the file is streamed to the browser, but only when using Manual:Image authorization . | |
<translate> Define function:</translate> | public static function onImgAuthBeforeStream( Title &$title, &$path, &$name, array &$result ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"ImgAuthBeforeStream": "MediaWiki\\Extension\\MyExtension\\Hooks::onImgAuthBeforeStream"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> ../img_auth.php |
<translate> Interface:</translate> | ImgAuthBeforeStreamHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:ImgAuthBeforeStream extensions</tvar>.</translate>
Details
If the hook returns true, it will go ahead and stream the file. If not, it will display the indexed messages returned in $result[0]
and $result[1]
.
&$title
: the Title object of the file as it would appear for the upload page&$path
: the original file and path name whenimg_auth
was invoked by the the web server&$name
: the name only component of the file&$result
: The location to pass back results of the hook routine (only used if failed)$result[0]
: The index of the header message$result[1]
: The index of the body text message$result[2 through n]
: Parameters passed to body text message. Please note the header message cannot receive/use parameters.
IMPORTANT: Parameters $result[0]
, and $result[1]
are message indices, NOT actual messages. They will be resolved and localized using wfMsgHTML($msgIndex). Parameters are only be passed to the body text message. For help in defining and using messages, see: System Messages
Example
This example hook routinely checks to see if the file was stored in Namespace mode, and if so, modifies the Title to include the namespace. If the title is now invalid, returns indexes to the header and body text of the user messages as well as the name of the file ($name
) as a parameter which is passed used by the body text.
$wgHooks['ImgAuthBeforeStream'][] = 'NSFileRepoImgAuthCheck';
function NSFileRepoImgAuthCheck($title, $path, $name, $result) {
global $wgContLang;
# See if stored in a NS path
$subdirs = explode('/',$path);
if (strlen($subdirs[1]) == 3 && is_numeric($subdirs[1]) && $subdirs[1] >= 100) {
$title = Title::makeTitleSafe( NS_FILE, $wgContLang->getNsText($subdirs[1]).":".$name );
if( !$title instanceof Title ) {
$result = array('img-auth-accessdenied','img-auth-badtitle',$name);
return false;
}
}
return true;
}