diff options
Diffstat (limited to 'www/wiki/extensions/Translate/specials/SpecialTranslations.php')
-rw-r--r-- | www/wiki/extensions/Translate/specials/SpecialTranslations.php | 153 |
1 files changed, 62 insertions, 91 deletions
diff --git a/www/wiki/extensions/Translate/specials/SpecialTranslations.php b/www/wiki/extensions/Translate/specials/SpecialTranslations.php index 2ce54d32..4dab4b05 100644 --- a/www/wiki/extensions/Translate/specials/SpecialTranslations.php +++ b/www/wiki/extensions/Translate/specials/SpecialTranslations.php @@ -5,7 +5,7 @@ * @file * @author Siebrand Mazeland * @author Niklas Laxstörm - * @license GPL-2.0+ + * @license GPL-2.0-or-later */ /** @@ -23,7 +23,7 @@ class SpecialTranslations extends SpecialAllPages { return 'pages'; } - function getDescription() { + public function getDescription() { return $this->msg( 'translations' )->text(); } @@ -35,9 +35,9 @@ class SpecialTranslations extends SpecialAllPages { public function execute( $par ) { $this->setHeaders(); $this->outputHeader(); - $this->includeAssets(); $out = $this->getOutput(); + $out->addModuleStyles( 'ext.translate.legacy' ); $par = (string)$par; @@ -71,9 +71,10 @@ class SpecialTranslations extends SpecialAllPages { if ( !$title ) { $title = Title::makeTitle( NS_MEDIAWIKI, '' ); - $out->addHTML( $this->namespaceMessageForm( $title ) ); + $this->namespaceMessageForm( $title ); } else { - $out->addHTML( $this->namespaceMessageForm( $title ) . '<br />' ); + $this->namespaceMessageForm( $title ); + $out->addHTML( '<br />' ); $this->showTranslations( $title ); } } @@ -81,52 +82,44 @@ class SpecialTranslations extends SpecialAllPages { /** * Message input fieldset * - * @param Title $title (default: null) - * @return string HTML for fieldset. + * @param Title|null $title (default: null) */ protected function namespaceMessageForm( Title $title = null ) { - global $wgScript; - - $namespaces = new XmlSelect( 'namespace', 'namespace' ); - $namespaces->setDefault( $title->getNamespace() ); + $options = []; foreach ( $this->getSortedNamespaces() as $text => $index ) { - $namespaces->addOption( $text, $index ); + $options[ $text ] = $index; } - $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) ); - $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); - $out .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ); - $out .= Xml::openElement( 'fieldset' ); - $out .= Xml::element( - 'legend', - null, - $this->msg( 'translate-translations-fieldset-title' )->text() - ); - $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) ); - $out .= "<tr> - <td class='mw-label'>" . - Xml::label( $this->msg( 'translate-translations-messagename' )->text(), 'message' ) . - "</td> - <td class='mw-input'>" . - Xml::input( 'message', 30, $title->getText(), array( 'id' => 'message' ) ) . - "</td> - </tr> - <tr> - <td class='mw-label'>" . - Xml::label( $this->msg( 'translate-translations-project' )->text(), 'namespace' ) . - "</td> - <td class='mw-input'>" . - $namespaces->getHTML() . ' ' . - Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . - '</td> - </tr>'; - $out .= Xml::closeElement( 'table' ); - $out .= Xml::closeElement( 'fieldset' ); - $out .= Xml::closeElement( 'form' ); - $out .= Xml::closeElement( 'div' ); - - return $out; + $formDescriptor = [ + 'textbox' => [ + 'type' => 'text', + 'name' => 'message', + 'id' => 'message', + 'label-message' => 'translate-translations-messagename', + 'size' => 30, + 'default' => $title->getText(), + ], + 'selector' => [ + 'type' => 'select', + 'name' => 'namespace', + 'id' => 'namespace', + 'label-message' => 'translate-translations-project', + 'options' => $options, + 'default' => $title->getNamespace(), + ] + ]; + + $context = new DerivativeContext( $this->getContext() ); + $context->setTitle( $this->getPageTitle() ); // Remove subpage + + $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $context ); + $htmlForm + ->setMethod( 'get' ) + ->setSubmitTextMsg( 'allpagessubmit' ) + ->setWrapperLegendMsg( 'translate-translations-fieldset-title' ) + ->prepareForm() + ->displayForm( false ); } /** @@ -137,7 +130,7 @@ class SpecialTranslations extends SpecialAllPages { public function getSortedNamespaces() { global $wgTranslateMessageNamespaces, $wgContLang; - $nslist = array(); + $nslist = []; foreach ( $wgTranslateMessageNamespaces as $ns ) { $nslist[$wgContLang->getFormattedNsText( $ns )] = $ns; } @@ -162,19 +155,19 @@ class SpecialTranslations extends SpecialAllPages { return; } - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $res = $dbr->select( 'page', - array( 'page_namespace', 'page_title' ), - array( + [ 'page_namespace', 'page_title' ], + [ 'page_namespace' => $namespace, 'page_title ' . $dbr->buildLike( "$message/", $dbr->anyString() ), - ), + ], __METHOD__, - array( + [ 'ORDER BY' => 'page_title', 'USE INDEX' => 'name_title', - ) + ] ); if ( !$res->numRows() ) { @@ -192,7 +185,7 @@ class SpecialTranslations extends SpecialAllPages { } // Normal output. - $titles = array(); + $titles = []; foreach ( $res as $s ) { $titles[] = $s->page_title; @@ -200,9 +193,9 @@ class SpecialTranslations extends SpecialAllPages { $pageInfo = TranslateUtils::getContents( $titles, $namespace ); - $tableheader = Xml::openElement( 'table', array( + $tableheader = Xml::openElement( 'table', [ 'class' => 'mw-sp-translate-table sortable' - ) ); + ] ); $tableheader .= Xml::openElement( 'tr' ); $tableheader .= Xml::element( 'th', null, $this->msg( 'allmessagesname' )->text() ); @@ -212,9 +205,6 @@ class SpecialTranslations extends SpecialAllPages { // Adapted version of TranslateUtils:makeListing() by Nikerabbit. $out = $tableheader; - $canTranslate = $this->getUser()->isAllowed( 'translate' ); - - $ajaxPageList = array(); $historyText = ' <sup>' . $this->msg( 'translate-translations-history-short' )->escaped() . '</sup> '; @@ -223,7 +213,6 @@ class SpecialTranslations extends SpecialAllPages { foreach ( $res as $s ) { $key = $s->page_title; $tTitle = Title::makeTitle( $s->page_namespace, $key ); - $ajaxPageList[] = $tTitle->getPrefixedDBkey(); $tHandle = new MessageHandle( $tTitle ); $code = $tHandle->getCode(); @@ -231,25 +220,19 @@ class SpecialTranslations extends SpecialAllPages { $text = TranslateUtils::getLanguageName( $code, $this->getLanguage()->getCode() ); $text .= $separator; $text .= $this->msg( 'parentheses' )->params( $code )->plain(); - $text = htmlspecialchars( $text ); - - if ( $canTranslate ) { - $tools['edit'] = TranslationHelpers::ajaxEditLink( - $tTitle, - $text - ); - } else { - $tools['edit'] = Linker::link( $tTitle, $text ); - } + $tools['edit'] = Html::element( + 'a', + [ 'href' => TranslateUtils::getEditorUrl( $tHandle ) ], + $text + ); - $tools['history'] = Linker::link( + $tools['history'] = $this->getLinkRenderer()->makeLink( $tTitle, - $historyText, - array( - 'action', + new HtmlArmor( $historyText ), + [ 'title' => $this->msg( 'history-title', $tTitle->getPrefixedDBkey() )->text() - ), - array( 'action' => 'history' ) + ], + [ 'action' => 'history' ] ); if ( MessageHandle::hasFuzzyString( $pageInfo[$key][0] ) || $tHandle->isFuzzy() ) { @@ -258,19 +241,19 @@ class SpecialTranslations extends SpecialAllPages { $class = 'def'; } - $languageAttributes = array(); + $languageAttributes = []; if ( Language::isKnownLanguageTag( $code ) ) { $language = Language::factory( $code ); - $languageAttributes = array( + $languageAttributes = [ 'lang' => $language->getHtmlCode(), 'dir' => $language->getDir(), - ); + ]; } $formattedContent = TranslateUtils::convertWhiteSpaceToHTML( $pageInfo[$key][0] ); $leftColumn = $tools['history'] . $tools['edit']; - $out .= Xml::tags( 'tr', array( 'class' => $class ), + $out .= Xml::tags( 'tr', [ 'class' => $class ], Xml::tags( 'td', null, $leftColumn ) . Xml::tags( 'td', $languageAttributes, $formattedContent ) ); @@ -278,17 +261,5 @@ class SpecialTranslations extends SpecialAllPages { $out .= Xml::closeElement( 'table' ); $this->getOutput()->addHTML( $out ); - - $vars = array( 'trlKeys' => $ajaxPageList ); - $this->getOutput()->addScript( Skin::makeVariablesScript( $vars ) ); - } - - /** - * Add JavaScript assets - */ - private function includeAssets() { - $out = $this->getOutput(); - TranslationHelpers::addModules( $out ); - $out->addModuleStyles( 'ext.translate.legacy' ); } } |