static function printForm(&$form_name, &$target_name, $alt_forms = array()) { global $wgOut, $wgRequest; if (method_exists('ApiMain', 'getContext')) { $module = new SFAutoeditAPI(new ApiMain(), 'sfautoedit'); } else { // TODO: remove else branch when raising supported version to MW 1.19 $module = new SFAutoeditAPI(new ApiMain($wgRequest), 'sfautoedit'); } $module->setOption('form', $form_name); $module->setOption('target', $target_name); // if the page was submitted, formdata should be complete => do not preload $module->setOption('preload', !$wgRequest->getCheck('wpSave') && !$wgRequest->getCheck('wpPreview')); $module->execute(); // if action was successful and action was a Save, return if ($module->getStatus() === 200 && $module->getAction() === SFAutoeditAPI::ACTION_SAVE) { return; } // override the default title for this page if a title was specified in the form $result = $module->getOptions(); $target_title = Title::newFromText($result['target']); if ($result['form'] !== '') { if ($target_name === null || $target_name === '') { $wgOut->setPageTitle($result['form']); } else { $wgOut->setPageTitle($result['form'] . ': ' . $target_name); } } $text = ''; if (count($alt_forms) > 0) { $text .= '<div class="infoMessage">' . wfMessage('sf_formedit_altforms')->escaped() . ' '; $text .= self::printAltFormsList($alt_forms, $target_name); $text .= "</div>\n"; } $text .= '<form name="createbox" id="sfForm" method="post" class="createbox">'; $pre_form_html = ''; wfRunHooks('sfHTMLBeforeForm', array(&$target_title, &$pre_form_html)); $text .= $pre_form_html; $text .= $result['formHTML']; SFUtils::addJavascriptAndCSS(); $javascript_text = $result['formJS']; if (!empty($javascript_text)) { $wgOut->addScript(' <script type="text/javascript">' . "\n{$javascript_text}\n" . '</script>' . "\n"); } $wgOut->addHTML($text); return null; }
function printForm($form_name, $targetName, $alt_forms = array()) { $out = $this->getOutput(); $req = $this->getRequest(); $module = new SFAutoeditAPI(new ApiMain(), 'sfautoedit'); $module->setOption('form', $form_name); $module->setOption('target', $targetName); if ($req->getCheck('wpSave') || $req->getCheck('wpPreview') || $req->getCheck('wpDiff')) { // If the page was submitted, form data should be // complete => do not preload (unless it's a partial // form). if ($req->getCheck('partial')) { $module->setOption('preload', true); } else { $module->setOption('preload', false); } } else { if (!empty($targetName) && Title::newFromText($targetName)->exists()) { // If target page exists, do not overwrite it with // preload data; just preload the page's data. $module->setOption('preload', true); } else { if ($req->getCheck('preload')) { // if page does not exist and preload parameter is set, pass that on $module->setOption('preload', $req->getText('preload')); } else { // nothing set, so do not set preload } } } $module->execute(); $text = ''; // if action was successful and action was a Save, return if ($module->getStatus() === 200) { if ($module->getAction() === SFAutoeditAPI::ACTION_SAVE) { return; } } else { $resultData = $module->getResultData(); if (array_key_exists('errors', $resultData)) { foreach ($resultData['errors'] as $error) { // FIXME: This should probably not be hard-coded to WARNING but put into a setting if ($error['level'] <= SFAutoeditAPI::WARNING) { $text .= Html::rawElement('p', array('class' => 'error'), $error['message']) . "\n"; } } } } // Override the default title for this page if a title was // specified in the form. $result = $module->getOptions(); $targetTitle = Title::newFromText($result['target']); // Set page title depending on whether an explicit title was // specified in the form definition. if (array_key_exists('formtitle', $result)) { // set page title depending on whether the target page exists if (empty($targetName)) { $pageTitle = $result['formtitle']; } else { $pageTitle = $result['formtitle'] . ': ' . $targetName; } } elseif ($result['form'] !== '') { // Set page title depending on whether the target page // exists. if (empty($targetName)) { $pageTitle = wfMessage('sf_formedit_createtitlenotarget', $result['form'])->text(); } elseif ($targetTitle->exists()) { $pageTitle = wfMessage('sf_formedit_edittitle', $result['form'], $targetName)->text(); } else { $pageTitle = wfMessage('sf_formedit_createtitle', $result['form'], $targetName)->text(); } } elseif (count($alt_forms) > 0) { // We use the 'creating' message here, instead of // 'sf_formedit_createtitlenotarget', to differentiate // between a page with no (default) form, and one with // no target; in English they'll show up as // "Creating ..." and "Create ...", respectively. // Does this make any difference? Who knows. $pageTitle = wfMessage('creating', $targetName)->text(); } elseif ($result['form'] == '') { //FIXME: This looks weird; a simple else should be enough, right? // display error message if the form is not specified in the URL $pageTitle = wfMessage('formedit')->text(); $text .= Html::element('p', array('class' => 'error'), wfMessage('sf_formedit_badurl')->text()) . "\n"; $out->addHTML($text); } $out->setPageTitle($pageTitle); if (count($alt_forms) > 0) { $text .= '<div class="infoMessage">'; if ($result['form'] != '') { $text .= wfMessage('sf_formedit_altforms')->escaped(); } else { $text .= wfMessage('sf_formedit_altformsonly')->escaped(); } $text .= ' ' . $this->printAltFormsList($alt_forms, $targetName); $text .= "</div>\n"; } $text .= '<form name="createbox" id="sfForm" method="post" class="createbox">'; $pre_form_html = ''; Hooks::run('sfHTMLBeforeForm', array(&$targetTitle, &$pre_form_html)); $text .= $pre_form_html; if (isset($result['formHTML'])) { $text .= $result['formHTML']; } SFUtils::addFormRLModules(); if (isset($result['formJS'])) { if (method_exists('ResourceLoader', 'makeInlineScript')) { // MW 1.25+ $out->addScript(ResourceLoader::makeInlineScript($result['formJS'])); } else { $out->addScript(' <script type="text/javascript">' . "\n{$result['formJS']}\n" . '</script>' . "\n"); } } $out->addHTML($text); return null; }