From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- .../LocalisationUpdate/reader/JSONReader.php | 30 ++++++++++++ extensions/LocalisationUpdate/reader/PHPReader.php | 54 ++++++++++++++++++++++ extensions/LocalisationUpdate/reader/Reader.php | 19 ++++++++ .../LocalisationUpdate/reader/ReaderFactory.php | 36 +++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 extensions/LocalisationUpdate/reader/JSONReader.php create mode 100644 extensions/LocalisationUpdate/reader/PHPReader.php create mode 100644 extensions/LocalisationUpdate/reader/Reader.php create mode 100644 extensions/LocalisationUpdate/reader/ReaderFactory.php (limited to 'extensions/LocalisationUpdate/reader') diff --git a/extensions/LocalisationUpdate/reader/JSONReader.php b/extensions/LocalisationUpdate/reader/JSONReader.php new file mode 100644 index 00000000..636168c8 --- /dev/null +++ b/extensions/LocalisationUpdate/reader/JSONReader.php @@ -0,0 +1,30 @@ +code = $code; + } + + public function parse( $contents ) { + $messages = FormatJson::decode( $contents, true ); + unset( $messages['@metadata'] ); + + if ( $this->code ) { + return array( $this->code => $messages ); + } + + // Assuming that the array is keyed by language codes + return $messages; + } +} diff --git a/extensions/LocalisationUpdate/reader/PHPReader.php b/extensions/LocalisationUpdate/reader/PHPReader.php new file mode 100644 index 00000000..986d7b52 --- /dev/null +++ b/extensions/LocalisationUpdate/reader/PHPReader.php @@ -0,0 +1,54 @@ +code = $code; + } + + public function parse( $contents ) { + if ( strpos( $contents, '$messages' ) === false ) { + // This happens for some core languages that only have a fallback. + return array(); + } + + $php = $this->cleanupFile( $contents ); + $reader = new QuickArrayReader( "getVar( 'messages' ); + + if ( $this->code ) { + return array( $this->code => $messages ); + } + + // Assuming that the array is keyed by language codes + return $messages; + } + + /** + * Removes all unneeded content from a file and returns it. + * + * @param string $contents String + * @return string PHP code without PHP tags + */ + protected function cleanupFile( $contents ) { + // We hate the windows vs linux linebreaks. + $contents = preg_replace( '/\r\n?/', "\n", $contents ); + + // We only want message arrays. + $results = array(); + preg_match_all( '/\$messages(?:.*\s)*?\);/', $contents, $results ); + + // But we want them all in one string. + return implode( "\n\n", $results[0] ); + } +} diff --git a/extensions/LocalisationUpdate/reader/Reader.php b/extensions/LocalisationUpdate/reader/Reader.php new file mode 100644 index 00000000..f55a9372 --- /dev/null +++ b/extensions/LocalisationUpdate/reader/Reader.php @@ -0,0 +1,19 @@ + array( 'key' => 'value' ) ); + * @param string $contents File contents as a string. + * @return array + */ + public function parse( $contents ); +} diff --git a/extensions/LocalisationUpdate/reader/ReaderFactory.php b/extensions/LocalisationUpdate/reader/ReaderFactory.php new file mode 100644 index 00000000..530ab3f9 --- /dev/null +++ b/extensions/LocalisationUpdate/reader/ReaderFactory.php @@ -0,0 +1,36 @@ +