示例#1
0
 /**
  *	This method will try to store the data in mOptions.
  *
  * It will return true on success or an error message on failure.
  * The used form and target page will be available in mOptions after
  * execution of the method.
  *
  * This method also sets HTTP response headers according to the result.
  *
  * @param bool $prefillFromExisting If this is set, existing values in the page will be used to prefill the form.
  * @return true or an error message
  */
 public function storeSemanticData($prefillFromExisting = true)
 {
     global $wgOut, $wgRequest;
     // If the wiki is read-only we might as well stop right away
     if (wfReadOnly()) {
         return $this->reportError(wfMsg('sf_autoedit_readonly', wfReadOnlyReason()));
     }
     // ensure 'form' key exists
     if (!array_key_exists('form', $this->mOptions)) {
         $this->mOptions['form'] = null;
     }
     // ensure 'target' key exists
     if (!array_key_exists('target', $this->mOptions)) {
         $this->mOptions['target'] = null;
     }
     // If we have no target article and no form we might as well stop right away
     if (!$this->mOptions['target'] && !$this->mOptions['form']) {
         return $this->reportError(wfMsg('sf_autoedit_notargetspecified'));
     }
     // check if form was specified
     if (!$this->mOptions['form']) {
         // If no form was specified, find the default one for
         // this page.
         $title = Title::newFromText($this->mOptions['target']);
         $form_names = SFFormLinker::getDefaultFormsForPage($title);
         // if no form can be found, return
         if (count($form_names) == 0) {
             return $this->reportError(wfMsg('sf_autoedit_noformfound'));
         }
         // if more than one form found, return
         if (count($form_names) > 1) {
             return $this->reportError(wfMsg('sf_autoedit_toomanyformsfound'));
         }
         // There should now be exactly one form.
         $this->mOptions['form'] = $form_names[0];
     }
     // we only care for the form's body
     $wgOut->setArticleBodyOnly(true);
     $formedit = new SFFormEdit();
     $data = array();
     $oldRequest = $wgRequest;
     // Get the form definition and target page (if there is one),
     // as specified in the options string, then create the actual
     // HTML form from them, and call that form to modify or create
     // the page.
     if ($prefillFromExisting) {
         $wgRequest = new FauxRequest($this->mOptions, true);
         // get the Semantic Form
         if ($this->mOptions['target']) {
             $formedit->execute($this->mOptions['form'] . '/' . $this->mOptions['target']);
         } else {
             $formedit->execute($this->mOptions['form']);
         }
         // extract its data
         $form = $this->parseDataFromHTMLFrag($data, trim($wgOut->getHTML()), 'sfForm');
         if (!$form) {
             // something went wrong
             $wgRequest = $oldRequest;
             return $this->reportError(wfMsg('sf_autoedit_nosemanticform', array($this->mOptions['target'], $this->mOptions['form'])));
         }
     } else {
         self::addToArray($data, "wpSave", "Save");
     }
     // and modify as specified
     $data = SFUtils::array_merge_recursive_distinct($data, $this->mOptions);
     ////////////////////////////////////////////////////////////////////////
     // Store the modified form
     // $wgOut->clearHTML();
     $wgRequest = new FauxRequest($data, true);
     // get the MW form
     if ($this->mOptions['target']) {
         $formedit->execute($this->mOptions['form'] . '/' . $this->mOptions['target'], false);
     } else {
         $formedit->execute($this->mOptions['form'], false);
     }
     $this->mOptions['form'] = $formedit->mForm;
     $this->mOptions['target'] = $formedit->mTarget;
     $wgRequest = $oldRequest;
     if ($formedit->mError) {
         return $this->reportError($formedit->mError);
     } else {
         if (!headers_sent()) {
             header("X-Location: " . $wgOut->getRedirect());
             header("X-Form: " . $formedit->mForm);
             header("X-Target: " . $formedit->mTarget);
         }
         if ($this->isApiQuery()) {
             $this->getResult()->addValue(null, 'result', array('code' => '200', 'location' => $wgOut->getRedirect(), 'form' => $formedit->mForm, 'target' => $formedit->mTarget));
         }
     }
     return true;
 }
示例#2
0
 /**
  * The function called if we're in index.php (as opposed to one of the
  * special pages)
  */
 static function displayForm($action, $article)
 {
     global $wgOut, $sfgUseFormEditPage;
     // return "true" if the call failed (meaning, pass on handling
     // of the hook to others), and "false" otherwise
     if ($action != 'formedit') {
         return true;
     }
     // @todo: This looks like bad code. If we can't find a form, we
     // should be showing an informative error page rather than
     // making it look like an edit form page does not exist.
     $title = $article->getTitle();
     $form_names = SFFormLinker::getDefaultFormsForPage($title);
     if (count($form_names) == 0) {
         return true;
     }
     if (count($form_names) > 1) {
         $warning_text = "\t" . '<div class="warningMessage">' . wfMsg('sf_formedit_morethanoneform') . "</div>\n";
         $wgOut->addHTML($warning_text);
     }
     $form_name = $form_names[0];
     if ($sfgUseFormEditPage) {
         # Experimental new feature extending from the internal
         # EditPage class
         $editor = new SFFormEditPage($article, $form_name);
         $editor->edit();
         return false;
     }
     $page_name = SFUtils::titleString($title);
     $msg = SFFormEdit::printForm($form_name, $page_name);
     if ($msg) {
         // Some error occurred - display it.
         $msgdata = null;
         if (is_array($msg)) {
             if (count($msg) > 1) {
                 $msgdata = $msg[1];
             }
             $msg = $msg[0];
         }
         $wgOut->addHTML(Html::element('p', array('class' => 'error'), wfMsg($msg, $msgdata)));
     }
     return false;
 }
 /**
  * The function called if we're in index.php (as opposed to one of the
  * special pages)
  */
 static function displayForm($action, $article)
 {
     // @todo: This looks like bad code. If we can't find a form, we
     // should be showing an informative error page rather than
     // making it look like an edit form page does not exist.
     $title = $article->getTitle();
     $form_names = SFFormLinker::getDefaultFormsForPage($title);
     if (count($form_names) == 0) {
         return true;
     }
     $output = $action->getOutput();
     if (count($form_names) > 1) {
         $warning_text = "\t" . '<div class="warningbox">' . wfMessage('sf_formedit_morethanoneform')->text() . "</div>\n";
         $output->addWikiText($warning_text);
     }
     $form_name = $form_names[0];
     $page_name = SFUtils::titleString($title);
     SFFormEdit::printForm($form_name, $page_name);
     return false;
 }
 /**
  * The function called if we're in index.php (as opposed to one of the
  * special pages)
  */
 static function displayForm($action, $article)
 {
     $output = $action->getOutput();
     $title = $article->getTitle();
     $form_names = SFFormLinker::getDefaultFormsForPage($title);
     if (count($form_names) == 0) {
         // If no form is set, display an interface to let the
         // user choose out of all the forms defined on this wiki
         // (or none at all).
         self::displayFormChooser($output, $title);
         return true;
     }
     if (count($form_names) > 1) {
         $warning_text = "\t" . '<div class="warningbox">' . wfMessage('sf_formedit_morethanoneform')->text() . "</div>\n";
         $output->addWikiText($warning_text);
     }
     $form_name = $form_names[0];
     $page_name = SFUtils::titleString($title);
     $sfFormEdit = new SFFormEdit();
     $sfFormEdit->printForm($form_name, $page_name);
     return false;
 }
示例#5
0
 /**
  * The function called if we're in index.php (as opposed to one of the
  * special pages)
  */
 static function displayForm($action, $article)
 {
     // TODO: This function will be called as a hook handler and $action will
     //  be a string before MW 1.18. From 1.18 onwards this function will
     //  only be called for formedit actions, i.e. the if statement can be
     //  removed then.
     // return "true" if the call failed (meaning, pass on handling
     // of the hook to others), and "false" otherwise
     if (is_string($action) && $action !== 'formedit') {
         return true;
     }
     // @todo: This looks like bad code. If we can't find a form, we
     // should be showing an informative error page rather than
     // making it look like an edit form page does not exist.
     $title = $article->getTitle();
     $form_names = SFFormLinker::getDefaultFormsForPage($title);
     if (count($form_names) == 0) {
         return true;
     }
     // For backward-compatibility
     if (is_string($action)) {
         global $wgOut;
         $output = $wgOut;
     } else {
         $output = $action->getOutput();
     }
     if (count($form_names) > 1) {
         $warning_text = "\t" . '<div class="warningbox">' . wfMessage('sf_formedit_morethanoneform')->text() . "</div>\n";
         $output->addWikiText($warning_text);
     }
     $form_name = $form_names[0];
     $page_name = SFUtils::titleString($title);
     SFFormEdit::printForm($form_name, $page_name);
     return false;
 }
示例#6
0
 /**
  * The function called if we're in index.php (as opposed to one of the
  * special pages)
  */
 static function displayForm($action, $article)
 {
     global $sfgUseFormEditPage;
     // TODO: This function will be called as a hook handler and $action will
     //  be a string before MW 1.18. From 1.18 onwards this function will#
     //  only be called for formedit actions, i.e. the if statement can be
     //  removed then.
     // return "true" if the call failed (meaning, pass on handling
     // of the hook to others), and "false" otherwise
     if (is_string($action) && $action !== 'formedit') {
         return true;
     }
     // @todo: This looks like bad code. If we can't find a form, we
     // should be showing an informative error page rather than
     // making it look like an edit form page does not exist.
     $title = $article->getTitle();
     $form_names = SFFormLinker::getDefaultFormsForPage($title);
     if (count($form_names) == 0) {
         return true;
     }
     // For backward-compatibility
     if (is_string($action)) {
         global $wgOut;
         $output = $wgOut;
     } else {
         $output = $action->getOutput();
     }
     if (count($form_names) > 1) {
         $warning_text = "\t" . '<div class="warningbox">' . wfMsg('sf_formedit_morethanoneform') . "</div>\n";
         $output->addWikiText($warning_text);
     }
     $form_name = $form_names[0];
     if ($sfgUseFormEditPage) {
         # Experimental new feature extending from the internal
         # EditPage class
         $editor = new SFFormEditPage($article, $form_name);
         $editor->edit();
         return false;
     }
     $page_name = SFUtils::titleString($title);
     $msg = SFFormEdit::printForm($form_name, $page_name);
     if ($msg) {
         // Some error occurred - display it.
         $msgdata = null;
         if (is_array($msg)) {
             if (count($msg) > 1) {
                 $msgdata = $msg[1];
             }
             $msg = $msg[0];
         }
         $output->addHTML(Html::element('p', array('class' => 'error'), wfMsg($msg, $msgdata)));
     }
     return false;
 }