Index: trunk/extensions/LilyPond/LilyPond.php |
— | — | @@ -72,16 +72,25 @@ |
73 | 73 | /** |
74 | 74 | * @param $parser Parser |
75 | 75 | */ |
76 | | -function wfLilyPondExtension( $parser ) { |
| 76 | +function wfLilyPondExtension( &$parser ) { |
77 | 77 | $parser->setHook( "lilypond", "renderLilyPondFragment" ); |
78 | 78 | $parser->setHook( "lilymidi", "renderLilyPondMidiFragment" ); |
79 | 79 | $parser->setHook( "lilybook", "renderLilyPond" ); |
80 | 80 | } |
81 | 81 | |
| 82 | +/** |
| 83 | + * @param $lilypond_code string |
| 84 | + * @return string |
| 85 | + */ |
82 | 86 | function renderLilyPondMidiFragment( $lilypond_code ) { |
83 | 87 | return renderLilyPondFragment( $lilypond_code, true ); |
84 | 88 | } |
85 | 89 | |
| 90 | +/** |
| 91 | + * @param $lilypond_code string |
| 92 | + * @param $midi bool |
| 93 | + * @return string |
| 94 | + */ |
86 | 95 | function renderLilyPondFragment( $lilypond_code, $midi = false ) { |
87 | 96 | return renderLilyPond( "\\header {\n" |
88 | 97 | . "\ttagline = ##f\n" |
— | — | @@ -98,11 +107,16 @@ |
99 | 108 | . "}\n", $lilypond_code ); |
100 | 109 | } |
101 | 110 | |
| 111 | +/** |
| 112 | + * @param $lilypond_code |
| 113 | + * @param $short_code bool |
| 114 | + * @return string |
| 115 | + */ |
102 | 116 | function renderLilyPond( $lilypond_code, $short_code = false ) { |
103 | 117 | global $wgMathPath, $wgMathDirectory, $wgTmpDirectory, $wgLilypond, $wgLilypondPreMidi, |
104 | 118 | $wgLilypondPostMidi, $wgLilypondTrim, $wgLilypondBorderX, $wgLilypondBorderY; |
105 | 119 | |
106 | | - $mf = wfMsg( "math_failure" ); |
| 120 | + $mf = wfMsg( "math_failure" ); |
107 | 121 | |
108 | 122 | $md5 = md5( $lilypond_code ); |
109 | 123 | |
— | — | @@ -139,7 +153,10 @@ |
140 | 154 | |
141 | 155 | # Ensure that the temp and output dirs are available before continuing. |
142 | 156 | if ( !file_exists( $wgMathDirectory ) ) { |
143 | | - if ( !@mkdir( $wgMathDirectory ) ) { |
| 157 | + wfSuppressWarnings(); |
| 158 | + $res = mkdir( $wgMathDirectory ); |
| 159 | + wfRestoreWarnings(); |
| 160 | + if ( !$res ) { |
144 | 161 | return "<b>$mf (" . wfMsg( "math_bad_output" ) . |
145 | 162 | $wgMathDirectory . ")</b>"; |
146 | 163 | } |
— | — | @@ -148,7 +165,10 @@ |
149 | 166 | return "<b>$mf (" . wfMsg( "math_bad_output" ) . ")</b>"; |
150 | 167 | } |
151 | 168 | if ( !file_exists( $wgTmpDirectory ) ) { |
152 | | - if ( !@mkdir( $wgTmpDirectory ) ) { |
| 169 | + wfSuppressWarnings(); |
| 170 | + $res = mkdir( $wgTmpDirectory ); |
| 171 | + wfRestoreWarnings(); |
| 172 | + if ( !$res ) { |
153 | 173 | return "<b>$mf (" . wfMsg( "math_bad_tmpdir" ) |
154 | 174 | . ")</b>"; |
155 | 175 | } |
— | — | @@ -258,6 +278,11 @@ |
259 | 279 | return $pre . $link . $post; |
260 | 280 | } |
261 | 281 | |
| 282 | +/** |
| 283 | + * @param $source |
| 284 | + * @param $dest |
| 285 | + * @param $bgColour |
| 286 | + */ |
262 | 287 | function trimImage( $source, $dest, $bgColour ) { |
263 | 288 | $srcImage = imagecreatefrompng( $source ); |
264 | 289 | $width = imagesx( $srcImage ); |
— | — | @@ -319,6 +344,13 @@ |
320 | 345 | imagepng( $dstImage, $dest ); |
321 | 346 | } |
322 | 347 | |
| 348 | +/** |
| 349 | + * @param $source |
| 350 | + * @param $dest |
| 351 | + * @param $bgColour |
| 352 | + * @param $borderWidth |
| 353 | + * @param $borderHeight |
| 354 | + */ |
323 | 355 | function frameImage( $source, $dest, $bgColour, $borderWidth, $borderHeight ) { |
324 | 356 | $srcImage = imagecreatefrompng( $source ); |
325 | 357 | $width = imagesx( $srcImage ); |