Index: trunk/extensions/Translate/MessageGroups.php |
— | — | @@ -649,7 +649,10 @@ |
650 | 650 | foreach ( $messages as $key => $m ) { |
651 | 651 | $rev = $page->getTransrev( $key .'/' . $messages->code ); |
652 | 652 | if ( $rev === false ) { |
653 | | - $m->database = TRANSLATE_FUZZY . $m->database; |
| 653 | + if ( !$m->database === null ) { |
| 654 | + //TODO: fixme, ugly ugly ugly |
| 655 | + $m->database = TRANSLATE_FUZZY . $m->database; |
| 656 | + } |
654 | 657 | continue; |
655 | 658 | } |
656 | 659 | foreach ( $markedRevs as $r ) { |
Index: trunk/extensions/Translate/tag/TranslatablePage.php |
— | — | @@ -105,7 +105,7 @@ |
106 | 106 | $len = strlen($matches[2][0][0]); // len of the content |
107 | 107 | $end = $start + $len; |
108 | 108 | |
109 | | - $ret = $this->sectionise( &$sections, substr( $contents, $start, $len ) ); |
| 109 | + $ret = $this->sectionise( $sections, substr( $contents, $start, $len ) ); |
110 | 110 | |
111 | 111 | $tagPlaceHolders[$ph] = |
112 | 112 | self::index_replace( $contents, $ret, $start, $end ); |
— | — | @@ -142,7 +142,7 @@ |
143 | 143 | return substr( $string, 0, $start ) . $rep . substr( $string, $end ); |
144 | 144 | } |
145 | 145 | |
146 | | - protected function sectionise( $sections, $text ) { |
| 146 | + protected function sectionise( &$sections, $text ) { |
147 | 147 | $flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE; |
148 | 148 | $parts = preg_split( '~(\s*\n\n\s*|\s*$)~', $text, -1, $flags ); |
149 | 149 | |
— | — | @@ -197,12 +197,13 @@ |
198 | 198 | } |
199 | 199 | |
200 | 200 | protected function addTag( $tag, $revision, $value = null ) { |
| 201 | + |
201 | 202 | $dbw = wfGetDB( DB_MASTER ); |
202 | 203 | |
203 | | - // Can this be done in one query? |
204 | | - $id = $dbw->selectField( 'revtag_type', 'rtt_id', |
205 | | - array( 'rtt_name' => $tag ), __METHOD__ ); |
| 204 | + $id = $this->getTagId( $tag ); |
206 | 205 | |
| 206 | + if ( is_object($revision) ) throw new MWException('Got object, excepted id'); |
| 207 | + |
207 | 208 | $conds = array( |
208 | 209 | 'rt_page' => $this->getTitle()->getArticleId(), |
209 | 210 | 'rt_type' => $id, |
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | |
69 | 69 | // This will modify the sections to include name property |
70 | 70 | $error = false; |
71 | | - $sections = $this->checkInput( $page, &$error ); |
| 71 | + $sections = $this->checkInput( $page, $error ); |
72 | 72 | // Non-fatal error which prevents saving |
73 | 73 | if ( $error === false && $wgRequest->wasPosted() ) { |
74 | 74 | $err = $this->markForTranslation( $page, $sections ); |
— | — | @@ -198,7 +198,13 @@ |
199 | 199 | } |
200 | 200 | |
201 | 201 | global $wgLang; |
202 | | - return $wgLang->semicolonList( $actions ); |
| 202 | + if ( method_exists( $wgLang, 'semicolonList' ) ) { |
| 203 | + // BC for <1.15 |
| 204 | + $actionText .= $wgLang->semicolonList( $actions ); |
| 205 | + } else { |
| 206 | + $actionText = implode( '; ', $actions ); |
| 207 | + } |
| 208 | + return $actionText; |
203 | 209 | } |
204 | 210 | |
205 | 211 | public function checkInput( TranslatablePage $page, &$error = false ) { |
— | — | @@ -302,6 +308,13 @@ |
303 | 309 | if ( !$status->isOK() ) return array( 'tpt-edit-failed', $status->getWikiText() ); |
304 | 310 | |
305 | 311 | $newrevision = $status->value['revision']; |
| 312 | + |
| 313 | + // In theory it is either null or Revision object, |
| 314 | + // never revision object with null id, but who knows |
| 315 | + if ( $newrevision instanceof Revision ) { |
| 316 | + $newrevision = $newrevision->getId(); |
| 317 | + } |
| 318 | + |
306 | 319 | if ( $newrevision === null ) { |
307 | 320 | // Probably a no-change edit, so no new revision was assigned |
308 | 321 | $newrevision = $page->getTitle()->getLatestRevId(); |
— | — | @@ -323,10 +336,8 @@ |
324 | 337 | $dbw = wfGetDB( DB_MASTER ); |
325 | 338 | $dbw->delete( 'translate_sections', array( 'trs_page' => $page->getTitle()->getArticleId() ), __METHOD__ ); |
326 | 339 | $ok = $dbw->insert( 'translate_sections', $inserts, __METHOD__ ); |
327 | | - if ( $ok === false ) return array( 'tpt-insert-failed' ); |
328 | 340 | |
329 | 341 | $page->addMarkedTag( $newrevision, $changed ); |
330 | | - |
331 | 342 | // Re-generate caches |
332 | 343 | MessageIndex::cache( NS_TRANSLATIONS ); |
333 | 344 | $page->getTranslationPercentages( true ); |
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php |
— | — | @@ -288,23 +288,12 @@ |
289 | 289 | return true; |
290 | 290 | } |
291 | 291 | |
292 | | - public static function onLoadExtensionSchemaUpdates() { |
| 292 | + public static function schemaUpdates() { |
293 | 293 | global $wgExtNewTables; |
294 | 294 | $dir = dirname( __FILE__ ) . '/..'; |
295 | 295 | $wgExtNewTables[] = array( 'translate_sections', "$dir/translate.sql" ); |
296 | 296 | $wgExtNewTables[] = array( 'revtag_type', "$dir/revtags.sql" ); |
297 | 297 | |
298 | | - // Add our tags if they are not registered yet |
299 | | - // tp:tag is called also the ready tag |
300 | | - $tags = array( 'tp:mark', 'tp:tag', 'tp:transver' ); |
301 | | - |
302 | | - $dbw = wfGetDB( DB_MASTER ); |
303 | | - foreach ( $tags as $tag ) { |
304 | | - // TODO: use insert ignore |
305 | | - $field = array( 'rtt_name' => $tag ); |
306 | | - $ret = $dbw->selectField( 'revtag_type', 'rtt_name', $field, __METHOD__ ); |
307 | | - if ( $ret !== $tag ) $dbw->insert( 'revtag_type', $field, __METHOD__ ); |
308 | | - } |
309 | 298 | return true; |
310 | 299 | } |
311 | 300 | |
— | — | @@ -368,7 +357,12 @@ |
369 | 358 | |
370 | 359 | if ( !count($actions) ) return; |
371 | 360 | $legend = "<div style=\"font-size: x-small; text-align: center\">"; |
372 | | - $legend .= $wgLang->semicolonList( $actions ); |
| 361 | + if ( method_exists( $wgLang, 'semicolonList' ) ) { |
| 362 | + // BC for <1.15 |
| 363 | + $legend .= $wgLang->semicolonList( $actions ); |
| 364 | + } else { |
| 365 | + $legend .= implode( '; ', $actions ); |
| 366 | + } |
373 | 367 | $legend .= '</div><hr />'; |
374 | 368 | |
375 | 369 | global $wgOut; |
Index: trunk/extensions/Translate/tag/TPSection.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | $rep = "\\1 $header\n"; |
27 | 27 | $count = 0; |
28 | 28 | |
29 | | - $text = preg_replace( $re, $rep, $this->text, 1, &$count ); |
| 29 | + $text = preg_replace( $re, $rep, $this->text, 1, $count ); |
30 | 30 | if ( $count === 0 ) { |
31 | 31 | $text = $header . "\n" . $this->text; |
32 | 32 | } |
Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -13,8 +13,11 @@ |
14 | 14 | const MSG = 'translate-edit-'; |
15 | 15 | |
16 | 16 | static function addNavigation( &$outputpage, &$text ) { |
17 | | - global $wgUser, $wgTitle; |
| 17 | + global $wgUser, $wgTitle, $wgTranslateMessageNamespaces; |
18 | 18 | $ns = $wgTitle->getNamespace(); |
| 19 | + |
| 20 | + if ( !in_array( $ns, $wgTranslateMessageNamespaces) ) return true; |
| 21 | + |
19 | 22 | list( $key, $code ) = self::figureMessage( $wgTitle ); |
20 | 23 | |
21 | 24 | $group = self::getMessageGroup( $ns, $key ); |
— | — | @@ -104,6 +107,10 @@ |
105 | 108 | |
106 | 109 | |
107 | 110 | static function addTools( $object ) { |
| 111 | + global $wgTranslateMessageNamespaces; |
| 112 | + $ns = $object->mTitle->getNamespace(); |
| 113 | + if ( !in_array( $ns, $wgTranslateMessageNamespaces) ) return true; |
| 114 | + |
108 | 115 | $object->editFormTextTop .= self::editBoxes( $object ); |
109 | 116 | global $wgMessageCache, $wgLang; |
110 | 117 | return true; |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -212,6 +212,16 @@ |
213 | 213 | // Page translation hooks |
214 | 214 | global $wgHooks; |
215 | 215 | |
| 216 | + // Database schema |
| 217 | + $wgHooks['LoadExtensionSchemaUpdates'][] = 'PageTranslationHooks::schemaUpdates'; |
| 218 | + |
| 219 | + // Do not activate hooks if not setup properly |
| 220 | + if ( !efTranslateCheckPT() ) { |
| 221 | + $wgEnablePageTranslation = false; |
| 222 | + return true; |
| 223 | + } |
| 224 | + |
| 225 | + |
216 | 226 | // Register our css, is there a better place for this? |
217 | 227 | $wgHooks['OutputPageBeforeHTML'][] = 'PageTranslationHooks::injectCss'; |
218 | 228 | |
— | — | @@ -238,13 +248,54 @@ |
239 | 249 | |
240 | 250 | $wgHooks['ArticleViewHeader'][] = 'PageTranslationHooks::test'; |
241 | 251 | |
242 | | - // Database schema |
243 | | - $wgHooks['LoadExtensionSchemaUpdates'][] = 'PageTranslationHooks::onLoadExtensionSchemaUpdates'; |
| 252 | + } |
244 | 253 | |
| 254 | +} |
| 255 | + |
| 256 | + |
| 257 | +function efTranslateCheckPT() { |
| 258 | + global $wgHooks, $wgMemc; |
| 259 | + |
| 260 | + $version = 2; |
| 261 | + global $wgMemc; |
| 262 | + $memcKey = wfMemcKey( 'pt' ); |
| 263 | + $ok = $wgMemc->get( $memcKey ); |
| 264 | + |
| 265 | + wfLoadExtensionMessages( 'PageTranslation' ); |
| 266 | + if ( $ok === $version ) { |
| 267 | + return true; |
245 | 268 | } |
246 | 269 | |
| 270 | + |
| 271 | + // Add our tags if they are not registered yet |
| 272 | + // tp:tag is called also the ready tag |
| 273 | + $tags = array( 'tp:mark', 'tp:tag', 'tp:transver' ); |
| 274 | + |
| 275 | + $dbw = wfGetDB( DB_MASTER ); |
| 276 | + if ( !$dbw->tableExists('revtag_type') ) { |
| 277 | + $wgHooks['SiteNoticeAfter'][] = array('efTranslateCheckWarn', wfMsg( 'tpt-install' ) ); |
| 278 | + return false; |
| 279 | + } |
| 280 | + |
| 281 | + foreach ( $tags as $tag ) { |
| 282 | + // TODO: use insert ignore |
| 283 | + $field = array( 'rtt_name' => $tag ); |
| 284 | + $ret = $dbw->selectField( 'revtag_type', 'rtt_name', $field, __METHOD__ ); |
| 285 | + if ( $ret !== $tag ) $dbw->insert( 'revtag_type', $field, __METHOD__ ); |
| 286 | + } |
| 287 | + |
| 288 | + $wgMemc->set( $memcKey, $version ); |
| 289 | + |
| 290 | + return true; |
247 | 291 | } |
248 | 292 | |
| 293 | +function efTranslateCheckWarn( $msg, &$sitenotice ) { |
| 294 | + global $wgOut; |
| 295 | + $sitenotice = $msg; |
| 296 | + $wgOut->enableClientCache( false ); |
| 297 | + return true; |
| 298 | +} |
| 299 | + |
249 | 300 | function efTranslateInitTags( $parser ) { |
250 | 301 | // For nice language list in-page |
251 | 302 | $parser->setHook( 'languages', array( 'PageTranslationHooks', 'languages' ) ); |
— | — | @@ -256,5 +307,3 @@ |
257 | 308 | function STDOUT() {} |
258 | 309 | function STDERR() {} |
259 | 310 | } |
260 | | - |
261 | | -$wgGroupPermissions['staff' ]['pagetranslation'] = true; |
Index: trunk/extensions/Translate/PageTranslation.i18n.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | |
25 | 25 | # Specific page on the special page |
26 | 26 | 'tpt-badtitle' => 'Page name given ($1) is not a valid title', |
27 | | - 'tpt-oldrevision' => '$2 is not the latest version of the page $1. |
| 27 | + 'tpt-oldrevision' => '$2 is not the latest version of the page [[$1]]. |
28 | 28 | Only latest versions can be marked for translation.', |
29 | 29 | 'tpt-notsuitable' => 'Page $1 is not suitable for translation. |
30 | 30 | Make sure it has <nowiki><translate></nowiki> tags and has a valid syntax.', |
— | — | @@ -35,7 +35,6 @@ |
36 | 36 | Before marking this version for translation, check that the changes to sections are minimised to avoid unnecessary work for translators.', |
37 | 37 | 'tpt-mark-summary' => 'Marked this version for translation', |
38 | 38 | 'tpt-edit-failed' => 'Could not update the page: $1', |
39 | | - 'tpt-insert-failed' => 'Could not add sections to the database.', |
40 | 39 | 'tpt-already-marked' => 'The latest version of this page has already been marked for translation.', |
41 | 40 | |
42 | 41 | # Page list on the special page |
— | — | @@ -58,7 +57,10 @@ |
59 | 58 | 'tpt-target-page' => 'This page cannot be updated manually. |
60 | 59 | This page is a translation of page [[$1]] and the translation can be updated using [$2 the translation tool].', |
61 | 60 | 'tpt-unknown-page' => 'This namespace is reserved for content page translations. |
62 | | -The page you are trying to edit does not seem to correspond any page marked for translation.' |
| 61 | +The page you are trying to edit does not seem to correspond any page marked for translation.', |
| 62 | + |
| 63 | + 'tpt-install' => 'Run php maintenance/update.php or web install to enable page translation feature.', |
| 64 | + 'tpt-install-ok' => 'Add <tt>$wgPageTranslationNoCheck = true;</tt> to your LocalSettings.php.' |
63 | 65 | ); |
64 | 66 | |
65 | 67 | /** Arabic (العربية) |
Index: trunk/extensions/Translate/utils/MessageIndex.php |
— | — | @@ -30,10 +30,8 @@ |
31 | 31 | } |
32 | 32 | |
33 | 33 | public static function cache( $namespace = null ) { |
34 | | - if ( $namespace !== null ) { |
35 | | - $namepace = MWNamespace::getCanonicalName( $namespace ); |
36 | | - if ( $namespace === false ) return null; |
37 | | - } |
| 34 | + $namespace = self::checkNs( $namespace ); |
| 35 | + if ( $namespace === null ) return null; |
38 | 36 | |
39 | 37 | $groups = MessageGroups::singleton()->getGroups(); |
40 | 38 | |
— | — | @@ -100,6 +98,9 @@ |
101 | 99 | } |
102 | 100 | |
103 | 101 | protected static function index( $namespace ) { |
| 102 | + $namespace = self::checkNs( $namespace ); |
| 103 | + if ( $namespace === null ) return null; |
| 104 | + |
104 | 105 | global $wgMemc; |
105 | 106 | $memcKey = wfMemcKey( 'messageindex', $namespace ); |
106 | 107 | $cache = unserialize( $wgMemc->get($memcKey) ); |
— | — | @@ -107,9 +108,17 @@ |
108 | 109 | // Missing? Update it |
109 | 110 | if ( !is_array($cache) ) self::cache( $namespace ); |
110 | 111 | $cache = unserialize( $wgMemc->get($memcKey) ); |
111 | | - if ( !is_array($cache) ) throw new MWException( "Caching failed" ); |
| 112 | + if ( !is_array($cache) ) throw new MWException( "Caching failed: $namespace" ); |
112 | 113 | |
113 | 114 | return $cache; |
114 | 115 | |
115 | 116 | } |
| 117 | + |
| 118 | + protected static function checkNs( $namespace ) { |
| 119 | + if ( $namespace !== null ) { |
| 120 | + $namepace = MWNamespace::getCanonicalName( $namespace ); |
| 121 | + if ( $namespace === false ) return null; |
| 122 | + } |
| 123 | + return $namespace; |
| 124 | + } |
116 | 125 | } |
\ No newline at end of file |
Index: trunk/extensions/Translate/utils/ToolBox.php |
— | — | @@ -8,8 +8,12 @@ |
9 | 9 | * actually is a translatable/translated message. |
10 | 10 | */ |
11 | 11 | static function toolboxAllTranslations( &$skin ) { |
12 | | - global $wgTitle; |
| 12 | + global $wgTitle, $wgTranslateMessageNamespaces; |
13 | 13 | |
| 14 | + $ns = $wgTitle->getNamespace(); |
| 15 | + if ( !in_array( $ns, $wgTranslateMessageNamespaces) ) return true; |
| 16 | + |
| 17 | + |
14 | 18 | $inMessageGroup = TranslateUtils::messageKeyToGroup( $wgTitle->getNamespace(), $wgTitle->getBaseText() ); |
15 | 19 | |
16 | 20 | if ( $inMessageGroup ) { |
Index: trunk/extensions/Translate/TranslateUtils.php |
— | — | @@ -296,9 +296,16 @@ |
297 | 297 | } |
298 | 298 | |
299 | 299 | public static function messageKeyToGroup( $namespace, $key ) { |
300 | | - $key = self::normaliseKey( $namespace, $key ); |
| 300 | + $normkey = self::normaliseKey( $namespace, $key ); |
301 | 301 | $index = self::messageIndex(); |
302 | | - return @$index[$key]; |
| 302 | + $group = @$index[$normkey]; |
| 303 | + |
| 304 | + global $wgEnablePageTranslation; |
| 305 | + if ( $wgEnablePageTranslation && !$group ) { |
| 306 | + $group = MessageIndex::messageToGroup( $namespace, $key ); |
| 307 | + } |
| 308 | + return $group; |
| 309 | + |
303 | 310 | } |
304 | 311 | |
305 | 312 | public static function normaliseKey( $namespace, $key ) { |