r64899 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64898‎ | r64899 | r64900 >
Date:20:10, 10 April 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Fix second level message loading and clean ugly code
Modified paths:
  • /trunk/extensions/Translate/js/quickedit.js (modified) (history)
  • /trunk/extensions/Translate/utils/MessageTable.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationEditPage.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/js/quickedit.js
@@ -21,8 +21,9 @@
2222 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
2323 */
2424
25 -function trlOpenJsEdit( page ) {
26 - var url = trlEditUrl.replace( "$1", page );
 25+function trlOpenJsEdit( page, group ) {
 26+ var url = wgScript + "?title=Special:Translate/editpage&page=$1&loadgroup=$2";
 27+ url = url.replace( "$1", page ).replace( "$2", group );
2728 var id = "jsedit" + page.replace( /[^a-zA-Z0-9_]/g, '_' );
2829
2930 var dialog = jQuery("#"+id);
Index: trunk/extensions/Translate/utils/MessageTable.php
@@ -68,13 +68,8 @@
6969
7070 // Helper stuff for JS
7171 $trlKeys = array_values( $this->collection->keys() );
72 - $editQuery = wfArrayToCgi( array(
73 - 'title' => SpecialPage::getTitleFor( 'Translate', 'editpage' )->getPrefixedText(),
74 - 'loadgroup' => $this->group->getId(),
75 - ));
7672
7773 $vars = array(
78 - 'trlEditUrl' => "$wgScript?$editQuery&page=$1",
7974 'trlKeys' => $trlKeys,
8075 'trlMsgNoNext' => wfMsg( 'translate-js-nonext' ),
8176 'trlMsgSaveFailed' => wfMsg( 'translate-js-save-failed' ),
Index: trunk/extensions/Translate/utils/TranslationEditPage.php
@@ -111,14 +111,15 @@
112112 return $data;
113113 }
114114
115 - public static function jsEdit( Title $title ) {
 115+ public static function jsEdit( Title $title, $group = "" ) {
116116 global $wgUser;
117117
118118 if ( !$wgUser->isAllowed( 'translate' ) ) return array();
119119 if ( !$wgUser->getOption( 'translate-jsedit' ) ) return array();
120120
121121 $jsTitle = Xml::escapeJsString( $title->getPrefixedDbKey() );
122 - return array( 'onclick' => "return trlOpenJsEdit( \"$jsTitle\" );" );
 122+ $jsGroup = Xml::escapeJsString( $group );
 123+ return array( 'onclick' => "return trlOpenJsEdit( \"$jsTitle\", \"$jsGroup\" );" );
123124 }
124125
125126 }
\ No newline at end of file
Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -177,7 +177,7 @@
178178
179179 $source_page = Title::newFromText( $s['context'] . "/$code" );
180180 if ( $source_page ) {
181 - $legend[$accuracy][] = self::editLink( $source_page, '•' );
 181+ $legend[$accuracy][] = self::ajaxEditLink( $source_page, '•' );
182182 }
183183
184184 $text = $this->suggestionField( $s['target'] );
@@ -423,7 +423,7 @@
424424
425425 $target = Title::makeTitleSafe( $ns, "$page/$fbcode" );
426426 if ( $target ) {
427 - $label = self::editLink( $target, htmlspecialchars( $label ) );
 427+ $label = self::ajaxEditLink( $target, htmlspecialchars( $label ) );
428428 }
429429
430430 $text = TranslateUtils::convertWhiteSpaceToHTML( $text );
@@ -452,7 +452,7 @@
453453 $ns = $this->title->getNamespace();
454454
455455 $title = Title::makeTitle( $ns, $page . '/' . $wgTranslateDocumentationLanguageCode );
456 - $edit = self::editLink( $title, wfMsgHtml( 'translate-edit-contribute' ) );
 456+ $edit = self::ajaxEditLink( $title, wfMsgHtml( 'translate-edit-contribute' ) );
457457 $info = TranslateUtils::getMessageContent( $page, $wgTranslateDocumentationLanguageCode, $ns );
458458
459459 $class = 'mw-sp-translate-edit-info';
@@ -611,17 +611,24 @@
612612 return $this->adder( $id ) . "\n" . Html::rawElement( 'span', array( 'id' => $id ), $contents );
613613 }
614614
615 - public static function editLink( $target, $text, $params = array() ) {
 615+ /**
 616+ * Ajax-enabled message editing link.
 617+ * @param $target Title: Title of the target message.
 618+ * @param $text String: Link text for Linker::link()
 619+ * @return link
 620+ */
 621+ public static function ajaxEditLink( $target, $text ) {
616622 global $wgUser;
617623
618624 list( $page, ) = self::figureMessage( $target );
619625 $group = TranslateUtils::messageKeyToGroup( $target->getNamespace(), $page );
620 - if ( $group ) $group = MessageGroups::getGroup( $group );
621 - $params += array( 'action' => 'edit' );
622 - if ( $group ) $params += array( 'loadgroup' => $group->getId() );
623626
624 - $jsEdit = TranslationEditPage::jsEdit( $target );
 627+ $params = array();
 628+ $params['action'] = 'edit';
 629+ $params['loadgroup'] = $group;
625630
 631+ $jsEdit = TranslationEditPage::jsEdit( $target, $group );
 632+
626633 return $wgUser->getSkin()->link( $target, $text, $jsEdit, $params );
627634 }
628635 }

Status & tagging log