protected function getQueryConditions()
 {
     global $wgTranslateMessageNamespaces;
     $db = wfGetDB(DB_SLAVE);
     $conds = array('rc_title ' . $db->buildLike($db->anyString(), '/en'), 'rc_namespace' => $wgTranslateMessageNamespaces, 'rc_type != ' . RC_LOG, 'rc_id > ' . $this->getRCCutoff(), 'rc_user' => FuzzyBot::getUser()->getId());
     return $conds;
 }
 public function getDefinitions()
 {
     $groups = MessageGroups::getAllGroups();
     $keys = array();
     /**
      * @var $g MessageGroup
      */
     foreach ($groups as $g) {
         $states = $g->getMessageGroupStates()->getStates();
         foreach (array_keys($states) as $state) {
             $keys["Translate-workflow-state-{$state}"] = $state;
         }
     }
     $defs = TranslateUtils::getContents(array_keys($keys), $this->getNamespace());
     foreach ($keys as $key => $state) {
         if (!isset($defs[$key])) {
             // @todo Use jobqueue
             $title = Title::makeTitleSafe($this->getNamespace(), $key);
             $page = new WikiPage($title);
             $content = ContentHandler::makeContent($state, $title);
             $page->doEditContent($content, wfMessage('translate-workflow-autocreated-summary', $state)->inContentLanguage()->text(), 0, false, FuzzyBot::getUser());
         } else {
             // Use the wiki translation as definition if available.
             // getContents returns array( content, last author )
             list($content, ) = $defs[$key];
             $keys[$key] = $content;
         }
     }
     return $keys;
 }
	/**
	 * @param $target Title
	 * @return RenderJob
	 */
	public static function newJob( Title $target ) {
		$job = new self( $target );
		$job->setUser( FuzzyBot::getUser() );
		$job->setFlags( EDIT_FORCE_BOT );
		$job->setSummary( wfMsgForContent( 'tpt-render-summary' ) );

		return $job;
	}
 /**
  * @param $target Title
  * @return TranslateRenderJob
  */
 public static function newJob(Title $target)
 {
     $job = new self($target);
     $job->setUser(FuzzyBot::getUser());
     $job->setFlags(EDIT_FORCE_BOT);
     $job->setSummary(wfMessage('tpt-render-summary')->inContentLanguage()->text());
     return $job;
 }
	/**
	 * @param $source Title
	 * @param $target Title
	 * @param $params array, should include base-source and base-target
	 * @param $performer
	 * @return MoveJob
	 */
	public static function newJob( Title $source, Title $target, array $params, /*User*/ $performer ) {
		$job = new self( $source );
		$job->setUser( FuzzyBot::getUser() );
		$job->setTarget( $target->getPrefixedText() );
		$job->setSummary( wfMsgForContent( 'pt-movepage-logreason', $params['base-source'] ) );
		$job->setParams( $params );
		$job->setPerformer( $performer );
		$job->lock();
		return $job;
	}
	/**
	 * @static
	 * @param $target Title
	 * @param $base
	 * @param $full
	 * @param $performer
	 * @return DeleteJob
	 */
	public static function newJob( Title $target, $base, $full, /*User*/ $performer ) {
		$job = new self( $target );
		$job->setUser( FuzzyBot::getUser() );
		$job->setFull( $full );
		$job->setBase( $base );
		$msg = $job->getFull() ? 'pt-deletepage-full-logreason' : 'pt-deletepage-lang-logreason';
		$job->setSummary( wfMsgForContent( $msg, $base ) );
		$job->setPerformer( $performer );
		return $job;
	}
 public function testGetSetState()
 {
     $group = new WikiMessageGroup('testgroup', 'wewgweg');
     $ok = ApiGroupReview::changeState($group, 'fi', 'newstate', FuzzyBot::getUser());
     $this->assertTrue($ok, 'state was changed');
     $state = ApiGroupReview::getState($group, 'fi');
     $this->assertEquals('newstate', $state, 'state was changed to expected value');
     $ok = ApiGroupReview::changeState($group, 'fi', 'newstate', FuzzyBot::getUser());
     $this->assertFalse($ok, 'state was not changed again');
 }
 /**
  * @param $source Title
  * @param $target Title
  * @param $params array, should include base-source and base-target
  * @param $performer
  * @return TranslateMoveJob
  */
 public static function newJob(Title $source, Title $target, array $params, $performer)
 {
     $job = new self($source);
     $job->setUser(FuzzyBot::getUser());
     $job->setTarget($target->getPrefixedText());
     $summary = wfMessage('pt-movepage-logreason', $params['base-source']);
     $summary = $summary->inContentLanguage()->text();
     $job->setSummary($summary);
     $job->setParams($params);
     $job->setPerformer($performer);
     $job->lock();
     return $job;
 }
 public function run()
 {
     $title = $this->title;
     $handle = new MessageHandle($title);
     $code = $handle->getCode();
     if (!$handle->isValid() && !$code) {
         return true;
     }
     $groups = self::getGroupsWithTransitions($handle);
     foreach ($groups as $id => $transitions) {
         $group = MessageGroups::getGroup($id);
         $stats = MessageGroupStats::forItem($id, $code);
         $state = self::getNewState($stats, $transitions);
         if ($state) {
             ApiGroupReview::changeState($group, $code, $state, FuzzyBot::getUser());
         }
     }
     return true;
 }
 function run()
 {
     global $wgTranslateDocumentationLanguageCode;
     $title = $this->title;
     $params = $this->params;
     $user = FuzzyBot::getUser();
     $flags = EDIT_DEFER_UPDATES | EDIT_FORCE_BOT;
     $wikiPage = WikiPage::factory($title);
     $summary = wfMessage('translate-manage-import-summary')->inContentLanguage()->plain();
     $content = ContentHandler::makeContent($params['content'], $title);
     $wikiPage->doEditContent($content, $summary, $flags, false, $user);
     // NOTE: message documentation is excluded from fuzzying!
     if ($params['fuzzy']) {
         $handle = new MessageHandle($title);
         $key = $handle->getKey();
         $languages = TranslateUtils::getLanguageNames('en');
         unset($languages[$wgTranslateDocumentationLanguageCode]);
         $languages = array_keys($languages);
         $dbw = wfGetDB(DB_MASTER);
         $fields = array('page_id', 'page_latest');
         $conds = array('page_namespace' => $title->getNamespace());
         $pages = array();
         foreach ($languages as $code) {
             $otherTitle = Title::makeTitleSafe($title->getNamespace(), "{$key}/{$code}");
             $pages[$otherTitle->getDBKey()] = true;
         }
         unset($pages[$title->getDBKey()]);
         if (count($pages) === 0) {
             return true;
         }
         $conds['page_title'] = array_keys($pages);
         $res = $dbw->select('page', $fields, $conds, __METHOD__);
         $inserts = array();
         foreach ($res as $row) {
             $inserts[] = array('rt_type' => RevTag::getType('fuzzy'), 'rt_page' => $row->page_id, 'rt_revision' => $row->page_latest);
         }
         $dbw->replace('revtag', array(array('rt_type', 'rt_page', 'rt_revision')), $inserts, __METHOD__);
     }
     return true;
 }
	/**
	 * 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;
	}
 /**
  * Does the actual edit if possible.
  * @param Title $title
  * @param string $text
  * @param bool $dryrun Whether to really do it or just show what would be done.
  * @param string $comment Edit summary.
  */
 private function updateMessage($title, $text, $dryrun, $comment = null)
 {
     global $wgTranslateDocumentationLanguageCode;
     $this->reportProgress("Updating {$title->getPrefixedText()}... ", $title);
     if (!$title instanceof Title) {
         $this->reportProgress("INVALID TITLE!", $title);
         return;
     }
     $items = explode('/', $title->getText(), 2);
     if (isset($items[1]) && $items[1] === $wgTranslateDocumentationLanguageCode) {
         $this->reportProgress("IGNORED!", $title);
         return;
     }
     if ($dryrun) {
         $this->reportProgress("DRY RUN!", $title);
         return;
     }
     $wikipage = new WikiPage($title);
     $content = ContentHandler::makeContent($text, $title);
     $status = $wikipage->doEditContent($content, $comment ? $comment : 'Marking as fuzzy', EDIT_FORCE_BOT | EDIT_UPDATE, false, FuzzyBot::getUser());
     $success = $status === true || is_object($status) && $status->isOK();
     $this->reportProgress($success ? 'OK' : 'FAILED', $title);
 }
	/**
	 * @static
	 * @param Title $title
	 * @param  $message
	 * @param  $comment
	 * @param  $user
	 * @param int $editFlags
	 * @return array|String
	 */
	public static function doFuzzy( $title, $message, $comment, $user, $editFlags = 0 ) {
		global $wgUser;

		if ( !$wgUser->isAllowed( 'translate-manage' ) ) {
			return wfMsg( 'badaccess-group0' );
		}

		$dbw = wfGetDB( DB_MASTER );

		// Work on all subpages of base title.
		$messageInfo = TranslateEditAddons::figureMessage( $title );
		$titleText = $messageInfo[0];

		$conds = array(
			'page_namespace' => $title->getNamespace(),
			'page_latest=rev_id',
			'rev_text_id=old_id',
			'page_title' . $dbw->buildLike( "$titleText/", $dbw->anyString() ),
		);

		$rows = $dbw->select(
			array( 'page', 'revision', 'text' ),
			array( 'page_title', 'page_namespace', 'old_text', 'old_flags' ),
			$conds,
			__METHOD__
		);

		// Edit with fuzzybot if there is no user.
		if ( !$user ) {
			$user = FuzzyBot::getUser();
		}

		// Process all rows.
		$changed = array();
		foreach ( $rows as $row ) {
			global $wgTranslateDocumentationLanguageCode;

			$ttitle = Title::makeTitle( $row->page_namespace, $row->page_title );

			// No fuzzy for English original or documentation language code.
			if ( $ttitle->getSubpageText() == 'en' || $ttitle->getSubpageText() == $wgTranslateDocumentationLanguageCode ) {
				// Use imported text, not database text.
				$text = $message;
			} else {
				$text = Revision::getRevisionText( $row );
				$text = self::makeTextFuzzy( $text );
			}

			// Do actual import
			$changed[] = self::doImport(
				$ttitle,
				$text,
				$comment,
				$user,
				$editFlags
			);
		}

		// Format return text
		$text = '';
		foreach ( $changed as $c ) {
			$key = array_shift( $c );
			$text .= "* " . wfMsgExt( $key, array(), $c ) . "\n";
		}

		return array( 'translate-manage-import-fuzzy', "\n" . $text );
	}
 /**
  * @todo Very long code block; split up.
  *
  * @param $group MessageGroup
  * @param $code
  */
 public function importForm($group, $code)
 {
     $this->setSubtitle($group, $code);
     $formParams = array('method' => 'post', 'action' => $this->getTitle()->getFullURL(array('group' => $group->getId())), 'class' => 'mw-translate-manage');
     global $wgRequest, $wgLang;
     if ($wgRequest->wasPosted() && $wgRequest->getBool('process', false) && $this->user->isAllowed('translate-manage') && $this->user->matchEditToken($wgRequest->getVal('token'))) {
         $process = true;
     } else {
         $process = false;
     }
     $this->out->addHTML(Xml::openElement('form', $formParams) . Html::hidden('title', $this->getTitle()->getPrefixedText()) . Html::hidden('token', $this->user->editToken()) . Html::hidden('group', $group->getId()) . Html::hidden('process', 1));
     // BEGIN
     $cache = new MessageGroupCache($group, $code);
     if (!$cache->exists() && $code === 'en') {
         $cache->create();
     }
     $collection = $group->initCollection($code);
     $collection->loadTranslations();
     $diff = new DifferenceEngine();
     $diff->showDiffStyle();
     $diff->setReducedLineNumbers();
     $ignoredMessages = $collection->getTags('ignored');
     if (!is_array($ignoredMessages)) {
         $ignoredMessages = array();
     }
     $messages = $group->load($code);
     $changed = array();
     foreach ($messages as $key => $value) {
         // ignored? ignore!
         if (in_array($key, $ignoredMessages)) {
             continue;
         }
         $fuzzy = $old = false;
         if (isset($collection[$key])) {
             $old = $collection[$key]->translation();
         }
         // No changes at all, ignore.
         if (str_replace(TRANSLATE_FUZZY, '', $old) === $value) {
             continue;
         }
         if ($old === false) {
             $name = wfMsgHtml('translate-manage-import-new', '<code style="font-weight:normal;">' . htmlspecialchars($key) . '</code>');
             $text = TranslateUtils::convertWhiteSpaceToHTML($value);
             $changed[] = MessageWebImporter::makeSectionElement($name, 'new', $text);
         } else {
             if (TranslateEditAddons::hasFuzzyString($old)) {
                 // NO-OP
             } else {
                 $transTitle = MessageWebImporter::makeTranslationTitle($group, $key, $code);
                 if (TranslateEditAddons::isFuzzy($transTitle)) {
                     $old = TRANSLATE_FUZZY . $old;
                 }
             }
             $diff->setText($old, $value);
             $text = $diff->getDiff('', '');
             $type = 'changed';
             if ($process) {
                 if (!count($changed)) {
                     $changed[] = '<ul>';
                 }
                 $action = $wgRequest->getVal(MessageWebImporter::escapeNameForPHP("action-{$type}-{$key}"));
                 if ($action === null) {
                     $message = wfMsgExt('translate-manage-inconsistent', 'parseinline', wfEscapeWikiText("action-{$type}-{$key}"));
                     $changed[] = "<li>{$message}</li></ul>";
                     $process = false;
                 } else {
                     // Initialise processing time counter.
                     if (!isset($this->time)) {
                         $this->time = wfTimestamp();
                     }
                     $fuzzybot = FuzzyBot::getUser();
                     $message = MessageWebImporter::doAction($action, $group, $key, $code, $value, '', $fuzzybot, EDIT_FORCE_BOT);
                     $key = array_shift($message);
                     $params = $message;
                     $message = wfMsgExt($key, 'parseinline', $params);
                     $changed[] = "<li>{$message}</li>";
                     if ($this->checkProcessTime()) {
                         $process = false;
                         $duration = $wgLang->formatNum($this->processingTime);
                         $message = wfMsgExt('translate-manage-toolong', 'parseinline', $duration);
                         $changed[] = "<li>{$message}</li></ul>";
                     }
                     continue;
                 }
             }
             if ($code !== 'en') {
                 $actions = array('import', 'conflict', 'ignore');
             } else {
                 $actions = array('import', 'fuzzy', 'ignore');
             }
             $act = array();
             if ($this->user->isAllowed('translate-manage')) {
                 $defaction = $fuzzy ? 'conflict' : 'import';
                 foreach ($actions as $action) {
                     $label = wfMsg("translate-manage-action-{$action}");
                     $name = MessageWebImporter::escapeNameForPHP("action-{$type}-{$key}");
                     $selected = $wgRequest->getVal($name, $defaction);
                     $id = Sanitizer::escapeId("action-{$key}-{$action}");
                     $act[] = Xml::radioLabel($label, $name, $action, $id, $action === $selected);
                 }
             }
             $name = wfMsg('translate-manage-import-diff', '<code style="font-weight:normal;">' . htmlspecialchars($key) . '</code>', implode(' ', $act));
             $changed[] = MessageWebImporter::makeSectionElement($name, $type, $text);
         }
     }
     if (!$process) {
         $collection->filter('hastranslation', false);
         $keys = $collection->getMessageKeys();
         $diff = array_diff($keys, array_keys($messages));
         foreach ($diff as $s) {
             $name = wfMsgHtml('translate-manage-import-deleted', '<code style="font-weight:normal;">' . htmlspecialchars($s) . '</code>');
             $text = TranslateUtils::convertWhiteSpaceToHTML($collection[$s]->translation());
             $changed[] = MessageWebImporter::makeSectionElement($name, 'deleted', $text);
         }
     }
     if ($process || !count($changed) && $code !== 'en') {
         if (!count($changed)) {
             $this->out->addWikiMsg('translate-manage-nochanges-other');
         }
         if (!count($changed) || strpos($changed[count($changed) - 1], '<li>') !== 0) {
             $changed[] = '<ul>';
         }
         $cache->create();
         $message = wfMsgExt('translate-manage-import-rebuild', 'parseinline');
         $changed[] = "<li>{$message}</li>";
         $message = wfMsgExt('translate-manage-import-done', 'parseinline');
         $changed[] = "<li>{$message}</li></ul>";
         $this->out->addHTML(implode("\n", $changed));
     } else {
         // END
         if (count($changed)) {
             if ($code === 'en') {
                 $this->out->addWikiMsg('translate-manage-intro-en');
             } else {
                 $lang = TranslateUtils::getLanguageName($code, false, $wgLang->getCode());
                 $this->out->addWikiMsg('translate-manage-intro-other', $lang);
             }
             $this->out->addHTML(Html::hidden('language', $code));
             $this->out->addHTML(implode("\n", $changed));
             if ($this->user->isAllowed('translate-manage')) {
                 $this->out->addHTML(Xml::submitButton(wfMsg('translate-manage-submit')));
             }
         } elseif ($this->user->isAllowed('translate-manage')) {
             $cache->create();
             // Update timestamp
             $this->out->addWikiMsg('translate-manage-nochanges');
         }
     }
     $this->out->addHTML('</form>');
     if ($code === 'en') {
         $this->doModLangs($group);
     } else {
         $this->out->addHTML('<p>' . $this->skin->link($this->getTitle(), wfMsgHtml('translate-manage-return-to-group'), array(), array('group' => $group->getId())) . '</p>');
     }
 }
 /**
  * Lists all translators that have contributed to the latest revisions of
  * each translation. Causes translations to be loaded from the database.
  * Is not affected by filters.
  * @return string[] List of usernames.
  */
 public function getAuthors()
 {
     $this->loadTranslations();
     $authors = array_flip($this->authors);
     foreach ($this->messages as $m) {
         // Check if there are authors
         /**
          * @var TMessage $m
          */
         $author = $m->getProperty('last-translator-text');
         if ($author === null) {
             continue;
         }
         if (!isset($authors[$author])) {
             $authors[$author] = 1;
         } else {
             $authors[$author]++;
         }
     }
     # arsort( $authors, SORT_NUMERIC );
     ksort($authors);
     $fuzzyBot = FuzzyBot::getName();
     foreach ($authors as $author => $edits) {
         if ($author !== $fuzzyBot) {
             $filteredAuthors[] = $author;
         }
     }
     return isset($filteredAuthors) ? $filteredAuthors : array();
 }
Exemple #16
0
 public function getDefinitions()
 {
     global $wgTranslateWorkflowStates;
     $defs = array();
     foreach (array_keys($wgTranslateWorkflowStates) as $state) {
         $titleString = "Translate-workflow-state-{$state}";
         $definitionText = $state;
         // Automatically create pages for workflow states in the original language
         $title = Title::makeTitle($this->getNamespace(), $titleString);
         if (!$title->exists()) {
             $page = new WikiPage($title);
             $page->doEdit($state, wfMessage('translate-workflow-autocreated-summary', $state)->inContentLanguage()->text(), 0, false, FuzzyBot::getUser());
         } else {
             $definitionText = Revision::newFromTitle($title)->getText();
         }
         $defs[$titleString] = $definitionText;
     }
     return $defs;
 }
	/**
	 * 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;
	}
 /**
  * Does the actual edit.
  * @param Title $title
  * @param string $translation
  * @param string $comment Edit summary.
  */
 public function import($title, $translation, $comment)
 {
     $flags = EDIT_FORCE_BOT;
     if ($this->norc) {
         $flags |= EDIT_SUPPRESS_RC;
     }
     $this->reportProgress("Importing {$title->getPrefixedText()}: ", $title);
     $wikipage = new WikiPage($title);
     $content = ContentHandler::makeContent($translation, $title);
     $status = $wikipage->doEditContent($content, $comment, $flags, false, FuzzyBot::getUser());
     $success = $status === true || is_object($status) && $status->isOK();
     $this->reportProgress($success ? 'OK' : 'FAILED', $title);
 }