r112782 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112781‎ | r112782 | r112783 >
Date:08:52, 1 March 2012
Author:nikerabbit
Status:ok
Tags:
Comment:
* Improve logging
* Normalize parameters
* Remove unset values from database
* Encapsulate code better
Modified paths:
  • /trunk/extensions/Translate/PageTranslation.i18n.php (modified) (history)
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslateMetadata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -671,24 +671,7 @@
672672 $logger->addEntry( 'mark', $page->getTitle(), null, array( serialize( $params ) ) );
673673
674674
675 - // Save the priority languages if any
676 - $priorityLangs = trim( $wgRequest->getVal( 'prioritylangs' ) );
677 - $priorityForce = $wgRequest->getCheck( 'forcelimit' );
678 - $priorityReason = $wgRequest->getVal( 'priorityreason' );
679 - // FIXME: does not log removals
680 - if ( $priorityLangs ) {
681 - $groupId = $page->getMessageGroupId();
682 - // FIXME: does not normalise input to a,b,c,d
683 - TranslateMetadata::set( $groupId, 'prioritylangs', trim( $priorityLangs, ',' ) );
684 - TranslateMetadata::set( $groupId, 'priorityforce', $priorityForce ? 'on' : 'off' );
685 - TranslateMetadata::set( $groupId, 'priorityreason', trim( $priorityReason ) );
686 - $params = array(
687 - 'user' => $wgUser->getName(),
688 - 'languages' => $priorityLangs,
689 - 'force' => $priorityForce,
690 - );
691 - $logger->addEntry( 'prioritylanguages', $page->getTitle(), null, array( serialize( $params ) ) );
692 - }
 675+ $this->handlePriorityLanguages( $wgRequest, $page, $wgUser );
693676
694677 $page->getTitle()->invalidateCache();
695678 $this->setupRenderJobs( $page );
@@ -699,6 +682,44 @@
700683 return false;
701684 }
702685
 686+ protected function handlePriorityLanguages( WebRequest $request, TranslatablePage $page, User $user ) {
 687+ // new priority languages
 688+ $npLangs = trim( $request->getVal( 'prioritylangs' ) );
 689+ $npForce = $request->getCheck( 'forcelimit' ) ? 'on' : 'off';
 690+ $npReason = trim( $request->getText( 'priorityreason' ) );
 691+
 692+ // Normalize
 693+ $npLangs = array_map( 'trim', explode( ',', $npLangs ) );
 694+ $npLangs = array_unique( $npLangs );
 695+ $npLangs = implode( ',', $npLangs );
 696+ if ( $npLangs === '' ) {
 697+ $npLangs = false;
 698+ $npForce = false;
 699+ $npReason = false;
 700+ }
 701+
 702+ $groupId = $page->getMessageGroupId();
 703+ // old priority languages
 704+ $opLangs = TranslateMetadata::get( $groupId, 'prioritylangs' );
 705+ $opForce = TranslateMetadata::get( $groupId, 'priorityforce' );
 706+ $opReason = TranslateMetadata::get( $groupId, 'priorityreason' );
 707+
 708+ TranslateMetadata::set( $groupId, 'prioritylangs', $npLangs );
 709+ TranslateMetadata::set( $groupId, 'priorityforce', $npForce );
 710+ TranslateMetadata::set( $groupId, 'priorityreason', $npReason );
 711+
 712+ if ( $opLangs !== $npLangs || $opForce !== $npForce || $opReason !== $npReason ) {
 713+ $params = array(
 714+ 'user' => $user->getName(),
 715+ 'languages' => $npLangs,
 716+ 'force' => $npForce,
 717+ 'reason' => $npReason,
 718+ );
 719+ $logger = new LogPage( 'pagetranslation' );
 720+ $logger->addEntry( 'prioritylanguages', $page->getTitle(), null, array( serialize( $params ) ) );
 721+ }
 722+ }
 723+
703724 /**
704725 * @param $page Article
705726 * @param $changed
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -585,7 +585,9 @@
586586 } elseif ( $action === 'deletelok' ) {
587587 return wfMsgExt( 'pt-log-delete-lang-ok', $opts, $title->getPrefixedText(), $user );
588588 } elseif ( $action === 'prioritylanguages' ) {
589 - if ( $_['force'] === 'on' ) {
 589+ if ( $_['languages'] === false ) {
 590+ return wfMsgExt( 'pt-log-priority-langs-unset', $opts, $title->getPrefixedText(), $user );
 591+ } elseif ( $_['force'] === 'on' ) {
590592 return wfMsgExt( 'pt-log-priority-langs-force', $opts, $title->getPrefixedText(), $user, $_['languages'] );
591593 } else {
592594 return wfMsgExt( 'pt-log-priority-langs', $opts, $title->getPrefixedText(), $user , $_['languages'] );
Index: trunk/extensions/Translate/PageTranslation.i18n.php
@@ -132,6 +132,7 @@
133133 'pt-log-delete-full-nok' => '{{GENDER:$2|encountered}} a problem while deleting translatable page [[:$1]]',
134134 'pt-log-delete-lang-ok' => '{{GENDER:$2|completed}} deletion of translation page $1',
135135 'pt-log-delete-lang-nok' => '{{GENDER:$2|encountered}} a problem while deleting translation page [[:$1]]',
 136+ 'pt-log-priority-langs-unset' => '{{GENDER:$2|removed}} priority languages from translatable page [[:$1]]',
136137 'pt-log-priority-langs' => '{{GENDER:$2|set}} the priority languages for translatable page [[:$1]] to $3',
137138 'pt-log-priority-langs-force' => '{{GENDER:$2|limited}} languages for translatable page [[:$1]] to $3',
138139
Index: trunk/extensions/Translate/utils/TranslateMetadata.php
@@ -33,7 +33,12 @@
3434 public static function set( $group, $key, $value ) {
3535 $dbw = wfGetDB( DB_MASTER );
3636 $data = array( 'tmd_group' => $group, 'tmd_key' => $key, 'tmd_value' => $value );
37 - $dbw->replace( 'translate_metadata', array( array( 'tmd_group', 'tmd_key' ) ), $data, __METHOD__ );
 37+ if ( $value === false ) {
 38+ unset( $data['tmd_value'] );
 39+ $dbw->delete( 'translate_metadata', $data );
 40+ } else {
 41+ $dbw->replace( 'translate_metadata', array( array( 'tmd_group', 'tmd_key' ) ), $data, __METHOD__ );
 42+ }
3843 }
3944
4045 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r112667Logging for Language preference changes for a translatable page.santhosh05:07, 29 February 2012
r112668UI for the language restriction for page translation...santhosh05:33, 29 February 2012

Status & tagging log