Exemplo n.º 1
0
 /**
  * Returns the HTML for a section of the form comprising one template.
  */
 static function printTemplateSection($template_num = 'tnum', $templateXML = null, $psTemplate = null)
 {
     global $wgPageSchemasHandlerClasses;
     if (is_null($psTemplate)) {
         $psTemplateFields = array();
     } else {
         $psTemplateFields = $psTemplate->getFields();
     }
     $attrs = array('class' => 'multipleInstanceTemplateCheckbox');
     $templateXMLElements = array();
     $text = "\t";
     if (is_null($templateXML)) {
         $text .= '<div class="templateBox" id="starterTemplate" style="display: none">' . "\n";
         $templateName = '';
         $templateFormat = null;
     } else {
         $text .= '<div class="templateBox" >' . "\n";
         $templateName = (string) $templateXML->attributes()->name;
         if ((string) $templateXML->attributes()->multiple == "multiple") {
             $attrs['checked'] = 'checked';
         }
         $templateFormat = (string) $templateXML->attributes()->format;
         $templateXMLElements = $templateXML->children();
     }
     $templateNameInput = wfMessage('ps-namelabel')->parse() . ' ';
     $templateNameInput .= Html::input('t_name_' . $template_num, $templateName, 'text');
     $templateHTML = "\t\t" . Html::rawElement('p', null, $templateNameInput) . "\n";
     $templateIsMultipleInput = Html::input('is_multiple_' . $template_num, null, 'checkbox', $attrs);
     $templateHTML .= "\t\t" . Html::rawElement('p', null, $templateIsMultipleInput . ' ' . wfMessage('ps-multiple-temp-label')->parse());
     // Use an input from the Semantic Forms extension for the
     // template format.
     // This is against the basic principles of Page Schemas, which
     // is that other extensions should rely on it, not the other
     // way around. However, the creation of templates is a special
     // case: they're a standard MediaWiki component, but the
     // creation of them is (for no strong reason) done by Semantic
     // Forms. In the future, this may change.
     if (class_exists('SFCreateTemplate') && method_exists('SFCreateTemplate', 'printTemplateStyleInput')) {
         $templateHTML .= SFCreateTemplate::printTemplateStyleInput('template_format_' . $template_num, $templateFormat);
     }
     $template_add_xml = "";
     // TODO - set this correctly.
     /*
     		foreach ( $templateXMLElements as $templateXMLElement ) {
     			if ( !empty( $templateXMLElement ) && $templateXMLElement->getName() != 'Field' ) {
     				$template_add_xml .= (string)$templateXMLElement->asXML();
     			}
     		}
     */
     // We're just going to assume that all attributes related to
     // templates apply only to multiple-instance templates - and
     // that these fields should only be shown if the "multiple
     // instances" checkbox is selected.
     // For now, that's a safe assumption, although that may change.
     $templateHTML .= "\n\t\t" . '<div class="multipleInstanceTemplateAttributes">';
     foreach ($wgPageSchemasHandlerClasses as $psHandlerClass) {
         $valuesFromExtension = call_user_func(array($psHandlerClass, "getTemplateEditingHTML"), $psTemplate);
         if (is_null($valuesFromExtension)) {
             continue;
         }
         $label = call_user_func(array($psHandlerClass, "getTemplateDisplayString"));
         $color = call_user_func(array($psHandlerClass, "getDisplayColor"));
         $html = self::printFieldHTMLForExtension($valuesFromExtension, $label, $color);
         $templateHTML .= str_replace('num', $template_num, $html);
     }
     $templateHTML .= "\n\t\t" . '</div><!-- multipleInstanceTemplateAttributes -->';
     $templateHTML .= "\n\t\t" . '<div class="fieldsList">';
     $fieldNumInTemplate = 0;
     // If this is a "starter" template, create the starter
     // field HTML.
     if (is_null($psTemplate)) {
         $templateHTML .= self::printFieldSection();
     }
     foreach ($templateXMLElements as $templateXMLElement) {
         if (empty($templateXMLElement)) {
             // Do nothing (?)
         } elseif ($templateXMLElement->getName() == "Field") {
             if (array_key_exists($fieldNumInTemplate, $psTemplateFields)) {
                 $psTemplateField = $psTemplateFields[$fieldNumInTemplate];
             } else {
                 continue;
                 //$psTemplateField = new PSTemplateField();
             }
             $templateHTML .= self::printFieldSection($templateXMLElement, $psTemplateField);
             $fieldNumInTemplate++;
         }
     }
     $templateHTML .= "\t</div><!-- fieldsList -->\n";
     $add_field_button = Xml::element('input', array('type' => 'button', 'class' => 'editSchemaAddField', 'value' => wfMessage('ps-add-field')->parse()));
     $templateHTML .= Xml::tags('p', null, $add_field_button) . "\n";
     $templateHTML .= "<hr />\n";
     $templateHTML .= "\n\t\t\t\t" . Html::hidden("t_add_xml_{$template_num}", $template_add_xml);
     //$additionalXMLInput = "\n\t\t\t\t" . Html::textarea( "t_add_xml_$template_num", $template_add_xml, array( 'rows' => 4, 'style' => 'width: 100%;' ) );
     //$templateHTML .= "\n<p>" . wfMessage('ps-add-xml-label')->parse() . "\n\t\t\t\t" . $additionalXMLInput . "\n\t\t\t</p>";
     $templateHTML .= '<p>' . Html::input('remove-template', wfMessage('ps-remove-template')->text(), 'button', array('class' => 'deleteTemplate')) . "</p>\n";
     $text .= self::printFormSection(wfMessage('ps-template')->parse(), '#CCC', $templateHTML, 'editSchemaTemplateSection');
     $text .= "\t</div><!-- templateBox-->\n";
     return $text;
 }
    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);
    }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
    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);
    }