r54818 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54817‎ | r54818 | r54819 >
Date:22:17, 11 August 2009
Author:siebrand
Status:deferred
Tags:
Comment:
* new style magic words support for MediaFunctions
* add localisation support for MediaFunctions magic in Translate
* stylize.php, formatting updates, trailing whitespace removed
* bump version
Modified paths:
  • /trunk/extensions/MediaFunctions/LICENCE (modified) (history)
  • /trunk/extensions/MediaFunctions/MediaFunctions.class.php (modified) (history)
  • /trunk/extensions/MediaFunctions/MediaFunctions.i18n.magic.php (modified) (history)
  • /trunk/extensions/MediaFunctions/MediaFunctions.i18n.php (modified) (history)
  • /trunk/extensions/MediaFunctions/MediaFunctions.php (modified) (history)
  • /trunk/extensions/Translate/groups/mediawiki-defines.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/groups/mediawiki-defines.txt
@@ -555,6 +555,7 @@
556556 magicfile = MathStatFunctions/MathStatFunctions.i18n.magic.php
557557
558558 Media Functions
 559+magicfile = MediaFunctions/MediaFunctions.i18n.magic.php
559560
560561 Meta Keywords
561562 optional = metakeywords, metadescription
Index: trunk/extensions/MediaFunctions/LICENCE
@@ -2,7 +2,7 @@
33 All rights reserved
44
55 Redistribution and use in source and binary forms, with or without
6 -modification, are permitted provided that the following conditions
 6+modification, are permitted provided that the following conditions
77 are met:
88
99 1. Redistributions of source code must retain the above copyright
@@ -24,4 +24,4 @@
2525 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2626 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
2727 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
28 -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
 28+USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Index: trunk/extensions/MediaFunctions/MediaFunctions.class.php
@@ -23,7 +23,7 @@
2424 * @return string
2525 */
2626 public static function mediamime( $parser, $name = '' ) {
27 - if( ( $file = self::resolve( $name ) ) instanceof File ) {
 27+ if ( ( $file = self::resolve( $name ) ) instanceof File ) {
2828 $parser->mOutput->addImage( $file->getTitle()->getDBkey() );
2929 return $file->getMimeType();
3030 }
@@ -38,7 +38,7 @@
3939 * @return string
4040 */
4141 public static function mediasize( $parser, $name = '' ) {
42 - if( ( $file = self::resolve( $name ) ) instanceof File ) {
 42+ if ( ( $file = self::resolve( $name ) ) instanceof File ) {
4343 $parser->mOutput->addImage( $file->getTitle()->getDBkey() );
4444 return $parser->mOptions->getSkin()->formatSize( $file->getSize() );
4545 }
@@ -53,7 +53,7 @@
5454 * @return string
5555 */
5656 public static function mediaheight( $parser, $name = '' ) {
57 - if( ( $file = self::resolve( $name ) ) instanceof File ) {
 57+ if ( ( $file = self::resolve( $name ) ) instanceof File ) {
5858 $parser->mOutput->addImage( $file->getTitle()->getDBkey() );
5959 return $file->getHeight();
6060 }
@@ -68,7 +68,7 @@
6969 * @return string
7070 */
7171 public static function mediawidth( $parser, $name = '' ) {
72 - if( ( $file = self::resolve( $name ) ) instanceof File ) {
 72+ if ( ( $file = self::resolve( $name ) ) instanceof File ) {
7373 $parser->mOutput->addImage( $file->getTitle()->getDBkey() );
7474 return $file->getWidth();
7575 }
@@ -84,7 +84,7 @@
8585 * @return string
8686 */
8787 public static function mediadimensions( $parser, $name = '' ) {
88 - if( ( $file = self::resolve( $name ) ) instanceof File ) {
 88+ if ( ( $file = self::resolve( $name ) ) instanceof File ) {
8989 $parser->mOutput->addImage( $file->getTitle()->getDBkey() );
9090 return $file->getDimensionsString();
9191 }
@@ -100,11 +100,11 @@
101101 * @return string
102102 */
103103 public static function mediaexif( $parser, $name = '', $meta = '' ) {
104 - if( ( $file = self::resolve( $name ) ) instanceof File ) {
 104+ if ( ( $file = self::resolve( $name ) ) instanceof File ) {
105105 $parser->mOutput->addImage( $file->getTitle()->getDBkey() );
106 - if( $meta && $file->getHandler()->getMetadataType( $file ) == 'exif' ) {
 106+ if ( $meta && $file->getHandler()->getMetadataType( $file ) == 'exif' ) {
107107 $data = unserialize( $file->getMetadata() );
108 - if( $data && isset( $data[$meta] ) )
 108+ if ( $data && isset( $data[$meta] ) )
109109 return htmlspecialchars( $data[$meta] );
110110 }
111111 return '';
@@ -123,10 +123,10 @@
124124 * @return mixed File or string
125125 */
126126 private static function resolve( $text ) {
127 - if( $text ) {
 127+ if ( $text ) {
128128 $title = Title::newFromText( $text );
129 - if( $title instanceof Title ) {
130 - if( $title->getNamespace() != NS_IMAGE )
 129+ if ( $title instanceof Title ) {
 130+ if ( $title->getNamespace() != NS_IMAGE )
131131 $title = Title::makeTitle( NS_IMAGE, $title->getText() );
132132 $file = wfFindFile( $title );
133133 return $file instanceof File
Index: trunk/extensions/MediaFunctions/MediaFunctions.i18n.magic.php
@@ -8,42 +8,26 @@
99 * @version 1.1
1010 */
1111
 12+$magicWords = array();
 13+
1214 /**
13 - * Get translated magic words, if available
14 - *
15 - * @param string $lang Language code
16 - * @return array
 15+ * English
1716 */
18 -function efMediaFunctionsWords( $lang ) {
19 - $words = array();
 17+$magicWords['en'] = array(
 18+ 'mediamime' => array( 0, 'mediamime' ),
 19+ 'mediasize' => array( 0, 'mediasize' ),
 20+ 'mediaheight' => array( 0, 'mediaheight' ),
 21+ 'mediawidth' => array( 0, 'mediawidth' ),
 22+ 'mediadimensions' => array( 0, 'mediadimensions' ),
 23+ 'mediaexif' => array( 0, 'mediaexif' ),
 24+);
2025
21 - /**
22 - * English
23 - */
24 - $words['en'] = array(
25 - 'mediamime' => array( 0, 'mediamime' ),
26 - 'mediasize' => array( 0, 'mediasize' ),
27 - 'mediaheight' => array( 0, 'mediaheight' ),
28 - 'mediawidth' => array( 0, 'mediawidth' ),
29 - 'mediadimensions' => array( 0, 'mediadimensions' ),
30 - 'mediaexif' => array( 0, 'mediaexif' ),
31 - );
32 -
33 - /**
34 - * Dutch
35 - */
36 - $words['nl'] = array(
37 - 'mediamime' => array( 0, 'mediamime' ),
38 - 'mediasize' => array( 0, 'mediagrootte', 'mediasize' ),
39 - 'mediaheight' => array( 0, 'mediahoogte', 'mediaheight' ),
40 - 'mediawidth' => array( 0, 'mediabreedte', 'mediawidth' ),
41 - 'mediadimensions' => array( 0, 'mediaafmetingen', 'mediadimensions' ),
42 - 'mediaexif' => array( 0, 'mediaexif' ),
43 - );
44 -
45 - # English is used as a fallback, and the English synonyms are
46 - # used if a translation has not been provided for a given word
47 - return ( $lang == 'en' || !isset( $words[$lang] ) )
48 - ? $words['en']
49 - : array_merge( $words['en'], $words[$lang] );
50 -}
 26+/**
 27+ * Dutch
 28+ */
 29+$magicWords['nl'] = array(
 30+ 'mediasize' => array( 0, 'mediagrootte', 'mediasize' ),
 31+ 'mediaheight' => array( 0, 'mediahoogte', 'mediaheight' ),
 32+ 'mediawidth' => array( 0, 'mediabreedte', 'mediawidth' ),
 33+ 'mediadimensions' => array( 0, 'mediaafmetingen', 'mediadimensions' ),
 34+);
Index: trunk/extensions/MediaFunctions/MediaFunctions.i18n.php
@@ -7,6 +7,8 @@
88 * @version 1.2
99 */
1010
 11+require_once( dirname( __FILE__ ) . '/MediaFunctions.i18n.magic.php' );
 12+
1113 $messages = array();
1214
1315 /* English
Index: trunk/extensions/MediaFunctions/MediaFunctions.php
@@ -1,28 +1,27 @@
22 <?php
3 -if (!defined('MEDIAWIKI')) die();
 3+if ( !defined( 'MEDIAWIKI' ) ) die();
44 /**
55 * Parser functions for MediaWiki providing information
66 * about various media files
77 *
88 * @addtogroup Extensions
99 * @author Rob Church <robchur@gmail.com>
10 - * @version 1.1
 10+ * @version 1.2
1111 */
1212
1313 $wgExtensionCredits['parserhook'][] = array(
1414 'path' => __FILE__,
1515 'name' => 'MediaFunctions',
16 - 'version' => '1.1',
 16+ 'version' => '1.2',
1717 'author' => 'Rob Church',
1818 'url' => 'http://www.mediawiki.org/wiki/Extension:MediaFunctions',
1919 'description' => 'Parser functions for obtaining information about media files',
2020 'descriptionmsg' => 'mediafunctions-desc',
2121 );
2222
23 -$dir = dirname(__FILE__) . '/';
 23+$dir = dirname( __FILE__ ) . '/';
2424 $wgExtensionMessagesFiles['MediaFunctions'] = $dir . 'MediaFunctions.i18n.php';
2525 $wgAutoloadClasses['MediaFunctions'] = $dir . 'MediaFunctions.class.php';
26 -$wgHooks['LanguageGetMagic'][] = 'efMediaFunctionsGetMagic';
2726 $wgExtensionFunctions[] = 'efMediaFunctionsSetup';
2827
2928 /**
@@ -38,17 +37,3 @@
3938 $wgParser->setFunctionHook( 'mediadimensions', array( 'MediaFunctions', 'mediadimensions' ) );
4039 $wgParser->setFunctionHook( 'mediaexif', array( 'MediaFunctions', 'mediaexif' ) );
4140 }
42 -
43 -/**
44 - * Associate magic words with synonyms
45 - *
46 - * @param array $words Magic words
47 - * @param string $lang Language code
48 - * @return bool
49 - */
50 -function efMediaFunctionsGetMagic( &$words, $lang ) {
51 - require_once( dirname( __FILE__ ) . '/MediaFunctions.i18n.magic.php' );
52 - foreach( efMediaFunctionsWords( $lang ) as $word => $trans )
53 - $words[$word] = $trans;
54 - return true;
55 -}

Status & tagging log