Index: trunk/extensions/MediaFunctions/MediaFunctions.class.php |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | * |
7 | 7 | * @addtogroup Extensions |
8 | 8 | * @author Rob Church <robchur@gmail.com> |
| 9 | + * @version 1.0 |
9 | 10 | */ |
10 | 11 | class MediaFunctions { |
11 | 12 | |
— | — | @@ -55,6 +56,46 @@ |
56 | 57 | } |
57 | 58 | |
58 | 59 | /** |
| 60 | + * Get the height of an image |
| 61 | + * |
| 62 | + * @param Parser $parser Calling parser |
| 63 | + * @param string $name File name |
| 64 | + * @return string |
| 65 | + */ |
| 66 | + public static function mediaheight( $parser, $name = '' ) { |
| 67 | + $title = self::resolve( $name ); |
| 68 | + if( $title instanceof Title ) { |
| 69 | + $parser->mOutput->addImage( $title->getDBkey() ); |
| 70 | + $file = wfFindFile( $title ); |
| 71 | + return $file instanceof File |
| 72 | + ? $file->getHeight() |
| 73 | + : self::error( self::ERR_NOT_EXIST, $name ); |
| 74 | + } else { |
| 75 | + return self::error( self::ERR_INVALID_TITLE, $name ); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Get the width of an image |
| 81 | + * |
| 82 | + * @param Parser $parser Calling parser |
| 83 | + * @param string $name File name |
| 84 | + * @return string |
| 85 | + */ |
| 86 | + public static function mediawidth( $parser, $name = '' ) { |
| 87 | + $title = self::resolve( $name ); |
| 88 | + if( $title instanceof Title ) { |
| 89 | + $parser->mOutput->addImage( $title->getDBkey() ); |
| 90 | + $file = wfFindFile( $title ); |
| 91 | + return $file instanceof File |
| 92 | + ? $file->getWidth() |
| 93 | + : self::error( self::ERR_NOT_EXIST, $name ); |
| 94 | + } else { |
| 95 | + return self::error( self::ERR_INVALID_TITLE, $name ); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + /** |
59 | 100 | * Convert a string title into a Title |
60 | 101 | * |
61 | 102 | * The string can be with or without namespace, and might |
Index: trunk/extensions/MediaFunctions/MediaFunctions.i18n.php |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | * |
7 | 7 | * @addtogroup Extensions |
8 | 8 | * @author Rob Church <robchur@gmail.com> |
| 9 | + * @version 1.0 |
9 | 10 | */ |
10 | 11 | |
11 | 12 | /** |
— | — | @@ -20,8 +21,10 @@ |
21 | 22 | * English |
22 | 23 | */ |
23 | 24 | $words['en'] = array( |
24 | | - 'mediamime' => array( 0, 'mediamime' ), |
25 | | - 'mediasize' => array( 0, 'mediasize' ), |
| 25 | + 'mediamime' => array( 0, 'mediamime' ), |
| 26 | + 'mediasize' => array( 0, 'mediasize' ), |
| 27 | + 'mediaheight' => array( 0, 'mediaheight' ), |
| 28 | + 'mediawidth' => array( 0, 'mediawidth' ), |
26 | 29 | ); |
27 | 30 | |
28 | 31 | # English is used as a fallback, and the English synonyms are |
Index: trunk/extensions/MediaFunctions/MediaFunctions.php |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | * |
8 | 8 | * @addtogroup Extensions |
9 | 9 | * @author Rob Church <robchur@gmail.com> |
| 10 | + * @version 1.0 |
10 | 11 | */ |
11 | 12 | |
12 | 13 | if( defined( 'MEDIAWIKI' ) ) { |
— | — | @@ -28,6 +29,8 @@ |
29 | 30 | global $wgParser, $wgMessageCache; |
30 | 31 | $wgParser->setFunctionHook( 'mediamime', array( 'MediaFunctions', 'mediamime' ) ); |
31 | 32 | $wgParser->setFunctionHook( 'mediasize', array( 'MediaFunctions', 'mediasize' ) ); |
| 33 | + $wgParser->setFunctionHook( 'mediaheight', array( 'MediaFunctions', 'mediaheight' ) ); |
| 34 | + $wgParser->setFunctionHook( 'mediawidth', array( 'MediaFunctions', 'mediawidth' ) ); |
32 | 35 | require_once( dirname( __FILE__ ) . '/MediaFunctions.i18n.php' ); |
33 | 36 | foreach( efMediaFunctionsMessages() as $lang => $messages ) |
34 | 37 | $wgMessageCache->addMessages( $messages, $lang ); |