/**
	 * Does the actual edit.
	 * @param $title Title
	 * @param $translation \string
	 * @param $comment \string Edit summary.
	 */
	public function import( $title, $translation, $comment ) {
		global $wgUser;

		$old = $wgUser;
		$wgUser = FuzzyBot::getUser();

		$flags = EDIT_FORCE_BOT;
		if ( $this->norc ) {
			$flags |= EDIT_SUPPRESS_RC;
		}

		$article = new Article( $title, 0 );
		STDOUT( "Importing {$title->getPrefixedText()}: ", $title );
		$status = $article->doEdit( $translation, $comment, $flags );
		$success = $status === true || ( is_object( $status ) && $status->isOK() );
		STDOUT( $success ? 'OK' : 'FAILED', $title );

		$wgUser = $old;
	}
	}

	$qualify = array();

	$g = MessageGroups::singleton()->getGroup( $group );
	$collection = $g->initCollection( 'en' );
	foreach ( $languages as $code ) {
		$collection->resetForNewLanguage( $code );
		// Initialise messages
		$collection->filter( 'ignored' );
		$collection->filter( 'optional' );
		// Store the count of real messages for later calculation.
		$total = count( $collection );
		$collection->filter( 'translated', false );
		$translated = count( $collection );

		if ( $translated / $total > $threshold / 100 ) {
			$qualify[] = $code;
		}
	}

	return $qualify;
}

foreach ( $notice as $group => $languages ) {
	$languages = array_unique( $languages );
	sort( $languages );
	$languagelist = implode( ', ', $languages );
	STDOUT( "# Committed $group: $languagelist" );
}
Example #3
0
 /**
  * @param $hugearray array
  * @param $g
  * @param $ignore bool
  */
 protected function checkAndAdd(&$hugearray, $g, $ignore = false)
 {
     if ($g instanceof MessageGroupBase) {
         $cache = new MessageGroupCache($g);
         if ($cache->exists()) {
             $keys = $cache->getKeys();
         } else {
             $keys = array_keys($g->getDefinitions());
         }
     } else {
         $messages = $g->getDefinitions();
         if (!is_array($messages)) {
             return;
         }
         $keys = array_keys($messages);
     }
     $id = $g->getId();
     STDOUT("{$id} ", 'main');
     $namespace = $g->getNamespace();
     foreach ($keys as $key) {
         # Force all keys to lower case, because the case doesn't matter and it is
         # easier to do comparing when the case of first letter is unknown, because
         # mediawiki forces it to upper case
         $key = TranslateUtils::normaliseKey($namespace, $key);
         if (isset($hugearray[$key])) {
             if (!$ignore) {
                 $to = implode(', ', (array) $hugearray[$key]);
                 STDERR("Key {$key} already belongs to {$to}, conflict with {$id}");
             }
             if (is_array($hugearray[$key])) {
                 // Hard work is already done, just add a new reference
                 $hugearray[$key][] =& $id;
             } else {
                 // Store the actual reference, then remove it from array, to not
                 // replace the references value, but to store a array of new
                 // references instead. References are hard!
                 $value =& $hugearray[$key];
                 unset($hugearray[$key]);
                 $hugearray[$key] = array(&$value, &$id);
             }
         } else {
             $hugearray[$key] =& $id;
         }
     }
     unset($id);
     // Disconnect the previous references to this $id
 }
	/**
	 * Actually adds the new translation.
	 * @param $namespace
	 * @param $page
	 * @param $text
	 */
	private function updateMessage( $namespace, $page, $text ) {
		$title = Title::makeTitleSafe( $namespace, $page );

		if ( !$title instanceof Title ) {
			STDOUT( "INVALID TITLE!", $page );
			return;
		}
		STDOUT( "Updating {$title->getPrefixedText()}... ", $title );

		if ( $this->dryrun ) {
			STDOUT( "DRY RUN!", $title );
			return;
		}

		$article = new Article( $title, 0 );

		$status = $article->doEdit( $text, 'Updating translation from gettext import', 0, false, $this->user );

		if ( $status === true || ( is_object( $status ) && $status->isOK() ) ) {
			STDOUT( "OK!", $title );
		} else {
			STDOUT( "Failed!", $title );
		}
	}
 * Get counts for edits per language code after filtering out edits by FuzzyBot
 */
$codes = array();
foreach ( $rows as $_ ) {
	// Filter out edits by $wgTranslateFuzzyBotName
	if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) {
		continue;
	}

	list( , $code ) = 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;
	}

	STDOUT( "$code\t$num" );
}
Example #6
0
	/**
	 * Does the actual edit if possible.
	 * @param $title \type{Title}
	 * @param $text \string
	 * @param $dryrun \bool Whether to really do it or just show what would be done.
	 * @param $comment \string Edit summary.
	 */
	private function updateMessage( $title, $text, $dryrun, $comment = null ) {
		global $wgTranslateDocumentationLanguageCode, $wgUser;

		$oldUser = $wgUser;
		$wgUser = FuzzyBot::getUser();

		STDOUT( "Updating {$title->getPrefixedText()}... ", $title );
		if ( !$title instanceof Title ) {
			STDOUT( "INVALID TITLE!", $title );
			return;
		}

		$items = explode( '/', $title->getText(), 2 );
		if ( isset( $items[1] ) && $items[1] === $wgTranslateDocumentationLanguageCode ) {
			STDOUT( "IGNORED!", $title );
			return;
		}

		if ( $dryrun ) {
			STDOUT( "DRY RUN!", $title );
			return;
		}

		$article = new Article( $title, 0 );

		$status = $article->doEdit( $text, $comment ? $comment : 'Marking as fuzzy', EDIT_FORCE_BOT | EDIT_UPDATE );

		$success = $status === true || ( is_object( $status ) && $status->isOK() );
		STDOUT( $success ? 'OK' : 'FAILED', $title );

		$wgUser = $oldUser;
	}
# This obviously doesn't work with external storage etc
$dbr = wfGetDB( DB_SLAVE );
$tables = array( 'page', 'revision', 'text' );
$vars = array( 'page_namespace', 'page_title', 'old_text', 'old_flags' );
$conds = array(
	'page_latest = rev_id',
	'rev_text_id = old_id',
	'page_namespace' => NS_MEDIAWIKI
);

STDOUT( "Running query... ", 1 );
$res = $dbr->select( $tables, $vars, $conds, __FILE__ );

$target = fopen( $targetf, 'w+b' );

STDOUT( "Processing...", 1 );
foreach ( $res as $r ) {
	if ( $r->old_flags !== 'utf-8' ) {
		STDERR( "Oops, no text for {$r->page_title} in {$r->page_namespace}" );
		continue;
	}

	list( $key, $code ) = TranslateUtils::figureMessage( $r->page_title );

	if ( $key === '' ) {
		continue;
	}

	if ( $code === '' ) {
		continue;
	}
	foreach ( $codes as $code ) {
		STDOUT( "$code ", $id );

		$problematic = array();

		$collection->resetForNewLanguage( $code );
		$collection->loadTranslations();

		foreach ( $collection as $key => $message ) {
			$prob = $checker->checkMessageFast( $message,  $code );
			if ( $prob ) {

				if ( $verbose ) {
					// Print it
					$nsText = $wgContLang->getNsText( $g->namespaces[0] );
					STDOUT( "# [[$nsText:$key/$code]]" );
				}

				// Add it to the array
				$problematic[] = array( $g->namespaces[0], "$key/$code" );
			}
		}

		tagFuzzy( $problematic );
	}
}

function tagFuzzy( $problematic ) {
	if ( !count( $problematic ) ) {
		return;
	}