/**
  * The second form, which still allows changing some things.
  * Lists all the action which would take place.
  */
 protected function showConfirmation()
 {
     global $wgOut, $wgLang;
     $wgOut->addWikiMsg('pt-deletepage-intro');
     $target = $this->title;
     $count = 1;
     // Base page
     $wgOut->wrapWikiMsg('== $1 ==', 'pt-deletepage-list-pages');
     if (!$this->singleLanguage()) {
         $this->printChangeLine($this->title);
     }
     $wgOut->wrapWikiMsg('=== $1 ===', 'pt-deletepage-list-translation');
     $translationPages = $this->getTranslationPages();
     foreach ($translationPages as $old) {
         $count++;
         $this->printChangeLine($old);
     }
     $wgOut->wrapWikiMsg('=== $1 ===', 'pt-deletepage-list-section');
     $sectionPages = $this->getSectionPages($target);
     foreach ($sectionPages as $old) {
         $count++;
         $this->printChangeLine($old);
     }
     $wgOut->wrapWikiMsg('=== $1 ===', 'pt-deletepage-list-other');
     $subpages = $this->getSubpages();
     foreach ($subpages as $old) {
         if (TranslatablePage::isTranslationPage($old)) {
             continue;
         }
         if ($this->doSubpages) {
             $count++;
         }
         $this->printChangeLine($old, $this->doSubpages);
     }
     $wgOut->addWikiText("----\n");
     $wgOut->addWikiMsg('pt-deletepage-list-count', $wgLang->formatNum($count));
     $br = Html::element('br');
     $readonly = array('readonly' => 'readonly');
     $subaction = array('name' => 'subaction');
     $formParams = array('method' => 'post', 'action' => $this->getTitle($this->text)->getLocalURL());
     $form = array();
     if ($this->singleLanguage()) {
         $form[] = Xml::fieldset(wfMsg('pt-deletepage-lang-legend'));
     } else {
         $form[] = Xml::fieldset(wfMsg('pt-deletepage-full-legend'));
     }
     $form[] = Html::openElement('form', $formParams);
     $form[] = Html::hidden('wpEditToken', $this->user->editToken());
     $this->addInputLabel($form, wfMsg('pt-deletepage-current'), 'wpTitle', 30, $this->text, $readonly);
     $this->addInputLabel($form, wfMsg('pt-deletepage-reason'), 'reason', 60, $this->reason);
     $form[] = Xml::checkLabel(wfMsg('pt-deletepage-subpages'), 'subpages', 'mw-subpages', $this->doSubpages, $readonly) . $br;
     $form[] = Xml::submitButton(wfMsg('pt-deletepage-action-perform'), $subaction);
     $form[] = Xml::submitButton(wfMsg('pt-deletepage-action-other'), $subaction);
     $form[] = Xml::closeElement('form');
     $form[] = Xml::closeElement('fieldset');
     $wgOut->addHTML(implode("\n", $form));
 }
Exemplo n.º 2
0
 /**
  * Get token to watch (or unwatch) a page for a user
  *
  * @param Title $title Title object of page to watch
  * @param User $title User for whom the action is going to be performed
  * @param string $action Optionally override the action to 'unwatch'
  * @return string Token
  * @since 1.18
  */
 public static function getWatchToken(Title $title, User $user, $action = 'watch')
 {
     if ($action != 'unwatch') {
         $action = 'watch';
     }
     $salt = array($action, $title->getDBkey());
     // This token stronger salted and not compatible with ApiWatch
     // It's title/action specific because index.php is GET and API is POST
     return $user->editToken($salt);
 }
Exemplo n.º 3
0
 /**
  * @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>');
     }
 }
	protected function showPermissions( $step ) {
		global $wgLang, $wgRequest;
		$header = new HtmlTag( 'h2' );
		$step_message = 'translate-fs-permissions-title';
		$header->content( wfMsg( $step_message ) )->style( 'opacity', 0.4 );

		if ( $step ) {
			$this->out->addHtml( $header );
			return $step;
		}

		if ( $wgRequest->wasPosted() &&
			$this->user->matchEditToken( $wgRequest->getVal( 'token' ) ) &&
			$wgRequest->getText( 'step' ) === 'permissions' )
		{
			// This is ridiculous
			global $wgCaptchaTriggers;
			$captcha = $wgCaptchaTriggers;
			$wgCaptchaTriggers = null;

			$language = $wgRequest->getVal( 'primary-language' );
			$message = $wgRequest->getText( 'message', '...' );
			$params = array(
				'action' => 'threadaction',
				'threadaction' => 'newthread',
				'token' => $this->user->editToken(),
				'talkpage' => 'Project:Translator',
				'subject' => "{{LanguageHeader|$language}}",
				'reason' => 'Using Special:FirstSteps',
				'text' => $message,
			);
			$request = new FauxRequest( $params, true, $_SESSION );
			$api = new ApiMain( $request, true );
			$api->execute();
			$result = $api->getResultData();
			$wgCaptchaTriggers = $captcha;
			$page = $result['threadaction']['thread']['thread-title'];
			$this->user->setOption( 'translate-firststeps-request', $page );
			$this->user->saveSettings();
		}

		$page = $this->user->getOption( 'translate-firststeps-request' );
		if ( $this->user->isAllowed( 'translate' ) ) {
			$header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
			$this->out->addHtml( $header );
			return $step;
		} elseif ( $page ) {
			$header->content( $header->content . wfMsg( 'translate-fs-pagetitle-pending' ) );
			$this->out->addHtml( $header->style( 'opacity', false ) );
			$this->out->addWikiMsg( 'translate-fs-permissions-pending', $page );
			return $step_message;
		}

		$this->out->addHtml( $header->style( 'opacity', false ) );
		$this->out->addWikiMsg( 'translate-fs-permissions-help' );

		$output = Html::openElement( 'form', array( 'method' => 'post' ) );
		$output .= Html::hidden( 'step', 'permissions' );
		$output .= Html::hidden( 'token', $this->user->editToken() );
		$output .= Html::hidden( 'title', $this->getTitle() );
		$name = $id = 'primary-language';
		$selector = new XmlSelect();
		$selector->addOptions( $this->languages( $wgLang->getCode() ) );
		$selector->setAttribute( 'id', $id );
		$selector->setAttribute( 'name', $name );
		$selector->setDefault( $wgLang->getCode() );
		$text = wfMessage( 'translate-fs-permissions-planguage' )->text();
		$output .= Xml::label( $text, $id ) . "&#160;" . $selector->getHtml() . '<br />';
		$output .= Html::element( 'textarea', array( 'rows' => 5, 'name' => 'message' ), '' );
		$output .= Xml::submitButton( wfMsg( 'translate-fs-permissions-submit' ) );
		$output .= Html::closeElement( 'form' );

		$this->out->addHtml( $output );
		return $step_message;
	}
	/**
	 * Displays the sections and changes for the user to review
	 * @param $page TranslatablePage
	 * @param $sections array
	 */
	public function showPage( TranslatablePage $page, Array $sections ) {
		global $wgOut, $wgContLang;

		$wgOut->setSubtitle( $this->user->getSkin()->link( $page->getTitle() ) );
		$wgOut->addModules( 'ext.translate.special.pagetranslation' );

		$wgOut->addWikiMsg( 'tpt-showpage-intro' );

		$formParams = array(
			'method' => 'post',
			'action' => $this->getTitle()->getFullURL(),
			'class'  => 'mw-tpt-sp-markform',
		);

		$wgOut->addHTML(
			Xml::openElement( 'form', $formParams ) .
			Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
			Html::hidden( 'revision', $page->getRevision() ) .
			Html::hidden( 'target', $page->getTitle()->getPrefixedtext() ) .
			Html::hidden( 'token', $this->user->editToken() )
		);

		$wgOut->wrapWikiMsg( '==$1==', 'tpt-sections-oldnew' );

		$diffOld = wfMsgHtml( 'tpt-diff-old' );
		$diffNew = wfMsgHtml( 'tpt-diff-new' );

		foreach ( $sections as $s ) {
			if ( $s->type === 'new' ) {
				$input = Xml::input( 'tpt-sect-' . $s->id, 15, $s->name );
				$name = wfMsgHtml( 'tpt-section-new', $input );
			} else {
				$name = wfMsgHtml( 'tpt-section', htmlspecialchars( $s->name ) );
			}

			if ( $s->type === 'changed' ) {
				$diff = new DifferenceEngine;
				if ( method_exists( 'DifferenceEngine', 'setTextLanguage' ) ) {
					$diff->setTextLanguage( $wgContLang );
				}
				$diff->setReducedLineNumbers();
				$diff->setText( $s->getOldText(), $s->getText() );
				$text = $diff->getDiff( $diffOld, $diffNew );
				$diffOld = $diffNew = null;
				$diff->showDiffStyle();

				$id = "tpt-sect-{$s->id}-action-nofuzzy";
				$text = Xml::checkLabel( wfMsg( 'tpt-action-nofuzzy' ), $id, $id, false ) . $text;
			} else {
				$text = TranslateUtils::convertWhiteSpaceToHTML( $s->getText() );
			}

			# For changed text, the language is set by $diff->setTextLanguage()
			$lang = $s->type === 'changed' ? null : $wgContLang;
			$wgOut->addHTML( MessageWebImporter::makeSectionElement( $name, $s->type, $text, $lang ) );
		}

		$deletedSections = $page->getParse()->getDeletedSections();
		if ( count( $deletedSections ) ) {
			$wgOut->wrapWikiMsg( '==$1==', 'tpt-sections-deleted' );

			foreach ( $deletedSections as $s ) {
				$name = wfMsgHtml( 'tpt-section-deleted', htmlspecialchars( $s->id ) );
				$text = TranslateUtils::convertWhiteSpaceToHTML( $s->getText() );
				$wgOut->addHTML( MessageWebImporter::makeSectionElement( $name, $s->type, $text, $wgContLang ) );
			}
		}

		// Display template changes if applicable
		if ( $page->getMarkedTag() !== false ) {
			$newTemplate = $page->getParse()->getTemplatePretty();
			$oldPage = TranslatablePage::newFromRevision( $page->getTitle(), $page->getMarkedTag() );
			$oldTemplate = $oldPage->getParse()->getTemplatePretty();

			if ( $oldTemplate !== $newTemplate ) {
				$wgOut->wrapWikiMsg( '==$1==', 'tpt-sections-template' );

				$diff = new DifferenceEngine;
				if ( method_exists( 'DifferenceEngine', 'setTextLanguage' ) ) {
					$diff->setTextLanguage( $wgContLang );
				}
				$diff->setText( $oldTemplate, $newTemplate );
				$text = $diff->getDiff( wfMsgHtml( 'tpt-diff-old' ), wfMsgHtml( 'tpt-diff-new' ) );
				$diff->showDiffStyle();
				$diff->setReducedLineNumbers();

				$contentParams = array( 'class' => 'mw-tpt-sp-content' );
				$wgOut->addHTML( Xml::tags( 'div', $contentParams, $text ) );
			}
		}

		$wgOut->addHTML(
			Xml::submitButton( wfMsg( 'tpt-submit' ) ) .
			Xml::closeElement( 'form' )
		);
	}