Index: trunk/extensions/Translate/tag/TranslatablePage.php |
— | — | @@ -181,15 +181,15 @@ |
182 | 182 | return $section; |
183 | 183 | } |
184 | 184 | |
185 | | - public function addMarkedTag( $revision ) { |
186 | | - $this->addTag( 'tp:mark', $revision ); |
| 185 | + public function addMarkedTag( $revision, $value = null ) { |
| 186 | + $this->addTag( 'tp:mark', $revision, $value ); |
187 | 187 | } |
188 | 188 | |
189 | 189 | public function addReadyTag( $revision ) { |
190 | 190 | $this->addTag( 'tp:tag', $revision ); |
191 | 191 | } |
192 | 192 | |
193 | | - protected function addTag( $tag, $revision ) { |
| 193 | + protected function addTag( $tag, $revision, $value = null ) { |
194 | 194 | $dbw = wfGetDB( DB_MASTER ); |
195 | 195 | |
196 | 196 | // Can this be done in one query? |
— | — | @@ -202,6 +202,7 @@ |
203 | 203 | 'rt_revision' => $revision |
204 | 204 | ); |
205 | 205 | $dbw->delete( 'revtag', $conds, __METHOD__ ); |
| 206 | + if ( $value !== null ) $conds['rt_value'] = serialize($value); |
206 | 207 | $dbw->insert( 'revtag', $conds, __METHOD__ ); |
207 | 208 | } |
208 | 209 | |
— | — | @@ -215,16 +216,14 @@ |
216 | 217 | protected function getTag( $tag, $dbt = DB_SLAVE ) { |
217 | 218 | $db = wfGetDB( $dbt ); |
218 | 219 | |
219 | | - // Can this be done in one query? |
220 | | - $id = $db->selectField( 'revtag_type', 'rtt_id', |
221 | | - array( 'rtt_name' => $tag ), __METHOD__ ); |
| 220 | + $id = $this->getTagId( $tag ); |
222 | 221 | |
223 | 222 | $fields = 'rt_revision'; |
224 | 223 | $conds = array( |
225 | 224 | 'rt_page' => $this->getTitle()->getArticleId(), |
226 | 225 | 'rt_type' => $id, |
227 | 226 | ); |
228 | | - $options = array( 'ORDER BY', 'rt_revision DESC' ); |
| 227 | + $options = array( 'ORDER BY' => 'rt_revision DESC' ); |
229 | 228 | return $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options ); |
230 | 229 | } |
231 | 230 | |
— | — | @@ -251,7 +250,7 @@ |
252 | 251 | 'rt_page' => $this->getTitle()->getArticleId(), |
253 | 252 | 'rt_type' => $id, |
254 | 253 | ); |
255 | | - $options = array( 'ORDER BY', 'rt_revision DESC' ); |
| 254 | + $options = array( 'ORDER BY' => 'rt_revision DESC' ); |
256 | 255 | return $db->select( 'revtag', $fields, $conds, __METHOD__, $options ); |
257 | 256 | } |
258 | 257 | |
— | — | @@ -315,7 +314,16 @@ |
316 | 315 | $rev = $this->getTransrev( $key .'/' . $collection->code ); |
317 | 316 | foreach ( $markedRevs as $r ) { |
318 | 317 | if ( $rev === $r->rt_revision ) break; |
319 | | - $score *= 0.8; |
| 318 | + $changed = unserialize($r->rt_value); |
| 319 | + |
| 320 | + // Get a suitable section key |
| 321 | + $parts = explode( '/', $key ); |
| 322 | + $ikey = $parts[count($parts)-1]; |
| 323 | + |
| 324 | + // If the section was changed, reduce the score |
| 325 | + if ( in_array($ikey, $changed, true) ) { |
| 326 | + $score *= 0.8; |
| 327 | + } |
320 | 328 | } |
321 | 329 | $total += $score; |
322 | 330 | } |
— | — | @@ -324,9 +332,7 @@ |
325 | 333 | |
326 | 334 | protected function getTransRev( $suffix ) { |
327 | 335 | $id = $this->getTagId( 'tp:transver' ); |
328 | | - $title = Title::makeTitle( NS_TRANSLATIONS, |
329 | | - $this->getTitle()->getPrefixedText() . '/' . $suffix |
330 | | - ); |
| 336 | + $title = Title::makeTitle( NS_TRANSLATIONS, $suffix ); |
331 | 337 | |
332 | 338 | $db = wfGetDB( DB_SLAVE ); |
333 | 339 | $fields = 'rt_value'; |
— | — | @@ -334,14 +340,14 @@ |
335 | 341 | 'rt_page' => $title->getArticleId(), |
336 | 342 | 'rt_type' => $id, |
337 | 343 | ); |
338 | | - $options = array( 'ORDER BY', 'rt_revision DESC' ); |
| 344 | + $options = array( 'ORDER BY' => 'rt_revision DESC' ); |
339 | 345 | return $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options ); |
340 | 346 | |
341 | 347 | } |
342 | 348 | |
343 | 349 | protected function getTagId( $tag ) { |
344 | 350 | static $tagcache = array(); |
345 | | - if ( !isset( $tagcache[$tag] ) ) { |
| 351 | + if ( !isset($tagcache[$tag]) ) { |
346 | 352 | $db = wfGetDB( DB_SLAVE ); |
347 | 353 | $tagcache[$tag] = $db->selectField( |
348 | 354 | 'revtag_type', // Table |
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php |
— | — | @@ -308,21 +308,26 @@ |
309 | 309 | } |
310 | 310 | |
311 | 311 | $inserts = array(); |
| 312 | + $changed = array(); |
312 | 313 | foreach ( $sections as $s ) { |
| 314 | + if ( $s->type === 'changed' ) $changed[] = $s->name; |
313 | 315 | $inserts[] = array( |
314 | 316 | 'trs_page' => $page->getTitle()->getArticleId(), |
315 | 317 | 'trs_key' => $s->name, |
316 | 318 | 'trs_text' => $s->getText(), |
317 | 319 | ); |
318 | 320 | } |
| 321 | + // Don't add empty rows |
| 322 | + if ( !count($changed) ) $changed = null; |
319 | 323 | |
320 | 324 | $dbw = wfGetDB( DB_MASTER ); |
321 | 325 | $dbw->delete( 'translate_sections', array( 'trs_page' => $page->getTitle()->getArticleId() ), __METHOD__ ); |
322 | 326 | $ok = $dbw->insert( 'translate_sections', $inserts, __METHOD__ ); |
323 | 327 | if ( $ok === false ) return array( 'tpt-insert-failed' ); |
324 | 328 | |
325 | | - $page->addMarkedTag( $newrevision ); |
| 329 | + $page->addMarkedTag( $newrevision, $changed ); |
326 | 330 | |
| 331 | + MessageIndex::cache( NS_TRANSLATIONS ); |
327 | 332 | return false; |
328 | 333 | } |
329 | 334 | |
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php |
— | — | @@ -137,7 +137,16 @@ |
138 | 138 | |
139 | 139 | public static function languages( $data, $params, $parser ) { |
140 | 140 | $title = $parser->getTitle(); |
| 141 | + |
| 142 | + // Check if this is a source page or a translation page |
141 | 143 | $page = TranslatablePage::newFromTitle( $title ); |
| 144 | + if ( $page->getMarkedTag() === false ) { |
| 145 | + $title = Title::makeTitle( $title->getNamespace(), $title->getBaseText() ); |
| 146 | + $page = TranslatablePage::newFromTitle( $title ); |
| 147 | + } |
| 148 | + if ( $page->getMarkedTag() === false ) return ''; |
| 149 | + |
| 150 | + |
142 | 151 | $status = $page->getTranslationPercentages(); |
143 | 152 | if ( !$status ) return ''; |
144 | 153 | |
— | — | @@ -157,7 +166,7 @@ |
158 | 167 | $name = TranslateUtils::getLanguageName( $code, false, $wgLang->getCode() ); |
159 | 168 | |
160 | 169 | $percent *= 100; |
161 | | - if ( $percent < 10 ) continue; |
| 170 | + if ( $percent < 10 ) continue; // Hide.. not very useful |
162 | 171 | if ( $percent < 20 ) $image = 1; |
163 | 172 | elseif ( $percent < 40 ) $image = 2; |
164 | 173 | elseif ( $percent < 60 ) $image = 3; |
— | — | @@ -215,7 +224,7 @@ |
216 | 225 | |
217 | 226 | // Add the ready tag |
218 | 227 | $page = TranslatablePage::newFromTitle( $article->getTitle() ); |
219 | | - $page->addReadyTag( $revision->getId() ); |
| 228 | + $page->addReadyTag( $revision->getId() ); |
220 | 229 | |
221 | 230 | return true; |
222 | 231 | } |
— | — | @@ -290,15 +299,15 @@ |
291 | 300 | |
292 | 301 | $sk = $wgUser->getSkin(); |
293 | 302 | |
294 | | - $page = TranslatablePage::newFromText( $title, '' ); |
| 303 | + $page = TranslatablePage::newFromTitle( $title ); |
295 | 304 | |
296 | 305 | $marked = $page->getMarkedTag(); |
297 | 306 | $ready = $page->getReadyTag(); |
| 307 | + |
298 | 308 | if ( $marked === false && $ready === false ) return ''; |
299 | 309 | |
300 | 310 | $latest = $title->getLatestRevId(); |
301 | 311 | $canmark = $ready === $latest && $marked !== $latest; |
302 | | - |
303 | 312 | wfLoadExtensionMessages( 'PageTranslation' ); |
304 | 313 | |
305 | 314 | $actions = array(); |