/** * Adds link in toolbox to Special:Prefixindex to show all other * available translations for a message. Only shown when it * actually is a translatable/translated message. * * @param $skin Skin * * @return bool */ static function toolboxAllTranslations( &$skin ) { global $wgTranslateMessageNamespaces; if ( method_exists( $skin, 'getSkin' ) ) { $title = $skin->getSkin()->getTitle(); } else { global $wgTitle; $title = $wgTitle; } $ns = $title->getNamespace(); if ( !in_array( $ns, $wgTranslateMessageNamespaces ) ) { return true; } $inMessageGroup = TranslateUtils::messageKeyToGroup( $title->getNamespace(), $title->getBaseText() ); if ( $inMessageGroup ) { // Add a slash at the end, to not have basename in the result of Special:Prefixindex $message = $title->getNsText() . ":" . $title->getBaseText(); $desc = wfMsg( 'translate-sidebar-alltrans' ); $url = htmlspecialchars( SpecialPage::getTitleFor( 'Translations' )->getLocalURL( 'message=' . $message ) ); // Add the actual toolbox entry. // Add newlines and tabs for nicer HTML output. echo( "\n\t\t\t\t<li id=\"t-alltrans\"><a href=\"$url\">$desc</a></li>\n" ); } return true; }
public function getMessage($key, $code) { $id = TranslateUtils::messageKeyToGroup($this->getNamespace(), $key); $groups = $this->getGroups(); if (isset($groups[$id])) { return $groups[$id]->getMessage($key, $code); } else { return null; } }
$threshold = $options['threshold']; } else { $threshold = false; } $rows = TranslateUtils::translationChanges( $hours, true ); $exports = array(); foreach ( $rows as $row ) { $group = false; $code = false; // @todo Fixme list( $pieces, ) = explode( '/', $wgContLang->lcfirst( $row->rc_title ), 2 ); $mg = TranslateUtils::messageKeyToGroup( $row->rc_namespace, $pieces ); if ( !is_null( $mg ) ) { $group = $mg; } if ( strpos( $row->rc_title, '/' ) !== false ) { $code = $row->lang; } if ( $group && ( !count( $groupsFilter ) || in_array( $group, $groupsFilter ) ) ) { if ( $code && !in_array( $code, $skip ) ) { $exports[$group][$code] = true; } } }
/** * Builds a table with all translations of $title. * * @param $title Title (default: null) * @return void */ function showTranslations(Title $title) { global $wgOut, $wgUser, $wgLang; $sk = $wgUser->getSkin(); $namespace = $title->getNamespace(); $message = $title->getDBkey(); $inMessageGroup = TranslateUtils::messageKeyToGroup($title->getNamespace(), $title->getText()); if (!$inMessageGroup) { $wgOut->addWikiMsg('translate-translations-no-message', $title->getPrefixedText()); return; } $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace' => $namespace, 'page_title ' . $dbr->buildLike("{$message}/", $dbr->anyString())), __METHOD__, array('ORDER BY' => 'page_title', 'USE INDEX' => 'name_title')); if (!$res->numRows()) { $wgOut->addWikiMsg('translate-translations-no-message', $title->getPrefixedText()); return; } else { $wgOut->addWikiMsg('translate-translations-count', $wgLang->formatNum($res->numRows())); } // Normal output. $titles = array(); foreach ($res as $s) { $titles[] = $s->page_title; } $pageInfo = TranslateUtils::getContents($titles, $namespace); $tableheader = Xml::openElement('table', array('class' => 'mw-sp-translate-table sortable')); $tableheader .= Xml::openElement('tr'); $tableheader .= Xml::element('th', null, wfMsg('allmessagesname')); $tableheader .= Xml::element('th', null, wfMsg('allmessagescurrent')); $tableheader .= Xml::closeElement('tr'); // Adapted version of TranslateUtils:makeListing() by Nikerabbit. $out = $tableheader; $canTranslate = $wgUser->isAllowed('translate'); $ajaxPageList = array(); $historyText = " <sup>" . wfMsgHtml('translate-translations-history-short') . "</sup> "; foreach ($res as $s) { $key = $s->page_title; $tTitle = Title::makeTitle($s->page_namespace, $key); $ajaxPageList[] = $tTitle->getPrefixedDBkey(); $code = $this->getCode($s->page_title); $text = TranslateUtils::getLanguageName($code, false, $wgLang->getCode()) . " ({$code})"; $text = htmlspecialchars($text); if ($canTranslate) { $tools['edit'] = TranslationHelpers::ajaxEditLink($tTitle, $text); } else { $tools['edit'] = $sk->link($tTitle, $text); } $tools['history'] = $sk->link($tTitle, $historyText, array('action', 'title' => wfMsg('history-title', $tTitle->getPrefixedDBkey())), array('action' => 'history')); if (TranslateEditAddons::isFuzzy($tTitle)) { $class = 'orig'; } else { $class = 'def'; } $leftColumn = $tools['history'] . $tools['edit']; $out .= Xml::tags('tr', array('class' => $class), Xml::tags('td', null, $leftColumn) . Xml::tags('td', array('lang' => $code, 'dir' => Language::factory($code)->getDir()), TranslateUtils::convertWhiteSpaceToHTML($pageInfo[$key][0]))); } $out .= Xml::closeElement('table'); $wgOut->addHTML($out); $vars = array('trlKeys' => $ajaxPageList); $wgOut->addScript(Skin::makeVariablesScript($vars)); }
__METHOD__ ); $owners = array(); $keys = array(); $codes = Language::getLanguageNames(); $invalid = array(); foreach ( $rows as $row ) { list( $key, $code ) = TranslateUtils::figureMessage( $row->page_title ); if ( !$code ) { $code = 'en'; } $mg = TranslateUtils::messageKeyToGroup( $row->page_namespace, $key ); $ns = $wgContLang->getNsText( $row->page_namespace ); if ( is_null( $mg ) ) { $keys["$ns:$key"][] = $code; $owner = 'xx-unknown'; } else { $owner = $mg; } if ( !isset( $codes[$code] ) ) { $invalid[$code][] = "[[$ns:$key/$code]]"; } if ( !isset( $owners[$owner] ) ) { $owners[$owner] = 0;
/** * Tries to determine to which group this message belongs. It tries to get * group id from loadgroup GET-paramater, but fallbacks to messageIndex file * if no valid group was provided, or the group provided is a meta group. * * @param $namespace \int The namespace number for the key we are interested in. * @param $key \string The message key we are interested in. * @return MessageGroup which the key belongs to, or null. */ private static function getMessageGroup( $namespace, $key ) { global $wgRequest; $group = $wgRequest->getText( 'loadgroup', '' ); $mg = MessageGroups::getGroup( $group ); if ( $mg === null ) { $group = TranslateUtils::messageKeyToGroup( $namespace, $key ); if ( $group ) { $mg = MessageGroups::getGroup( $group ); } } return $mg; }