Index: trunk/extensions/Translate/scripts/populateFuzzy.php |
— | — | @@ -0,0 +1,63 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A script to populate fuzzy tags. |
| 5 | + * |
| 6 | + * @author Niklas Laxstrom |
| 7 | + * |
| 8 | + * @copyright Copyright © 2009, Niklas Laxström |
| 9 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 10 | + * @file |
| 11 | + */ |
| 12 | +require( dirname( __FILE__ ) . '/cli.inc' ); |
| 13 | + |
| 14 | +$db = wfGetDB( DB_MASTER ); |
| 15 | + |
| 16 | +$id = $db->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => 'fuzzy' ), __METHOD__ ); |
| 17 | +if ( $id === false ) { |
| 18 | + echo "Fuzzy tag is not registered\n"; |
| 19 | + exit(); |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +$count = $db->selectField( 'page', 'count(*)', array( 'page_namespace' => $wgTranslateMessageNamespaces ), __METHOD__ ); |
| 24 | +if ( !$count ) { |
| 25 | + echo "Nothing to update"; |
| 26 | + exit(); |
| 27 | +} |
| 28 | + |
| 29 | + |
| 30 | +$tables = array( 'page', 'text', 'revision' ); |
| 31 | +$fields = array( 'page_id', 'page_title', 'page_namespace', 'rev_id', 'old_text', 'old_flags' ); |
| 32 | +$conds = array( |
| 33 | + 'page_latest = rev_id', |
| 34 | + 'old_id = rev_text_id', |
| 35 | + 'page_namespace' => $wgTranslateMessageNamespaces, |
| 36 | +); |
| 37 | + |
| 38 | +$insert = array(); |
| 39 | + |
| 40 | +$limit = max(1000,intval($count/100)); |
| 41 | +$offset = 0; |
| 42 | +while (true) { |
| 43 | + echo "$offset/$count\n"; |
| 44 | + $options = array( 'LIMIT' => $limit, 'OFFSET' => $offset ); |
| 45 | + $res = $db->select( $tables, $fields, $conds, __METHOD__, $options ); |
| 46 | + if ( !$res->numRows() ) break; |
| 47 | + foreach ( $res as $r ) { |
| 48 | + $text = Revision::getRevisionText( $r ); |
| 49 | + if ( strpos( $text, TRANSLATE_FUZZY ) !== false ) { |
| 50 | + $inserts[] = array( |
| 51 | + 'rt_page' => $r->page_id, |
| 52 | + 'rt_revision' => $r->rev_id, |
| 53 | + 'rt_type' => $id |
| 54 | + ); |
| 55 | + } |
| 56 | + } |
| 57 | + $offset += $limit; |
| 58 | + |
| 59 | + $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ ); |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +echo $db->affectedRows() . "\n"; |
\ No newline at end of file |
Index: trunk/extensions/Translate/revtags.sql |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | rt_value blob null |
23 | 23 | ) /*$wgDBTableOptions*/; |
24 | 24 | -- Index for finding all revisions in a page with a given tag |
25 | | -CREATE INDEX /*i*/rt_type_page_revision ON /*$wgDBprefix*/revtag |
| 25 | +CREATE UNIQUE INDEX /*i*/rt_type_page_revision ON /*$wgDBprefix*/revtag |
26 | 26 | (rt_type, rt_page, rt_revision); |
27 | 27 | -- Index for finding the tags on a given revision |
28 | 28 | CREATE INDEX /*i*/rt_revision_type ON /*$wgDBprefix*/revtag (rt_revision, rt_type); |
\ No newline at end of file |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -183,11 +183,24 @@ |
184 | 184 | function wfMemOut() { } |
185 | 185 | |
186 | 186 | function efTranslateInit() { |
187 | | - global $wgTranslatePHPlot, $wgAutoloadClasses; |
| 187 | + global $wgTranslatePHPlot, $wgAutoloadClasses, $wgHooks; |
188 | 188 | if ( $wgTranslatePHPlot ) { |
189 | 189 | $wgAutoloadClasses['PHPlot'] = $wgTranslatePHPlot; |
190 | 190 | } |
191 | 191 | |
| 192 | + // Database schema |
| 193 | + $wgHooks['LoadExtensionSchemaUpdates'][] = 'PageTranslationHooks::schemaUpdates'; |
| 194 | + |
| 195 | + // Do not activate hooks if not setup properly |
| 196 | + if ( !efTranslateCheckPT() ) { |
| 197 | + $wgEnablePageTranslation = false; |
| 198 | + return true; |
| 199 | + } |
| 200 | + |
| 201 | + // Fuzzy tags for speed |
| 202 | + $wgHooks['ArticleSaveComplete'][] = 'efTranslateAddFuzzy'; |
| 203 | + |
| 204 | + |
192 | 205 | global $wgEnablePageTranslation; |
193 | 206 | if ( $wgEnablePageTranslation ) { |
194 | 207 | |
— | — | @@ -213,18 +226,6 @@ |
214 | 227 | $wgTranslateMessageNamespaces[] = NS_TRANSLATIONS; |
215 | 228 | |
216 | 229 | // Page translation hooks |
217 | | - global $wgHooks; |
218 | | - |
219 | | - // Database schema |
220 | | - $wgHooks['LoadExtensionSchemaUpdates'][] = 'PageTranslationHooks::schemaUpdates'; |
221 | | - |
222 | | - // Do not activate hooks if not setup properly |
223 | | - if ( !efTranslateCheckPT() ) { |
224 | | - $wgEnablePageTranslation = false; |
225 | | - return true; |
226 | | - } |
227 | | - |
228 | | - |
229 | 230 | // Register our css, is there a better place for this? |
230 | 231 | $wgHooks['OutputPageBeforeHTML'][] = 'PageTranslationHooks::injectCss'; |
231 | 232 | |
— | — | @@ -259,7 +260,7 @@ |
260 | 261 | function efTranslateCheckPT() { |
261 | 262 | global $wgHooks, $wgMemc; |
262 | 263 | |
263 | | - $version = "2"; // Must be a string |
| 264 | + $version = "3"; // Must be a string |
264 | 265 | global $wgMemc; |
265 | 266 | $memcKey = wfMemcKey( 'pt' ); |
266 | 267 | $ok = $wgMemc->get( $memcKey ); |
— | — | @@ -272,7 +273,7 @@ |
273 | 274 | |
274 | 275 | // Add our tags if they are not registered yet |
275 | 276 | // tp:tag is called also the ready tag |
276 | | - $tags = array( 'tp:mark', 'tp:tag', 'tp:transver' ); |
| 277 | + $tags = array( 'tp:mark', 'tp:tag', 'tp:transver', 'fuzzy' ); |
277 | 278 | |
278 | 279 | $dbw = wfGetDB( DB_MASTER ); |
279 | 280 | if ( !$dbw->tableExists('revtag_type') ) { |
— | — | @@ -310,3 +311,34 @@ |
311 | 312 | function STDOUT() {} |
312 | 313 | function STDERR() {} |
313 | 314 | } |
| 315 | + |
| 316 | +function efTranslateAddFuzzy( $article, $user, $text, $summary, |
| 317 | + $minor, $_, $_, $flags, $revision ) { |
| 318 | + |
| 319 | + global $wgTranslateMessageNamespaces; |
| 320 | + |
| 321 | + $ns = $article->getTitle()->getNamespace(); |
| 322 | + if ( !in_array( $ns, $wgTranslateMessageNamespaces) ) return true; |
| 323 | + |
| 324 | + // We are not interested in null revisions |
| 325 | + if ( $revision === null ) { |
| 326 | + $rev = $article->getTitle()->getLatestRevId(); |
| 327 | + } else { |
| 328 | + $rev = $revision->getID(); |
| 329 | + } |
| 330 | + |
| 331 | + // Add the ready tag |
| 332 | + $dbw = wfGetDB( DB_MASTER ); |
| 333 | + |
| 334 | + $id = $dbw->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => 'fuzzy' ), __METHOD__ ); |
| 335 | + |
| 336 | + $conds = array( |
| 337 | + 'rt_page' => $article->getTitle()->getArticleId(), |
| 338 | + 'rt_type' => $id, |
| 339 | + 'rt_revision' => $rev |
| 340 | + ); |
| 341 | + $dbw->delete( 'revtag', $conds, __METHOD__ ); |
| 342 | + $dbw->insert( 'revtag', $conds, __METHOD__ ); |
| 343 | + |
| 344 | + return true; |
| 345 | +} |
\ No newline at end of file |