Index: trunk/extensions/LilyPond/LilyPond.php |
— | — | @@ -67,14 +67,15 @@ |
68 | 68 | $wgLilypondBorderX = 0; |
69 | 69 | $wgLilypondBorderY = 0; |
70 | 70 | |
| 71 | +$wgHooks['ParserFirstCallInit'][] = 'wfLilyPondExtension'; |
71 | 72 | |
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" ); |
79 | 80 | } |
80 | 81 | |
81 | 82 | function renderLilyPondMidiFragment( $lilypond_code ) { |
— | — | @@ -99,13 +100,10 @@ |
100 | 101 | |
101 | 102 | function renderLilyPond( $lilypond_code, $short_code = false ) { |
102 | 103 | global $wgMathPath, $wgMathDirectory, $wgTmpDirectory, $wgLilypond, $wgLilypondPreMidi, |
103 | | - $wgLilypondPostMidii, $wgLilypondTrim, $wgLilypondBorderX, $wgLilypondBorderY; |
| 104 | + $wgLilypondPostMidi, $wgLilypondTrim, $wgLilypondBorderX, $wgLilypondBorderY; |
104 | 105 | |
105 | 106 | $mf = wfMsg( "math_failure" ); |
106 | | - $munk = wfMsg( "math_unknown_error" ); |
107 | 107 | |
108 | | - $fname = "renderMusic"; |
109 | | - |
110 | 108 | $md5 = md5( $lilypond_code ); |
111 | 109 | |
112 | 110 | if ( file_exists( $wgMathDirectory . "/" . $md5 . ".midi" ) ) { |
— | — | @@ -116,6 +114,7 @@ |
117 | 115 | $post = ""; |
118 | 116 | } |
119 | 117 | |
| 118 | + $link = ''; |
120 | 119 | # if short_code is supplied, this is a fragment |
121 | 120 | if ( $short_code ) { |
122 | 121 | $link = "<img src=\"" . $wgMathPath . "/" . $md5 . ".png\" alt=\"" |
— | — | @@ -125,8 +124,7 @@ |
126 | 125 | return $pre . $link . $post; |
127 | 126 | } |
128 | 127 | } else { |
129 | | - if ( file_exists( "$wgMathDirectory/$md5-1.png" ) ) { |
130 | | - $link = ""; |
| 128 | + if ( file_exists( "$wgMathDirectory/$md5-1.png" ) ) { |
131 | 129 | for ( $i = 1; file_exists( $wgMathDirectory . "/" . |
132 | 130 | $md5 . "-" . $i . ".png" ); |
133 | 131 | $i++ ) { |
— | — | @@ -174,7 +172,7 @@ |
175 | 173 | wfDebug( "Lilypond: $cmd\n" ); |
176 | 174 | $oldcwd = getcwd(); |
177 | 175 | chdir( $wgTmpDirectory ); |
178 | | - $contents = exec( $cmd, $output, $ret ); |
| 176 | + exec( $cmd, $output, $ret ); |
179 | 177 | chdir( $oldcwd ); |
180 | 178 | |
181 | 179 | if ( $ret != 0 ) { |
— | — | @@ -201,14 +199,16 @@ |
202 | 200 | $last_page = 0; |
203 | 201 | |
204 | 202 | while ( false !== ( $file = readdir( $files ) ) ) { |
205 | | - if ( substr( $file, 0, 32 ) != $md5 ) |
| 203 | + if ( substr( $file, 0, 32 ) != $md5 ) { |
206 | 204 | continue; |
| 205 | + } |
207 | 206 | |
208 | 207 | $file_absolute = $wgTmpDirectory . "/" . $file; |
209 | 208 | if ( !$short_code && preg_match( '/-page(\d+)\.png$/', |
210 | 209 | $file, $matches ) ) { |
211 | | - if ( $matches[1] > $last_page ) |
| 210 | + if ( $matches[1] > $last_page ) { |
212 | 211 | $last_page = $matches[1]; |
| 212 | + } |
213 | 213 | rename( $file_absolute, $wgMathDirectory . "/" . |
214 | 214 | $md5 . "-" . $matches[1] . ".png" ); |
215 | 215 | continue; |
— | — | @@ -227,8 +227,9 @@ |
228 | 228 | continue; |
229 | 229 | } |
230 | 230 | |
231 | | - if ( !is_file( $file_absolute ) ) |
| 231 | + if ( !is_file( $file_absolute ) ) { |
232 | 232 | continue; |
| 233 | + } |
233 | 234 | unlink( $file_absolute ); |
234 | 235 | } |
235 | 236 | closedir( $files ); |
— | — | @@ -247,12 +248,12 @@ |
248 | 249 | if ( $wgLilypondTrim ) { |
249 | 250 | $imgFile = $wgMathDirectory . "/" . $md5 . ".png"; |
250 | 251 | trimImage( $imgFile, $imgFile, 0xFFFFFF ); |
251 | | - } ; |
| 252 | + } |
252 | 253 | |
253 | 254 | if ( $wgLilypondBorderX > 0 || $wgLilypondBorderY > 0 ) { |
254 | 255 | $imgFile = $wgMathDirectory . "/" . $md5 . ".png"; |
255 | 256 | frameImage( $imgFile, $imgFile, 0xFFFFFF, $wgLilypondBorderX, $wgLilypondBorderY ); |
256 | | - } ; |
| 257 | + } |
257 | 258 | |
258 | 259 | return $pre . $link . $post; |
259 | 260 | } |