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