Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
WorkflowStatesMessageGroup.php
Go to the documentation of this file.
1<?php
13use MediaWiki\MediaWikiServices;
14
17 // id and source are not needed
18 public function __construct() {
19 }
20
21 public function getId() {
22 return 'translate-workflow-states';
23 }
24
25 public function getLabel( IContextSource $context = null ) {
26 $msg = wfMessage( 'translate-workflowgroup-label' );
27 $msg = self::addContext( $msg, $context );
28
29 return $msg->plain();
30 }
31
32 public function getDescription( IContextSource $context = null ) {
33 $msg = wfMessage( 'translate-workflowgroup-desc' );
34 $msg = self::addContext( $msg, $context );
35
36 return $msg->plain();
37 }
38
39 public function getDefinitions() {
40 $groups = MessageGroups::getAllGroups();
41 $keys = [];
42
44 foreach ( $groups as $g ) {
45 $states = $g->getMessageGroupStates()->getStates();
46 foreach ( array_keys( $states ) as $state ) {
47 $keys["Translate-workflow-state-$state"] = $state;
48 }
49 }
50
51 $defs = TranslateUtils::getContents( array_keys( $keys ), $this->getNamespace() );
52 $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
53 foreach ( $keys as $key => $state ) {
54 if ( !isset( $defs[$key] ) ) {
55 // @todo Use jobqueue
56 $title = Title::makeTitleSafe( $this->getNamespace(), $key );
57 $page = $wikiPageFactory->newFromTitle( $title );
58 $content = ContentHandler::makeContent( $state, $title );
59
60 $page->doUserEditContent(
61 $content,
62 FuzzyBot::getUser(),
63 wfMessage( 'translate-workflow-autocreated-summary', $state )->inContentLanguage()->text()
64 );
65 } else {
66 // Use the wiki translation as definition if available.
67 // getContents returns array( content, last author )
68 [ $content, ] = $defs[$key];
69 $keys[$key] = $content;
70 }
71 }
72
73 return $keys;
74 }
75}
FuzzyBot - the misunderstood workhorse.
Definition FuzzyBot.php:15
getNamespace()
Get the namespace where all the messages of this group belong.
Group for messages that can be controlled via a page in MediaWiki namespace.
getDescription(IContextSource $context=null)
Returns a longer description about the group.
getLabel(IContextSource $context=null)
getDefinitions()
Fetch definitions from database.