Index: trunk/extensions/FileInfo/FileInfo.php |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +// Stub extension created a couple years ago |
| 5 | +// (c) Brion Vibber 2007-2011 |
| 6 | +// GPLv2 blah blah |
| 7 | + |
| 8 | +// @todo add other file metadata types via {{#fileinfo:...}} |
| 9 | + |
| 10 | +# Define a setup function |
| 11 | +$wgExtensionFunctions[] = 'efFilesizeParserFunction_Setup'; |
| 12 | +# Add a hook to initialise the magic word |
| 13 | +$wgHooks['LanguageGetMagic'][] = 'efFilesizeParserFunction_Magic'; |
| 14 | + |
| 15 | +function efFilesizeParserFunction_Setup() { |
| 16 | + global $wgParser; |
| 17 | + # Set a function hook associating the "filesize" magic word with our function |
| 18 | + $wgParser->setFunctionHook( 'filesize', 'efFilesizeParserFunction_Render' ); |
| 19 | +} |
| 20 | + |
| 21 | +function efFilesizeParserFunction_Magic( &$magicWords, $langCode ) { |
| 22 | + # Add the magic word |
| 23 | + # The first array element is case sensitive, in this case it is not case sensitive |
| 24 | + # All remaining elements are synonyms for our parser function |
| 25 | + $magicWords['filesize'] = array( 0, 'filesize' ); |
| 26 | + # unless we return true, other parser functions extensions won't get loaded. |
| 27 | + return true; |
| 28 | +} |
| 29 | + |
| 30 | +function efFilesizeParserFunction_Render( &$parser, $filename = '' ) { |
| 31 | + # The parser function itself |
| 32 | + # The input parameters are wikitext with templates expanded |
| 33 | + # The output should be wikitext too |
| 34 | + $file = wfFindFile( $filename ); |
| 35 | + if( $file && $file->exists() ) { |
| 36 | + global $wgContLang; |
| 37 | + return $wgContLang->formatSize( $file->getSize() ); |
| 38 | + } else { |
| 39 | + return ''; |
| 40 | + } |
| 41 | +} |
Property changes on: trunk/extensions/FileInfo/FileInfo.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 42 | + native |