Example #1
0
 /**
  * Send the edit form and related headers to $wgOut
  * @param $formCallback Callback that takes an OutputPage parameter; will be called
  *     during form output near the top, for captchas and the like.
  */
 function showEditForm($formCallback = null)
 {
     global $wgOut, $wgUser;
     wfProfileIn(__METHOD__);
     #need to parse the preview early so that we know which templates are used,
     #otherwise users with "show preview after edit box" will get a blank list
     #we parse this near the beginning so that setHeaders can do the title
     #setting work instead of leaving it in getPreviewText
     $previewOutput = '';
     if ($this->formtype == 'preview') {
         $previewOutput = $this->getPreviewText();
     }
     wfRunHooks('EditPage::showEditForm:initial', array(&$this));
     $this->setHeaders();
     if ($this->showHeader() === false) {
         wfProfileOut(__METHOD__);
         return;
     }
     $wgOut->addHTML($this->editFormPageTop);
     if ($wgUser->getOption('previewontop')) {
         $this->displayPreviewArea($previewOutput, true);
     }
     $wgOut->addHTML($this->editFormTextTop);
     $showToolbar = true;
     if ($this->wasDeletedSinceLastEdit()) {
         if ($this->formtype == 'save') {
             // Hide the toolbar and edit area, user can click preview to get it back
             // Add an confirmation checkbox and explanation.
             $showToolbar = false;
         } else {
             $wgOut->wrapWikiMsg("<div class='error mw-deleted-while-editing'>\n\$1\n</div>", 'deletedwhileediting');
         }
     }
     $wgOut->addHTML(Html::openElement('form', array('id' => 'editform', 'name' => 'editform', 'method' => 'post', 'action' => $this->getActionURL($this->getContextTitle()), 'enctype' => 'multipart/form-data')));
     if (is_callable($formCallback)) {
         call_user_func_array($formCallback, array(&$wgOut));
     }
     wfRunHooks('EditPage::showEditForm:fields', array(&$this, &$wgOut));
     // Put these up at the top to ensure they aren't lost on early form submission
     $this->showFormBeforeText();
     if ($this->wasDeletedSinceLastEdit() && 'save' == $this->formtype) {
         $username = $this->lastDelete->user_name;
         $comment = $this->lastDelete->log_comment;
         // It is better to not parse the comment at all than to have templates expanded in the middle
         // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
         $key = $comment === '' ? 'confirmrecreate-noreason' : 'confirmrecreate';
         $wgOut->addHTML('<div class="mw-confirm-recreate">' . wfMsgExt($key, 'parseinline', $username, "<nowiki>{$comment}</nowiki>") . Xml::checkLabel(wfMsg('recreate'), 'wpRecreate', 'wpRecreate', false, array('title' => Linker::titleAttrib('recreate'), 'tabindex' => 1, 'id' => 'wpRecreate')) . '</div>');
     }
     # If a blank edit summary was previously provided, and the appropriate
     # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
     # user being bounced back more than once in the event that a summary
     # is not required.
     #####
     # For a bit more sophisticated detection of blank summaries, hash the
     # automatic one and pass that in the hidden field wpAutoSummary.
     if ($this->missingSummary || $this->section == 'new' && $this->nosummary) {
         $wgOut->addHTML(Html::hidden('wpIgnoreBlankSummary', true));
     }
     $autosumm = $this->autoSumm ? $this->autoSumm : md5($this->summary);
     $wgOut->addHTML(Html::hidden('wpAutoSummary', $autosumm));
     $wgOut->addHTML(Html::hidden('oldid', $this->oldid));
     if ($this->section == 'new') {
         $this->showSummaryInput(true, $this->summary);
         $wgOut->addHTML($this->getSummaryPreview(true, $this->summary));
     }
     $wgOut->addHTML($this->editFormTextBeforeContent);
     if (!$this->isCssJsSubpage && $showToolbar && $wgUser->getOption('showtoolbar')) {
         $wgOut->addHTML(EditPage::getEditToolbar());
     }
     if ($this->isConflict) {
         // In an edit conflict bypass the overrideable content form method
         // and fallback to the raw wpTextbox1 since editconflicts can't be
         // resolved between page source edits and custom ui edits using the
         // custom edit ui.
         $this->textbox2 = $this->textbox1;
         $this->textbox1 = $this->getCurrentText();
         $this->showTextbox1();
     } else {
         $this->showContentForm();
     }
     $wgOut->addHTML($this->editFormTextAfterContent);
     $wgOut->addWikiText($this->getCopywarn());
     $wgOut->addHTML($this->editFormTextAfterWarn);
     $this->showStandardInputs();
     $this->showFormAfterText();
     $this->showTosSummary();
     $this->showEditTools();
     $wgOut->addHTML($this->editFormTextAfterTools . "\n");
     $wgOut->addHTML(Html::rawElement('div', array('class' => 'templatesUsed'), Linker::formatTemplates($this->getTemplates(), $this->preview, $this->section != '')));
     $wgOut->addHTML(Html::rawElement('div', array('class' => 'hiddencats'), Linker::formatHiddenCategories($this->mArticle->getHiddenCategories())));
     if ($this->isConflict) {
         $this->showConflict();
     }
     $wgOut->addHTML($this->editFormTextBottom . "\n</form>\n");
     if (!$wgUser->getOption('previewontop')) {
         $this->displayPreviewArea($previewOutput, false);
     }
     wfProfileOut(__METHOD__);
 }
Example #2
0
 /**
  * Send the edit form and related headers to $wgOut
  * @param callable|null $formCallback That takes an OutputPage parameter; will be called
  *     during form output near the top, for captchas and the like.
  */
 function showEditForm($formCallback = null)
 {
     global $wgOut, $wgUser;
     wfProfileIn(__METHOD__);
     # need to parse the preview early so that we know which templates are used,
     # otherwise users with "show preview after edit box" will get a blank list
     # we parse this near the beginning so that setHeaders can do the title
     # setting work instead of leaving it in getPreviewText
     $previewOutput = '';
     if ($this->formtype == 'preview') {
         $previewOutput = $this->getPreviewText();
     }
     wfRunHooks('EditPage::showEditForm:initial', array(&$this, &$wgOut));
     $this->setHeaders();
     if ($this->showHeader() === false) {
         wfProfileOut(__METHOD__);
         return;
     }
     $wgOut->addHTML($this->editFormPageTop);
     if ($wgUser->getOption('previewontop')) {
         $this->displayPreviewArea($previewOutput, true);
     }
     $wgOut->addHTML($this->editFormTextTop);
     $showToolbar = true;
     if ($this->wasDeletedSinceLastEdit()) {
         if ($this->formtype == 'save') {
             // Hide the toolbar and edit area, user can click preview to get it back
             // Add an confirmation checkbox and explanation.
             $showToolbar = false;
         } else {
             $wgOut->wrapWikiMsg("<div class='error mw-deleted-while-editing'>\n\$1\n</div>", 'deletedwhileediting');
         }
     }
     // @todo add EditForm plugin interface and use it here!
     //       search for textarea1 and textares2, and allow EditForm to override all uses.
     $wgOut->addHTML(Html::openElement('form', array('id' => self::EDITFORM_ID, 'name' => self::EDITFORM_ID, 'method' => 'post', 'action' => $this->getActionURL($this->getContextTitle()), 'enctype' => 'multipart/form-data')));
     if (is_callable($formCallback)) {
         call_user_func_array($formCallback, array(&$wgOut));
     }
     // Add an empty field to trip up spambots
     $wgOut->addHTML(Xml::openElement('div', array('id' => 'antispam-container', 'style' => 'display: none;')) . Html::rawElement('label', array('for' => 'wpAntiSpam'), wfMessage('simpleantispam-label')->parse()) . Xml::element('input', array('type' => 'text', 'name' => 'wpAntispam', 'id' => 'wpAntispam', 'value' => '')) . Xml::closeElement('div'));
     wfRunHooks('EditPage::showEditForm:fields', array(&$this, &$wgOut));
     // Put these up at the top to ensure they aren't lost on early form submission
     $this->showFormBeforeText();
     if ($this->wasDeletedSinceLastEdit() && 'save' == $this->formtype) {
         $username = $this->lastDelete->user_name;
         $comment = $this->lastDelete->log_comment;
         // It is better to not parse the comment at all than to have templates expanded in the middle
         // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
         $key = $comment === '' ? 'confirmrecreate-noreason' : 'confirmrecreate';
         $wgOut->addHTML('<div class="mw-confirm-recreate">' . wfMessage($key, $username, "<nowiki>{$comment}</nowiki>")->parse() . Xml::checkLabel(wfMessage('recreate')->text(), 'wpRecreate', 'wpRecreate', false, array('title' => Linker::titleAttrib('recreate'), 'tabindex' => 1, 'id' => 'wpRecreate')) . '</div>');
     }
     # When the summary is hidden, also hide them on preview/show changes
     if ($this->nosummary) {
         $wgOut->addHTML(Html::hidden('nosummary', true));
     }
     # If a blank edit summary was previously provided, and the appropriate
     # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
     # user being bounced back more than once in the event that a summary
     # is not required.
     #####
     # For a bit more sophisticated detection of blank summaries, hash the
     # automatic one and pass that in the hidden field wpAutoSummary.
     if ($this->missingSummary || $this->section == 'new' && $this->nosummary) {
         $wgOut->addHTML(Html::hidden('wpIgnoreBlankSummary', true));
     }
     if ($this->undidRev) {
         $wgOut->addHTML(Html::hidden('wpUndidRevision', $this->undidRev));
     }
     if ($this->hasPresetSummary) {
         // If a summary has been preset using &summary= we don't want to prompt for
         // a different summary. Only prompt for a summary if the summary is blanked.
         // (Bug 17416)
         $this->autoSumm = md5('');
     }
     $autosumm = $this->autoSumm ? $this->autoSumm : md5($this->summary);
     $wgOut->addHTML(Html::hidden('wpAutoSummary', $autosumm));
     $wgOut->addHTML(Html::hidden('oldid', $this->oldid));
     $wgOut->addHTML(Html::hidden('format', $this->contentFormat));
     $wgOut->addHTML(Html::hidden('model', $this->contentModel));
     if ($this->section == 'new') {
         $this->showSummaryInput(true, $this->summary);
         $wgOut->addHTML($this->getSummaryPreview(true, $this->summary));
     }
     $wgOut->addHTML($this->editFormTextBeforeContent);
     if (!$this->isCssJsSubpage && $showToolbar && $wgUser->getOption('showtoolbar')) {
         $wgOut->addHTML(EditPage::getEditToolbar());
     }
     if ($this->blankArticle) {
         $wgOut->addHTML(Html::hidden('wpIgnoreBlankArticle', true));
     }
     if ($this->isConflict) {
         // In an edit conflict bypass the overridable content form method
         // and fallback to the raw wpTextbox1 since editconflicts can't be
         // resolved between page source edits and custom ui edits using the
         // custom edit ui.
         $this->textbox2 = $this->textbox1;
         $content = $this->getCurrentContent();
         $this->textbox1 = $this->toEditText($content);
         $this->showTextbox1();
     } else {
         $this->showContentForm();
     }
     $wgOut->addHTML($this->editFormTextAfterContent);
     $this->showStandardInputs();
     $this->showFormAfterText();
     $this->showTosSummary();
     $this->showEditTools();
     $wgOut->addHTML($this->editFormTextAfterTools . "\n");
     $wgOut->addHTML(Html::rawElement('div', array('class' => 'templatesUsed'), Linker::formatTemplates($this->getTemplates(), $this->preview, $this->section != '')));
     $wgOut->addHTML(Html::rawElement('div', array('class' => 'hiddencats'), Linker::formatHiddenCategories($this->mArticle->getHiddenCategories())));
     $wgOut->addHTML(Html::rawElement('div', array('class' => 'limitreport'), self::getPreviewLimitReport($this->mParserOutput)));
     $wgOut->addModules('mediawiki.action.edit.collapsibleFooter');
     if ($this->isConflict) {
         try {
             $this->showConflict();
         } catch (MWContentSerializationException $ex) {
             // this can't really happen, but be nice if it does.
             $msg = wfMessage('content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage());
             $wgOut->addWikiText('<div class="error">' . $msg->text() . '</div>');
         }
     }
     // Marker for detecting truncated form data.  This must be the last
     // parameter sent in order to be of use, so do not move me.
     $wgOut->addHTML(Html::hidden('wpUltimateParam', true));
     $wgOut->addHTML($this->editFormTextBottom . "\n</form>\n");
     if (!$wgUser->getOption('previewontop')) {
         $this->displayPreviewArea($previewOutput, false);
     }
     wfProfileOut(__METHOD__);
 }