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