summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/Translate/translationaids/TranslationAid.php')
-rw-r--r--MLEB/Translate/translationaids/TranslationAid.php94
1 files changed, 15 insertions, 79 deletions
diff --git a/MLEB/Translate/translationaids/TranslationAid.php b/MLEB/Translate/translationaids/TranslationAid.php
index 9c0f26a9..a8068a34 100644
--- a/MLEB/Translate/translationaids/TranslationAid.php
+++ b/MLEB/Translate/translationaids/TranslationAid.php
@@ -4,15 +4,13 @@
*
* @file
* @author Niklas Laxström
- * @copyright Copyright © 2013, Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
*/
/**
* Multipurpose class for translation aids:
* - interface for translation aid classes
* - listing of available translation aids
- * - some utility functions for translation aid classes
*
* @defgroup TranslationAids Translation Aids
* @since 2013-01-01
@@ -33,12 +31,21 @@ abstract class TranslationAid {
*/
protected $context;
- public function __construct( MessageGroup $group, MessageHandle $handle,
- IContextSource $context
+ /**
+ * @var TranslationAidDataProvider
+ */
+ protected $dataProvider;
+
+ public function __construct(
+ MessageGroup $group,
+ MessageHandle $handle,
+ IContextSource $context,
+ TranslationAidDataProvider $dataProvider
) {
$this->group = $group;
$this->handle = $handle;
$this->context = $context;
+ $this->dataProvider = $dataProvider;
}
/**
@@ -50,91 +57,20 @@ abstract class TranslationAid {
* to 'suggestion' and then list of arrays, each containing fields for the
* information of the suggestions. See InOtherLanguagesAid for example.
*
- * @throw TranslationHelperException Used to signal unexpected errors to aid
+ * @throws TranslationHelperException Used to signal unexpected errors to aid
* debugging
* @return array
*/
abstract public function getData();
/**
- * Get the message definition. Cached for performance.
- *
- * @return string
- */
- public function getDefinition() {
- static $cache = array();
-
- $key = $this->handle->getTitle()->getPrefixedText();
-
- if ( array_key_exists( $key, $cache ) ) {
- return $cache[$key];
- }
-
- if ( method_exists( $this->group, 'getMessageContent' ) ) {
- $cache[$key] = $this->group->getMessageContent( $this->handle );
- } else {
- $cache[$key] = $this->group->getMessage(
- $this->handle->getKey(),
- $this->group->getSourceLanguage()
- );
- }
-
- return $cache[$key];
- }
-
- /**
- * @return Content
- */
- protected function getDefinitionContent() {
- $text = $this->getDefinition();
-
- return ContentHandler::makeContent( $text, $this->handle->getTitle() );
- }
-
- /**
- * Get the translations in all languages. Cached for performance.
- * Fuzzy translation are not included.
- *
- * @return array Language code => Translation
- */
- public function getTranslations() {
- static $cache = array();
-
- $key = $this->handle->getTitle()->getPrefixedText();
-
- if ( array_key_exists( $key, $cache ) ) {
- return $cache[$key];
- }
-
- $data = ApiQueryMessageTranslations::getTranslations( $this->handle );
- $namespace = $this->handle->getTitle()->getNamespace();
-
- $cache[$key] = array();
-
- foreach ( $data as $page => $info ) {
- $tTitle = Title::makeTitle( $namespace, $page );
- $tHandle = new MessageHandle( $tTitle );
-
- $fuzzy = MessageHandle::hasFuzzyString( $info[0] ) || $tHandle->isFuzzy();
- if ( $fuzzy ) {
- continue;
- }
-
- $code = $tHandle->getCode();
- $cache[$key][$code] = $info[0];
- }
-
- return $cache[$key];
- }
-
- /**
* List of available message types mapped to the classes
* implementing them.
*
* @return array
*/
public static function getTypes() {
- $types = array(
+ $types = [
'definition' => 'MessageDefinitionAid',
'translation' => 'CurrentTranslationAid',
'inotherlanguages' => 'InOtherLanguagesAid',
@@ -145,7 +81,7 @@ abstract class TranslationAid {
'support' => 'SupportAid',
'gettext' => 'GettextDocumentationAid',
'insertables' => 'InsertablesAid',
- );
+ ];
return $types;
}