function run() { // Initialization $title = $this->title; list(, $code) = TranslateUtils::figureMessage($title->getPrefixedText()); // Return the actual translation page... $page = TranslatablePage::isTranslationPage($title); if (!$page) { var_dump($this->params); var_dump($title); throw new MWException("Oops, this should not happen!"); } $group = $page->getMessageGroup(); $collection = $group->initCollection($code); $text = $page->getParse()->getTranslationPageText($collection); // Other stuff $user = $this->getUser(); $summary = $this->getSummary(); $flags = $this->getFlags(); $page = WikiPage::factory($title); // @todo FuzzyBot hack PageTranslationHooks::$allowTargetEdit = true; $content = ContentHandler::makeContent($text, $page->getTitle()); $page->doEditContent($content, $summary, $flags, false, $user); PageTranslationHooks::$allowTargetEdit = false; return true; }
public function execute($par) { $request = $this->getRequest(); $par = (string) $par; // Yes, the use of getVal() and getText() is wanted, see bug T22365 $this->text = $request->getVal('wpTitle', $par); $this->title = Title::newFromText($this->text); $this->reason = $request->getText('reason'); // Checkboxes that default being checked are tricky $this->doSubpages = $request->getBool('subpages', !$request->wasPosted()); $user = $this->getUser(); if ($this->doBasicChecks() !== true) { return; } $out = $this->getOutput(); // Real stuff starts here if (TranslatablePage::isSourcePage($this->title)) { $title = $this->msg('pt-deletepage-full-title', $this->title->getPrefixedText()); $out->setPagetitle($title); $this->code = ''; $this->page = TranslatablePage::newFromTitle($this->title); } else { $page = TranslatablePage::isTranslationPage($this->title); if ($page) { $title = $this->msg('pt-deletepage-lang-title', $this->title->getPrefixedText()); $out->setPagetitle($title); list(, $this->code) = TranslateUtils::figureMessage($this->title->getText()); $this->page = $page; } else { throw new ErrorPageError('pt-deletepage-invalid-title', 'pt-deletepage-invalid-text'); } } if (!$user->isAllowed('pagetranslation')) { throw new PermissionsError('pagetranslation'); } // Is there really no better way to do this? $subactionText = $request->getText('subaction'); switch ($subactionText) { case $this->msg('pt-deletepage-action-check')->text(): $subaction = 'check'; break; case $this->msg('pt-deletepage-action-perform')->text(): $subaction = 'perform'; break; case $this->msg('pt-deletepage-action-other')->text(): $subaction = ''; break; default: $subaction = ''; } if ($subaction === 'check' && $this->checkToken() && $request->wasPosted()) { $this->showConfirmation(); } elseif ($subaction === 'perform' && $this->checkToken() && $request->wasPosted()) { $this->performAction(); } else { $this->showForm(); } }
public function execute() { $hours = (int) $this->getOption('days'); $hours = $hours ? $hours * 7 : 7 * 24; $top = (int) $this->getOption('top'); $top = $top ? $top : 10; $bots = $this->hasOption('bots'); $namespaces = array(); if ($this->hasOption('ns')) { $input = explode(',', $this->getOption('ns')); foreach ($input as $namespace) { if (is_numeric($namespace)) { array_push($namespaces, $namespace); } } } /** * Select set of edits to report on */ $rows = TranslateUtils::translationChanges($hours, $bots, $namespaces); /** * Get counts for edits per language code after filtering out edits by FuzzyBot */ $codes = array(); global $wgTranslateFuzzyBotName; foreach ($rows as $_) { // Filter out edits by $wgTranslateFuzzyBotName if ($_->rc_user_text === $wgTranslateFuzzyBotName) { continue; } list(, $code) = TranslateUtils::figureMessage($_->rc_title); if (!isset($codes[$code])) { $codes[$code] = 0; } $codes[$code]++; } /** * Sort counts and report descending up to $top rows. */ arsort($codes); $i = 0; foreach ($codes as $code => $num) { if ($i++ === $top) { break; } $this->output("{$code}\t{$num}\n"); } }
function run() { // Initialization $title = $this->title; list( , $code ) = TranslateUtils::figureMessage( $title->getPrefixedText() ); // Return the actual translation page... $page = TranslatablePage::isTranslationPage( $title ); if ( !$page ) { var_dump( $this->params ); var_dump( $title ); throw new MWException( "Oops, this should not happen!" ); } $group = $page->getMessageGroup(); $collection = $group->initCollection( $code ); $collection->loadTranslations( DB_MASTER ); $text = $page->getParse()->getTranslationPageText( $collection ); // Other stuff $user = $this->getUser(); $summary = $this->getSummary(); $flags = $this->getFlags(); $article = new Article( $title, 0 ); // @todo FuzzyBot hack PageTranslationHooks::$allowTargetEdit = true; // Do the edit $status = $article->doEdit( $text, $summary, $flags, false, $user ); SpecialPageTranslation::superDebug( __METHOD__, 'edit', $user, $title, $flags, $status ); PageTranslationHooks::$allowTargetEdit = false; // purge cache $page->getTranslationPercentages( true ); return true; }
protected static function translationPageHeader(Title $title) { if (!$title->exists()) { return; } // Check if applicable $page = TranslatablePage::isTranslationPage($title); if ($page === false) { return; } list(, $code) = TranslateUtils::figureMessage($title->getText()); // Get the translation percentage $pers = $page->getTranslationPercentages(); $per = 0; if (isset($pers[$code])) { $per = $pers[$code] * 100; } $titleText = $page->getTitle()->getPrefixedText(); // This url might get cached $url = wfExpandUrl($page->getTranslationUrl($code), PROTO_RELATIVE); // Output $context = RequestContext::getMain(); $language = $context->getLanguage(); $wrap = Html::rawElement('div', array('class' => 'mw-translate-page-info', 'lang' => $language->getCode(), 'dir' => $language->getDir()), '$1'); $out = $context->getOutput(); $out->wrapWikiMsg($wrap, array('tpt-translation-intro', $url, ':' . $titleText, $language->formatNum($per))); $out->addHTML('<hr />'); }
/** * Fetch the available translation pages from database * @return Title[] */ public function getTranslationPages() { // Avoid replication lag issues $dbr = wfGetDB(DB_MASTER); $prefix = $this->getTitle()->getDBkey() . '/'; $likePattern = $dbr->buildLike($prefix, $dbr->anyString()); $res = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace' => $this->getTitle()->getNamespace(), "page_title {$likePattern}"), __METHOD__); $titles = TitleArray::newFromResult($res); $filtered = array(); // Make sure we only get translation subpages while ignoring others $codes = Language::fetchLanguageNames(); $prefix = $this->getTitle()->getText(); /** @var Title $title */ foreach ($titles as $title) { list($name, $code) = TranslateUtils::figureMessage($title->getText()); if (!isset($codes[$code]) || $name !== $prefix) { continue; } $filtered[] = $title; } return $filtered; }
public function indexOf( $row ) { // We need to check that there is only one user per day. if ( $this->opts['count'] === 'users' ) { $date = $this->formatTimestamp( $row->rc_timestamp ); if ( isset( $this->usercache[$date][$row->rc_user_text] ) ) { return -1; } else { $this->usercache[$date][$row->rc_user_text] = 1; } } // Do not consider language-less pages. if ( strpos( $row->rc_title, '/' ) === false ) { return false; } // No filters, just one key to track. if ( !$this->groups && !$this->codes ) { return 'all'; } // The key-building needs to be in sync with ::labels(). list( $key, $code ) = TranslateUtils::figureMessage( $row->rc_title ); $groups = array(); $codes = array(); if ( $this->groups ) { /* * Get list of keys that the message belongs to, and filter * out those which are not requested. */ $groups = TranslateUtils::messageKeyToGroups( $row->rc_namespace, $key ); $groups = array_intersect( $this->groups, $groups ); } if ( $this->codes ) { $codes = array( $code ); } return $this->combineTwoArrays( $groups, $codes ); }
/** * @param $title Title * @return bool|TranslatablePage */ public static function isTranslationPage(Title $title) { list($key, $code) = TranslateUtils::figureMessage($title->getText()); if ($key === '' || $code === '') { return false; } $codes = Language::getLanguageNames(false); global $wgTranslateDocumentationLanguageCode; unset($codes[$wgTranslateDocumentationLanguageCode]); if (!isset($codes[$code])) { return false; } $newtitle = self::changeTitleText($title, $key); if (!$newtitle) { return false; } $page = TranslatablePage::newFromTitle($newtitle); if ($page->getMarkedTag() === false) { return false; } return $page; }
$dbr = wfGetDB( DB_SLAVE ); $rows = $dbr->select( array( 'page' ), array( 'page_title', 'page_namespace' ), array( 'page_namespace' => $wgTranslateMessageNamespaces, ), __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; }
/** * Set the right page content language for message group translations ("Page/xx"). * Hook: PageContentLanguage * @param $title Title * @param $pageLang * @return bool */ public static function onPageContentLanguage( $title, &$pageLang ) { global $wgTranslateMessageNamespaces; // For translation pages, parse plural, grammar etc with correct language, and set the right direction if ( in_array( $title->getNamespace(), $wgTranslateMessageNamespaces ) ) { list( , $code ) = TranslateUtils::figureMessage( $title->getText() ); $pageLang = $code; } return true; }
protected static function translationPageHeader(Title $title) { global $wgOut; if (!$title->exists()) { return; } // Check if applicable $page = TranslatablePage::isTranslationPage($title); if ($page === false) { return; } list(, $code) = TranslateUtils::figureMessage($title->getText()); // Get the translation percentage $pers = $page->getTranslationPercentages(); $per = 0; if (isset($pers[$code])) { $per = $pers[$code] * 100; } $titleText = $page->getTitle()->getPrefixedText(); $url = $page->getTranslationUrl($code); // Output $wrap = '<div class="mw-translate-page-info">$1</div>'; $wgOut->wrapWikiMsg($wrap, array('tpt-translation-intro', $url, $titleText, $per)); if (floor($per) < 100) { $group = $page->getMessageGroup(); $collection = $group->initCollection($code); $collection->filter('fuzzy', false); if (count($collection)) { $wrap = '<div class="mw-translate-page-info mw-translate-fuzzy">$1</div>'; $wgOut->wrapWikiMsg($wrap, array('tpt-translation-intro-fuzzy')); } } $wgOut->addHTML('<hr />'); }
public function execute() { global $wgContLang; $dbw = TranslationMemoryUpdater::getDatabaseHandle(); if ( $dbw === null ) { $this->error( "Database file not configured" ); $this->exit(); } $dbw->setFlag( DBO_TRX ); // HUGE speed improvement $groups = MessageGroups::singleton()->getGroups(); // TODO: encapsulate list of valid language codes $languages = Language::getLanguageNames( false ); unset( $languages['en'] ); foreach ( $groups as $id => $group ) { if ( $group->isMeta() ) { continue; } $this->output( "Processing: {$group->getLabel()} ", $id ); $capitalized = MWNamespace::isCapitalized( $group->getNamespace() ); $ns_text = $wgContLang->getNsText( $group->getNamespace() ); $definitions = $group->load( $group->getSourceLanguage() ); foreach ( $definitions as $key => $definition ) { // TODO: would be nice to do key normalisation closer to the message groups, to avoid transforming back and forth. // But how to preserve the original keys... $key = strtr( $key, ' ', '_' ); $key = $capitalized ? $wgContLang->ucfirst( $key ) : $key; $dbr = wfGetDB( DB_SLAVE ); $tables = array( 'page', 'revision', 'text' ); // selectFields to stfu Revision class $vars = array_merge( Revision::selectTextFields(), array( 'page_title' ), Revision::selectFields() ); $conds = array( 'page_latest = rev_id', 'rev_text_id = old_id', 'page_namespace' => $group->getNamespace(), 'page_title ' . $dbr->buildLike( "$key/", $dbr->anyString() ) ); $res = $dbr->select( $tables, $vars, $conds, __METHOD__ ); // Assure that there is at least one translation if ( $res->numRows() < 1 ) { continue; } $insert = array( 'text' => $definition, 'context' => "$ns_text:$key", 'length' => strlen( $definition ), 'lang' => $group->getSourceLanguage(), ); $source_id = $dbw->selectField( '`sources`', 'sid', $insert, __METHOD__ ); if ( $source_id === false ) { $dbw->insert( '`sources`', $insert, __METHOD__ ); $source_id = $dbw->insertId(); } $this->output( ' ', $id ); foreach ( $res as $row ) { list( , $code ) = TranslateUtils::figureMessage( $row->page_title ); $revision = new Revision( $row ); $insert = array( 'text' => $revision->getText(), 'lang' => $code, 'time' => wfTimestamp(), 'sid' => $source_id ); // We only do SQlite which doesn't need to know unique indexes $dbw->replace( '`targets`', null, $insert, __METHOD__ ); } $this->output( "{$res->numRows()}", $id ); } // each translation> $dbw->commit(); } // each group> }