function execute($query) { global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; $this->setHeaders(); // Cycle through the query values, setting the appropriate // local variables. $category_name = $wgRequest->getVal('category_name'); $default_form = $wgRequest->getVal('default_form'); $parent_category = $wgRequest->getVal('parent_category'); $category_name_error_str = null; $save_page = $wgRequest->getCheck('wpSave'); $preview_page = $wgRequest->getCheck('wpPreview'); if ($save_page || $preview_page) { // Validate category name if ($category_name === '') { $category_name_error_str = wfMsg('sf_blank_error'); } else { // Redirect to wiki interface $wgOut->setArticleBodyOnly(true); $title = Title::makeTitleSafe(NS_CATEGORY, $category_name); $full_text = SFCreateCategory::createCategoryText($default_form, $category_name, $parent_category); $text = SFUtils::printRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null); $wgOut->addHTML($text); return; } } $all_forms = SFUtils::getAllForms(); // Set 'title' as hidden field, in case there's no URL niceness global $wgContLang; $mw_namespace_labels = $wgContLang->getNamespaces(); $special_namespace = $mw_namespace_labels[NS_SPECIAL]; $text = <<<END \t<form action="" method="get"> END; $text .= "\t" . Html::hidden('title', "{$special_namespace}:CreateCategory") . "\n"; $firstRow = wfMsg('sf_createcategory_name') . ' ' . Html::input('category_name', null, 'text', array('size' => 25)) . "\n"; if (!is_null($category_name_error_str)) { $firstRow .= Html::element('span', array('style' => 'color: red;'), $category_name_error_str) . "\n"; } $firstRow .= "\t" . wfMsg('sf_createcategory_defaultform') . "\n"; $formSelector = "\t" . Html::element('option', null, null) . "\n"; foreach ($all_forms as $form) { $formSelector .= "\t" . Html::element('option', null, $form) . "\n"; } $firstRow .= Html::rawElement('select', array('id' => 'form_dropdown', 'name' => 'default_form'), $formSelector); $text .= Html::rawElement('p', null, $firstRow); $subcategory_label = wfMsg('sf_createcategory_makesubcategory'); $text .= <<<END \t<p>{$subcategory_label} \t<select id="category_dropdown" name="parent_category"> \t<option></option> END; $categories = SFUtils::getCategoriesForPage(); foreach ($categories as $category) { $category = str_replace('_', ' ', $category); $text .= "\t" . Html::element('option', null, $category) . "\n"; } $text .= "\t</select>\n"; $editButtonsText = "\t" . Html::input('wpSave', wfMsg('savearticle'), 'submit', array('id' => 'wpSave')) . "\n"; $editButtonsText .= "\t" . Html::input('wpPreview', wfMsg('preview'), 'submit', array('id' => 'wpPreview')) . "\n"; $text .= "\t" . Html::rawElement('div', array('class' => 'editButtons'), $editButtonsText) . "\n"; $text .= <<<END \t<br /><hr /<br /> END; $sk = $wgUser->getSkin(); $create_form_link = SFUtils::linkForSpecialPage($sk, 'CreateForm'); $text .= "\t" . Html::rawElement('p', null, $create_form_link . '.') . "\n"; $text .= "\t</form>\n"; $wgOut->addExtensionStyle($sfgScriptPath . "/skins/SemanticForms.css"); $wgOut->addHTML($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 ); }
function execute($query) { global $wgOut, $wgRequest, $sfgScriptPath; $this->setHeaders(); // Cycle through the query values, setting the appropriate // local variables. if (!is_null($query)) { $presetCategoryName = str_replace('_', ' ', $query); $wgOut->setPageTitle(wfMessage('sf-createcategory-with-name', $presetCategoryName)->text()); $category_name = $presetCategoryName; } else { $presetCategoryName = null; $category_name = $wgRequest->getVal('category_name'); } $default_form = $wgRequest->getVal('default_form'); $parent_category = $wgRequest->getVal('parent_category'); $category_name_error_str = null; $save_page = $wgRequest->getCheck('wpSave'); $preview_page = $wgRequest->getCheck('wpPreview'); if ($save_page || $preview_page) { // Guard against cross-site request forgeries (CSRF). $validToken = $this->getUser()->matchEditToken($wgRequest->getVal('csrf'), 'CreateCategory'); if (!$validToken) { $text = "This appears to be a cross-site request forgery; canceling save."; $wgOut->addHTML($text); return; } // Validate category name if ($category_name === '') { $category_name_error_str = wfMessage('sf_blank_error')->text(); } else { // Redirect to wiki interface $wgOut->setArticleBodyOnly(true); $title = Title::makeTitleSafe(NS_CATEGORY, $category_name); $full_text = SFCreateCategory::createCategoryText($default_form, $category_name, $parent_category); $text = SFUtils::printRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null); $wgOut->addHTML($text); return; } } $all_forms = SFUtils::getAllForms(); // Set 'title' as hidden field, in case there's no URL niceness global $wgContLang; $mw_namespace_labels = $wgContLang->getNamespaces(); $text = "\t" . '<form action="" method="post">' . "\n"; $firstRow = ''; if (is_null($presetCategoryName)) { $text .= "\t" . Html::hidden('title', $this->getTitle()->getPrefixedText()) . "\n"; $firstRow .= wfMessage('sf_createcategory_name')->text() . ' ' . Html::input('category_name', null, 'text', array('size' => 25)) . "\n"; if (!is_null($category_name_error_str)) { $firstRow .= Html::element('span', array('style' => 'color: red;'), $category_name_error_str) . "\n"; } } $firstRow .= "\t" . wfMessage('sf_createcategory_defaultform')->text() . "\n"; $formSelector = "\t" . Html::element('option', null, null) . "\n"; foreach ($all_forms as $form) { $formSelector .= "\t" . Html::element('option', null, $form) . "\n"; } $firstRow .= Html::rawElement('select', array('id' => 'form_dropdown', 'name' => 'default_form'), $formSelector); $text .= Html::rawElement('p', null, $firstRow) . "\n"; $secondRow = wfMessage('sf_createcategory_makesubcategory')->text() . ' '; $selectBody = "\t" . Html::element('option', null, null) . "\n"; $categories = SFUtils::getCategoriesForPage(); foreach ($categories as $category) { $category = str_replace('_', ' ', $category); $selectBody .= "\t" . Html::element('option', null, $category) . "\n"; } $secondRow .= Html::rawElement('select', array('id' => 'category_dropdown', 'name' => 'parent_category'), $selectBody); $text .= Html::rawElement('p', null, $secondRow) . "\n"; $text .= "\t" . Html::hidden('csrf', $this->getUser()->getEditToken('CreateCategory')) . "\n"; $editButtonsText = "\t" . Html::input('wpSave', wfMessage('savearticle')->text(), 'submit', array('id' => 'wpSave')) . "\n"; $editButtonsText .= "\t" . Html::input('wpPreview', wfMessage('preview')->text(), 'submit', array('id' => 'wpPreview')) . "\n"; $text .= "\t" . Html::rawElement('div', array('class' => 'editButtons'), $editButtonsText) . "\n"; $text .= "\t</form>\n"; $wgOut->addExtensionStyle($sfgScriptPath . "/skins/SemanticForms.css"); $wgOut->addHTML($text); }
function createAllPages() { $out = $this->getOutput(); $req = $this->getRequest(); $user = $this->getUser(); $template_name = trim($req->getVal("template_name")); $template_multiple = $req->getBool("template_multiple"); // If this is a multiple-instance template, there // shouldn't be a corresponding form or category. if ($template_multiple) { $form_name = null; $category_name = null; } else { $form_name = trim($req->getVal("form_name")); $category_name = trim($req->getVal("category_name")); } if ($template_name === '' || !$template_multiple && ($form_name === '' || $category_name === '')) { $out->addWikiMsg('sf_createclass_missingvalues'); return; } $fields = array(); $jobs = array(); // Cycle through all the rows passed in. for ($i = 1; $req->getVal("field_name_{$i}") != ''; $i++) { // Go through the query values, setting the appropriate // local variables. $field_name = trim($req->getVal("field_name_{$i}")); $property_name = trim($req->getVal("property_name_{$i}")); $property_type = $req->getVal("property_type_{$i}"); $allowed_values = $req->getVal("allowed_values_{$i}"); $is_list = $req->getCheck("is_list_{$i}"); // Create an SFTemplateField object based on these // values, and add it to the $fields array. $field = SFTemplateField::create($field_name, $field_name, $property_name, $is_list); if (defined('CARGO_VERSION')) { $field->setFieldType($property_type); // Hopefully it's safe to use a Cargo // utility method here. $possibleValues = CargoUtils::smartSplit(',', $allowed_values); $field->setPossibleValues($possibleValues); } $fields[] = $field; // Create the property, and make a job for it. if (defined('SMW_VERSION') && !empty($property_name)) { $full_text = SFCreateProperty::createPropertyText($property_type, '', $allowed_values); $property_title = Title::makeTitleSafe(SMW_NS_PROPERTY, $property_name); $params = array(); $params['user_id'] = $user->getId(); $params['page_text'] = $full_text; $params['edit_summary'] = wfMessage('sf_createproperty_editsummary', $property_type)->inContentLanguage()->text(); $jobs[] = new SFCreatePageJob($property_title, $params); } } // Also create the "connecting property", if there is one. $connectingProperty = trim($req->getVal('connecting_property')); if (defined('SMW_VERSION') && $connectingProperty != '') { global $smwgContLang; $datatypeLabels = $smwgContLang->getDatatypeLabels(); $property_type = $datatypeLabels['_wpg']; $full_text = SFCreateProperty::createPropertyText($property_type, '', $allowed_values); $property_title = Title::makeTitleSafe(SMW_NS_PROPERTY, $connectingProperty); $params = array(); $params['user_id'] = $user->getId(); $params['page_text'] = $full_text; $params['edit_summary'] = wfMessage('sf_createproperty_editsummary', $property_type)->inContentLanguage()->text(); $jobs[] = new SFCreatePageJob($property_title, $params); } // Create the template, and save it (might as well save // one page, instead of just creating jobs for all of them). $template_format = $req->getVal("template_format"); $sfTemplate = new SFTemplate($template_name, $fields); if (defined('CARGO_VERSION')) { $sfTemplate->mCargoTable = trim($req->getVal("cargo_table")); } if (defined('SMW_VERSION') && $template_multiple) { $sfTemplate->setConnectingProperty($connectingProperty); } else { $sfTemplate->setCategoryName($category_name); } $sfTemplate->setFormat($template_format); $full_text = $sfTemplate->createText(); $template_title = Title::makeTitleSafe(NS_TEMPLATE, $template_name); $edit_summary = ''; if (method_exists('WikiPage', 'doEditContent')) { // MW 1.21+ $template_page = new WikiPage($template_title); $content = new WikitextContent($full_text); $template_page->doEditContent($content, $edit_summary); } else { // MW <= 1.20 $template_article = new Article($template_title); $template_article->doEdit($full_text, $edit_summary); } // Create the form, and make a job for it. if ($form_name != '') { $form_template = SFTemplateInForm::create($template_name, '', false); $form_items = array(); $form_items[] = array('type' => 'template', 'name' => $form_template->getTemplateName(), 'item' => $form_template); $form = SFForm::create($form_name, $form_items); $full_text = $form->createMarkup(); $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); $params = array(); $params['user_id'] = $user->getId(); $params['page_text'] = $full_text; $jobs[] = new SFCreatePageJob($form_title, $params); } // Create the category, and make a job for it. if ($category_name != '') { $full_text = SFCreateCategory::createCategoryText($form_name, $category_name, ''); $category_title = Title::makeTitleSafe(NS_CATEGORY, $category_name); $params = array(); $params['user_id'] = $user->getId(); $params['page_text'] = $full_text; $jobs[] = new SFCreatePageJob($category_title, $params); } if (class_exists('JobQueueGroup')) { JobQueueGroup::singleton()->push($jobs); } else { // MW <= 1.20 Job::batchInsert($jobs); } $out->addWikiMsg('sf_createclass_success'); }
/** * The function called if we're in index.php (as opposed to one of the * special pages). */ static function displayForm($action, $article) { $title = $article->getTitle(); if ($title->getNamespace() == SMW_NS_PROPERTY) { $createPropertyPage = new SFCreateProperty(); $createPropertyPage->execute($title->getText()); } elseif ($title->getNamespace() == NS_TEMPLATE) { $createTemplatePage = new SFCreateTemplate(); $createTemplatePage->execute($title->getText()); } elseif ($title->getNamespace() == SF_NS_FORM) { $createFormPage = new SFCreateForm(); $createFormPage->execute($title->getText()); } elseif ($title->getNamespace() == NS_CATEGORY) { $createCategoryPage = new SFCreateCategory(); $createCategoryPage->execute($title->getText()); } 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 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 formcreate 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 !== 'formcreate') { return true; } $title = $article->getTitle(); if ($title->getNamespace() == SMW_NS_PROPERTY) { $createPropertyPage = new SFCreateProperty(); $createPropertyPage->execute($title->getText()); } elseif ($title->getNamespace() == NS_TEMPLATE) { $createTemplatePage = new SFCreateTemplate(); $createTemplatePage->execute($title->getText()); } elseif ($title->getNamespace() == SF_NS_FORM) { $createFormPage = new SFCreateForm(); $createFormPage->execute($title->getText()); } elseif ($title->getNamespace() == NS_CATEGORY) { $createCategoryPage = new SFCreateCategory(); $createCategoryPage->execute($title->getText()); } return false; }
static function createAllPages() { global $wgOut, $wgRequest, $wgUser; $template_name = trim($wgRequest->getVal("template_name")); $template_multiple = $wgRequest->getBool("template_multiple"); // If this is a multiple-instance template, there // shouldn't be a corresponding form or category. if ($template_multiple) { $form_name = null; $category_name = null; } else { $form_name = trim($wgRequest->getVal("form_name")); $category_name = trim($wgRequest->getVal("category_name")); } if ($template_name === '' || !$template_multiple && ($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("field_name_{$i}"); $i++) { // go through the query values, setting the appropriate local variables $property_name = trim($wgRequest->getVal("property_name_{$i}")); $field_name = trim($wgRequest->getVal("field_name_{$i}")); $property_type = $wgRequest->getVal("property_type_{$i}"); $allowed_values = $wgRequest->getVal("allowed_values_{$i}"); $is_list = $wgRequest->getCheck("is_list_{$i}"); // Create an SFTemplateField object 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. if (!empty($property_name)) { $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 (might as well save // one page, instead of just creating jobs for all of them). $template_format = $wgRequest->getVal("template_format"); $full_text = SFTemplateField::createTemplateText($template_name, $fields, null, $category_name, null, null, $template_format); $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'); }