Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -12,7 +12,8 @@ |
13 | 13 | const MSG = 'translate-edit-'; |
14 | 14 | |
15 | 15 | static function addTools( $object ) { |
16 | | - if( $object->mTitle->getNamespace() === NS_MEDIAWIKI ) { |
| 16 | + global $wgTranslateMessageNamespaces; |
| 17 | + if( in_array($object->mTitle->getNamespace(), $wgTranslateMessageNamespaces) ) { |
17 | 18 | $object->editFormTextTop .= self::editBoxes( $object ); |
18 | 19 | } |
19 | 20 | return true; |
— | — | @@ -87,7 +88,7 @@ |
88 | 89 | * @param $key The message key we are interested in. |
89 | 90 | * @return MessageGroup which the key belongs to, or null. |
90 | 91 | */ |
91 | | - private static function getMessageGroup( $key ) { |
| 92 | + private static function getMessageGroup( $namespace, $key ) { |
92 | 93 | global $wgRequest; |
93 | 94 | $group = $wgRequest->getText('loadgroup', '' ); |
94 | 95 | $mg = MessageGroups::getGroup( $group ); |
— | — | @@ -95,7 +96,7 @@ |
96 | 97 | # If we were not given group, or the group given was meta... |
97 | 98 | if ( is_null( $mg ) || $mg->isMeta() ) { |
98 | 99 | # .. then try harder, because meta groups are *inefficient* |
99 | | - $group = TranslateUtils::messageKeyToGroup( $key ); |
| 100 | + $group = TranslateUtils::messageKeyToGroup( $namespace, $key ); |
100 | 101 | if ( $group ) { |
101 | 102 | $mg = MessageGroups::getGroup( $group ); |
102 | 103 | } |
— | — | @@ -110,9 +111,11 @@ |
111 | 112 | |
112 | 113 | list( $key, $code ) = self::figureMessage( $object ); |
113 | 114 | |
114 | | - $group = self::getMessageGroup( $key ); |
| 115 | + $group = self::getMessageGroup( $object->mTitle->getNamespace(), $key ); |
115 | 116 | if ( $group === null ) return; |
116 | 117 | |
| 118 | + list( $nsMain, /* $nsTalk */) = $group->namespaces; |
| 119 | + |
117 | 120 | $en = $group->getMessage( $key, 'en' ); |
118 | 121 | $xx = $group->getMessage( $key, $code ); |
119 | 122 | |
— | — | @@ -141,6 +144,9 @@ |
142 | 145 | $title = Title::makeTitle( NS_MEDIAWIKI, $key . '/' . $wgTranslateDocumentationLanguageCode ); |
143 | 146 | $edit = $wgUser->getSkin()->makeKnownLinkObj( $title, wfMsgHtml( self::MSG . 'contribute' ), 'action=edit' ); |
144 | 147 | $info = TranslateUtils::getMessageContent( $key, $wgTranslateDocumentationLanguageCode ); |
| 148 | + if ( !$info ) { |
| 149 | + $info = $group->getMessage( $key, $wgTranslateDocumentationLanguageCode ); |
| 150 | + } |
145 | 151 | $class = 'mw-sp-translate-edit-info'; |
146 | 152 | |
147 | 153 | if ( !$info ) { |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
13 | 13 | */ |
14 | 14 | |
15 | | -define( 'TRANSLATE_VERSION', '8.43' ); |
| 15 | +define( 'TRANSLATE_VERSION', '8.44' ); |
16 | 16 | |
17 | 17 | $wgExtensionCredits['specialpage'][] = array( |
18 | 18 | 'name' => 'Translate', |
— | — | @@ -82,6 +82,8 @@ |
83 | 83 | |
84 | 84 | $wgTranslateBlacklist = array(); |
85 | 85 | |
| 86 | +$wgTranslateMessageNamespaces = array( NS_MEDIAWIKI ); |
| 87 | + |
86 | 88 | /** AC = Available classes */ |
87 | 89 | $wgTranslateAC = array( |
88 | 90 | 'core' => 'CoreMessageGroup', |
Index: trunk/extensions/Translate/CreateMessageIndex.php |
— | — | @@ -21,11 +21,14 @@ |
22 | 22 | echo "Something wrong with $id... skipping\n"; |
23 | 23 | continue; |
24 | 24 | } |
| 25 | + |
| 26 | + $namespace = $g->namespaces[0]; |
| 27 | + |
25 | 28 | foreach ( $messages as $key => $data ) { |
26 | 29 | # Force all keys to lower case, because the case doesn't matter and it is |
27 | 30 | # easier to do comparing when the case of first letter is unknown, because |
28 | 31 | # mediawiki forces it to upper case |
29 | | - $key = strtolower( $key ); |
| 32 | + $key = strtolower( "$namespace:$key" ); |
30 | 33 | if ( isset($hugearray[$key]) ) { |
31 | 34 | echo "Key $key already belongs to $hugearray[$key], conflict with $id\n"; |
32 | 35 | } else { |
Index: trunk/extensions/Translate/TranslateTasks.php |
— | — | @@ -69,7 +69,6 @@ |
70 | 70 | public final function init( MessageGroup $messageGroup, TaskOptions $options ) { |
71 | 71 | $this->messageGroup = $messageGroup; |
72 | 72 | $this->options = $options; |
73 | | - $this->messages = new MessageCollection( $this->options->getLanguage() ); |
74 | 73 | } |
75 | 74 | |
76 | 75 | protected $process = array(); |
— | — | @@ -130,24 +129,8 @@ |
131 | 130 | } |
132 | 131 | |
133 | 132 | protected function preinit() { |
134 | | - $definitions = $this->messageGroup->getDefinitions(); |
135 | | - foreach ( $definitions as $key => $definition ) { |
136 | | - $this->messages->add( new TMessage( $key, $definition ) ); |
137 | | - } |
138 | | - |
139 | | - $bools = $this->messageGroup->getBools(); |
140 | | - foreach ( $bools['optional'] as $key ) { |
141 | | - if ( isset($this->messages[$key]) ) { |
142 | | - $this->messages[$key]->optional = true; |
143 | | - } |
144 | | - } |
145 | | - |
146 | | - foreach ( $bools['ignored'] as $key ) { |
147 | | - if ( isset($this->messages[$key]) ) { |
148 | | - $this->messages[$key]->ignored = true; |
149 | | - } |
150 | | - } |
151 | | - |
| 133 | + $this->messages = |
| 134 | + $this->messageGroup->initCollection( $this->options->getLanguage() ); |
152 | 135 | } |
153 | 136 | |
154 | 137 | protected function filterIgnored() { |
— | — | @@ -167,9 +150,7 @@ |
168 | 151 | } |
169 | 152 | |
170 | 153 | protected function postinit() { |
171 | | - $this->messages->populatePageExistence(); |
172 | | - $this->messages->populateTranslationsFromDatabase(); |
173 | | - $this->messageGroup->fill( $this->messages ); |
| 154 | + $this->messageGroup->fillCollection( $this->messages ); |
174 | 155 | } |
175 | 156 | |
176 | 157 | protected function output() { |
— | — | @@ -180,7 +161,9 @@ |
181 | 162 | $tableheader . |
182 | 163 | TranslateUtils::makeListing( |
183 | 164 | $this->messages, |
184 | | - $this->messageGroup->getId() |
| 165 | + $this->messageGroup->getId(), |
| 166 | + false, |
| 167 | + $this->messageGroup->namespaces |
185 | 168 | ) . |
186 | 169 | $tablefooter; |
187 | 170 | } |
— | — | @@ -268,7 +251,8 @@ |
269 | 252 | TranslateUtils::makeListing( |
270 | 253 | $this->messages, |
271 | 254 | $this->messageGroup->getId(), |
272 | | - true /* Review mode */ |
| 255 | + true, /* Review mode */ |
| 256 | + $this->messageGroup->namespaces |
273 | 257 | ) . |
274 | 258 | $tablefooter; |
275 | 259 | } |
Index: trunk/extensions/Translate/README |
— | — | @@ -45,6 +45,8 @@ |
46 | 46 | * $wgTranslateBlacklist added to prevent edits to certain language/group combinations |
47 | 47 | * new exporters |
48 | 48 | * changed the way of adding MediaWiki extensions |
| 49 | +* support for having messages in namespaces other than NS_MEDIAWIKi |
| 50 | +* try to load qqq from files if not found from the database |
49 | 51 | |
50 | 52 | == Changes in version 8 == |
51 | 53 | * Released 2008-02-06 |
Index: trunk/extensions/Translate/TranslateUtils.php |
— | — | @@ -24,113 +24,115 @@ |
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | | - * Initializes messages array. |
| 28 | + * Fills the page/talk exists bools according to their existence in the |
| 29 | + * database. |
| 30 | + * |
| 31 | + * @param $messages MessageCollection |
| 32 | + * @param $namespaces Array: two-item 1-d array with namespace numbers |
29 | 33 | */ |
30 | | - public static function initializeMessages( Array $definitions, $sortCallback = null ) { |
31 | | - wfMemIn( __METHOD__ ); |
32 | | - $messages = array(); |
| 34 | + public static function fillExistence( MessageCollection $messages, |
| 35 | + array $namespaces ) { |
| 36 | + wfMemIn( __METHOD__ ); wfProfileIn( __METHOD__ ); |
33 | 37 | |
34 | | - if ( is_callable( $sortCallback ) ) { |
35 | | - call_user_func_array( $sortCallback, array( &$definitions ) ); |
| 38 | + // Filter the titles so that we can find the respective pages from the db |
| 39 | + $code = $messages->code; |
| 40 | + $titles = array(); |
| 41 | + foreach ( $messages->keys() as $key ) { |
| 42 | + $titles[] = self::title( $key, $code ); |
36 | 43 | } |
37 | 44 | |
38 | | - foreach ( $definitions as $key => $value ) { |
39 | | - $messages[$key]['definition'] = $value; // the very original message |
40 | | - $messages[$key]['database'] = null; // current translation in db |
41 | | - $messages[$key]['author'] = null; // Author of the latest revision |
42 | | - $messages[$key]['infile'] = null; // current translation in file |
43 | | - $messages[$key]['fallback'] = null; // current fallback |
44 | | - $messages[$key]['optional'] = false; |
45 | | - $messages[$key]['ignored'] = false; |
46 | | - $messages[$key]['changed'] = false; |
47 | | - $messages[$key]['pageexists'] = false; |
48 | | - $messages[$key]['talkexists'] = false; |
| 45 | + // Quick return if nothing to search |
| 46 | + if ( !count($titles) ) return; |
| 47 | + |
| 48 | + // Fetch from database, we will get existing titles as the result |
| 49 | + $dbr = wfGetDB( DB_SLAVE ); |
| 50 | + $rows = $dbr->select( |
| 51 | + 'page', |
| 52 | + array( 'page_namespace', 'page_title' ), |
| 53 | + array( |
| 54 | + 'page_namespace' => $namespaces, |
| 55 | + 'page_title' => $titles, |
| 56 | + ), |
| 57 | + __METHOD__ |
| 58 | + ); |
| 59 | + |
| 60 | + // Now store the pages we found... |
| 61 | + foreach ( $rows as $row ) { |
| 62 | + if ( $row->page_namespace == $namespaces[0] ) { |
| 63 | + $pages[$row->page_title] = true; |
| 64 | + } elseif ( $row->page_namespace == $namespaces[1]) { |
| 65 | + $talks[$row->page_title] = true; |
| 66 | + } |
49 | 67 | } |
| 68 | + $rows->free(); |
50 | 69 | |
51 | | - wfMemOut( __METHOD__ ); |
52 | | - return $messages; |
53 | | - } |
54 | | - |
55 | | - /** |
56 | | - * Fills the page/talk exists bools according to their existence in the |
57 | | - * database. |
58 | | - * |
59 | | - * @param $messages Instance of MessageCollection |
60 | | - */ |
61 | | - public static function fillExistence( MessageCollection $messages ) { |
62 | | - wfMemIn( __METHOD__ ); |
63 | | - self::doExistenceQuery(); |
| 70 | + // ... and loop again to populate the collection |
64 | 71 | foreach ( $messages->keys() as $key ) { |
65 | | - $messages[$key]->pageExists = isset( self::$pageExists[self::title( $key, $messages->code )] ); |
66 | | - $messages[$key]->talkExists = isset( self::$talkExists[self::title( $key, $messages->code )] ); |
| 72 | + $messages[$key]->pageExists = isset( $pages[self::title( $key, $code )] ); |
| 73 | + $messages[$key]->talkExists = isset( $talks[self::title( $key, $code )] ); |
67 | 74 | } |
68 | | - wfMemOut( __METHOD__ ); |
| 75 | + |
| 76 | + wfProfileOut( __METHOD__ ); wfMemOut( __METHOD__ ); |
69 | 77 | } |
70 | 78 | |
71 | 79 | /** |
72 | 80 | * Fills the actual translation from database, if any. |
| 81 | + * TranslateUtils::fillExistence must be called before this to populate page |
| 82 | + * existences. |
73 | 83 | * |
74 | | - * @param $messages Instance of MessageCollection |
| 84 | + * @param $messages MessageCollection |
| 85 | + * @param $namespaces Array: two-item 1-d array with namespace numbers |
75 | 86 | */ |
76 | | - public static function fillContents( MessageCollection $messages ) { |
77 | | - wfMemIn( __METHOD__ ); |
| 87 | + public static function fillContents( MessageCollection $messages, |
| 88 | + array $namespaces ) { |
| 89 | + wfMemIn( __METHOD__ ); wfProfileIn( __METHOD__ ); |
| 90 | + |
78 | 91 | $titles = array(); |
79 | 92 | foreach ( $messages->keys() as $key ) { |
80 | | - $titles[self::title( $key, $messages->code )] = null; |
| 93 | + // Only fetch messages for pages that exists |
| 94 | + if ( $messages[$key]->pageExists ) { |
| 95 | + $titles[] = self::title( $key, $messages->code ); |
| 96 | + } |
81 | 97 | } |
82 | | - // Determine for which messages are not fetched already |
83 | | - $missing = array_diff( $titles, self::$contents ); |
84 | 98 | |
| 99 | + if ( !count($titles) ) return; |
85 | 100 | |
86 | | - // Don't fetch pages that do not exists |
87 | | - self::doExistenceQuery(); |
88 | | - foreach ( array_keys( $missing ) as $message ) { |
89 | | - if ( !isset(self::$pageExists[$message] ) ) { |
90 | | - unset( $missing[$message] ); |
91 | | - } |
92 | | - } |
| 101 | + // Fetch contents |
| 102 | + $titles = self::getContents( $titles, $namespaces[0] ); |
93 | 103 | |
94 | | - // Fetch contents for the rest |
95 | | - if ( count( $missing ) ) { |
96 | | - self::getContents( array_keys( $missing ) ); |
97 | | - } |
98 | | - |
99 | 104 | foreach ( $messages->keys() as $key ) { |
100 | 105 | $title = self::title( $key, $messages->code ); |
101 | | - if ( isset( self::$contents[$title] ) ) { |
102 | | - $messages[$key]->database = self::$contents[$title]; |
103 | | - $messages[$key]->addAuthor( self::$editors[$title] ); |
| 106 | + if ( isset($titles[$title]) ) { |
| 107 | + $messages[$key]->database = $titles[$title][0]; |
| 108 | + $messages[$key]->addAuthor( $titles[$title][1] ); |
104 | 109 | } |
105 | 110 | } |
106 | 111 | |
107 | | - self::$contents = array(); |
108 | | - self::$editors = array(); |
109 | | - wfMemOut( __METHOD__ ); |
| 112 | + wfProfileOut( __METHOD__ ); wfMemOut( __METHOD__ ); |
110 | 113 | } |
111 | 114 | |
112 | | - public static function getMessageContent( $key, $language ) { |
113 | | - wfMemIn( __METHOD__ ); |
114 | | - wfProfileIn( __METHOD__ ); |
| 115 | + public static function getMessageContent( $key, $language, |
| 116 | + $namespace = NS_MEDIAWIKI ) { |
| 117 | + |
115 | 118 | $title = self::title( $key, $language ); |
116 | | - if ( !isset(self::$contents[$title]) ) { |
117 | | - self::getContents( array( $title ) ); |
118 | | - } |
119 | | - wfProfileOut( __METHOD__ ); |
120 | | - wfMemOut( __METHOD__ ); |
121 | | - return isset(self::$contents[$title]) ? self::$contents[$title] : null; |
| 119 | + $data = self::getContents( array($title), $namespace ); |
| 120 | + return isset($data[$title][0]) ? $data[$title][0] : null; |
122 | 121 | } |
123 | 122 | |
124 | | - private static $contents = array(); |
125 | | - private static $editors = array(); |
126 | | - private static function getContents( Array $titles ) { |
127 | | - wfMemIn( __METHOD__ ); |
128 | | - wfProfileIn( __METHOD__ ); |
| 123 | + /** |
| 124 | + * Fetches contents for titles in given namespace |
| 125 | + * |
| 126 | + * @param $titles Mixed: string or array of titles. |
| 127 | + * @param $namespace Mixed: the number of the namespace to look in for. |
| 128 | + */ |
| 129 | + private static function getContents( $titles, $namespace ) { |
| 130 | + wfMemIn( __METHOD__ ); wfProfileIn( __METHOD__ ); |
129 | 131 | $dbr = wfGetDB( DB_SLAVE ); |
130 | 132 | $rows = $dbr->select( array( 'page', 'revision', 'text' ), |
131 | 133 | array( 'page_title', 'old_text', 'old_flags', 'rev_user_text' ), |
132 | 134 | array( |
133 | 135 | 'page_is_redirect' => 0, |
134 | | - 'page_namespace' => NS_MEDIAWIKI, |
| 136 | + 'page_namespace' => $namespace, |
135 | 137 | 'page_latest=rev_id', |
136 | 138 | 'rev_text_id=old_id', |
137 | 139 | 'page_title' => $titles |
— | — | @@ -140,25 +142,20 @@ |
141 | 143 | |
142 | 144 | |
143 | 145 | foreach ( $rows as $row ) { |
144 | | - self::$contents[$row->page_title] = Revision::getRevisionText( $row ); |
145 | | - self::$editors[$row->page_title] = $row->rev_user_text; |
| 146 | + $titles[$row->page_title] = array( |
| 147 | + Revision::getRevisionText( $row ), |
| 148 | + $row->rev_user_text |
| 149 | + ); |
146 | 150 | } |
| 151 | + $rows->free(); |
147 | 152 | |
148 | | - $rows->free(); |
149 | | - wfProfileOut( __METHOD__ ); |
150 | | - wfMemOut( __METHOD__ ); |
| 153 | + return $titles; |
| 154 | + wfProfileOut( __METHOD__ ); wfMemOut( __METHOD__ ); |
151 | 155 | } |
152 | 156 | |
153 | | - private static $pageExists = null; |
154 | | - private static $talkExists = null; |
155 | | - private static function doExistenceQuery() { |
| 157 | + private static function doExistenceQuery( MessageCollection $message) { |
156 | 158 | wfMemIn( __METHOD__ ); |
157 | 159 | wfProfileIn( __METHOD__ ); |
158 | | - if ( self::$pageExists !== null && self::$talkExists !== null ) { |
159 | | - wfProfileOut( __METHOD__ ); |
160 | | - wfMemOut( __METHOD__ ); |
161 | | - return; |
162 | | - } |
163 | 160 | |
164 | 161 | $dbr = wfGetDB( DB_SLAVE ); |
165 | 162 | $rows = $dbr->select( |
— | — | @@ -232,8 +229,11 @@ |
233 | 230 | return $tableheader; |
234 | 231 | } |
235 | 232 | |
236 | | - public static function makeListing( MessageCollection $messages, $group, $review = false ) { |
237 | | - wfMemIn( __METHOD__ ); |
| 233 | + public static function makeListing( MessageCollection $messages, $group, |
| 234 | + $review = false, array $namespaces ) { |
| 235 | + |
| 236 | + wfMemIn( __METHOD__ ); wfProfileIn( __METHOD__ ); |
| 237 | + |
238 | 238 | global $wgUser; |
239 | 239 | $sk = $wgUser->getSkin(); |
240 | 240 | wfLoadExtensionMessages( 'Translate' ); |
— | — | @@ -250,8 +250,8 @@ |
251 | 251 | $title = self::title( $key, $messages->code ); |
252 | 252 | $tools = array(); |
253 | 253 | |
254 | | - $page['object'] = Title::makeTitle( NS_MEDIAWIKI, $title ); |
255 | | - $talk['object'] = Title::makeTitle( NS_MEDIAWIKI_TALK, $title ); |
| 254 | + $page['object'] = Title::makeTitle( $namespaces[0], $title ); |
| 255 | + $talk['object'] = Title::makeTitle( $namespaces[1], $title ); |
256 | 256 | |
257 | 257 | $original = $m->definition; |
258 | 258 | $message = $m->translation ? $m->translation : $original; |
— | — | @@ -307,7 +307,7 @@ |
308 | 308 | |
309 | 309 | } |
310 | 310 | |
311 | | - wfMemOut( __METHOD__ ); |
| 311 | + wfProfileOut( __METHOD__ ); wfMemOut( __METHOD__ ); |
312 | 312 | return $output; |
313 | 313 | } |
314 | 314 | |
— | — | @@ -376,8 +376,8 @@ |
377 | 377 | return $selector->getHTML(); |
378 | 378 | } |
379 | 379 | |
380 | | - public static function messageKeyToGroup( $key ) { |
381 | | - $key = strtolower( $key ); |
| 380 | + public static function messageKeyToGroup( $namespace, $key ) { |
| 381 | + $key = strtolower( "$namespace:$key" ); |
382 | 382 | $index = self::messageIndex(); |
383 | 383 | return @$index[$key]; |
384 | 384 | } |
Index: trunk/extensions/Translate/Message.php |
— | — | @@ -190,7 +190,6 @@ |
191 | 191 | private $authors = array(); |
192 | 192 | |
193 | 193 | private $infile = null; |
194 | | - private $fallback = null; |
195 | 194 | private $database = null; |
196 | 195 | |
197 | 196 | private $optional = false; |
— | — | @@ -259,7 +258,7 @@ |
260 | 259 | } |
261 | 260 | |
262 | 261 | private static $callable = array( 'authors', 'changed', 'translated', 'translation', 'fuzzy' ); |
263 | | - private static $writable = array( 'infile', 'fallback', 'database', 'pageExists', 'talkExists', 'optional', 'ignored' ); |
| 262 | + private static $writable = array( 'infile', 'database', 'pageExists', 'talkExists', 'optional', 'ignored' ); |
264 | 263 | |
265 | 264 | public function __get( $name ) { |
266 | 265 | if ( property_exists( $this, $name ) ) { |
Index: trunk/extensions/Translate/ffs/Simple.php |
— | — | @@ -218,7 +218,7 @@ |
219 | 219 | |
220 | 220 | protected function exportStaticHeader( $target ) { |
221 | 221 | if( $this->staticHeader ) { |
222 | | - fwrite( $target, $this->staticHeader ); |
| 222 | + fwrite( $target, $this->staticHeader . "\n" ); |
223 | 223 | } |
224 | 224 | } |
225 | 225 | |