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():
string {
53 return $this->msg(
'translations' );
58 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
68 $this->outputHeader();
70 $out = $this->getOutput();
71 $out->addModuleStyles(
'ext.translate.specialpages.styles' );
75 if ( $this->including() ) {
76 $title = Title::newFromText( $par );
78 $out->addWikiMsg(
'translate-translations-including-no-param' );
80 $this->showTranslations( $title );
89 $request = $this->getRequest();
90 $message = $request->getText(
'message', $par );
91 $namespace = $request->getInt(
'namespace', NS_MAIN );
93 $title = Title::newFromText( $message, $namespace );
96 'Help:Extension:Translate/Statistics_and_reporting#Translations_in_all_languages'
100 $title = Title::makeTitle( NS_MEDIAWIKI,
'' );
101 $this->namespaceMessageForm( $title );
103 $this->namespaceMessageForm( $title );
104 $out->addHTML(
'<br />' );
105 $this->showTranslations( $title );
112 private function namespaceMessageForm( Title $title ): void {
118 'label-message' =>
'translate-translations-messagename',
120 'default' => $title->getText(),
124 'name' =>
'namespace',
126 'label-message' =>
'translate-translations-project',
127 'options' => $this->getSortedNamespaces(),
128 'default' => $title->getNamespace(),
132 HTMLForm::factory(
'ooui', $formDescriptor, $this->getContext() )
134 ->setTitle( $this->getPageTitle() )
135 ->setSubmitTextMsg(
'allpagessubmit' )
136 ->setWrapperLegendMsg(
'translate-translations-fieldset-title' )
138 ->displayForm(
false );
146 private function getSortedNamespaces(): array {
148 foreach ( $this->getConfig()->
get(
'TranslateMessageNamespaces' ) as $ns ) {
149 $nslist[$this->contentLanguage->getFormattedNsText( $ns )] = $ns;
159 private function showTranslations( Title $title ): void {
160 $handle = new MessageHandle( $title );
161 $namespace = $title->getNamespace();
162 $message = $handle->getKey();
164 if ( !$handle->isValid() ) {
165 $this->getOutput()->addWikiMsg(
'translate-translations-no-message', $title->getPrefixedText() );
170 $dbr = $this->loadBalancer->getConnection( DB_REPLICA );
172 $titles = $dbr->newSelectQueryBuilder()
173 ->select(
'page_title' )
176 'page_namespace' => $namespace,
177 'page_title ' . $dbr->buildLike(
"$message/", $dbr->anyString() ),
179 ->caller( __METHOD__ )
180 ->orderBy(
'page_title' )
181 ->fetchFieldValues();
184 $this->getOutput()->addWikiMsg(
185 'translate-translations-no-message',
186 $title->getPrefixedText()
191 $this->getOutput()->addWikiMsg(
192 'translate-translations-count',
193 Message::numParam( count( $titles ) )
197 $pageInfo = Utilities::getContents( $titles, $namespace );
203 Html::element(
'th', [], $this->msg(
'allmessagesname' )->text() ) .
204 Html::element(
'th', [], $this->msg(
'allmessagescurrent' )->text() )
208 $historyText =
"\u{00A0}<sup>" .
209 $this->msg(
'translate-translations-history-short' )->escaped() .
211 $separator = $this->msg(
'word-separator' )->plain();
213 foreach ( $titles as $key ) {
214 $tTitle = Title::makeTitle( $namespace, $key );
215 $tHandle =
new MessageHandle( $tTitle );
217 $code = $tHandle->getCode();
219 $text = Utilities::getLanguageName( $code, $this->getLanguage()->getCode() );
221 $text .= $this->msg(
'parentheses' )->params( $code )->plain();
223 'edit' => Html::element(
225 [
'href' => Utilities::getEditorUrl( $tHandle ) ],
228 'history' => $this->getLinkRenderer()->makeLink(
230 new HtmlArmor( $historyText ),
232 'title' => $this->msg(
'history-title', $tTitle->getPrefixedDBkey() )->text()
234 [
'action' =>
'history' ]
239 if ( MessageHandle::hasFuzzyString( $pageInfo[$key][0] ) || $tHandle->isFuzzy() ) {
240 $class =
'mw-sp-translate-fuzzy';
243 $languageAttributes = [];
244 if ( $this->languageNameUtils->isKnownLanguageTag( $code ) ) {
245 $language = $tHandle->getEffectiveLanguage();
246 $languageAttributes = [
247 'lang' => $language->getHtmlCode(),
248 'dir' => $language->getDir(),
252 $formattedContent = Utilities::convertWhiteSpaceToHTML( $pageInfo[$key][0] );
254 $rows[] = Html::rawElement(
256 [
'class' => $class ],
257 Html::rawElement(
'td', [], $tools[
'history'] . $tools[
'edit'] ) .
258 Html::rawElement(
'td', $languageAttributes, $formattedContent )
262 $out = Html::rawElement(
264 [
'class' =>
'mw-sp-translate-table sortable wikitable' ],
265 "\n" . implode(
"\n", $rows ) .
"\n"
267 $this->getOutput()->addHTML( $out );