Ejemplo n.º 1
0
 /**
  * Entry point : initialise variables and call subfunctions.
  * @param $par \string Message key. Becomes "MediaWiki:Allmessages" when called like
  *             Special:Translations/MediaWiki:Allmessages (default null)
  */
 function execute($par)
 {
     global $wgRequest, $wgOut;
     $this->setHeaders();
     $this->outputHeader();
     self::includeAssets();
     if ($this->including()) {
         $title = Title::newFromText($par);
         if (!$title) {
             $wgOut->addWikiMsg('translate-translations-including-no-param');
         } else {
             $this->showTranslations($title);
         }
         return;
     }
     /**
      * GET values.
      */
     $message = $wgRequest->getText('message');
     $namespace = $wgRequest->getInt('namespace', NS_MAIN);
     if ($message !== '') {
         $title = Title::newFromText($message, $namespace);
     } else {
         $title = Title::newFromText($par, $namespace);
     }
     TranslateUtils::addSpecialHelpLink($wgOut, 'Help:Extension:Translate/Statistics_and_reporting#Translations_in_all_languages');
     if (!$title) {
         $title = Title::makeTitle(NS_MEDIAWIKI, '');
         $wgOut->addHTML($this->namespaceMessageForm($title));
     } else {
         $wgOut->addHTML($this->namespaceMessageForm($title) . '<br />');
         $this->showTranslations($title);
     }
 }
 public function execute($par)
 {
     $this->setHeaders();
     $out = $this->getOutput();
     $out->addModules('ext.translate.special.managegroups');
     TranslateUtils::addSpecialHelpLink($out, 'Help:Extension:Translate/Group_management');
     $changefile = TranslateUtils::cacheFile(self::CHANGEFILE);
     if (!file_exists($changefile)) {
         // @todo Tell them when changes was last checked/process
         // or how to initiate recheck.
         $out->addWikiMsg('translate-smg-nochanges');
         return;
     }
     $user = $this->getUser();
     $allowed = $user->isAllowed(self::RIGHT);
     $req = $this->getRequest();
     if (!$req->wasPosted()) {
         $this->showChanges($allowed, $this->getLimit());
         return;
     }
     $token = $req->getVal('token');
     if (!$allowed || !$user->matchEditToken($token)) {
         throw new PermissionsError(self::RIGHT);
     }
     $this->processSubmit();
 }
 public function execute($par)
 {
     $out = $this->getOutput();
     $lang = $this->getLanguage();
     // Only for manual debugging nowdays
     $this->purge = false;
     $this->setHeaders();
     $out->addModules('ext.translate.special.supportedlanguages');
     TranslateUtils::addSpecialHelpLink($out, 'Help:Extension:Translate/Statistics_and_reporting#List_of_languages_and_translators');
     $this->outputHeader();
     $dbr = wfGetDB(DB_SLAVE);
     if ($dbr->getType() === 'sqlite') {
         $out->addWikiText('<div class=errorbox>SQLite is not supported.</div>');
         return;
     }
     $out->addWikiMsg('supportedlanguages-localsummary');
     $names = Language::fetchLanguageNames(null, 'all');
     $languages = $this->languageCloud();
     // There might be all sorts of subpages which are not languages
     $languages = array_intersect_key($languages, $names);
     $this->outputLanguageCloud($languages, $names);
     $out->addWikiMsg('supportedlanguages-count', $lang->formatNum(count($languages)));
     if ($par && Language::isKnownLanguageTag($par)) {
         $code = $par;
         $out->addWikiMsg('supportedlanguages-colorlegend', $this->getColorLegend());
         $users = $this->fetchTranslators($code);
         if ($users === false) {
             // generic-pool-error is from MW core
             $out->wrapWikiMsg('<div class="warningbox">$1</div>', 'generic-pool-error');
             return;
         }
         global $wgTranslateAuthorBlacklist;
         $users = $this->filterUsers($users, $code, $wgTranslateAuthorBlacklist);
         $this->preQueryUsers($users);
         $this->showLanguage($code, $users);
     }
 }
 /**
  * Constructs and outputs file input form with supported methods.
  */
 protected function outputForm()
 {
     global $wgOut;
     $wgOut->addModules('ext.translate.special.importtranslations');
     TranslateUtils::addSpecialHelpLink($wgOut, 'Help:Extension:Translate/Off-line_translation');
     /**
      * Ugly but necessary form building ahead, ohoy
      */
     $this->out->addHTML(Xml::openElement('form', array('action' => $this->getTitle()->getLocalUrl(), 'method' => 'post', 'enctype' => 'multipart/form-data', 'id' => 'mw-translate-import')) . Html::hidden('token', $this->user->editToken()) . Html::hidden('title', $this->getTitle()->getPrefixedText()) . Xml::openElement('table') . Xml::openElement('tr') . Xml::openElement('td'));
     $class = array('class' => 'mw-translate-import-inputs');
     $this->out->addHTML(Xml::radioLabel(wfMsg('translate-import-from-url'), 'upload-type', 'url', 'mw-translate-up-url', $this->request->getText('upload-type') === 'url') . "\n" . Xml::closeElement('td') . Xml::openElement('td') . "\n" . Xml::input('upload-url', 50, $this->request->getText('upload-url'), array('id' => 'mw-translate-up-url-input') + $class) . "\n" . Xml::closeElement('td') . Xml::closeElement('tr') . Xml::openElement('tr') . Xml::openElement('td') . "\n");
     $this->out->addHTML(Xml::radioLabel(wfMsg('translate-import-from-wiki'), 'upload-type', 'wiki', 'mw-translate-up-wiki', $this->request->getText('upload-type') === 'wiki') . "\n" . Xml::closeElement('td') . Xml::openElement('td') . "\n" . Xml::input('upload-wiki', 50, $this->request->getText('upload-wiki', 'File:'), array('id' => 'mw-translate-up-wiki-input') + $class) . "\n" . Xml::closeElement('td') . Xml::closeElement('tr') . Xml::openElement('tr') . Xml::openElement('td') . "\n" . Xml::radioLabel(wfMsg('translate-import-from-local'), 'upload-type', 'local', 'mw-translate-up-local', $this->request->getText('upload-type') === 'local') . "\n" . Xml::closeElement('td') . Xml::openElement('td') . "\n" . Xml::input('upload-local', 50, $this->request->getText('upload-local'), array('type' => 'file', 'id' => 'mw-translate-up-local-input') + $class) . "\n" . Xml::closeElement('td') . Xml::closeElement('tr') . Xml::closeElement('table') . Xml::submitButton(wfMsg('translate-import-load')) . Xml::closeElement('form'));
 }
 /**
  * Constructs and outputs file input form with supported methods.
  */
 protected function outputForm()
 {
     $this->getOutput()->addModules('ext.translate.special.importtranslations');
     TranslateUtils::addSpecialHelpLink($this->getOutput(), 'Help:Extension:Translate/Off-line_translation');
     /**
      * Ugly but necessary form building ahead, ohoy
      */
     $this->getOutput()->addHTML(Xml::openElement('form', array('action' => $this->getPageTitle()->getLocalUrl(), 'method' => 'post', 'enctype' => 'multipart/form-data', 'id' => 'mw-translate-import')) . Html::hidden('token', $this->getUser()->getEditToken()) . Html::hidden('title', $this->getPageTitle()->getPrefixedText()) . Xml::inputLabel($this->msg('translate-import-from-local')->text(), 'upload-local', 'mw-translate-up-local-input', 50, $this->getRequest()->getText('upload-local'), array('type' => 'file')) . Xml::submitButton($this->msg('translate-import-load')->text()) . Xml::closeElement('form'));
 }
 /**
  * Access point for this special page.
  */
 public function execute($parameters)
 {
     global $wgTranslateBlacklist, $wgContLang;
     $out = $this->getOutput();
     $out->addModuleStyles(array('ext.translate.special.translate.styles', 'jquery.uls.grid'));
     $out->addModules('ext.translate.special.translate');
     $this->setHeaders();
     $request = $this->getRequest();
     // @todo Move to api or so
     if ($parameters === 'editpage') {
         $editpage = TranslationEditPage::newFromRequest($request);
         if ($editpage) {
             $editpage->execute();
             return;
         }
     }
     if (!defined('ULS_VERSION')) {
         throw new ErrorPageError('translate-ulsdep-title', 'translate-ulsdep-body');
     }
     $this->setup($parameters);
     $isBeta = self::isBeta($request);
     if ($this->options['group'] === '' || $isBeta && !$this->group) {
         $this->groupInformation();
         return;
     }
     $errors = $this->getFormErrors();
     if ($isBeta && $this->options['taction'] !== 'export') {
         $out->addHTML(Html::openElement('div', array('class' => 'grid ext-translate-container')));
         $out->addHTML($this->tuxSettingsForm($errors));
         $out->addHTML($this->messageSelector());
     } else {
         $out->addModuleStyles('ext.translate.legacy');
         TranslateUtils::addSpecialHelpLink($out, 'Help:Extension:Translate/Translation_example');
         // Show errors nicely.
         $out->addHTML($this->settingsForm($errors));
     }
     if (count($errors)) {
         return;
     } else {
         $checks = array($this->options['group'], strtok($this->options['group'], '-'), '*');
         foreach ($checks as $check) {
             if (isset($wgTranslateBlacklist[$check][$this->options['language']])) {
                 $reason = $wgTranslateBlacklist[$check][$this->options['language']];
                 $out->addWikiMsg('translate-page-disabled', $reason);
                 if ($isBeta) {
                     // Close div.ext-translate-container
                     $out->addHTML(Html::closeElement('div'));
                 }
                 return;
             }
         }
     }
     $params = array($this->getContext(), $this->task, $this->group, $this->options);
     if (!Hooks::run('SpecialTranslate::executeTask', $params)) {
         return;
     }
     // Initialise and get output.
     if (!$this->task) {
         return;
     }
     $this->task->init($this->group, $this->options, $this->nondefaults, $this->getContext());
     $output = $this->task->execute();
     if ($this->task->plainOutput()) {
         $out->disable();
         header('Content-type: text/plain; charset=UTF-8');
         echo $output;
     } else {
         $description = $this->getGroupDescription($this->group);
         $taskid = $this->options['task'];
         if (in_array($taskid, array('untranslated', 'reviewall'), true)) {
             $hasOptional = count($this->group->getTags('optional'));
             if ($hasOptional) {
                 $linktext = $this->msg('translate-page-description-hasoptional-open')->escaped();
                 $params = array('task' => 'optional') + $this->nondefaults;
                 $link = Linker::link($this->getPageTitle(), $linktext, array(), $params);
                 $note = $this->msg('translate-page-description-hasoptional')->rawParams($link)->parseAsBlock();
                 if ($description) {
                     $description .= '<br />' . $note;
                 } else {
                     $description = $note;
                 }
             }
         }
         $groupId = $this->group->getId();
         // PHP is such an awesome language
         $priorityLangs = TranslateMetadata::get($groupId, 'prioritylangs');
         $priorityLangs = array_flip(array_filter(explode(',', $priorityLangs)));
         $priorityLangsCount = count($priorityLangs);
         if ($priorityLangsCount && !isset($priorityLangs[$this->options['language']])) {
             $priorityForce = TranslateMetadata::get($groupId, 'priorityforce');
             if ($priorityForce === 'on') {
                 // Hide table
                 $priorityMessageClass = 'errorbox';
                 $priorityMessageKey = 'tpt-discouraged-language-force';
             } else {
                 $priorityMessageClass = 'warningbox';
                 $priorityMessageKey = 'tpt-discouraged-language';
             }
             $priorityLanguageNames = array();
             $languageNames = TranslateUtils::getLanguageNames($this->getLanguage()->getCode());
             foreach (array_keys($priorityLangs) as $langCode) {
                 $priorityLanguageNames[] = $languageNames[$langCode];
             }
             $priorityReason = TranslateMetadata::get($groupId, 'priorityreason');
             if ($priorityReason !== '') {
                 $priorityReason = "\n\n" . $this->msg('tpt-discouraged-language-reason', Xml::element('span', array('lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir()), $priorityReason))->parse();
             }
             $description .= Html::RawElement('div', array('class' => $priorityMessageClass), $this->msg($priorityMessageKey, '', $languageNames[$this->options['language']], $this->getLanguage()->listToText($priorityLanguageNames))->parseAsBlock() . $priorityReason);
         }
         if ($description) {
             $description = Xml::fieldset($this->msg('translate-page-description-legend')->text(), $description, array('class' => 'mw-sp-translate-description'));
         }
         if ($isBeta) {
             $out->addHTML($output);
         } else {
             $out->addHTML($description . $output);
         }
         ApiTranslateUser::trackGroup($this->group, $this->getUser());
     }
     if ($isBeta) {
         $out->addHTML(Html::closeElement('div'));
     }
 }
	function execute( $par ) {
		global $wgRequest, $wgOut;

		$request = $wgRequest;

		$this->purge = $request->getVal( 'action' ) === 'purge';
		$this->table = new StatsTable();

		$this->setHeaders();
		$this->outputHeader();

		$wgOut->addModules( 'ext.translate.special.languagestats' );
		$wgOut->addModules( 'ext.translate.messagetable' );

		$params = explode( '/', $par  );
		if ( isset( $params[0] ) && trim( $params[0] ) ) {
			$this->target = $params[0];
		}
		if ( isset( $params[1] ) ) {
			$this->noComplete = (bool)$params[1];
		}
		if ( isset( $params[2] ) ) {
			$this->noEmpty = (bool)$params[2];
		}

		// Whether the form has been submitted
		$submitted = $request->getVal( 'x' ) === 'D';

		// Default booleans to false if the form was submitted
		if ( !$this->including() ) {
			$this->target = $request->getVal( $this->targetValueName, $this->target );
			$this->noComplete = $request->getBool( 'suppresscomplete', $this->noComplete && !$submitted );
			$this->noEmpty = $request->getBool( 'suppressempty', $this->noEmpty && !$submitted );
		}

		if ( !$this->including() ) {
			TranslateUtils::addSpecialHelpLink( $wgOut, 'Help:Extension:Translate/Statistics_and_reporting' );
			$wgOut->addHTML( $this->getForm() );
		}

		$allowedValues = $this->getAllowedValues();
		if ( in_array( $this->target, $allowedValues, true ) ) {
			$this->outputIntroduction();
			$output = $this->getTable();
			if ( $this->incomplete ) {
				$wgOut->wrapWikiMsg( "<div class='error'>$1</div>", 'translate-langstats-incomplete' );
			}
			if ( $this->nothing ) {
				$wgOut->wrapWikiMsg( "<div class='error'>$1</div>", 'translate-mgs-nothing' );
			}
			$wgOut->addHTML( $output );
		} elseif ( $submitted ) {
			$this->invalidTarget();
		}

	}
 /**
  * The special page running code
  */
 public function execute($parameters)
 {
     $this->setup($parameters);
     $this->setHeaders();
     $out = $this->getOutput();
     TranslateUtils::addSpecialHelpLink($out, '//translatewiki.net/wiki/FAQ#Special:AdvancedTranslate', true);
     $out->addHTML($this->getForm());
     if (!$this->options['module']) {
         return;
     }
     switch ($this->options['module']) {
         case 'alias':
         case self::MODULE_SPECIAL:
             $o = new SpecialPageAliasesCM($this->options['language']);
             break;
         case self::MODULE_MAGIC:
             $o = new MagicWordsCM($this->options['language']);
             break;
         case self::MODULE_NAMESPACE:
             $o = new NamespaceCM($this->options['language']);
             break;
         default:
             throw new MWException("Unknown module {$this->options['module']}");
     }
     $request = $this->getRequest();
     if ($request->wasPosted() && $this->options['savetodb']) {
         if (!$this->getUser()->isAllowed('translate')) {
             throw new PermissionsError('translate');
         }
         $errors = array();
         $o->loadFromRequest($request);
         $o->validate($errors);
         if ($errors) {
             $out->wrapWikiMsg('<div class="error">$1</div>', 'translate-magic-notsaved');
             $this->outputErrors($errors);
             $out->addHTML($o->output());
             return;
         } else {
             $o->save($request);
             $out->wrapWikiMsg('<strong>$1</strong>', 'translate-magic-saved');
             $out->addHTML($o->output());
             return;
         }
     }
     if ($this->options['export']) {
         $output = $o->export();
         if ($output === '') {
             $out->addWikiMsg('translate-magic-nothing-to-export');
             return;
         }
         $result = Xml::element('textarea', array('rows' => '30'), $output);
         $out->addHTML($result);
         return;
     }
     $out->addWikiMsg('translate-magic-help');
     $errors = array();
     $o->validate($errors);
     if ($errors) {
         $this->outputErrors($errors);
     }
     $out->addHTML($o->output());
 }
	/**
	 * Constructs the form which can be used to generate custom graphs.
	 * @param $opts FormOptions
	 */
	protected function form( FormOptions $opts ) {
		global $wgOut, $wgScript;

		$this->setHeaders();
		TranslateUtils::addSpecialHelpLink( $wgOut, 'Help:Extension:Translate/Statistics_and_reporting' );
		$wgOut->addWikiMsg( 'translate-statsf-intro' );

		$wgOut->addHTML(
			Xml::fieldset( wfMsg( 'translate-statsf-options' ) ) .
			Html::openElement( 'form', array( 'action' => $wgScript ) ) .
			Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
			Html::hidden( 'preview', 1 ) .
			'<table>'
		);

		$submit = Xml::submitButton( wfMsg( 'translate-statsf-submit' ) );

		$wgOut->addHTML(
			$this->eInput( 'width', $opts ) .
			$this->eInput( 'height', $opts ) .
			'<tr><td colspan="2"><hr /></td></tr>' .
			$this->eInput( 'start', $opts, 12 ) .
			$this->eInput( 'days', $opts ) .
			$this->eRadio( 'scale', $opts, array( 'months', 'weeks', 'days', 'hours' ) ) .
			$this->eRadio( 'count', $opts, array( 'edits', 'users', 'registrations' ) ) .
			'<tr><td colspan="2"><hr /></td></tr>' .
			$this->eLanguage( 'language', $opts ) .
			$this->eGroup( 'group', $opts ) .
			'<tr><td colspan="2"><hr /></td></tr>' .
			'<tr><td colspan="2">' . $submit . '</td></tr>'
		);

		$wgOut->addHTML(
			'</table>' .
			'</form>' .
			'</fieldset>'
		);

		if ( !$opts['preview'] ) {
			return;
		}

		$spiParams = '';
		foreach ( $opts->getChangedValues() as $key => $v ) {
			if ( $key === 'preview' ) {
				continue;
			}

			if ( $spiParams !== '' ) {
				$spiParams .= ';';
			}

			$spiParams .= wfEscapeWikiText( "$key=$v" );
		}

		if ( $spiParams !== '' ) {
			$spiParams = '/' . $spiParams;
		}

		$titleText = $this->getTitle()->getPrefixedText();

		$wgOut->addHTML(
			Html::element( 'hr' ) .
			Html::element( 'pre', null, "{{{$titleText}{$spiParams}}}" )
		);

		$wgOut->addHTML(
			Html::element( 'hr' ) .
			Html::rawElement( 'div', array( 'style' => 'margin: 1em auto; text-align: center;' ), $this->image( $opts ) )
		);
	}
 public function execute($parameters)
 {
     $this->setHeaders();
     $user = $this->getUser();
     $request = $this->getRequest();
     $target = $request->getText('target', $parameters);
     $revision = $request->getInt('revision', 0);
     $action = $request->getVal('do');
     $out = $this->getOutput();
     TranslateUtils::addSpecialHelpLink($out, 'Help:Extension:Translate/Page_translation_example');
     // No specific page or invalid input
     $title = Title::newFromText($target);
     if (!$title) {
         if ($target !== '') {
             $out->addWikiMsg('tpt-badtitle');
         } else {
             $this->listPages();
         }
         return;
     }
     // Check permissions
     if (!$user->isAllowed('pagetranslation')) {
         throw new PermissionsError('pagetranslation');
     }
     // Check permissions
     if ($request->wasPosted() && !$user->matchEditToken($request->getText('token'))) {
         throw new PermissionsError('pagetranslation');
     }
     // We are processing some specific page
     if (!$title->exists()) {
         $out->addWikiMsg('tpt-nosuchpage', $title->getPrefixedText());
         return;
     }
     if ($action === 'discourage' || $action === 'encourage') {
         $id = TranslatablePage::getMessageGroupIdFromTitle($title);
         $current = MessageGroups::getPriority($id);
         if ($action === 'encourage') {
             $new = '';
         } else {
             $new = 'discouraged';
         }
         if ($new !== $current) {
             MessageGroups::setPriority($id, $new);
             $entry = new ManualLogEntry('pagetranslation', $action);
             $entry->setPerformer($user);
             $entry->setTarget($title);
             $logid = $entry->insert();
             $entry->publish($logid);
         }
         $this->listPages();
         $group = MessageGroups::getGroup($id);
         $parents = MessageGroups::getSharedGroups($group);
         MessageGroupStats::clearGroup($parents);
         return;
     }
     if ($action === 'unlink') {
         if (!$request->wasPosted()) {
             $this->showUnlinkConfirmation($title);
             return;
         } else {
             $page = TranslatablePage::newFromTitle($title);
             $content = ContentHandler::makeContent(self::getStrippedSourcePageText($page->getParse()), $title);
             $status = WikiPage::factory($title)->doEditContent($content, $this->msg('tpt-unlink-summary')->inContentLanguage()->text(), EDIT_FORCE_BOT | EDIT_UPDATE);
             if (!$status->isOK()) {
                 $out->wrapWikiMsg('<div class="errorbox">$1</div>', array('tpt-edit-failed', $status->getWikiText()));
                 return;
             }
             $page = TranslatablePage::newFromTitle($title);
             $this->unmarkPage($page, $user);
             $out->wrapWikiMsg('<div class="successbox">$1</div>', array('tpt-unmarked', $title->getPrefixedText()));
             $this->listPages();
             return;
         }
     }
     if ($action === 'unmark') {
         $page = TranslatablePage::newFromTitle($title);
         $this->unmarkPage($page, $user);
         $out->wrapWikiMsg('<div class="successbox">$1</div>', array('tpt-unmarked', $title->getPrefixedText()));
         $this->listPages();
         return;
     }
     if ($revision === 0) {
         // Get the latest revision
         $revision = intval($title->getLatestRevID());
     }
     $page = TranslatablePage::newFromRevision($title, $revision);
     if (!$page instanceof TranslatablePage) {
         $out->wrapWikiMsg('<div class="errorbox">$1</div>', array('tpt-notsuitable', $title->getPrefixedText(), $revision));
         return;
     }
     if ($revision !== intval($title->getLatestRevID())) {
         // We do want to notify the reviewer if the underlying page changes during review
         $target = $title->getFullUrl(array('oldid' => $revision));
         $link = "<span class='plainlinks'>[{$target} {$revision}]</span>";
         $out->wrapWikiMsg('<div class="warningbox">$1</div>', array('tpt-oldrevision', $title->getPrefixedText(), $link));
         $this->listPages();
         return;
     }
     $lastrev = $page->getMarkedTag();
     if ($lastrev !== false && $lastrev === $revision) {
         $out->wrapWikiMsg('<div class="warningbox">$1</div>', array('tpt-already-marked'));
         $this->listPages();
         return;
     }
     // This will modify the sections to include name property
     $error = false;
     $sections = $this->checkInput($page, $error);
     // Non-fatal error which prevents saving
     if ($error === false && $request->wasPosted()) {
         // Check if user wants to translate title
         // If not, remove it from the list of sections
         if (!$request->getCheck('translatetitle')) {
             $sections = array_filter($sections, function ($s) {
                 return $s->id !== 'Page display title';
             });
         }
         $err = $this->markForTranslation($page, $sections);
         if ($err) {
             call_user_func_array(array($out, 'addWikiMsg'), $err);
         } else {
             $this->showSuccess($page);
             $this->listPages();
         }
         return;
     }
     $this->showPage($page, $sections);
 }
 public function execute($par)
 {
     global $wgLanguageCode;
     $this->setHeaders();
     $this->checkPermissions();
     $server = TTMServer::primary();
     if (!$server instanceof SearchableTTMServer) {
         throw new ErrorPageError('tux-sst-nosolr-title', 'tux-sst-nosolr-body');
     }
     $out = $this->getOutput();
     $out->addModuleStyles('jquery.uls.grid');
     $out->addModuleStyles('ext.translate.special.searchtranslations.styles');
     $out->addModuleStyles('ext.translate.special.translate.styles');
     $out->addModules('ext.translate.special.searchtranslations');
     $out->addModules('ext.translate.special.searchtranslations.operatorsuggest');
     TranslateUtils::addSpecialHelpLink($out, 'Help:Extension:Translate#searching');
     $this->opts = $opts = new FormOptions();
     $opts->add('query', '');
     $opts->add('sourcelanguage', $wgLanguageCode);
     $opts->add('language', '');
     $opts->add('group', '');
     $opts->add('grouppath', '');
     $opts->add('filter', '');
     $opts->add('match', '');
     $opts->add('case', '');
     $opts->add('limit', $this->limit);
     $opts->add('offset', 0);
     $opts->fetchValuesFromRequest($this->getRequest());
     $queryString = $opts->getValue('query');
     if ($queryString === '') {
         $this->showEmptySearch();
         return;
     }
     $params = $opts->getAllValues();
     $filter = $opts->getValue('filter');
     try {
         $translationSearch = new CrossLanguageTranslationSearchQuery($params, $server);
         if (in_array($filter, $translationSearch->getAvailableFilters())) {
             if ($opts->getValue('language') === '') {
                 $params['language'] = $this->getLanguage()->getCode();
                 $opts->setValue('language', $params['language']);
             }
             $documents = $translationSearch->getDocuments();
             $total = $translationSearch->getTotalHits();
             $resultset = $translationSearch->getResultSet();
         } else {
             $resultset = $server->search($queryString, $params, $this->hl);
             $documents = $server->getDocuments($resultset);
             $total = $server->getTotalHits($resultset);
         }
     } catch (TTMServerException $e) {
         error_log('Translation search server unavailable:' . $e->getMessage());
         throw new ErrorPageError('tux-sst-solr-offline-title', 'tux-sst-solr-offline-body');
     }
     // Part 1: facets
     $facets = $server->getFacets($resultset);
     $facetHtml = '';
     if (count($facets['language']) > 0) {
         if ($filter !== '') {
             $facets['language'] = array_merge($facets['language'], array($opts->getValue('language') => $total));
         }
         $facetHtml = Html::element('div', array('class' => 'row facet languages', 'data-facets' => FormatJson::encode($this->getLanguages($facets['language'])), 'data-language' => $opts->getValue('language')), $this->msg('tux-sst-facet-language'));
     }
     if (count($facets['group']) > 0) {
         $facetHtml .= Html::element('div', array('class' => 'row facet groups', 'data-facets' => FormatJson::encode($this->getGroups($facets['group'])), 'data-group' => $opts->getValue('group')), $this->msg('tux-sst-facet-group'));
     }
     // Part 2: results
     $resultsHtml = '';
     $title = Title::newFromText($queryString);
     if ($title && !in_array($filter, $translationSearch->getAvailableFilters())) {
         $handle = new MessageHandle($title);
         $code = $handle->getCode();
         $language = $opts->getValue('language');
         if ($handle->isValid() && $code !== '' && $code !== $language) {
             $groupId = $handle->getGroup()->getId();
             $helpers = new TranslationHelpers($title, $groupId);
             $document['wiki'] = wfWikiId();
             $document['localid'] = $handle->getTitleForBase()->getPrefixedText();
             $document['content'] = $helpers->getTranslation();
             $document['language'] = $handle->getCode();
             array_unshift($documents, $document);
             $total++;
         }
     }
     foreach ($documents as $document) {
         $text = $document['content'];
         $text = TranslateUtils::convertWhiteSpaceToHTML($text);
         list($pre, $post) = $this->hl;
         $text = str_replace($pre, '<strong class="tux-search-highlight">', $text);
         $text = str_replace($post, '</strong>', $text);
         $title = Title::newFromText($document['localid'] . '/' . $document['language']);
         if (!$title) {
             // Should not ever happen but who knows...
             continue;
         }
         $resultAttribs = array('class' => 'row tux-message', 'data-title' => $title->getPrefixedText(), 'data-language' => $document['language']);
         $handle = new MessageHandle($title);
         if ($handle->isValid()) {
             $groupId = $handle->getGroup()->getId();
             $helpers = new TranslationHelpers($title, $groupId);
             $resultAttribs['data-definition'] = $helpers->getDefinition();
             $resultAttribs['data-translation'] = $helpers->getTranslation();
             $resultAttribs['data-group'] = $groupId;
             $uri = $title->getLocalUrl(array('action' => 'edit'));
             $link = Html::element('a', array('href' => $uri), $this->msg('tux-sst-edit')->text());
         } else {
             $url = wfParseUrl($document['uri']);
             $domain = $url['host'];
             $link = Html::element('a', array('href' => $document['uri']), $this->msg('tux-sst-view-foreign', $domain)->text());
         }
         $access = Html::rawElement('div', array('class' => 'row tux-edit tux-message-item'), $link);
         $titleText = $title->getPrefixedText();
         $titleAttribs = array('class' => 'row tux-title', 'dir' => 'ltr');
         $textAttribs = array('class' => 'row tux-text', 'lang' => wfBCP47($document['language']), 'dir' => Language::factory($document['language'])->getDir());
         $resultsHtml = $resultsHtml . Html::openElement('div', $resultAttribs) . Html::rawElement('div', $textAttribs, $text) . Html::element('div', $titleAttribs, $titleText) . $access . Html::closeElement('div');
     }
     $resultsHtml .= Html::rawElement('hr', array('class' => 'tux-pagination-line'));
     $prev = $next = '';
     $offset = $this->opts->getValue('offset');
     $params = $this->opts->getChangedValues();
     if ($total - $offset > $this->limit) {
         $newParams = array('offset' => $offset + $this->limit) + $params;
         $attribs = array('class' => 'mw-ui-button pager-next', 'href' => $this->getPageTitle()->getLocalUrl($newParams));
         $next = Html::element('a', $attribs, $this->msg('tux-sst-next')->text());
     }
     if ($offset) {
         $newParams = array('offset' => max(0, $offset - $this->limit)) + $params;
         $attribs = array('class' => 'mw-ui-button pager-prev', 'href' => $this->getPageTitle()->getLocalUrl($newParams));
         $prev = Html::element('a', $attribs, $this->msg('tux-sst-prev')->text());
     }
     $resultsHtml .= Html::rawElement('div', array('class' => 'tux-pagination-links'), "{$prev} {$next}");
     $search = $this->getSearchInput($queryString);
     $count = $this->msg('tux-sst-count')->numParams($total);
     $this->showSearch($search, $count, $facetHtml, $resultsHtml, $total);
 }
Ejemplo n.º 12
0
 /**
  * Access point for this special page.
  */
 public function execute($parameters)
 {
     global $wgOut, $wgTranslateBlacklist, $wgRequest;
     $wgOut->addModules('ext.translate.special.translate');
     $this->setHeaders();
     // @todo Move to api or so
     if ($parameters === 'editpage') {
         $editpage = TranslationEditPage::newFromRequest($wgRequest);
         if ($editpage) {
             $editpage->execute();
             return;
         }
     }
     $this->setup($parameters);
     $errors = array();
     if ($this->options['group'] === '') {
         TranslateUtils::addSpecialHelpLink($wgOut, 'Help:Extension:Translate/Translation_example');
         $this->groupInformation();
         return;
     }
     $codes = Language::getLanguageNames(false);
     if (!$this->options['language'] || !isset($codes[$this->options['language']])) {
         $errors['language'] = wfMsgExt('translate-page-no-such-language', array('parse'));
         $this->options['language'] = $this->defaults['language'];
     }
     if (!$this->task instanceof TranslateTask) {
         $errors['task'] = wfMsgExt('translate-page-no-such-task', array('parse'));
         $this->options['task'] = $this->defaults['task'];
     }
     if (!$this->group instanceof MessageGroup) {
         $errors['group'] = wfMsgExt('translate-page-no-such-group', array('parse'));
         $this->options['group'] = $this->defaults['group'];
     }
     TranslateUtils::addSpecialHelpLink($wgOut, 'Help:Extension:Translate/Translation_example');
     // Show errors nicely.
     $wgOut->addHTML($this->settingsForm($errors));
     if (count($errors)) {
         return;
     } else {
         $checks = array($this->options['group'], strtok($this->options['group'], '-'), '*');
         foreach ($checks as $check) {
             $reason = @$wgTranslateBlacklist[$check][$this->options['language']];
             if ($reason !== null) {
                 $wgOut->addWikiMsg('translate-page-disabled', $reason);
                 return;
             }
         }
     }
     // Proceed.
     $taskOptions = new TaskOptions($this->options['language'], $this->options['limit'], $this->options['offset'], array($this, 'cbAddPagingNumbers'));
     // Initialise and get output.
     $this->task->init($this->group, $taskOptions);
     $output = $this->task->execute();
     if ($this->task->plainOutput()) {
         $wgOut->disable();
         header('Content-type: text/plain; charset=UTF-8');
         echo $output;
     } else {
         $description = $this->getGroupDescription($this->group);
         $taskid = $this->options['task'];
         if (in_array($taskid, array('untranslated', 'reviewall'), true)) {
             $hasOptional = count($this->group->getTags('optional'));
             if ($hasOptional) {
                 $linker = class_exists('DummyLinker') ? new DummyLinker() : new Linker();
                 $linktext = wfMessage('translate-page-description-hasoptional-open')->escaped();
                 $params = array('task' => 'optional') + $this->nondefaults;
                 $link = $linker->link($this->getTitle(), $linktext, array(), $params);
                 $note = wfMessage('translate-page-description-hasoptional')->rawParams($link)->parseAsBlock();
                 if ($description) {
                     $description .= '<br>' . $note;
                 } else {
                     $description = $note;
                 }
             }
         }
         $status = $this->getWorkflowStatus();
         if ($status !== false) {
             $description = $status . $description;
         }
         if ($description) {
             $description = Xml::fieldset(wfMsg('translate-page-description-legend'), $description);
         }
         $links = $this->doStupidLinks();
         if ($this->paging['count'] === 0) {
             $wgOut->addHTML($description . $links);
         } else {
             $wgOut->addHTML($description . $links . $output . $links);
         }
     }
 }
Ejemplo n.º 13
0
 public function execute($par)
 {
     global $wgRequest;
     $this->out->setPageTitle(htmlspecialchars(wfMsg('translate-managegroups')));
     $group = $wgRequest->getText('group');
     $group = MessageGroups::getGroup($group);
     if (!$group instanceof FileBasedMessageGroup) {
         $group = null;
     }
     if ($group) {
         if ($wgRequest->getBool('rebuildall', false) && $wgRequest->wasPosted() && $this->user->isAllowed('translate-manage') && $this->user->matchEditToken($wgRequest->getVal('token'))) {
             $languages = explode(',', $wgRequest->getText('codes'));
             foreach ($languages as $code) {
                 $cache = new MessageGroupCache($group, $code);
                 $cache->create();
             }
         }
         $code = $wgRequest->getText('language', 'en');
         // Go to English for undefined codes.
         $codes = array_keys(Language::getLanguageNames(false));
         if (!in_array($code, $codes)) {
             $code = 'en';
         }
         if ($wgRequest->getVal('from') !== 'main') {
             $this->importForm($group, $code);
             return;
         }
     }
     // Main list
     global $wgLang, $wgOut;
     $groups = MessageGroups::singleton()->getGroups();
     TranslateUtils::addSpecialHelpLink($wgOut, 'Help:Extension:Translate/Group_management');
     $wgOut->wrapWikiMsg('<h2>$1</h2>', 'translate-manage-listgroups');
     $separator = wfMsg('word-separator');
     $languages = array_keys(Language::getLanguageNames(false));
     foreach ($groups as $group) {
         if (!$group instanceof FileBasedMessageGroup) {
             continue;
         }
         wfDebug(__METHOD__ . ": {$group->getId()}\n");
         $id = $group->getId();
         $link = $this->skin->link($this->getTitle(), $group->getLabel(), array('id' => "mw-group-{$id}"), array('group' => $id));
         $out = $link . $separator;
         $cache = new MessageGroupCache($group);
         if ($cache->exists()) {
             $timestamp = wfTimestamp(TS_MW, $cache->getTimestamp());
             $out .= wfMsg('translate-manage-cacheat', $wgLang->date($timestamp), $wgLang->time($timestamp));
             $modified = array();
             foreach ($languages as $code) {
                 $cache = new MessageGroupCache($group, $code);
                 if (!$cache->isValid()) {
                     $modified[] = $code;
                 }
             }
             if (count($modified)) {
                 $out = '[' . implode(",", $modified) . '] ' . $out;
                 if (!in_array('en', $modified) && $this->user->isAllowed('translate-manage')) {
                     $out .= $this->rebuildButton($group, $modified, 'main');
                 }
             } else {
                 // @todo FIXME: should be in CSS file.
                 $out = Html::rawElement('span', array('style' => 'color:grey'), $out);
             }
         } else {
             $out .= wfMsg('translate-manage-newgroup');
         }
         $wgOut->addHtml($out);
         $wgOut->addHtml('<hr>');
     }
     $wgOut->wrapWikiMsg('<h2>$1</h2>', 'translate-manage-listgroups-old');
     $wgOut->addHTML('<ul>');
     foreach ($groups as $group) {
         if ($group instanceof FileBasedMessageGroup) {
             continue;
         }
         $wgOut->addHtml(Xml::element('li', null, $group->getLabel()));
     }
     $wgOut->addHTML('</ul>');
 }
 public function execute($par)
 {
     global $wgLang, $wgOut, $wgRequest;
     $this->purge = $wgRequest->getVal('action') === 'purge';
     $this->setHeaders();
     TranslateUtils::addSpecialHelpLink($wgOut, 'Help:Extension:Translate/Statistics_and_reporting#List_of_languages_and_translators');
     $wgOut->addModules('ext.translate.special.supportedlanguages');
     $cache = wfGetCache(CACHE_ANYTHING);
     $cachekey = wfMemcKey('translate-supportedlanguages', $wgLang->getCode());
     $data = $cache->get($cachekey);
     if (!$this->purge && is_string($data)) {
         $wgOut->addHtml($data);
         return;
     }
     $this->outputHeader();
     $wgOut->addWikiMsg('supportedlanguages-colorlegend', $this->getColorLegend());
     $wgOut->addWikiMsg('supportedlanguages-localsummary');
     // Check if CLDR extension has been installed.
     $cldrInstalled = class_exists('LanguageNames');
     if ($cldrInstalled) {
         $locals = LanguageNames::getNames($wgLang->getCode(), LanguageNames::FALLBACK_NORMAL, LanguageNames::LIST_MW_AND_CLDR);
     }
     $natives = Language::getLanguageNames(false);
     ksort($natives);
     $this->outputLanguageCloud($natives);
     // Requires NS_PORTAL. If not present, display error text.
     if (!defined('NS_PORTAL')) {
         $users = $this->fetchTranslatorsAuto();
     } else {
         $users = $this->fetchTranslatorsPortal($natives);
     }
     $this->preQueryUsers($users);
     list($editcounts, $lastedits) = $this->getUserStats();
     global $wgUser;
     $skin = $wgUser->getSkin();
     // Information to be used inside the foreach loop.
     $linkInfo['rc']['title'] = SpecialPage::getTitleFor('Recentchanges');
     $linkInfo['rc']['msg'] = wfMsg('supportedlanguages-recenttranslations');
     $linkInfo['stats']['title'] = SpecialPage::getTitleFor('LanguageStats');
     $linkInfo['stats']['msg'] = wfMsg('languagestats');
     foreach (array_keys($natives) as $code) {
         if (!isset($users[$code])) {
             continue;
         }
         // If CLDR is installed, add localised header and link title.
         if ($cldrInstalled) {
             $headerText = wfMsg('supportedlanguages-portallink', $code, $locals[$code], $natives[$code]);
         } else {
             // No CLDR, so a less localised header and link title.
             $headerText = wfMsg('supportedlanguages-portallink-nocldr', $code, $natives[$code]);
         }
         $headerText = htmlspecialchars($headerText);
         $wgOut->addHtml(Html::openElement('h2', array('id' => $code)));
         if (defined('NS_PORTAL')) {
             $portalTitle = Title::makeTitleSafe(NS_PORTAL, $code);
             $wgOut->addHtml($skin->linkKnown($portalTitle, $headerText));
         } else {
             $wgOut->addHtml($headerText);
         }
         $wgOut->addHTML("</h2>");
         // Add useful links for language stats and recent changes for the language.
         $links = array();
         $links[] = $skin->link($linkInfo['stats']['title'], $linkInfo['stats']['msg'], array(), array('code' => $code, 'suppresscomplete' => '1'), array('known', 'noclasses'));
         $links[] = $skin->link($linkInfo['rc']['title'], $linkInfo['rc']['msg'], array(), array('translations' => 'only', 'trailer' => "/" . $code), array('known', 'noclasses'));
         $linkList = $wgLang->listToText($links);
         $wgOut->addHTML("<p>" . $linkList . "</p>\n");
         $this->makeUserList($users[$code], $editcounts, $lastedits);
     }
     $wgOut->addHtml(Html::element('hr'));
     $wgOut->addWikiMsg('supportedlanguages-count', $wgLang->formatNum(count($users)));
     $cache->set($cachekey, $wgOut->getHTML(), 3600);
 }