[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @file 4 * @author Niklas Laxström 5 * @license GPL-2.0+ 6 */ 7 8 /** 9 * Reads MediaWiki PHP i18n files. 10 */ 11 class LU_PHPReader implements LU_Reader { 12 /// @var string Language tag 13 protected $code; 14 15 public function __construct( $code = null ) { 16 $this->code = $code; 17 } 18 19 public function parse( $contents ) { 20 if ( strpos( $contents, '$messages' ) === false ) { 21 // This happens for some core languages that only have a fallback. 22 return array(); 23 } 24 25 $php = $this->cleanupFile( $contents ); 26 $reader = new QuickArrayReader( "<?php $php" ); 27 $messages = $reader->getVar( 'messages' ); 28 29 if ( $this->code ) { 30 return array( $this->code => $messages ); 31 } 32 33 // Assuming that the array is keyed by language codes 34 return $messages; 35 } 36 37 /** 38 * Removes all unneeded content from a file and returns it. 39 * 40 * @param string $contents String 41 * @return string PHP code without PHP tags 42 */ 43 protected function cleanupFile( $contents ) { 44 // We hate the windows vs linux linebreaks. 45 $contents = preg_replace( '/\r\n?/', "\n", $contents ); 46 47 // We only want message arrays. 48 $results = array(); 49 preg_match_all( '/\$messages(?:.*\s)*?\);/', $contents, $results ); 50 51 // But we want them all in one string. 52 return implode( "\n\n", $results[0] ); 53 } 54 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |