r98435 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98434‎ | r98435 | r98436 >
Date:19:23, 29 September 2011
Author:reedy
Status:ok
Tags:
Comment:
Add braces, fix whitespace

Swap $wgExtensionFunctions for ParserFirstCallInit

Fix global typo and unused variables

Fix possibly undefined string
Modified paths:
  • /trunk/extensions/LilyPond/LilyPond.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LilyPond/LilyPond.php
@@ -67,14 +67,15 @@
6868 $wgLilypondBorderX = 0;
6969 $wgLilypondBorderY = 0;
7070
 71+$wgHooks['ParserFirstCallInit'][] = 'wfLilyPondExtension';
7172
72 -$wgExtensionFunctions[] = "wfLilyPondExtension";
73 -
74 -function wfLilyPondExtension() {
75 - global $wgParser;
76 - $wgParser->setHook( "lilypond", "renderLilyPondFragment" );
77 - $wgParser->setHook( "lilymidi", "renderLilyPondMidiFragment" );
78 - $wgParser->setHook( "lilybook", "renderLilyPond" );
 73+/**
 74+ * @param $parser Parser
 75+ */
 76+function wfLilyPondExtension( $parser ) {
 77+ $parser->setHook( "lilypond", "renderLilyPondFragment" );
 78+ $parser->setHook( "lilymidi", "renderLilyPondMidiFragment" );
 79+ $parser->setHook( "lilybook", "renderLilyPond" );
7980 }
8081
8182 function renderLilyPondMidiFragment( $lilypond_code ) {
@@ -99,13 +100,10 @@
100101
101102 function renderLilyPond( $lilypond_code, $short_code = false ) {
102103 global $wgMathPath, $wgMathDirectory, $wgTmpDirectory, $wgLilypond, $wgLilypondPreMidi,
103 - $wgLilypondPostMidii, $wgLilypondTrim, $wgLilypondBorderX, $wgLilypondBorderY;
 104+ $wgLilypondPostMidi, $wgLilypondTrim, $wgLilypondBorderX, $wgLilypondBorderY;
104105
105106 $mf = wfMsg( "math_failure" );
106 - $munk = wfMsg( "math_unknown_error" );
107107
108 - $fname = "renderMusic";
109 -
110108 $md5 = md5( $lilypond_code );
111109
112110 if ( file_exists( $wgMathDirectory . "/" . $md5 . ".midi" ) ) {
@@ -116,6 +114,7 @@
117115 $post = "";
118116 }
119117
 118+ $link = '';
120119 # if short_code is supplied, this is a fragment
121120 if ( $short_code ) {
122121 $link = "<img src=\"" . $wgMathPath . "/" . $md5 . ".png\" alt=\""
@@ -125,8 +124,7 @@
126125 return $pre . $link . $post;
127126 }
128127 } else {
129 - if ( file_exists( "$wgMathDirectory/$md5-1.png" ) ) {
130 - $link = "";
 128+ if ( file_exists( "$wgMathDirectory/$md5-1.png" ) ) {
131129 for ( $i = 1; file_exists( $wgMathDirectory . "/" .
132130 $md5 . "-" . $i . ".png" );
133131 $i++ ) {
@@ -174,7 +172,7 @@
175173 wfDebug( "Lilypond: $cmd\n" );
176174 $oldcwd = getcwd();
177175 chdir( $wgTmpDirectory );
178 - $contents = exec( $cmd, $output, $ret );
 176+ exec( $cmd, $output, $ret );
179177 chdir( $oldcwd );
180178
181179 if ( $ret != 0 ) {
@@ -201,14 +199,16 @@
202200 $last_page = 0;
203201
204202 while ( false !== ( $file = readdir( $files ) ) ) {
205 - if ( substr( $file, 0, 32 ) != $md5 )
 203+ if ( substr( $file, 0, 32 ) != $md5 ) {
206204 continue;
 205+ }
207206
208207 $file_absolute = $wgTmpDirectory . "/" . $file;
209208 if ( !$short_code && preg_match( '/-page(\d+)\.png$/',
210209 $file, $matches ) ) {
211 - if ( $matches[1] > $last_page )
 210+ if ( $matches[1] > $last_page ) {
212211 $last_page = $matches[1];
 212+ }
213213 rename( $file_absolute, $wgMathDirectory . "/" .
214214 $md5 . "-" . $matches[1] . ".png" );
215215 continue;
@@ -227,8 +227,9 @@
228228 continue;
229229 }
230230
231 - if ( !is_file( $file_absolute ) )
 231+ if ( !is_file( $file_absolute ) ) {
232232 continue;
 233+ }
233234 unlink( $file_absolute );
234235 }
235236 closedir( $files );
@@ -247,12 +248,12 @@
248249 if ( $wgLilypondTrim ) {
249250 $imgFile = $wgMathDirectory . "/" . $md5 . ".png";
250251 trimImage( $imgFile, $imgFile, 0xFFFFFF );
251 - } ;
 252+ }
252253
253254 if ( $wgLilypondBorderX > 0 || $wgLilypondBorderY > 0 ) {
254255 $imgFile = $wgMathDirectory . "/" . $md5 . ".png";
255256 frameImage( $imgFile, $imgFile, 0xFFFFFF, $wgLilypondBorderX, $wgLilypondBorderY );
256 - } ;
 257+ }
257258
258259 return $pre . $link . $post;
259260 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r98439r98435 — tabs not spacesmah20:14, 29 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98414Add LilyPond modulemah16:17, 29 September 2011
r98424re r98414 -- add , check defined MEDIAWIKI, don't use shell varsmah18:18, 29 September 2011

Status & tagging log