Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MessageGroupReview.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\MessageGroupProcessing;
5
6use ManualLogEntry;
7use MediaWiki\HookContainer\HookContainer;
9use SpecialPage;
10use User;
11use Wikimedia\Rdbms\ILoadBalancer;
12
20
22 protected $hookContainer;
24 protected $loadBalancer;
25
26 public function __construct( ILoadBalancer $loadBalancer, HookContainer $hookContainer ) {
27 $this->loadBalancer = $loadBalancer;
28 $this->hookContainer = $hookContainer;
29 }
30
32 public function getState( MessageGroup $group, string $code ) {
33 $dbw = $this->loadBalancer->getMaintenanceConnectionRef( DB_PRIMARY );
34 $table = 'translate_groupreviews';
35
36 $field = 'tgr_state';
37 $conds = [
38 'tgr_group' => $group->getId(),
39 'tgr_lang' => $code
40 ];
41
42 return $dbw->selectField( $table, $field, $conds, __METHOD__ );
43 }
44
45 public function changeState( MessageGroup $group, string $code, string $newState, User $user ): bool {
46 $currentState = self::getState( $group, $code );
47 if ( $currentState === $newState ) {
48 return false;
49 }
50
51 $table = 'translate_groupreviews';
52 $index = [ 'tgr_group', 'tgr_lang' ];
53 $row = [
54 'tgr_group' => $group->getId(),
55 'tgr_lang' => $code,
56 'tgr_state' => $newState,
57 ];
58 $dbw = $this->loadBalancer->getMaintenanceConnectionRef( DB_PRIMARY );
59 $dbw->replace( $table, [ $index ], $row, __METHOD__ );
60
61 $entry = new ManualLogEntry( 'translationreview', 'group' );
62 $entry->setPerformer( $user );
63 $entry->setTarget( SpecialPage::getTitleFor( 'Translate', $group->getId() ) );
64 // @todo
65 // $entry->setComment( $comment );
66 $entry->setParameters( [
67 '4::language' => $code,
68 '5::group-label' => $group->getLabel(),
69 '6::old-state' => $currentState,
70 '7::new-state' => $newState,
71 ] );
72
73 $logid = $entry->insert();
74 $entry->publish( $logid );
75
76 $this->hookContainer->run( 'TranslateEventMessageGroupStateChange',
77 [ $group, $code, $currentState, $newState ] );
78
79 return true;
80 }
81}
Provides methods to get and change the state of a message group.
Interface for message groups.
getId()
Returns the unique identifier for this group.
getLabel(IContextSource $context=null)
Returns the human readable label (as plain text).