getOutput(); $req = $this->getRequest(); $this->setHeaders(); if ( $req->getCheck( 'showinputtypeoptions' ) ) { $out->disable(); // handle Ajax action $inputType = $req->getVal( 'showinputtypeoptions' ); $fieldFormText = $req->getVal( 'formfield' ); $paramValues = array(); // @TODO - is any of this "params" stuff necessary? // For now, it's removed - if the setting of params is // going to be re-added, that has to be done in the JS. /* foreach ( $req->getArray('params') as $key => $value ) { if ( ( $pos = strpos( $key, '_' . $fieldFormText ) ) != false ) { $paramName = substr( $key, 0, $pos ); // Spaces got replaced by underlines in // the query. $paramName = str_replace( '_', ' ', $paramName ); $paramValues[$paramName] = $value; } } */ echo self::showInputTypeOptions( $inputType, $fieldFormText, $paramValues ); } else { $this->doSpecialCreateForm( $query ); } } function doSpecialCreateForm( $query ) { $out = $this->getOutput(); $req = $this->getRequest(); $db = wfGetDB( DB_SLAVE ); if ( !is_null( $query ) ) { $presetFormName = str_replace( '_', ' ', $query ); $out->setPageTitle( wfMessage( 'pf-createform-with-name', $presetFormName )->text() ); $form_name = $presetFormName; } else { $presetFormName = null; $form_name = $req->getVal( 'form_name' ); } $section_name_error_str = '' . wfMessage( 'pf_blank_error' )->escaped() . ''; $out->addModules( array( 'ext.pageforms.collapsible', 'ext.pageforms.PF_CreateForm' ) ); // Get the names of all templates on this site. $all_templates = array(); $res = $db->select( 'page', 'page_title', array( 'page_namespace' => NS_TEMPLATE, 'page_is_redirect' => 0 ), __METHOD__, array( 'ORDER BY' => 'page_title' ) ); if ( $db->numRows( $res ) > 0 ) { while ( $row = $db->fetchRow( $res ) ) { $template_name = str_replace( '_', ' ', $row[0] ); $all_templates[] = $template_name; } } $deleted_template_loc = null; $deleted_section_loc = null; // To keep the templates and sections $form_items = array(); // Handle inputs. foreach ( $req->getValues() as $var => $val ) { # ignore variables that are not of the right form if ( strpos( $var, "_" ) != false ) { # get the template declarations and work from there list( $action, $id ) = explode( "_", $var, 2 ); if ( $action == "template" ) { // If the button was pressed to remove // this template, just don't add it to // the array. if ( $req->getVal( "del_$id" ) != null ) { $deleted_template_loc = $id; } else { $form_template = PFTemplateInForm::create( $val, $req->getVal( "label_$id" ), $req->getVal( "allow_multiple_$id" ) ); $form_items[] = array( 'type' => 'template', 'name' => $form_template->getTemplateName(), 'item' => $form_template ); } } elseif ( $action == "section" ) { if ( $req->getVal( "delsection_$id" ) != null ) { $deleted_section_loc = $id; } else { $form_section = PFPageSection::create( $val ); $form_items[] = array( 'type' => 'section', 'name' => $form_section->getSectionName(), 'item' => $form_section ); } } } } if ( $req->getVal( 'add_field' ) != null ) { $form_template = PFTemplateInForm::create( $req->getVal( 'new_template' ), "", false ); $template_loc = $req->getVal( 'before_template' ); $template_count = 0; if ( $template_loc === null ) { $new_template_loc = 0; $template_loc = 0; } else { // Count the number of templates before the // location of the template to be added for ( $i = 0; $i < $template_loc; $i++ ) { if ( $form_items[$i]['type'] == 'template' ) { $template_count++; } } $new_template_loc = $template_count; } // @HACK - array_splice() doesn't work for objects, so // we have to first insert a stub element into the // array, then replace that with the actual object. array_splice( $form_items, $template_loc, 0, "stub" ); $form_items[$template_loc] = array( 'type' => 'template', 'name' => $form_template->getTemplateName(), 'item' => $form_template ); } else { $template_loc = null; $new_template_loc = null; } if ( $req->getVal( 'add_section' ) != null ) { $form_section = PFPageSection::create( $req->getVal( 'sectionname' ) ); $section_loc = $req->getVal( 'before_section' ); $section_count = 0; if ( $section_loc === null ) { $new_section_loc = 0; $section_loc = 0; } else { // Count the number of sections before the // location of the section to be added for ( $i = 0; $i < $section_loc; $i++ ) { if ( $form_items[$i]['type'] == 'section' ) { $section_count++; } } $new_section_loc = $section_count; } // The same used hack for templates array_splice( $form_items, $section_loc, 0, "stub" ); $form_items[$section_loc] = array( 'type' => 'section', 'name' => $form_section->getSectionName(), 'item' => $form_section ); } else { $section_loc = null; $new_section_loc = null; } // Now cycle through the templates and fields, modifying each // one per the query variables. $templates = 0; $sections = 0; foreach ( $form_items as $fi ) { if ( $fi['type'] == 'template' ) { foreach ( $fi['item']->getFields() as $j => $field ) { $old_i = PFFormUtils::getChangedIndex( $templates, $new_template_loc, $deleted_template_loc ); foreach ( $req->getValues() as $key => $value ) { if ( ( $pos = strpos( $key, '_' . $old_i . '_' . $j ) ) != false ) { $paramName = substr( $key, 0, $pos ); // Spaces got replaced by // underlines in the query. $paramName = str_replace( '_', ' ', $paramName ); } else { continue; } if ( $paramName == 'label' ) { $field->template_field->setLabel( $value ); } elseif ( $paramName == 'input type' ) { $input_type = $req->getVal( "input_type_" . $old_i . "_" . $j ); if ( $input_type == 'hidden' ) { $field->setInputType( $input_type ); $field->setIsHidden( true ); } elseif ( substr( $input_type, 0, 1 ) == '.' ) { // It's the default input type - // don't do anything. } else { $field->setInputType( $input_type ); } } else { if ( ! empty( $value ) ) { if ( $value == 'on' ) { $value = true; } $field->setFieldArg( $paramName, $value ); } } } } $templates++; } elseif ( $fi['type'] == 'section' ) { $section = $fi['item']; $old_i = PFFormUtils::getChangedIndex( $sections, $new_section_loc, $deleted_section_loc ); foreach ( $req->getValues() as $key => $value ) { if ( ( $pos = strpos( $key, '_section_' . $old_i ) ) != false ) { $paramName = substr( $key, 0, $pos ); $paramName = str_replace( '_', ' ', $paramName ); } else { continue; } if ( !empty( $value ) ) { if ( $value == 'on' ) { $value = true; } if ( $paramName == 'level' ) { $section->setSectionLevel( $value ); } elseif ( $paramName == 'hidden' ) { $section->setIsHidden( $value ); } elseif ( $paramName == 'restricted' ) { $section->setIsRestricted( $value ); } elseif ( $paramName == 'mandatory' ) { $section->setIsMandatory( $value ); } else { $section->setSectionArgs( $paramName, $value ); } } } $sections++; } } $form = PFForm::create( $form_name, $form_items ); // If a submit button was pressed, create the form-definition // file, then redirect. $save_page = $req->getCheck( 'wpSave' ); $preview_page = $req->getCheck( 'wpPreview' ); if ( $save_page || $preview_page ) { $validToken = $this->getUser()->matchEditToken( $req->getVal( 'csrf' ), 'CreateForm' ); if ( !$validToken ) { $text = "This appears to be a cross-site request forgery; canceling save."; $out->addHTML( $text ); return; } // Validate form name. if ( $form->getFormName() == "" ) { $form_name_error_str = wfMessage( 'pf_blank_error' )->text(); } else { // Redirect to wiki interface. $out->setArticleBodyOnly( true ); $title = Title::makeTitleSafe( PF_NS_FORM, $form->getFormName() ); $full_text = $form->createMarkup(); $text = PFUtils::printRedirectForm( $title, $full_text, "", $save_page, $preview_page, false, false, false, null, null ); $out->addHTML( $text ); return; } } $text = "\t" . '