function createMarkup() { $title = Title::makeTitle(SF_NS_FORM, $this->mFormName); $fs = SFUtils::getSpecialPage('FormStart'); $form_start_url = SFUtils::titleURLString($fs->getTitle()) . "/" . $title->getPartialURL(); $form_description = wfMsgForContent('sf_form_docu', $this->mFormName, $form_start_url); $form_input = "{{#forminput:form=" . $this->mFormName; if (!is_null($this->mAssociatedCategory)) { $form_input .= "|autocomplete on category=" . $this->mAssociatedCategory; } $form_input .= "}}\n"; $text = <<<END <noinclude> {$form_description} {$form_input} </noinclude><includeonly> END; if (!empty($this->mPageNameFormula) || !empty($this->mCreateTitle) || !empty($this->mEditTitle)) { $text .= "{{{info"; if (!empty($this->mPageNameFormula)) { $text .= "|page name=" . $this->mPageNameFormula; } if (!empty($this->mCreateTitle)) { $text .= "|create title=" . $this->mCreateTitle; } if (!empty($this->mEditTitle)) { $text .= "|edit title=" . $this->mEditTitle; } $text .= "}}}\n"; } $text .= <<<END <div id="wikiPreview" style="display: none; padding-bottom: 25px; margin-bottom: 25px; border-bottom: 1px solid #AAAAAA;"></div> END; foreach ($this->mTemplates as $template) { $text .= $template->createMarkup() . "\n"; } $free_text_label = wfMsgForContent('sf_form_freetextlabel'); $text .= <<<END '''{$free_text_label}:''' {{{standard input|free text|rows=10}}} {{{standard input|summary}}} {{{standard input|minor edit}}} {{{standard input|watch}}} {{{standard input|save}}} {{{standard input|preview}}} {{{standard input|changes}}} {{{standard input|cancel}}} </includeonly> END; return $text; }
function execute( $query ) { global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; global $wgLang, $smwgContLang; # Check permissions if ( !$wgUser->isAllowed( 'createclass' ) ) { $this->displayRestrictionError(); return; } $this->setHeaders(); $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css" ); $numStartingRows = 10; self::addJavascript( $numStartingRows ); $property_name_error_str = ''; $save_page = $wgRequest->getCheck( 'save' ); if ( $save_page ) { $template_name = trim( $wgRequest->getVal( "template_name" ) ); $form_name = trim( $wgRequest->getVal( "form_name" ) ); $category_name = trim( $wgRequest->getVal( "category_name" ) ); if ( $template_name === '' | $form_name === '' || $category_name === '' ) { $wgOut->addWikiMsg( 'sf_createclass_missingvalues' ); return; } $fields = array(); $jobs = array(); // cycle through all the rows passed in for ( $i = 1; $wgRequest->getCheck( "property_name_$i" ); $i++ ) { // go through the query values, setting the appropriate local variables $property_name = trim( $wgRequest->getVal( "property_name_$i" ) ); if ( empty( $property_name ) ) continue; $field_name = trim( $wgRequest->getVal( "field_name_$i" ) ); if ( $field_name === '' ) $field_name = $property_name; $property_type = $wgRequest->getVal( "property_type_$i" ); $allowed_values = $wgRequest->getVal( "allowed_values_$i" ); $is_list = $wgRequest->getCheck( "is_list_$i" ); // create an SFTemplateField based on these // values, and add it to the $fields array $field = SFTemplateField::create( $field_name, $field_name, $property_name, $is_list ); $fields[] = $field; // create the property, and make a job for it $full_text = SFCreateProperty::createPropertyText( $property_type, '', $allowed_values ); $property_title = Title::makeTitleSafe( SMW_NS_PROPERTY, $property_name ); $params = array(); $params['user_id'] = $wgUser->getId(); $params['page_text'] = $full_text; $jobs[] = new SFCreatePageJob( $property_title, $params ); } // create the template, and save it $full_text = SFTemplateField::createTemplateText( $template_name, $fields, null, $category_name, null, null, null ); $template_title = Title::makeTitleSafe( NS_TEMPLATE, $template_name ); $template_article = new Article( $template_title, 0 ); $edit_summary = ''; $template_article->doEdit( $full_text, $edit_summary ); // create the form, and make a job for it $form_template = SFTemplateInForm::create( $template_name, '', false ); $form_templates = array( $form_template ); $form = SFForm::create( $form_name, $form_templates ); $full_text = $form->createMarkup(); $form_title = Title::makeTitleSafe( SF_NS_FORM, $form_name ); $params = array(); $params['user_id'] = $wgUser->getId(); $params['page_text'] = $full_text; $jobs[] = new SFCreatePageJob( $form_title, $params ); // create the category, and make a job for it $full_text = SFCreateCategory::createCategoryText( $form_name, $category_name, '' ); $category_title = Title::makeTitleSafe( NS_CATEGORY, $category_name ); $params = array(); $params['user_id'] = $wgUser->getId(); $params['page_text'] = $full_text; $jobs[] = new SFCreatePageJob( $category_title, $params ); Job::batchInsert( $jobs ); $wgOut->addWikiMsg( 'sf_createclass_success' ); return; } $datatype_labels = $smwgContLang->getDatatypeLabels(); // make links to all the other 'Create...' pages, in order to // link to them at the top of the page $sk = $wgUser->getSkin(); $creation_links = array(); $creation_links[] = SFUtils::linkForSpecialPage( $sk, 'CreateProperty' ); $creation_links[] = SFUtils::linkForSpecialPage( $sk, 'CreateTemplate' ); $creation_links[] = SFUtils::linkForSpecialPage( $sk, 'CreateForm' ); $creation_links[] = SFUtils::linkForSpecialPage( $sk, 'CreateCategory' ); $create_class_docu = wfMsg( 'sf_createclass_docu', $wgLang->listToText( $creation_links ) ); $leave_field_blank = wfMsg( 'sf_createclass_leavefieldblank' ); $form_name_label = wfMsg( 'sf_createclass_nameinput' ); $template_name_label = wfMsg( 'sf_createtemplate_namelabel' ); $category_name_label = wfMsg( 'sf_createcategory_name' ); $property_name_label = wfMsg( 'sf_createproperty_propname' ); $field_name_label = wfMsg( 'sf_createtemplate_fieldname' ); $type_label = wfMsg( 'sf_createproperty_proptype' ); $allowed_values_label = wfMsg( 'sf_createclass_allowedvalues' ); $list_of_values_label = wfMsg( 'sf_createclass_listofvalues' ); $text = <<<END <form action="" method="post"> <p>$create_class_docu</p> <p>$leave_field_blank</p> <p>$template_name_label <input type="text" size="30" name="template_name"></p> <p>$form_name_label <input type="text" size="30" name="form_name"></p> <p>$category_name_label <input type="text" size="30" name="category_name"></p> <div> <table id="mainTable"> <tr> <th colspan="2">$property_name_label</th> <th>$field_name_label</th> <th>$type_label</th> <th>$allowed_values_label</th> <th>$list_of_values_label</th> </tr> END; // Make one more row than what we're displaying - use the // last row as a "starter row", to be cloned when the // "Add another" button is pressed. for ( $i = 1; $i <= $numStartingRows + 1; $i++ ) { if ( $i == $numStartingRows + 1 ) { $rowString = 'id="starterRow" style="display: none"'; $n = 'starter'; } else { $rowString = ''; $n = $i; } $text .= <<<END <tr $rowString> <td>$n.</td> <td><input type="text" size="25" name="property_name_$n" /></td> <td><input type="text" size="25" name="field_name_$n" /></td> <td> <select name="property_type_$n"> END; $optionsStr =""; foreach ( $datatype_labels as $label ) { $text .= " <option>$label</option>\n"; $optionsStr .= $label . ","; } $text .= <<<END </select> </td> <td><input type="text" size="25" name="allowed_values_$n" /></td> <td><input type="checkbox" name="is_list_$n" /></td> END; } $text .= <<<END </tr> </table> </div> END; $add_another_button = Html::element( 'input', array( 'type' => 'button', 'value' => wfMsg( 'sf_formedit_addanother' ), 'onclick' => "createClassAddRow()" ) ); $text .= Html::rawElement( 'p', null, $add_another_button ) . "\n"; // Set 'title' as hidden field, in case there's no URL niceness $cc = $this->getTitle(); $text .= SFFormUtils::hiddenFieldHTML( 'title', SFUtils::titleURLString( $cc ) ); $text .= Html::element( 'input', array( 'type' => 'submit', 'name' => 'save', 'value' => wfMsg( 'sf_createclass_create' ) ) ); $text .= "</form>\n"; $wgOut->addHTML( $text ); }
/** * Helper function for formEditLink() - gets the 'default form' and * 'alternate form' properties for a page, and creates the * corresponding Special:FormEdit link, if any such properties are * defined */ static function getFormEditLinkForPage($target_page_title, $page_name, $page_namespace) { $default_forms = self::getFormsThatPagePointsTo($page_name, $page_namespace, self::DEFAULT_FORM); $alt_forms = self::getFormsThatPagePointsTo($page_name, $page_namespace, self::ALTERNATE_FORM); if (count($default_forms) == 0 && count($alt_forms) == 0) { return null; } $fe = SpecialPageFactory::getPage('FormEdit'); $fe_url = $fe->getTitle()->getLocalURL(); if (count($default_forms) > 0) { $form_edit_url = $fe_url . "/" . $default_forms[0] . "/" . SFUtils::titleURLString($target_page_title); } else { $form_edit_url = $fe_url; $form_edit_url .= strpos($form_edit_url, "?") ? "&" : "?"; $form_edit_url .= 'target=' . urlencode(SFUtils::titleString($target_page_title)); } foreach ($alt_forms as $i => $alt_form) { $form_edit_url .= strpos($form_edit_url, "?") ? "&" : "?"; $form_edit_url .= "alt_form[{$i}]={$alt_form}"; } // Add "redlink=1" to the query string, so that the user will // go to the actual page if it now exists. $form_edit_url .= strpos($form_edit_url, "?") ? "&" : "?"; $form_edit_url .= "redlink=1"; return $form_edit_url; }
/** * Helper function for formEditLink() - gets the 'default form' and * 'alternate form' properties for a page, and creates the * corresponding Special:FormEdit link, if any such properties are * defined */ static function getFormEditLinkForPage( $target_page_title, $page_name, $page_namespace ) { $default_forms = self::getFormsThatPagePointsTo( $page_name, $page_namespace, self::DEFAULT_FORM ); $alt_forms = self::getFormsThatPagePointsTo( $page_name, $page_namespace, self::ALTERNATE_FORM ); if ( ( count( $default_forms ) == 0 ) && ( count( $alt_forms ) == 0 ) ) { return null; } $fe = SFUtils::getSpecialPage( 'FormEdit' ); $fe_url = $fe->getTitle()->getLocalURL(); if ( count( $default_forms ) > 0 ) { $form_edit_url = $fe_url . "/" . $default_forms[0] . "/" . SFUtils::titleURLString( $target_page_title ); } else { $form_edit_url = $fe_url . "/" . SFUtils::titleURLString( $target_page_title ); } foreach ( $alt_forms as $i => $alt_form ) { $form_edit_url .= ( strpos( $form_edit_url, "?" ) ) ? "&" : "?"; $form_edit_url .= "alt_form[$i]=$alt_form"; } return $form_edit_url; }
function doRedirect($form_name, $page_name, $params) { global $wgOut; $page_title = Title::newFromText($page_name); if ($page_title->exists()) { // It exists - see if page is a redirect; if // it is, edit the target page instead. $article = new Article($page_title, 0); $article->loadContent(); $redirect_title = Title::newFromRedirect($article->fetchContent()); if ($redirect_title != null) { $page_title = $redirect_title; $page_name = SFUtils::titleURLString($redirect_title); } // HACK - if this is the default form for // this page, send to the regular 'formedit' // tab page; otherwise, send to the 'Special:FormEdit' // page, with the form name hardcoded. // Is this logic necessary? Or should we just // out-guess the user and always send to the // standard form-edit page, with the 'correct' form? $default_forms = SFFormLinker::getDefaultFormsForPage($page_title); if (count($default_forms) > 0) { $default_form_name = $default_forms[0]; } else { $default_form_name = null; } if ($form_name == $default_form_name) { $redirect_url = $page_title->getLocalURL('action=formedit'); } else { $redirect_url = self::getFormEditURL($form_name, $page_name); } } else { $redirect_url = self::getFormEditURL($form_name, $page_name); // Of all the request values, send on to 'FormEdit' // only 'preload' and specific form fields - we can // identify the latter because they show up as arrays. foreach ($_REQUEST as $key => $val) { if (is_array($val)) { $template_name = urlencode($key); foreach ($val as $field_name => $value) { $field_name = urlencode($field_name); $value = urlencode($value); $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= $template_name . '[' . $field_name . ']=' . $value; } } elseif ($key == 'preload') { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= "{$key}={$val}"; } } } if (!is_null($params) && $params !== '') { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= $params; } $wgOut->setArticleBodyOnly(true); // Show "loading" animated image while people wait for the // redirect. global $sfgScriptPath; $text = "<p style=\"position: absolute; left: 45%; top: 45%;\"><img src=\"{$sfgScriptPath}/skins/loading.gif\" /></p>\n"; $text .= <<<END \t\t<script type="text/javascript"> \t\twindow.onload = function() { \t\t\twindow.location="{$redirect_url}"; \t\t} \t\t</script> END; $wgOut->addHTML($text); return; }
function execute($query) { global $wgLang, $smwgContLang; $out = $this->getOutput(); $req = $this->getRequest(); // Check permissions. if (!$this->getUser()->isAllowed('createclass')) { $this->displayRestrictionError(); return; } $this->setHeaders(); $numStartingRows = 5; $out->addJsConfigVars('$numStartingRows', $numStartingRows); $out->addModules(array('ext.semanticforms.SF_CreateClass')); $createAll = $req->getCheck('createAll'); if ($createAll) { // Guard against cross-site request forgeries (CSRF). $validToken = $this->getUser()->matchEditToken($req->getVal('csrf'), 'CreateClass'); if (!$validToken) { $text = "This appears to be a cross-site request forgery; canceling save."; $out->addHTML($text); return; } $this->createAllPages(); return; } $specialBGColor = '#eeffcc'; if (defined('SMW_VERSION')) { $possibleTypes = $smwgContLang->getDatatypeLabels(); } elseif (defined('CARGO_VERSION')) { global $wgCargoFieldTypes; $possibleTypes = $wgCargoFieldTypes; $specialBGColor = ''; } else { $possibleTypes = array(); } // Make links to all the other 'Create...' pages, in order to // link to them at the top of the page. $creation_links = array(); if (defined('SMW_VERSION')) { $creation_links[] = SFUtils::linkForSpecialPage('CreateProperty'); } $creation_links[] = SFUtils::linkForSpecialPage('CreateTemplate'); $creation_links[] = SFUtils::linkForSpecialPage('CreateForm'); $creation_links[] = SFUtils::linkForSpecialPage('CreateCategory'); $text = '<form action="" method="post">' . "\n"; $text .= "\t" . Html::rawElement('p', null, wfMessage('sf_createclass_docu')->rawParams($wgLang->listToText($creation_links))->escaped()) . "\n"; $templateNameLabel = wfMessage('sf_createtemplate_namelabel')->escaped(); $templateNameInput = Html::input('template_name', null, 'text', array('size' => 30)); $text .= "\t" . Html::rawElement('p', null, $templateNameLabel . ' ' . $templateNameInput) . "\n"; $templateInfo = SFCreateTemplate::printTemplateStyleInput('template_format'); $templateInfo .= Html::rawElement('p', null, Html::element('input', array('type' => 'checkbox', 'name' => 'template_multiple', 'id' => 'template_multiple', 'class' => "disableFormAndCategoryInputs")) . ' ' . wfMessage('sf_createtemplate_multipleinstance')->escaped()) . "\n"; // Either #set_internal or #subobject will be added to the // template, depending on whether Semantic Internal Objects is // installed. global $smwgDefaultStore; if (defined('SIO_VERSION') || $smwgDefaultStore == "SMWSQLStore3") { $templateInfo .= Html::rawElement('div', array('id' => 'connecting_property_div', 'style' => 'display: none;'), wfMessage('sf_createtemplate_connectingproperty')->escaped() . "\n" . Html::element('input', array('type' => 'text', 'name' => 'connecting_property'))) . "\n"; } $text .= Html::rawElement('blockquote', null, $templateInfo); $form_name_label = wfMessage('sf_createclass_nameinput')->text(); $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'form_name'), $form_name_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'form_name', 'id' => 'form_name'), null)) . "\n"; $category_name_label = wfMessage('sf_createcategory_name')->text(); $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'category_name'), $category_name_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'category_name', 'id' => 'category_name'), null)) . "\n"; if (defined('CARGO_VERSION') && !defined('SMW_VERSION')) { $cargo_table_label = wfMessage('sf_createtemplate_cargotablelabel')->escaped(); $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'cargo_table'), $cargo_table_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'cargo_table', 'id' => 'cargo_table'), null)) . "\n"; } $text .= "\t" . Html::element('br', null, null) . "\n"; $text .= <<<END \t<div> \t\t<table id="mainTable" style="border-collapse: collapse;"> END; if (defined('SMW_VERSION')) { $property_label = wfMessage('smw_pp_type')->escaped(); $text .= <<<END \t\t<tr> \t\t\t<th colspan="3" /> \t\t\t<th colspan="3" style="background: #ddeebb; padding: 4px;">{$property_label}</th> \t\t</tr> END; } $field_name_label = wfMessage('sf_createtemplate_fieldname')->escaped(); $list_of_values_label = wfMessage('sf_createclass_listofvalues')->escaped(); $text .= <<<END \t\t<tr> \t\t\t<th colspan="2">{$field_name_label}</th> \t\t\t<th style="padding: 4px;">{$list_of_values_label}</th> END; if (defined('SMW_VERSION')) { $property_name_label = wfMessage('sf_createproperty_propname')->escaped(); $text .= <<<END \t\t\t<th style="background: {$specialBGColor}; padding: 4px;">{$property_name_label}</th> END; } $type_label = wfMessage('sf_createproperty_proptype')->escaped(); $allowed_values_label = wfMessage('sf_createclass_allowedvalues')->escaped(); $text .= <<<END \t\t\t<th style="background: {$specialBGColor}; padding: 4px;">{$type_label}</th> \t\t\t<th style="background: {$specialBGColor}; padding: 4px;">{$allowed_values_label}</th> \t\t</tr> END; // Make one more row than what we're displaying - use the // last row as a "starter row", to be cloned when the // "Add another" button is pressed. for ($i = 1; $i <= $numStartingRows + 1; $i++) { if ($i == $numStartingRows + 1) { $rowString = 'id="starterRow" style="display: none"'; $n = 'starter'; } else { $rowString = ''; $n = $i; } $text .= <<<END \t\t<tr {$rowString} style="margin: 4px;"> \t\t\t<td>{$n}.</td> \t\t\t<td><input type="text" size="25" name="field_name_{$n}" /></td> \t\t\t<td style="text-align: center;"><input type="checkbox" name="is_list_{$n}" /></td> END; if (defined('SMW_VERSION')) { $text .= <<<END \t\t\t<td style="background: {$specialBGColor}; padding: 4px;"><input type="text" size="25" name="property_name_{$n}" /></td> END; } $text .= <<<END \t\t\t<td style="background: {$specialBGColor}; padding: 4px;"> END; $typeDropdownBody = ''; foreach ($possibleTypes as $typeName) { $typeDropdownBody .= "\t\t\t\t<option>{$typeName}</option>\n"; } $text .= "\t\t\t\t" . Html::rawElement('select', array('name' => "property_type_{$n}"), $typeDropdownBody) . "\n"; $text .= <<<END \t\t\t</td> \t\t\t<td style="background: {$specialBGColor}; padding: 4px;"><input type="text" size="25" name="allowed_values_{$n}" /></td> END; } $text .= <<<END \t\t</tr> \t\t</table> \t</div> END; $add_another_button = Html::element('input', array('type' => 'button', 'value' => wfMessage('sf_formedit_addanother')->text(), 'class' => "createClassAddRow")); $text .= Html::rawElement('p', null, $add_another_button) . "\n"; // Set 'title' as hidden field, in case there's no URL niceness $cc = $this->getTitle(); $text .= Html::hidden('title', SFUtils::titleURLString($cc)); $text .= "\t" . Html::hidden('csrf', $this->getUser()->getEditToken('CreateClass')) . "\n"; $text .= Html::element('input', array('type' => 'submit', 'name' => 'createAll', 'value' => wfMessage('sf_createclass_create')->text())); $text .= "</form>\n"; $out->addHTML($text); }
function createMarkup($standardInputs = array(), $freeTextLabel = null) { $title = Title::makeTitle(SF_NS_FORM, $this->mFormName); $fs = SpecialPageFactory::getPage('FormStart'); $form_start_url = SFUtils::titleURLString($fs->getTitle()) . "/" . $title->getPartialURL(); $form_description = wfMessage('sf_form_docu', $this->mFormName, $form_start_url)->inContentLanguage()->text(); $form_input = "{{#forminput:form=" . $this->mFormName; if (!is_null($this->mAssociatedCategory)) { $form_input .= "|autocomplete on category=" . $this->mAssociatedCategory; } $form_input .= "}}\n"; $text = <<<END <noinclude> {$form_description} {$form_input} </noinclude><includeonly> END; if (!empty($this->mPageNameFormula) || !empty($this->mCreateTitle) || !empty($this->mEditTitle)) { $text .= "{{{info"; if (!empty($this->mPageNameFormula)) { $text .= "|page name=" . $this->mPageNameFormula; } if (!empty($this->mCreateTitle)) { $text .= "|create title=" . $this->mCreateTitle; } if (!empty($this->mEditTitle)) { $text .= "|edit title=" . $this->mEditTitle; } $text .= "}}}\n"; } $text .= <<<END <div id="wikiPreview" style="display: none; padding-bottom: 25px; margin-bottom: 25px; border-bottom: 1px solid #AAAAAA;"></div> END; foreach ($this->mItems as $item) { if ($item['type'] == 'template') { $template = $item['item']; $text .= $template->createMarkup() . "\n"; } elseif ($item['type'] == 'section') { $section = $item['item']; $text .= $section->createMarkup() . "\n"; } } if (is_null($freeTextLabel)) { $freeTextLabel = wfMessage('sf_form_freetextlabel')->inContentLanguage()->text(); } // Add in standard inputs if they were specified. if (count($standardInputs) > 0) { if (array_key_exists('free text', $standardInputs)) { $text .= "'''{$freeTextLabel}:'''\n\n"; $text .= $standardInputs['free text'] . "\n\n\n"; } if (array_key_exists('summary', $standardInputs)) { $text .= $standardInputs['summary'] . "\n\n"; } if (array_key_exists('minor edit', $standardInputs)) { $text .= $standardInputs['minor edit'] . ' '; } if (array_key_exists('watch', $standardInputs)) { $text .= $standardInputs['watch']; } if (array_key_exists('minor edit', $standardInputs) || array_key_exists('watch', $standardInputs)) { $text .= "\n\n"; } if (array_key_exists('save', $standardInputs)) { $text .= $standardInputs['save'] . ' '; } if (array_key_exists('preview', $standardInputs)) { $text .= $standardInputs['preview'] . ' '; } if (array_key_exists('changes', $standardInputs)) { $text .= $standardInputs['changes'] . ' '; } if (array_key_exists('cancel', $standardInputs)) { $text .= $standardInputs['cancel']; } } else { $text .= <<<END '''{$freeTextLabel}:''' {{{standard input|free text|rows=10}}} {{{standard input|summary}}} {{{standard input|minor edit}}} {{{standard input|watch}}} {{{standard input|save}}} {{{standard input|preview}}} {{{standard input|changes}}} {{{standard input|cancel}}} END; } $text .= "\n</includeonly>\n"; return $text; }
function doRedirect($form_name, $page_name, $params) { global $wgOut; $page_title = Title::newFromText($page_name); if ($page_title->exists()) { // It exists - see if page is a redirect; if // it is, edit the target page instead. $article = new Article($page_title, 0); $article->loadContent(); $redirect_title = Title::newFromRedirect($article->fetchContent()); if ($redirect_title != null) { $page_title = $redirect_title; $page_name = SFUtils::titleURLString($redirect_title); } // HACK - if this is the default form for // this page, send to the regular 'formedit' // tab page; otherwise, send to the 'Special:FormEdit' // page, with the form name hardcoded. // Is this logic necessary? Or should we just // out-guess the user and always send to the // standard form-edit page, with the 'correct' form? $default_forms = SFFormLinker::getDefaultFormsForPage($page_title); if (count($default_forms) > 0) { $default_form_name = $default_forms[0]; } else { $default_form_name = null; } if ($form_name == $default_form_name) { $redirect_url = $page_title->getLocalURL('action=formedit'); } else { $redirect_url = self::getFormEditURL($form_name, $page_name); } } else { $redirect_url = self::getFormEditURL($form_name, $page_name); // Of all the request values, send on to 'FormEdit' // only 'preload' and specific form fields - we can // identify the latter because they show up as arrays. foreach ($_REQUEST as $key => $val) { if (is_array($val)) { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; // Re-add the key (i.e. the template // name), so we can make a nice query // string snippet out of the whole // thing. $wrapperArray = array($key => $val); $redirect_url .= urldecode(http_build_query($wrapperArray)); } elseif ($key == 'preload') { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= "{$key}={$val}"; } } } if (!is_null($params) && $params !== '') { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= $params; } $wgOut->setArticleBodyOnly(true); // Show "loading" animated image while people wait for the // redirect. global $sfgScriptPath; $text = <<<END \t<p style="position: absolute; left: 45%; top: 45%;"> \t<img src="{$sfgScriptPath}/skins/loading.gif" /> \t</p> \t<meta http-equiv="refresh" content="0; url={$redirect_url}" /> END; $wgOut->addHTML($text); return; }
function execute($query) { global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; global $wgLang, $smwgContLang; // Check permissions. if (!$wgUser->isAllowed('createclass')) { $this->displayRestrictionError(); return; } $this->setHeaders(); $wgOut->addExtensionStyle($sfgScriptPath . "/skins/SemanticForms.css"); $numStartingRows = 5; self::addJavascript($numStartingRows); $createAll = $wgRequest->getCheck('createAll'); if ($createAll) { self::createAllPages(); return; } $datatypeLabels = $smwgContLang->getDatatypeLabels(); // Make links to all the other 'Create...' pages, in order to // link to them at the top of the page. $creation_links = array(); $creation_links[] = SFUtils::linkForSpecialPage('CreateProperty'); $creation_links[] = SFUtils::linkForSpecialPage('CreateTemplate'); $creation_links[] = SFUtils::linkForSpecialPage('CreateForm'); $creation_links[] = SFUtils::linkForSpecialPage('CreateCategory'); $form_name_label = wfMessage('sf_createclass_nameinput')->text(); $category_name_label = wfMessage('sf_createcategory_name')->text(); $field_name_label = wfMessage('sf_createtemplate_fieldname')->text(); $list_of_values_label = wfMessage('sf_createclass_listofvalues')->text(); $property_name_label = wfMessage('sf_createproperty_propname')->text(); $type_label = wfMessage('sf_createproperty_proptype')->text(); $allowed_values_label = wfMessage('sf_createclass_allowedvalues')->text(); $text = '<form action="" method="post">' . "\n"; $text .= "\t" . Html::rawElement('p', null, wfMessage('sf_createclass_docu', $wgLang->listToText($creation_links))->text()) . "\n"; $templateNameLabel = wfMessage('sf_createtemplate_namelabel')->text(); $templateNameInput = Html::input('template_name', null, 'text', array('size' => 30)); $text .= "\t" . Html::rawElement('p', null, $templateNameLabel . ' ' . $templateNameInput) . "\n"; $templateInfo = SFCreateTemplate::printTemplateStyleInput('template_format'); $templateInfo .= Html::rawElement('p', null, Html::element('input', array('type' => 'checkbox', 'name' => 'template_multiple', 'id' => 'template_multiple', 'onclick' => "disableFormAndCategoryInputs()")) . ' ' . wfMessage('sf_createtemplate_multipleinstance')->text()) . "\n"; $text .= Html::rawElement('blockquote', null, $templateInfo); $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'form_name'), $form_name_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'form_name', 'id' => 'form_name'), null)) . "\n"; $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'category_name'), $category_name_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'category_name', 'id' => 'category_name'), null)) . "\n"; $text .= "\t" . Html::element('br', null, null) . "\n"; $property_label = wfMessage('smw_pp_type')->text(); $text .= <<<END \t<div> \t\t<table id="mainTable" style="border-collapse: collapse;"> \t\t<tr> \t\t\t<th colspan="3" /> \t\t\t<th colspan="3" style="background: #ddeebb; padding: 4px;">{$property_label}</th> \t\t</tr> \t\t<tr> \t\t\t<th colspan="2">{$field_name_label}</th> \t\t\t<th style="padding: 4px;">{$list_of_values_label}</th> \t\t\t<th style="background: #eeffcc; padding: 4px;">{$property_name_label}</th> \t\t\t<th style="background: #eeffcc; padding: 4px;">{$type_label}</th> \t\t\t<th style="background: #eeffcc; padding: 4px;">{$allowed_values_label}</th> \t\t</tr> END; // Make one more row than what we're displaying - use the // last row as a "starter row", to be cloned when the // "Add another" button is pressed. for ($i = 1; $i <= $numStartingRows + 1; $i++) { if ($i == $numStartingRows + 1) { $rowString = 'id="starterRow" style="display: none"'; $n = 'starter'; } else { $rowString = ''; $n = $i; } $text .= <<<END \t\t<tr {$rowString} style="margin: 4px;"> \t\t\t<td>{$n}.</td> \t\t\t<td><input type="text" size="25" name="field_name_{$n}" /></td> \t\t\t<td style="text-align: center;"><input type="checkbox" name="is_list_{$n}" /></td> \t\t\t<td style="background: #eeffcc; padding: 4px;"><input type="text" size="25" name="property_name_{$n}" /></td> \t\t\t<td style="background: #eeffcc; padding: 4px;"> END; $typeDropdownBody = ''; foreach ($datatypeLabels as $label) { $typeDropdownBody .= "\t\t\t\t<option>{$label}</option>\n"; } $text .= "\t\t\t\t" . Html::rawElement('select', array('name' => "property_type_{$n}"), $typeDropdownBody) . "\n"; $text .= <<<END \t\t\t</td> \t\t\t<td style="background: #eeffcc; padding: 4px;"><input type="text" size="25" name="allowed_values_{$n}" /></td> END; } $text .= <<<END \t\t</tr> \t\t</table> \t</div> END; $add_another_button = Html::element('input', array('type' => 'button', 'value' => wfMessage('sf_formedit_addanother')->text(), 'onclick' => "createClassAddRow()")); $text .= Html::rawElement('p', null, $add_another_button) . "\n"; // Set 'title' as hidden field, in case there's no URL niceness $cc = $this->getTitle(); $text .= Html::hidden('title', SFUtils::titleURLString($cc)); $text .= Html::element('input', array('type' => 'submit', 'name' => 'createAll', 'value' => wfMessage('sf_createclass_create')->text())); $text .= "</form>\n"; $wgOut->addHTML($text); }