r22854 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22853‎ | r22854 | r22855 >
Date:21:02, 8 June 2007
Author:robchurch
Status:old
Tags:
Comment:
* Version 1.0
* Introduce {{#mediaheight}} and {{#mediawidth}}
Modified paths:
  • /trunk/extensions/MediaFunctions/MediaFunctions.class.php (modified) (history)
  • /trunk/extensions/MediaFunctions/MediaFunctions.i18n.php (modified) (history)
  • /trunk/extensions/MediaFunctions/MediaFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MediaFunctions/MediaFunctions.class.php
@@ -5,6 +5,7 @@
66 *
77 * @addtogroup Extensions
88 * @author Rob Church <robchur@gmail.com>
 9+ * @version 1.0
910 */
1011 class MediaFunctions {
1112
@@ -55,6 +56,46 @@
5657 }
5758
5859 /**
 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+ /**
59100 * Convert a string title into a Title
60101 *
61102 * The string can be with or without namespace, and might
Index: trunk/extensions/MediaFunctions/MediaFunctions.i18n.php
@@ -5,6 +5,7 @@
66 *
77 * @addtogroup Extensions
88 * @author Rob Church <robchur@gmail.com>
 9+ * @version 1.0
910 */
1011
1112 /**
@@ -20,8 +21,10 @@
2122 * English
2223 */
2324 $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' ),
2629 );
2730
2831 # English is used as a fallback, and the English synonyms are
Index: trunk/extensions/MediaFunctions/MediaFunctions.php
@@ -6,6 +6,7 @@
77 *
88 * @addtogroup Extensions
99 * @author Rob Church <robchur@gmail.com>
 10+ * @version 1.0
1011 */
1112
1213 if( defined( 'MEDIAWIKI' ) ) {
@@ -28,6 +29,8 @@
2930 global $wgParser, $wgMessageCache;
3031 $wgParser->setFunctionHook( 'mediamime', array( 'MediaFunctions', 'mediamime' ) );
3132 $wgParser->setFunctionHook( 'mediasize', array( 'MediaFunctions', 'mediasize' ) );
 33+ $wgParser->setFunctionHook( 'mediaheight', array( 'MediaFunctions', 'mediaheight' ) );
 34+ $wgParser->setFunctionHook( 'mediawidth', array( 'MediaFunctions', 'mediawidth' ) );
3235 require_once( dirname( __FILE__ ) . '/MediaFunctions.i18n.php' );
3336 foreach( efMediaFunctionsMessages() as $lang => $messages )
3437 $wgMessageCache->addMessages( $messages, $lang );

Status & tagging log