Пример #1
0
 /**
  * Generates the html snippet for ajax edit. Echoes it to the output and
  * disabled all other output.
  */
 public function execute()
 {
     global $wgOut, $wgServer, $wgScriptPath, $wgUser, $wgRequest;
     $wgOut->disable();
     $data = $this->getEditInfo();
     $groupId = $wgRequest->getText('loadgroup', '');
     $helpers = new TranslationHelpers($this->getTitle(), $groupId);
     $id = "tm-target-{$helpers->dialogID()}";
     $helpers->setTextareaId($id);
     if ($this->suggestions === 'only') {
         echo $helpers->getBoxes($this->suggestions);
         return;
     }
     if ($this->suggestions === 'checks') {
         echo $helpers->getBoxes($this->suggestions);
         return;
     }
     $translation = $helpers->getTranslation();
     $targetLang = Language::factory($helpers->getTargetLanguage());
     $textareaParams = array('name' => 'text', 'class' => 'mw-translate-edit-area', 'id' => $id, 'lang' => $targetLang->getCode(), 'dir' => $targetLang->getDir());
     if (!$wgUser->isAllowed('translate')) {
         $textareaParams['readonly'] = 'readonly';
     }
     $textarea = Html::element('textarea', $textareaParams, $translation);
     $hidden = array();
     $hidden[] = Html::hidden('title', $this->getTitle()->getPrefixedDbKey());
     if (isset($data['revisions'][0]['timestamp'])) {
         $hidden[] = Html::hidden('basetimestamp', $data['revisions'][0]['timestamp']);
     }
     $hidden[] = Html::hidden('starttimestamp', $data['starttimestamp']);
     $hidden[] = Html::hidden('token', $data['edittoken']);
     $hidden[] = Html::hidden('format', 'json');
     $hidden[] = Html::hidden('action', 'edit');
     $summary = Xml::inputLabel(wfMsg('translate-js-summary'), 'summary', 'summary', 40);
     $save = Xml::submitButton(wfMsg('translate-js-save'), array('class' => 'mw-translate-save'));
     $saveAndNext = Xml::submitButton(wfMsg('translate-js-next'), array('class' => 'mw-translate-next'));
     $skip = Html::element('input', array('class' => 'mw-translate-skip', 'type' => 'button', 'value' => wfMsg('translate-js-skip')));
     if ($this->getTitle()->exists()) {
         $history = Html::element('input', array('class' => 'mw-translate-history', 'type' => 'button', 'value' => wfMsg('translate-js-history')));
     } else {
         $history = '';
     }
     $support = $this->getSupportButton($this->getTitle());
     if ($wgUser->isAllowed('translate')) {
         $bottom = "{$summary}{$save}{$saveAndNext}{$skip}{$history}{$support}";
     } else {
         $text = wfMessage('translate-edit-nopermission')->escaped();
         $button = $this->getPermissionPageButton();
         $bottom = "{$text} {$button}{$skip}{$history}{$support}";
     }
     // Use the api to submit edits
     $formParams = array('action' => "{$wgServer}{$wgScriptPath}/api.php", 'method' => 'post');
     $form = Html::rawElement('form', $formParams, implode("\n", $hidden) . "\n" . $helpers->getBoxes($this->suggestions) . "\n" . "{$textarea}\n{$bottom}");
     echo Html::rawElement('div', array('class' => 'mw-ajax-dialog'), $form);
 }
 /**
  * @param EditPage $editpage
  * @return string
  */
 private static function editBoxes(EditPage $editpage)
 {
     $context = $editpage->getArticle()->getContext();
     $request = $context->getRequest();
     $groupId = $request->getText('loadgroup', '');
     $th = new TranslationHelpers($editpage->getTitle(), $groupId);
     if ($editpage->firsttime && !$request->getCheck('oldid') && !$request->getCheck('undo')) {
         $editpage->textbox1 = (string) $th->getTranslation();
     } else {
         $th->setTranslation($editpage->textbox1);
     }
     TranslationHelpers::addModules($context->getOutput());
     return $th->getBoxes();
 }
	/**
	 * @param $object
	 * @return String
	 */
	private static function editBoxes( EditPage $object ) {
		global $wgOut, $wgRequest;

		$groupId = $wgRequest->getText( 'loadgroup', '' );
		$th = new TranslationHelpers( $object->mTitle, $groupId );
		if ( $object->firsttime && !$wgRequest->getCheck( 'oldid' ) && !$wgRequest->getCheck( 'undo' ) ) {
			$object->textbox1 = (string) $th->getTranslation();
		} else {
			$th->setTranslation( $object->textbox1 );
		}

		TranslationHelpers::addModules( $wgOut );

		return $th->getBoxes();
	}