Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php |
— | — | @@ -671,24 +671,7 @@ |
672 | 672 | $logger->addEntry( 'mark', $page->getTitle(), null, array( serialize( $params ) ) ); |
673 | 673 | |
674 | 674 | |
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 ); |
693 | 676 | |
694 | 677 | $page->getTitle()->invalidateCache(); |
695 | 678 | $this->setupRenderJobs( $page ); |
— | — | @@ -699,6 +682,44 @@ |
700 | 683 | return false; |
701 | 684 | } |
702 | 685 | |
| 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 | + |
703 | 724 | /** |
704 | 725 | * @param $page Article |
705 | 726 | * @param $changed |
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php |
— | — | @@ -585,7 +585,9 @@ |
586 | 586 | } elseif ( $action === 'deletelok' ) { |
587 | 587 | return wfMsgExt( 'pt-log-delete-lang-ok', $opts, $title->getPrefixedText(), $user ); |
588 | 588 | } 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' ) { |
590 | 592 | return wfMsgExt( 'pt-log-priority-langs-force', $opts, $title->getPrefixedText(), $user, $_['languages'] ); |
591 | 593 | } else { |
592 | 594 | return wfMsgExt( 'pt-log-priority-langs', $opts, $title->getPrefixedText(), $user , $_['languages'] ); |
Index: trunk/extensions/Translate/PageTranslation.i18n.php |
— | — | @@ -132,6 +132,7 @@ |
133 | 133 | 'pt-log-delete-full-nok' => '{{GENDER:$2|encountered}} a problem while deleting translatable page [[:$1]]', |
134 | 134 | 'pt-log-delete-lang-ok' => '{{GENDER:$2|completed}} deletion of translation page $1', |
135 | 135 | '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]]', |
136 | 137 | 'pt-log-priority-langs' => '{{GENDER:$2|set}} the priority languages for translatable page [[:$1]] to $3', |
137 | 138 | 'pt-log-priority-langs-force' => '{{GENDER:$2|limited}} languages for translatable page [[:$1]] to $3', |
138 | 139 | |
Index: trunk/extensions/Translate/utils/TranslateMetadata.php |
— | — | @@ -33,7 +33,12 @@ |
34 | 34 | public static function set( $group, $key, $value ) { |
35 | 35 | $dbw = wfGetDB( DB_MASTER ); |
36 | 36 | $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 | + } |
38 | 43 | } |
39 | 44 | |
40 | 45 | } |