MediaWiki REL1_33
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}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$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 When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:856