Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
WorkflowStatesMessageGroup.php
Go to the documentation of this file.
1<?php
12use MediaWiki\CommentStore\CommentStoreComment;
13use MediaWiki\Content\ContentHandler;
14use MediaWiki\Context\IContextSource;
18use MediaWiki\MediaWikiServices;
19use MediaWiki\Revision\SlotRecord;
20use MediaWiki\Title\Title;
21
24 // id and source are not needed
25 public function __construct() {
26 }
27
28 public function getId() {
29 return 'translate-workflow-states';
30 }
31
32 public function getLabel( ?IContextSource $context = null ) {
33 $msg = wfMessage( 'translate-workflowgroup-label' );
34 $msg = self::addContext( $msg, $context );
35
36 return $msg->plain();
37 }
38
39 public function getDescription( ?IContextSource $context = null ) {
40 $msg = wfMessage( 'translate-workflowgroup-desc' );
41 $msg = self::addContext( $msg, $context );
42
43 return $msg->plain();
44 }
45
46 public function getDefinitions() {
47 $groups = MessageGroups::getAllGroups();
48 $keys = [];
49
51 foreach ( $groups as $g ) {
52 $states = $g->getMessageGroupStates()->getStates();
53 foreach ( array_keys( $states ) as $state ) {
54 $keys["Translate-workflow-state-$state"] = $state;
55 }
56 }
57
58 if ( !$keys ) {
59 return [];
60 }
61
62 $defs = Utilities::getContents( array_keys( $keys ), $this->getNamespace() );
63 $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
64 foreach ( $keys as $key => $state ) {
65 if ( !isset( $defs[$key] ) ) {
66 // @todo Use jobqueue
67 $title = Title::makeTitleSafe( $this->getNamespace(), $key );
68 $page = $wikiPageFactory->newFromTitle( $title );
69 $content = ContentHandler::makeContent( $state, $title );
70 $fuzzyBotUser = FuzzyBot::getUser();
71
72 $updater = $page->newPageUpdater( $fuzzyBotUser )
73 ->setContent( SlotRecord::MAIN, $content );
74 if ( $fuzzyBotUser->authorizeWrite( 'autopatrol', $title ) ) {
75 $updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
76 }
77
78 $summary = wfMessage( 'translate-workflow-autocreated-summary', $state )->inContentLanguage()->text();
79 $updater->saveRevision(
80 CommentStoreComment::newUnsavedComment( $summary ),
81 EDIT_FORCE_BOT
82 );
83 } else {
84 // Use the wiki translation as definition if available.
85 // getContents returns array( content, last author )
86 [ $content, ] = $defs[$key];
87 $keys[$key] = $content;
88 }
89 }
90
91 return $keys;
92 }
93}
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.
getDefinitions()
Fetch definitions from database.
getLabel(?IContextSource $context=null)