r107336 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107335‎ | r107336 | r107337 >
Date:19:44, 26 December 2011
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
Adding POC {{#translationdialog:title}} functionality.
Modified paths:
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/Translate.magic.php (added) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/TranslateHooks.php (modified) (history)
  • /trunk/extensions/Translate/resources/ext.translate.quickedit.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.magic.php
@@ -0,0 +1,8 @@
 2+<?php
 3+
 4+$magicWords = array();
 5+
 6+/** English (English) */
 7+$magicWords['en'] = array(
 8+ 'translationdialog' => array( 0, 'translationdialog' ),
 9+);
\ No newline at end of file
Property changes on: trunk/extensions/Translate/Translate.magic.php
___________________________________________________________________
Added: svn:eol-style
110 + native
Index: trunk/extensions/Translate/Translate.php
@@ -47,6 +47,7 @@
4848 $wgExtensionMessagesFiles['PageTranslation'] = $dir . 'PageTranslation.i18n.php';
4949 $wgExtensionMessagesFiles['TranslateGroupDescriptions'] = $dir . 'TranslateGroupDescriptions.i18n.php';
5050 $wgExtensionMessagesFiles['TranslateAlias'] = $dir . 'Translate.alias.php';
 51+$wgExtensionMessagesFiles['TranslateMagic'] = $dir . 'Translate.magic.php';
5152
5253 // Register initialization code
5354 $wgExtensionFunctions[] = 'TranslateHooks::setupTranslate';
Index: trunk/extensions/Translate/TranslateHooks.php
@@ -155,6 +155,7 @@
156156 public static function setupParserHooks( $parser ) {
157157 // For nice language list in-page
158158 $parser->setHook( 'languages', array( 'PageTranslationHooks', 'languages' ) );
 159+ $parser->setFunctionHook( 'translationdialog', array( 'TranslateHooks', 'translationDialogMagicWord' ) );
159160 return true;
160161 }
161162
@@ -327,5 +328,28 @@
328329 return '';
329330 }
330331
 332+ /**
 333+ * Hook: ParserFirstCallInit
 334+ */
 335+ public static function translationDialogMagicWord( Parser $parser, $title = '' ) {
 336+ $title = Title::newFromText( $title );
 337+ $handle = new MessageHandle( $title );
 338+ $group = $handle->getGroup();
 339+ $callParams = array( $title->getPrefixedText(), $group->getId() );
 340+ $call = Xml::encodeJsCall( 'mw.translate.openDialog', $callParams );
331341
 342+ $js = <<<JAVASCRIPT
 343+mw.loader.using( 'ext.translate.quickedit', function() { $call; } ); return false;
 344+JAVASCRIPT;
 345+
 346+
 347+ $a = array(
 348+ 'href' => $title->getFullUrl( array( 'action' => 'edit' ) ),
 349+ 'onclick' => $js,
 350+ );
 351+
 352+ $output = Html::element( 'a', $a, wfMessage( 'translate-edit-jsopen' )->text() );
 353+ return $parser->insertStripItem( $output, $parser->mStripState );
 354+ }
 355+
332356 }
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -71,6 +71,7 @@
7272 'translate-optional' => '(optional)',
7373 'translate-ignored' => '(ignored)',
7474
 75+ 'translate-edit-jsopen' => 'edit',
7576 'translate-edit-title' => 'Edit "$1"',
7677 'translate-edit-definition' => 'Message definition',
7778 'translate-edit-translation' => 'Translation',
@@ -652,6 +653,7 @@
653654 'translate-workflow-set-doing' => 'Submit button text when waiting for reply from server',
654655 'translate-workflow-set-done' => 'Submit button text when submission completed succesfully',
655656 'translate-stats-workflow' => 'Column header on Special:LanguageStats and Special:MessageGroupStats',
 657+ 'translate-edit-jsopen' => 'Default linktext of <nowiki>{{#translationdialog:pagename}}</nowiki>',
656658 );
657659
658660 /** Faeag Rotuma (Faeag Rotuma)
Index: trunk/extensions/Translate/resources/ext.translate.quickedit.js
@@ -86,15 +86,21 @@
8787 $identical.makeCollapsible();
8888 }
8989
90 - form.find( '.mw-translate-next' ).click( function() {
91 - mw.translate.openNext( page );
92 - } );
 90+ if ( mw.config.get( 'trlKeys' ) ) {
 91+ form.find( '.mw-translate-next' ).click( function() {
 92+ mw.translate.openNext( page );
 93+ } );
9394
94 - form.find( '.mw-translate-skip' ).click( function() {
95 - mw.translate.openNext( page );
96 - dialog.dialog( 'close' );
97 - return false;
98 - } );
 95+ form.find( '.mw-translate-skip' ).click( function() {
 96+ mw.translate.openNext( page );
 97+ dialog.dialog( 'close' );
 98+ return false;
 99+ } );
 100+ } else {
 101+ form.find( '.mw-translate-next, .mw-translate-skip' )
 102+ .attr( 'disabled', 'disabled' )
 103+ .css( 'display', 'none' );
 104+ }
99105
100106 form.find( '.mw-translate-history' ).click( function() {
101107 window.open( mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?action=history&title=' + form.find( 'input[name=title]' ).val() );

Follow-up revisions

RevisionCommit summaryAuthorDate
r107338Bugfixesnikerabbit19:55, 26 December 2011
r107471Check for input in r107336nikerabbit06:37, 28 December 2011
r107555Followup r107336 - correct commentnikerabbit06:07, 29 December 2011

Comments

#Comment by Santhosh.thottingal (talk | contribs)   05:03, 27 December 2011

we need to some null checks and validations in the below lines

+		$handle = new MessageHandle( $title );
+		$group = $handle->getGroup();
+		$callParams = array( $title->getPrefixedText(), $group->getId() );

An invalid title causes error here:

PHP Fatal error: Call to a member function getId() on a non-object in /path/to/wiki/extensions/Translate/TranslateHooks.php on line 339,

Status & tagging log