Index: trunk/extensions/Score/Score.body.php |
— | — | @@ -113,6 +113,23 @@ |
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
| 117 | + * Creates the specified directory if it does not exist yet. |
| 118 | + * Otherwise does nothing. |
| 119 | + * |
| 120 | + * @param $path path to directory to be created. |
| 121 | + * |
| 122 | + * @throws ScoreException if the directory does not exist and could not be created. |
| 123 | + */ |
| 124 | + private static function createFactory( $path ) { |
| 125 | + if ( !is_dir( $path ) ) { |
| 126 | + $rc = wfMkdirParents( $path, 0700, __METHOD__ ); |
| 127 | + if ( !$rc ) { |
| 128 | + throw new ScoreException( wfMessage( 'score-nofactory' ) ); |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + /** |
117 | 134 | * Renders the lilypond code in a <score>…</score> tag. |
118 | 135 | * |
119 | 136 | * @param $code |
— | — | @@ -126,19 +143,11 @@ |
127 | 144 | global $wgTmpDirectory; |
128 | 145 | |
129 | 146 | try { |
130 | | - /* create working environment */ |
| 147 | + /* generate name for working environment */ |
131 | 148 | $factoryPrefix = 'MWLP.'; |
132 | 149 | $fuzz = md5( mt_rand() ); |
133 | 150 | $factoryDirectory = $wgTmpDirectory . "/$factoryPrefix$fuzz"; |
134 | | - $rc = wfMkdirParents( $factoryDirectory, 0700, __METHOD__ ); |
135 | | - if ( !$rc ) { |
136 | | - throw new ScoreException( wfMessage( 'score-nofactory' ) ); |
137 | | - } |
138 | | - } catch ( ScoreException $e ) { |
139 | | - return $e; |
140 | | - } |
141 | 151 | |
142 | | - try { |
143 | 152 | /* Midi rendering? */ |
144 | 153 | if ( array_key_exists( 'midi', $args ) ) { |
145 | 154 | $renderMidi = $args['midi']; |
— | — | @@ -164,6 +173,7 @@ |
165 | 174 | $lilypondCode = $code; |
166 | 175 | $altText = false; |
167 | 176 | } |
| 177 | + self::createFactory( $factoryDirectory ); |
168 | 178 | $rc = file_put_contents( $lilypondFile, $lilypondCode ); |
169 | 179 | if ( $rc === false ) { |
170 | 180 | throw new ScoreException( wfMessage( 'score-noinput', $lilypondFile ) ); |
— | — | @@ -177,6 +187,7 @@ |
178 | 188 | throw new ScoreException( wfMessage( 'score-invalidlang', $lang ) ); |
179 | 189 | } |
180 | 190 | |
| 191 | + /* Run LilyPond */ |
181 | 192 | $html = self::runLilypond( $factoryDirectory, $renderMidi, $altText ); |
182 | 193 | } catch ( ScoreException $e ) { |
183 | 194 | self::eraseFactory( $factoryDirectory ); |
— | — | @@ -242,6 +253,7 @@ |
243 | 254 | $lyFile = $factoryDirectory . '/file.ly'; |
244 | 255 | |
245 | 256 | /* Create ABC input file */ |
| 257 | + self::createFactory( $factoryDirectory ); |
246 | 258 | $rc = file_put_contents( $abcFile, ltrim( $code ) ); // abc2ly is picky about whitespace at the start of the file |
247 | 259 | if ( $rc === false ) { |
248 | 260 | throw new ScoreException( wfMessage( 'score-noabcinput', $abcFile ) ); |