Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -112,6 +112,10 @@ |
113 | 113 | $wgAutoloadClasses['TranslateYaml'] = $dir . 'utils/TranslateYaml.php'; |
114 | 114 | |
115 | 115 | $wgAutoloadClasses['TranslateBC'] = $dir . 'utils/CompatibilityCode.php'; |
| 116 | + |
| 117 | +$wgAutoloadClasses['MessageHandle'] = $dir . 'utils/MessageHandle.php'; |
| 118 | + |
| 119 | + |
116 | 120 | /**@}*/ |
117 | 121 | |
118 | 122 | /** |
Index: trunk/extensions/Translate/utils/MessageHandle.php |
— | — | @@ -0,0 +1,83 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class for pointing to messages, like Title class is for titles. |
| 6 | + * @since 2011-03-13 |
| 7 | + */ |
| 8 | +class MessageHandle { |
| 9 | + /// @var Title |
| 10 | + protected $title = null; |
| 11 | + /// @var String |
| 12 | + protected $key = null; |
| 13 | + /// @var String |
| 14 | + protected $code = null; |
| 15 | + /// @var String |
| 16 | + protected $groupIds = null; |
| 17 | + /// @var MessageGroup |
| 18 | + protected $group = false; |
| 19 | + |
| 20 | + public function __construct( Title $title ) { |
| 21 | + $this->title = $title; |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Check if a title is in a message namespace. |
| 26 | + * @param $title Title |
| 27 | + * @return \bool If title is in a message namespace. |
| 28 | + */ |
| 29 | + public function isMessageNamespace() { |
| 30 | + global $wgTranslateMessageNamespaces; |
| 31 | + $namespace = $this->getTitle()->getNamespace(); |
| 32 | + return in_array( $namespace, $wgTranslateMessageNamespaces ); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @return Array of the message and the language |
| 37 | + */ |
| 38 | + public function figureMessage() { |
| 39 | + if ( $this->key === null ) { |
| 40 | + $text = $this->getTitle()->getDBkey(); |
| 41 | + $pos = strrpos( $text, '/' ); |
| 42 | + |
| 43 | + if ( $pos === false ) { |
| 44 | + $this->code = ''; |
| 45 | + $this->key = $text; |
| 46 | + } else { |
| 47 | + $this->code = substr( $text, $pos + 1 ); |
| 48 | + $this->key = substr( $text, 0, $pos ); |
| 49 | + } |
| 50 | + } |
| 51 | + return array( $this->key, $this->code ); |
| 52 | + } |
| 53 | + |
| 54 | + public function getKey() { |
| 55 | + $this->figureMessage(); |
| 56 | + return $this->key; |
| 57 | + } |
| 58 | + |
| 59 | + public function getCode() { |
| 60 | + $this->figureMessage(); |
| 61 | + return $this->code; |
| 62 | + } |
| 63 | + |
| 64 | + public function getGroupIds() { |
| 65 | + if ( $this->groupIds === null ) { |
| 66 | + $this->groupIds = TranslateUtils::messageKeyToGroups( $this->getTitle()->getNamespace(), $this->getKey() ); |
| 67 | + } |
| 68 | + return $this->groupIds; |
| 69 | + } |
| 70 | + |
| 71 | + public function getGroup() { |
| 72 | + $ids = $this->getGroupIds(); |
| 73 | + return MessageGroups::getGroup( $ids[0] ); |
| 74 | + } |
| 75 | + |
| 76 | + public function exists() { |
| 77 | + return $this->isMessageNamespace() && $this->getGroupIds(); |
| 78 | + } |
| 79 | + |
| 80 | + public function getTitle() { |
| 81 | + return $this->title; |
| 82 | + } |
| 83 | + |
| 84 | +} |
Property changes on: trunk/extensions/Translate/utils/MessageHandle.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 85 | + native |