Index: trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php |
— | — | @@ -15,30 +15,58 @@ |
16 | 16 | |
17 | 17 | SpecialPage::addPage( new SpecialPage('CreateTemplate','',true,'doSpecialCreateTemplate',false) ); |
18 | 18 | |
19 | | -// beginning of new layout for CreateTemplate |
| 19 | +function cmp($a, $b) |
| 20 | +{ |
| 21 | + if ($a == $b) { |
| 22 | + return 0; |
| 23 | + } elseif ($a < $b) { |
| 24 | + return -1; |
| 25 | + } else { |
| 26 | + return 1; |
| 27 | + } |
| 28 | +} |
20 | 29 | function getSemanticProperties() { |
21 | | - $dbr =& wfGetDB( DB_SLAVE ); |
22 | | - $attributes = $dbr->tableName( 'smw_attributes' ); |
23 | | - // QueryPage uses the value from this SQL in an ORDER clause, |
24 | | - // so return attribute title in value, and its type in title. |
25 | | - $query = "SELECT distinct value_datatype as title, |
26 | | - attribute_title as value |
27 | | - FROM $attributes |
28 | | - GROUP BY attribute_title, value_datatype"; |
| 30 | + $dbr =& wfGetDB( DB_SLAVE ); |
| 31 | + $all_properties = array(); |
| 32 | + |
| 33 | + $res = $dbr->query("SELECT distinct attribute_title FROM " . |
| 34 | + $dbr->tableName('smw_attributes')); |
| 35 | + while ($row = $dbr->fetchRow($res)) { |
| 36 | + $attribute_name = str_replace('_', ' ', $row[0]); |
| 37 | + $all_properties[$attribute_name . ":="] = $attribute_name; |
| 38 | + } |
| 39 | + $dbr->freeResult($res); |
| 40 | + |
| 41 | + $res = $dbr->query("SELECT distinct relation_title FROM " . |
| 42 | + $dbr->tableName('smw_relations')); |
| 43 | + while ($row = $dbr->fetchRow($res)) { |
| 44 | + $relation_name = str_replace('_', ' ', $row[0]); |
| 45 | + $all_properties[$relation_name . "::"] = $relation_name; |
| 46 | + } |
| 47 | + $dbr->freeResult($res); |
| 48 | + |
| 49 | + uasort($all_properties, "cmp"); |
| 50 | + return $all_properties; |
29 | 51 | } |
30 | 52 | |
31 | | -function printFieldEntryBox($id, $f) { |
| 53 | +function printPropertiesDropdown($all_properties, $id, $property) { |
| 54 | + $dropdown_str = "<select name=\"semantic_field_call_$id\">\n"; |
| 55 | + $dropdown_str .= "<option value=\"\"></option>\n"; |
| 56 | + foreach ($all_properties as $prop_id => $prop_name) { |
| 57 | + $selected = ($property == $prop_id) ? "selected" : ""; |
| 58 | + $dropdown_str .= "<option value=\"$prop_id\" $selected>$prop_name</option>\n"; |
| 59 | + } |
| 60 | + $dropdown_str .= "</select>\n"; |
| 61 | + return $dropdown_str; |
| 62 | +} |
| 63 | + |
| 64 | +function printFieldEntryBox($id, $f, $all_properties) { |
| 65 | + $dropdown_html = printPropertiesDropdown($all_properties, $id, $f->semantic_field_call); |
32 | 66 | $text = ' <div class="field_box">' . "\n"; |
33 | 67 | $text .= ' <p>' . wfMsg('sf_createtemplate_fieldname') . ' <input size="15" name="name_' . $id . '" value="' . $f->field_name . '">' . "\n"; |
34 | | - $text .= ' ' . wfMsg('sf_createtemplate_displaylabel') . ' <input size="15" name="label_' . $id . '" value="' . $f->label . '"></p>' . "\n"; |
35 | | - $text .= ' <p>' . wfMsg('sf_createtemplate_semanticproperty') . ' <input size="15" name="semantic_field_' . $id . '" value="' . $f->semantic_field . '">' . "\n"; |
| 68 | + $text .= ' ' . wfMsg('sf_createtemplate_displaylabel') . ' <input size="15" name="label_' . $id . '" value="' . $f->label . '">' . "\n"; |
| 69 | + $text .= ' ' . wfMsg('sf_createtemplate_semanticproperty') . ' ' . $dropdown_html . $f->semantic_field . "\n"; |
36 | 70 | |
37 | | - $text .= " <input type=\"radio\" name=\"attr_or_rel_$id\" value=\"attribute\"" . |
38 | | - ($f->attr_or_rel == "attribute" ? " checked" : "") . '> ' . |
39 | | - wfMsg('sf_createtemplate_attribute') . "\n"; |
40 | | - $text .= " <input type=\"radio\" name=\"attr_or_rel_$id\" value=\"relation\"" . |
41 | | - ($f->attr_or_rel == "relation" ? " checked" : "") . '> ' . |
42 | | - wfMsg('sf_createtemplate_relation') . "\n"; |
43 | 71 | $text .= " \n\n"; |
44 | 72 | |
45 | 73 | if ($id != "new") { |
— | — | @@ -53,10 +81,13 @@ |
54 | 82 | } |
55 | 83 | |
56 | 84 | function doSpecialCreateTemplate() { |
57 | | - global $wgOut, $wgRequest; |
| 85 | + global $wgOut, $wgRequest, $wgUser; |
| 86 | + |
| 87 | + $all_properties = getSemanticProperties(); |
| 88 | + |
58 | 89 | # cycle through the query values, setting the appropriate local variables |
59 | 90 | $template_name = $wgRequest->getVal('template_name'); |
60 | | - $type_name = $wgRequest->getVal('type_name'); |
| 91 | + $category = $wgRequest->getVal('category'); |
61 | 92 | $cur_id = 1; |
62 | 93 | $fields = array(); |
63 | 94 | foreach ($wgRequest->getValues() as $var => $val) { |
— | — | @@ -67,14 +98,14 @@ |
68 | 99 | # do nothing - this field won't get added to the new list |
69 | 100 | } else { |
70 | 101 | $field = SFTemplateField::newWithValues($val, |
71 | | - $wgRequest->getVal('label_' . $old_id), |
72 | | - $wgRequest->getVal('semantic_field_' . $old_id), |
73 | | - $wgRequest->getVal('attr_or_rel_' . $old_id)); |
| 102 | + $wgRequest->getVal('label_' . $old_id), null, null); |
| 103 | + $field->semantic_field_call = $wgRequest->getVal('semantic_field_call_' . $old_id); |
74 | 104 | $fields[] = $field; |
75 | 105 | } |
76 | 106 | } |
77 | 107 | } |
78 | 108 | } |
| 109 | + $template_format = $wgRequest->getVal('template_format'); |
79 | 110 | |
80 | 111 | $preview_button_text = wfMsg('preview'); |
81 | 112 | if ($wgRequest->getVal('preview') == $preview_button_text) { |
— | — | @@ -85,7 +116,9 @@ |
86 | 117 | # redirect to wiki interface |
87 | 118 | $title = Title::newFromText($template_name, NS_TEMPLATE); |
88 | 119 | $submit_url = $title->getLocalURL('action=submit'); |
89 | | - $full_text = create_template_text($template_name, $fields, $type_name); |
| 120 | + $full_text = createTemplateText($template_name, $fields, $category, $template_format); |
| 121 | + // HTML-encode |
| 122 | + $full_text = str_replace('"', '"', $full_text); |
90 | 123 | $text .= <<<END |
91 | 124 | <form id="editform" name="editform" method="post" action="$submit_url"> |
92 | 125 | <input type="hidden" name="wpTextbox1" id="wpTextbox1" value="$full_text" /> |
— | — | @@ -102,21 +135,29 @@ |
103 | 136 | // set 'title' field, in case there's no URL niceness |
104 | 137 | $text .= ' <input type="hidden" name="title" value="Special:CreateTemplate">' . "\n"; |
105 | 138 | $text .= ' <p>' . wfMsg('sf_createtemplate_namelabel') . ' <input size="25" name="template_name" value="' . $template_name . '"> <font color="red">' . $template_name_error_str . '</font></p>' . "\n"; |
106 | | - $text .= ' <p>' . wfMsg('sf_createtemplate_categorylabel') . ' <input size="25" name="type_name" value="' . $type_name . '"></p>' . "\n"; |
| 139 | + $text .= ' <p>' . wfMsg('sf_createtemplate_categorylabel') . ' <input size="25" name="category" value="' . $category . '"></p>' . "\n"; |
107 | 140 | $text .= " <fieldset>\n"; |
108 | 141 | $text .= ' <legend>' . wfMsg('sf_createtemplate_templatefields') . "</legend>\n"; |
109 | 142 | $text .= ' <p>' . wfMsg('sf_createtemplate_fieldsdesc') . "</p>\n"; |
110 | 143 | |
111 | 144 | foreach ($fields as $i => $field) { |
112 | | - $text .= printFieldEntryBox($i + 1, $field); |
| 145 | + $text .= printFieldEntryBox($i + 1, $field, $all_properties); |
113 | 146 | } |
114 | 147 | $new_field = new SFTemplateField(); |
115 | | - $text .= printFieldEntryBox("new", $new_field); |
| 148 | + $text .= printFieldEntryBox("new", $new_field, $all_properties); |
116 | 149 | |
117 | 150 | $text .= ' <p><input type="submit" value="' . wfMsg('sf_createtemplate_addfield') . '"></p>' . "\n"; |
118 | 151 | $text .= " </fieldset>\n"; |
| 152 | + $text .= ' <p>' . wfMsg('sf_createtemplate_outputformat') . "\n"; |
| 153 | + $text .= ' <input type="radio" name="template_format" checked value="standard">' . wfMsg('sf_createtemplate_standardformat') . "\n"; |
| 154 | + $text .= ' <input type="radio" name="template_format" value="infobox">' . wfMsg('sf_createtemplate_infoboxformat') . "</p>\n"; |
119 | 155 | $text .= ' <p><input type="submit" name="preview" value="' . wfMsg('preview') . '"></p>' . "\n"; |
120 | 156 | $text .= " </form>\n"; |
| 157 | + $sk = $wgUser->getSkin(); |
| 158 | + $cp = SpecialPage::getPage('CreateProperty'); |
| 159 | + $create_property_link = $sk->makeKnownLinkObj($cp->getTitle(), $cp->getDescription()); |
| 160 | + $text .= " <br /><hr /><br />\n"; |
| 161 | + $text .= " <p>$create_property_link.</p>\n"; |
121 | 162 | |
122 | 163 | $wgOut->addLink( array( |
123 | 164 | 'rel' => 'stylesheet', |