Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
WorkflowStatesMessageGroup.php
Go to the documentation of this file.
1<?php
15use MediaWiki\MediaWikiServices;
16
19 // id and source are not needed
20 public function __construct() {
21 }
22
23 public function getId() {
24 return 'translate-workflow-states';
25 }
26
27 public function getLabel( IContextSource $context = null ) {
28 $msg = wfMessage( 'translate-workflowgroup-label' );
29 $msg = self::addContext( $msg, $context );
30
31 return $msg->plain();
32 }
33
34 public function getDescription( IContextSource $context = null ) {
35 $msg = wfMessage( 'translate-workflowgroup-desc' );
36 $msg = self::addContext( $msg, $context );
37
38 return $msg->plain();
39 }
40
41 public function getDefinitions() {
42 $groups = MessageGroups::getAllGroups();
43 $keys = [];
44
46 foreach ( $groups as $g ) {
47 $states = $g->getMessageGroupStates()->getStates();
48 foreach ( array_keys( $states ) as $state ) {
49 $keys["Translate-workflow-state-$state"] = $state;
50 }
51 }
52
53 $defs = Utilities::getContents( array_keys( $keys ), $this->getNamespace() );
54 $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
55 foreach ( $keys as $key => $state ) {
56 if ( !isset( $defs[$key] ) ) {
57 // @todo Use jobqueue
58 $title = Title::makeTitleSafe( $this->getNamespace(), $key );
59 $page = $wikiPageFactory->newFromTitle( $title );
60 $content = ContentHandler::makeContent( $state, $title );
61
62 $page->doUserEditContent(
63 $content,
64 FuzzyBot::getUser(),
65 wfMessage( 'translate-workflow-autocreated-summary', $state )->inContentLanguage()->text()
66 );
67 } else {
68 // Use the wiki translation as definition if available.
69 // getContents returns array( content, last author )
70 [ $content, ] = $defs[$key];
71 $keys[$key] = $content;
72 }
73 }
74
75 return $keys;
76 }
77}
Factory class for accessing message groups individually by id or all of them as a list.
FuzzyBot - the misunderstood workhorse.
Definition FuzzyBot.php:15
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:31
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.