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 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) { // 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; }
/** * 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; }
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'); }