FlatPhpFFS.php

Go to the documentation of this file.
00001 <?php
00016 class FlatPhpFFS extends SimpleFFS {
00017     public function getFileExtensions() {
00018         return array( '.php' );
00019     }
00020 
00021     //
00022     // READ
00023     //
00024     public function readFromVariable( $data ) {
00025         # Authors first
00026         $matches = array();
00027         preg_match_all( '/^ \* @author\s+(.+)$/m', $data, $matches );
00028         $authors = $matches[1];
00029 
00030         # Then messages
00031         $matches = array();
00032         $regex = '/^\$(.*?)\s*=\s*[\'"](.*?)[\'"];.*?$/mus';
00033         preg_match_all( $regex, $data, $matches, PREG_SET_ORDER );
00034         $messages = array();
00035 
00036         foreach ( $matches as $_ ) {
00037             $legal = Title::legalChars();
00038             $key = preg_replace( "/([^$legal]|\\\\)/ue", '\'\x\'.' . "dechex(ord('\\0'))", $_[1] );
00039             $value = str_replace( array( "\'", "\\\\" ), array( "'", "\\" ), $_[2] );
00040             $messages[$key] = $value;
00041         }
00042 
00043         $messages = $this->group->getMangler()->mangle( $messages );
00044 
00045         return array(
00046             'AUTHORS' => $authors,
00047             'MESSAGES' => $messages,
00048         );
00049     }
00050 
00051     //
00052     // WRITE
00053     //
00054     protected function writeReal( MessageCollection $collection ) {
00055         if ( isset( $this->extra['header'] ) ) {
00056             $output = $this->extra['header'];
00057         } else {
00058             $output = "<?php\n";
00059         }
00060 
00061         $output .= $this->doHeader( $collection );
00062 
00063         $mangler = $this->group->getMangler();
00064 
00068         foreach ( $collection as $item ) {
00069             $key = $mangler->unmangle( $item->key() );
00070             $key = stripcslashes( $key );
00071 
00072             $value = $item->translation();
00073             if ( $value === null ) {
00074                 continue;
00075             }
00076 
00077             $value = str_replace( TRANSLATE_FUZZY, '', $value );
00078             $value = addcslashes( $value, "'" );
00079 
00080             $output .= "\$$key = '$value';\n";
00081         }
00082 
00083         return $output;
00084     }
00085 
00086     protected function doHeader( MessageCollection $collection ) {
00087         global $wgSitename, $wgTranslateDocumentationLanguageCode;
00088 
00089         $code = $collection->code;
00090         $name = TranslateUtils::getLanguageName( $code );
00091         $native = TranslateUtils::getLanguageName( $code, $code );
00092 
00093         if ( $wgTranslateDocumentationLanguageCode ) {
00094             $docu = "\n * See the $wgTranslateDocumentationLanguageCode 'language' for " .
00095                 "message documentation incl. usage of parameters";
00096         } else {
00097             $docu = '';
00098         }
00099 
00100         $authors = $this->doAuthors( $collection );
00101 
00102         $output = <<<PHP
00113 PHP;
00114 
00115         return $output;
00116     }
00117 
00118     protected function doAuthors( MessageCollection $collection ) {
00119         $output = '';
00120         $authors = $collection->getAuthors();
00121         $authors = $this->filterAuthors( $authors, $collection->code );
00122 
00123         foreach ( $authors as $author ) {
00124             $output .= " * @author $author\n";
00125         }
00126 
00127         return $output;
00128     }
00129 }
Generated on Tue Oct 29 00:00:23 2013 for MediaWiki Translate Extension by  doxygen 1.6.3