29 private Language $contentLanguage;
30 private LanguageNameUtils $languageNameUtils;
31 private ILoadBalancer $loadBalancer;
32 private SearchEngineFactory $searchEngineFactory;
34 public function __construct(
35 Language $contentLanguage,
36 LanguageNameUtils $languageNameUtils,
37 ILoadBalancer $loadBalancer,
38 SearchEngineFactory $searchEngineFactory
40 parent::__construct(
'Translations' );
41 $this->contentLanguage = $contentLanguage;
42 $this->languageNameUtils = $languageNameUtils;
43 $this->loadBalancer = $loadBalancer;
44 $this->searchEngineFactory = $searchEngineFactory;
47 protected function getGroupName() {
51 public function getDescription() {
52 return $this->msg(
'translations' );
55 public function prefixSearchSubpages( $search, $limit, $offset ) {
56 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
66 $this->outputHeader();
68 $out = $this->getOutput();
69 $out->addModuleStyles(
'ext.translate.specialpages.styles' );
73 if ( $this->including() ) {
74 $title = Title::newFromText( $par );
76 $out->addWikiMsg(
'translate-translations-including-no-param' );
78 $this->showTranslations( $title );
87 $request = $this->getRequest();
88 $message = $request->getText(
'message', $par );
89 $namespace = $request->getInt(
'namespace', NS_MAIN );
91 $title = Title::newFromText( $message, $namespace );
94 'Help:Extension:Translate/Statistics_and_reporting#Translations_in_all_languages'
98 $title = Title::makeTitle( NS_MEDIAWIKI,
'' );
99 $this->namespaceMessageForm( $title );
101 $this->namespaceMessageForm( $title );
102 $out->addHTML(
'<br />' );
103 $this->showTranslations( $title );
110 private function namespaceMessageForm( Title $title ): void {
116 'label-message' =>
'translate-translations-messagename',
118 'default' => $title->getText(),
122 'name' =>
'namespace',
124 'label-message' =>
'translate-translations-project',
125 'options' => $this->getSortedNamespaces(),
126 'default' => $title->getNamespace(),
130 HTMLForm::factory(
'ooui', $formDescriptor, $this->getContext() )
132 ->setTitle( $this->getPageTitle() )
133 ->setSubmitTextMsg(
'allpagessubmit' )
134 ->setWrapperLegendMsg(
'translate-translations-fieldset-title' )
136 ->displayForm(
false );
144 private function getSortedNamespaces(): array {
146 foreach ( $this->getConfig()->
get(
'TranslateMessageNamespaces' ) as $ns ) {
147 $nslist[$this->contentLanguage->getFormattedNsText( $ns )] = $ns;
157 private function showTranslations( Title $title ): void {
158 $handle = new MessageHandle( $title );
159 $namespace = $title->getNamespace();
160 $message = $handle->getKey();
162 if ( !$handle->isValid() ) {
163 $this->getOutput()->addWikiMsg(
'translate-translations-no-message', $title->getPrefixedText() );
168 $dbr = $this->loadBalancer->getConnection( DB_REPLICA );
170 $titles = $dbr->newSelectQueryBuilder()
171 ->select(
'page_title' )
174 'page_namespace' => $namespace,
175 'page_title ' . $dbr->buildLike(
"$message/", $dbr->anyString() ),
177 ->caller( __METHOD__ )
178 ->orderBy(
'page_title' )
179 ->fetchFieldValues();
182 $this->getOutput()->addWikiMsg(
183 'translate-translations-no-message',
184 $title->getPrefixedText()
189 $this->getOutput()->addWikiMsg(
190 'translate-translations-count',
191 Message::numParam( count( $titles ) )
195 $pageInfo = Utilities::getContents( $titles, $namespace );
201 Html::element(
'th', [], $this->msg(
'allmessagesname' )->text() ) .
202 Html::element(
'th', [], $this->msg(
'allmessagescurrent' )->text() )
206 $historyText =
"\u{00A0}<sup>" .
207 $this->msg(
'translate-translations-history-short' )->escaped() .
209 $separator = $this->msg(
'word-separator' )->plain();
211 foreach ( $titles as $key ) {
212 $tTitle = Title::makeTitle( $namespace, $key );
213 $tHandle =
new MessageHandle( $tTitle );
215 $code = $tHandle->getCode();
217 $text = Utilities::getLanguageName( $code, $this->getLanguage()->getCode() );
219 $text .= $this->msg(
'parentheses' )->params( $code )->plain();
221 'edit' => Html::element(
223 [
'href' => Utilities::getEditorUrl( $tHandle ) ],
226 'history' => $this->getLinkRenderer()->makeLink(
228 new HtmlArmor( $historyText ),
230 'title' => $this->msg(
'history-title', $tTitle->getPrefixedDBkey() )->text()
232 [
'action' =>
'history' ]
237 if ( MessageHandle::hasFuzzyString( $pageInfo[$key][0] ) || $tHandle->isFuzzy() ) {
238 $class =
'mw-sp-translate-fuzzy';
241 $languageAttributes = [];
242 if ( $this->languageNameUtils->isKnownLanguageTag( $code ) ) {
243 $language = $tHandle->getEffectiveLanguage();
244 $languageAttributes = [
245 'lang' => $language->getHtmlCode(),
246 'dir' => $language->getDir(),
250 $formattedContent = Utilities::convertWhiteSpaceToHTML( $pageInfo[$key][0] );
252 $rows[] = Html::rawElement(
254 [
'class' => $class ],
255 Html::rawElement(
'td', [], $tools[
'history'] . $tools[
'edit'] ) .
256 Html::rawElement(
'td', $languageAttributes, $formattedContent )
260 $out = Html::rawElement(
262 [
'class' =>
'mw-sp-translate-table sortable wikitable' ],
263 "\n" . implode(
"\n", $rows ) .
"\n"
265 $this->getOutput()->addHTML( $out );