MediaWiki REL1_32
PHPReader.php
Go to the documentation of this file.
1<?php
8namespace LocalisationUpdate;
9
13class PHPReader implements Reader {
15 protected $code;
16
17 public function __construct( $code = null ) {
18 $this->code = $code;
19 }
20
26 public function parse( $contents ) {
27 if ( strpos( $contents, '$messages' ) === false ) {
28 // This happens for some core languages that only have a fallback.
29 return [];
30 }
31
32 $php = $this->cleanupFile( $contents );
33 $reader = new \QuickArrayReader( "<?php $php" );
34 $messages = $reader->getVar( 'messages' );
35
36 if ( $this->code ) {
37 return [ $this->code => $messages ];
38 }
39
40 // Assuming that the array is keyed by language codes
41 return $messages;
42 }
43
50 protected function cleanupFile( $contents ) {
51 // We hate the windows vs linux linebreaks.
52 $contents = preg_replace( '/\r\n?/', "\n", $contents );
53
54 // We only want message arrays.
55 $results = [];
56 preg_match_all( '/\$messages(?:.*\s)*?\‍);/', $contents, $results );
57
58 // But we want them all in one string.
59 return implode( "\n\n", $results[0] );
60 }
61}
$messages
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition hooks.txt:895