Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
GenerateTables | |
0.00% |
0 / 34 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
20 | |||
listFiles | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | /** |
4 | * This maintenance script regenerates data tables used for |
5 | * hieroglyphics rendering. |
6 | * |
7 | * Copyright (C) 2004 Guillaume Blanchard (Aoineko) |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write to the Free Software Foundation, Inc., |
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
22 | * http://www.gnu.org/copyleft/gpl.html |
23 | */ |
24 | |
25 | use MediaWiki\Utils\GitInfo; |
26 | use WikiHiero\WikiHiero; |
27 | |
28 | $IP = getenv( 'MW_INSTALL_PATH' ); |
29 | if ( $IP === false ) { |
30 | $IP = __DIR__ . '/../../..'; |
31 | } |
32 | require_once "$IP/maintenance/Maintenance.php"; |
33 | |
34 | class GenerateTables extends Maintenance { |
35 | |
36 | public function __construct() { |
37 | parent::__construct(); |
38 | $this->addDescription( 'Generate tables with hieroglyph information' ); |
39 | $this->requireExtension( 'WikiHiero' ); |
40 | |
41 | $this->moreTables = str_replace( "\r", '', $this->moreTables ); |
42 | } |
43 | |
44 | public function execute() { |
45 | $repo = new GitInfo( dirname( __DIR__ ) ); |
46 | $gitVersion = $repo->getHeadSHA1() ?: '<unknown revision>'; |
47 | |
48 | $wh_prefabs = "\$wh_prefabs = [\n"; |
49 | $wh_files = "\$wh_files = [\n"; |
50 | |
51 | $imgDir = dirname( __DIR__ ) . '/img/'; |
52 | |
53 | $files = $this->listFiles( $imgDir ); |
54 | foreach ( $files as $file ) { |
55 | [ $width, $height, , ] = getimagesize( $imgDir . $file ); |
56 | $wh_files .= "\t\"" . WikiHiero::getCode( $file ) . "\" => [ $width, $height ],\n"; |
57 | if ( strstr( $file, '&' ) ) { |
58 | $wh_prefabs .= "\t\"" . WikiHiero::getCode( $file ) . "\",\n"; |
59 | } |
60 | } |
61 | |
62 | $wh_prefabs .= "];"; |
63 | $wh_files .= "];"; |
64 | |
65 | $file = fopen( dirname( __DIR__ ) . '/data/tables.php', 'w+' ); |
66 | fwrite( $file, "<?php\n\n" ); |
67 | fwrite( $file, "// File created by generateTables.php version $gitVersion\n" ); |
68 | fwrite( $file, '// on ' . date( 'Y-m-d \a\t H:i' ) . "\n\n" ); |
69 | fwrite( $file, "$wh_prefabs\n\n$wh_files\n\n{$this->moreTables}\n" ); |
70 | fclose( $file ); |
71 | } |
72 | |
73 | /** |
74 | * @param string $dir |
75 | * @return string[] List of image files |
76 | */ |
77 | private function listFiles( $dir ) { |
78 | $files = []; |
79 | if ( is_dir( $dir ) ) { |
80 | $dh = opendir( $dir ); |
81 | if ( $dh ) { |
82 | // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition |
83 | while ( ( $file = readdir( $dh ) ) !== false ) { |
84 | if ( stristr( $file, WikiHiero::IMAGE_EXT ) ) { |
85 | $files[] = $file; |
86 | } |
87 | } |
88 | closedir( $dh ); |
89 | } |
90 | } else { |
91 | $this->fatalError( "Images directory $dir not found!\n" ); |
92 | } |
93 | |
94 | natcasesort( $files ); |
95 | return $files; |
96 | } |
97 | |
98 | private $moreTables = ' |
99 | $wh_phonemes = [ // phoneme -> Gardiner code conversion table |
100 | "mSa" => "A12", |
101 | "xr" => "A15", |
102 | "Xrd" => "A17", |
103 | "sr" => "A21", |
104 | "mniw" => "A33", |
105 | "qiz" => "A38", |
106 | "iry" => "A47", |
107 | "Sps" => "A50", |
108 | "Spsi" => "A51", |
109 | /* |
110 | "x" => "J1", |
111 | "mAa" => "J11", |
112 | "gs" => "J13", |
113 | "im" => "J13", |
114 | "M" => "J15", |
115 | "sA" => "J17", |
116 | "apr" => "J20", |
117 | "wDa" => "J21", |
118 | "nD" => "J27", |
119 | "qd" => "J28", |
120 | "Xkr" => "J30", |
121 | "Hp" => "J5", |
122 | "qn" => "J8", |
123 | */ |
124 | "x" => "Aa1", |
125 | "mAa" => "Aa11", |
126 | "gs" => "Aa13", |
127 | "im" => "Aa13", |
128 | "M" => "Aa15", |
129 | "sA" => "Aa17", |
130 | "apr" => "Aa20", |
131 | "wDa" => "Aa21", |
132 | "nD" => "Aa27", |
133 | "qd" => "Aa28", |
134 | "Xkr" => "Aa30", |
135 | "Hp" => "Aa5", |
136 | "qn" => "Aa8", |
137 | |
138 | "msi" => "B3", |
139 | "mAat" => "C10", |
140 | "HH" => "C11", |
141 | "DHwty" => "C3", |
142 | "Xnmw" => "C4", |
143 | "inpw" => "C6", |
144 | "stX" => "C7", |
145 | "mnw" => "C8", |
146 | "tp" => "D1", |
147 | "wDAt" => "D10", |
148 | "R" => "D153", |
149 | "fnD" => "D19", |
150 | "Hr" => "D2", |
151 | "r" => "D21", |
152 | "rA" => "D21", |
153 | "spt" => "D24", |
154 | "spty" => "D25", |
155 | "mnD" => "D27", |
156 | "kA" => "D28", |
157 | "Sny" => "D3", |
158 | "aHA" => "D34", |
159 | "a" => "D36", |
160 | "ir" => "D4", |
161 | "Dsr" => "D45", |
162 | "d" => "D46", |
163 | "Dba" => "D50", |
164 | "mt" => "D52", |
165 | "gH" => "D56", |
166 | "gHs" => "D56", |
167 | "rd" => "D56", |
168 | "sbq" => "D56", |
169 | "b" => "D58", |
170 | "ab" => "D59", |
171 | "wab" => "D60", |
172 | "sAH" => "D61", |
173 | "rmi" => "D9", |
174 | "zAb" => "E17", |
175 | "mAi" => "E22", |
176 | "l" => "E23", |
177 | "rw" => "E23", |
178 | "Aby" => "E24", |
179 | "wn" => "E34", |
180 | "zzmt" => "E6", |
181 | "wsr" => "F12", |
182 | "wp" => "F13", |
183 | "db" => "F16", |
184 | "Hw" => "F18", |
185 | "bH" => "F18", |
186 | "ns" => "F20", |
187 | "DrD" => "F21", |
188 | "idn" => "F21", |
189 | "msDr" => "F21", |
190 | "sDm" => "F21", |
191 | "kfA" => "F22", |
192 | "pH" => "F22", |
193 | "xpS" => "F23", |
194 | "wHm" => "F25", |
195 | "Xn" => "F26", |
196 | "sti" => "F29", |
197 | "Sd" => "F30", |
198 | "ms" => "F31", |
199 | "X" => "F32", |
200 | "sd" => "F33", |
201 | "ib" => "F34", |
202 | "nfr" => "F35", |
203 | "zmA" => "F36", |
204 | "imAx" => "F39", |
205 | "HAt" => "F4", |
206 | "Aw" => "F40", |
207 | "spr" => "F42", |
208 | "isw" => "F44", |
209 | "iwa" => "F44", |
210 | "pXr" => "F46", |
211 | "qAb" => "F46", |
212 | "SsA" => "F5", |
213 | "A" => "G1", |
214 | "mwt" => "G14", |
215 | "nbty" => "G16", |
216 | "m" => "G17", |
217 | "mm" => "G18", |
218 | "AA" => "G2", |
219 | "nH" => "G21", |
220 | "Db" => "G22", |
221 | "rxyt" => "G23", |
222 | "Ax" => "G25", |
223 | "dSr" => "G27", |
224 | "gm" => "G28", |
225 | "bA" => "G29", |
226 | "baHi" => "G32", |
227 | "aq" => "G35", |
228 | "wr" => "G36", |
229 | "nDs" => "G37", |
230 | "gb" => "G38", |
231 | "zA" => "G39", |
232 | "tyw" => "G4", |
233 | "pA" => "G40", |
234 | "xn" => "G41", |
235 | "wSA" => "G42", |
236 | "w" => "G43", |
237 | "ww" => "G44", |
238 | "mAw" => "G46", |
239 | "TA" => "G47", |
240 | "snD" => "G54", |
241 | "pq" => "H2", |
242 | "wSm" => "H2", |
243 | "pAq" => "H3", |
244 | "nr" => "H4", |
245 | "Sw" => "H6", |
246 | "aSA" => "I1", |
247 | "D" => "I10", |
248 | "DD" => "I11", |
249 | "Styw" => "I2", |
250 | "mzH" => "I3", |
251 | "sbk" => "I4", |
252 | "sAq" => "I5", |
253 | "km" => "I6", |
254 | "Hfn" => "I8", |
255 | "f" => "I9", |
256 | "in" => "K1", |
257 | "ad" => "K3", |
258 | "XA" => "K4", |
259 | "bz" => "K5", |
260 | "nSmt" => "K6", |
261 | "xpr" => "L1", |
262 | "bit" => "L2", |
263 | "srqt" => "L7", |
264 | "iAm" => "M1", |
265 | "wdn" => "M11", |
266 | "xA" => "M12", |
267 | "1000" => "M12", |
268 | "wAD" => "M13", |
269 | "HA" => "M16", |
270 | "i" => "M17", |
271 | "ii" => "M18", |
272 | "Hn" => "M2", |
273 | "sxt" => "M20", |
274 | "sm" => "M21", |
275 | "nn" => "M22A", |
276 | "sw" => "M23", |
277 | "rsw" => "M24", |
278 | "Sma" => "M26", |
279 | "nDm" => "M29", |
280 | "xt" => "M3", |
281 | "bnr" => "M30", |
282 | "bdt" => "M34", |
283 | "Dr" => "M36", |
284 | "rnp" => "M4", |
285 | "iz" => "M40", |
286 | "tr" => "M6", |
287 | "SA" => "M8", |
288 | "zSn" => "M9", |
289 | "pt" => "N1", |
290 | "Abd" => "N11", |
291 | "iaH" => "N11", |
292 | "dwA" => "N14", |
293 | "sbA" => "N14", |
294 | "dwAt" => "N15", |
295 | "tA" => "N16", |
296 | "iw" => "N18", |
297 | "wDb" => "N20", |
298 | "spAt" => "N24", |
299 | "xAst" => "N25", |
300 | "Dw" => "N26", |
301 | "Axt" => "N27", |
302 | "xa" => "N28", |
303 | "q" => "N29", |
304 | "iAt" => "N30", |
305 | "n" => "N35", |
306 | "mw" => "N35A", |
307 | "S" => "N37", |
308 | "iAdt" => "N4", |
309 | "idt" => "N4", |
310 | "Sm" => "N40", |
311 | "id" => "N41", |
312 | "hrw" => "N5", |
313 | "ra" => "N5", |
314 | "zw" => "N5", |
315 | "Hnmmt" => "N8", |
316 | "pzD" => "N9", |
317 | "pr" => "O1", |
318 | "aH" => "O11", |
319 | "wsxt" => "O15", |
320 | "kAr" => "O18", |
321 | "zH" => "O22", |
322 | "txn" => "O25", |
323 | "iwn" => "O28", |
324 | "aA" => "O29", |
325 | "zxnt" => "O30", |
326 | "z" => "O34", |
327 | "zb" => "O35", |
328 | "inb" => "O36", |
329 | "qnbt" => "O38A", |
330 | "h" => "O4", |
331 | "Szp" => "O42", |
332 | "ipt" => "O45", |
333 | "nxn" => "O47", |
334 | "niwt" => "O49", |
335 | "zp" => "O50", |
336 | "Snwt" => "O51", |
337 | "Hwt" => "O6", |
338 | "wHa" => "P4", |
339 | "TAw" => "P5", |
340 | "nfw" => "P5", |
341 | "aHa" => "P6", |
342 | "xrw" => "P8", |
343 | "st" => "Q1", |
344 | "wz" => "Q2", |
345 | "p" => "Q3", |
346 | "qrsw" => "Q6", |
347 | "xAt" => "R1", |
348 | "xAwt" => "R1", |
349 | "Dd" => "R11", |
350 | "dd" => "R11", |
351 | "imnt" => "R14", |
352 | "iAb" => "R15", |
353 | "wx" => "R16", |
354 | "xm" => "R22", |
355 | "Htp" => "R4", |
356 | "kAp" => "R5", |
357 | "kp" => "R5", |
358 | "snTr" => "R7", |
359 | "nTr" => "R8", |
360 | "nTrw" => "R8A", |
361 | "bd" => "R9", |
362 | "HDt" => "S1", |
363 | "mDH" => "S10", |
364 | "wsx" => "S11", |
365 | "nbw" => "S12", |
366 | "THn" => "S15", |
367 | "tHn" => "S15", |
368 | "mnit" => "S18", |
369 | "sDAw" => "S19", |
370 | "xtm" => "S20", |
371 | "sT" => "S22", |
372 | "dmD" => "S23", |
373 | "Tz" => "S24", |
374 | "Sndyt" => "S26", |
375 | "mnxt" => "S27", |
376 | "s" => "S29", |
377 | "N" => "S3", |
378 | "dSrt" => "S3", |
379 | "sf" => "S30", |
380 | "siA" => "S32", |
381 | "Tb" => "S33", |
382 | "anx" => "S34", |
383 | "Swt" => "S35", |
384 | "xw" => "S37", |
385 | "HqA" => "S38", |
386 | "awt" => "S39", |
387 | "wAs" => "S40", |
388 | "Dam" => "S41", |
389 | "abA" => "S42", |
390 | "sxm" => "S42", |
391 | "xrp" => "S42", |
392 | "md" => "S43", |
393 | "Ams" => "S44", |
394 | "nxxw" => "S45", |
395 | "K" => "S56", |
396 | "sxmty" => "S6", |
397 | "xprS" => "S7", |
398 | "Atf" => "S8", |
399 | "Swty" => "S9", |
400 | "pD" => "T10", |
401 | "sXr" => "T11", |
402 | "zin" => "T11", |
403 | "zwn" => "T11", |
404 | "Ai" => "T12", |
405 | "Ar" => "T12", |
406 | "rwD" => "T12", |
407 | "rwd" => "T12", |
408 | "rs" => "T13", |
409 | "qmA" => "T14", |
410 | "wrrt" => "T17", |
411 | "Sms" => "T18", |
412 | "qs" => "T19", |
413 | "wa" => "T21", |
414 | "sn" => "T22", |
415 | "iH" => "T24", |
416 | "DbA" => "T25", |
417 | "Xr" => "T28", |
418 | "nmt" => "T29", |
419 | "HD" => "T3", |
420 | "sSm" => "T31", |
421 | "nm" => "T34", |
422 | "HDD" => "T6", |
423 | "pd" => "T9", |
424 | "mA" => "U1", |
425 | "it" => "U10", |
426 | "HqAt" => "U11", |
427 | "Sna" => "U13", |
428 | "hb" => "U13", |
429 | "tm" => "U15", |
430 | "biA" => "U16", |
431 | "grg" => "U17", |
432 | "stp" => "U21", |
433 | "mnx" => "U22", |
434 | "Ab" => "U23", |
435 | "Hmt" => "U24", |
436 | "wbA" => "U26", |
437 | "DA" => "U28", |
438 | "rtH" => "U31", |
439 | "zmn" => "U32", |
440 | "ti" => "U33", |
441 | "xsf" => "U34", |
442 | "Hm" => "U36", |
443 | "mxAt" => "U38", |
444 | "mr" => "U6", |
445 | "100" => "V1", |
446 | "arq" => "V12", |
447 | "T" => "V13", |
448 | "iTi" => "V15", |
449 | "TmA" => "V19", |
450 | "XAr" => "V19", |
451 | "mDt" => "V19", |
452 | "sTA" => "V2", |
453 | "10" => "V20", |
454 | "mD" => "V20", |
455 | "mH" => "V22", |
456 | "wD" => "V24", |
457 | "aD" => "V26", |
458 | "H" => "V28", |
459 | "sk" => "V29", |
460 | "wAH" => "V29", |
461 | "sTAw" => "V3", |
462 | "nb" => "V30", |
463 | "k" => "V31", |
464 | "msn" => "V32", |
465 | "sSr" => "V33", |
466 | "idr" => "V37", |
467 | "wA" => "V4", |
468 | "snT" => "V5", |
469 | "sS" => "V6", |
470 | "Sn" => "V7", |
471 | "iab" => "W10", |
472 | "g" => "W11", |
473 | "nzt" => "W11", |
474 | "Hz" => "W14", |
475 | "xnt" => "W17", |
476 | "mi" => "W19", |
477 | "bAs" => "W2", |
478 | "Hnqt" => "W22", |
479 | "nw" => "W24", |
480 | "ini" => "W25", |
481 | "Hb" => "W3", |
482 | "Xnm" => "W9", |
483 | "t" => "X1", |
484 | "di" => "X8", |
485 | "rdi" => "X8", |
486 | "mDAt" => "Y1", |
487 | "mnhd" => "Y3", |
488 | "zS" => "Y3", |
489 | "mn" => "Y5", |
490 | "ibA" => "Y6", |
491 | "zSSt" => "Y8", |
492 | "imi" => "Z11", |
493 | "y" => "Z4", |
494 | "W" => "Z7", |
495 | |
496 | "<1" => "Ca1", // cartouche |
497 | "2>" => "Ca2", |
498 | "<2" => "Ca2a", |
499 | "1>" => "Ca1a", |
500 | "<0" => "Ca1", |
501 | "0>" => "Ca2", |
502 | "<h1" => "Cah1", // horus |
503 | "h1>" => "Cah1a", |
504 | "<h2" => "Cah2", |
505 | "h2>" => "Cah2a", |
506 | "<h3" => "Cah3", |
507 | "h3>" => "Cah3a", |
508 | "<h0" => "Cah1", |
509 | "h0>" => "Cah1a", |
510 | "<" => "Ca1", // cartouche |
511 | ">" => "Ca2", |
512 | "[&" => "Ba16", |
513 | "&]" => "Ba16", |
514 | "[{" => "Ba17", |
515 | "}]" => "Ba17a", |
516 | "[[" => "Ba15", |
517 | "]]" => "Ba15a", |
518 | "[\"" => "", |
519 | "\"]" => "", |
520 | "[\'" => "", |
521 | "\']" => "", |
522 | ]; |
523 | '; |
524 | |
525 | } |
526 | |
527 | $maintClass = GenerateTables::class; |
528 | require_once RUN_MAINTENANCE_IF_MAIN; |