r24681 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24680‎ | r24681 | r24682 >
Date:17:48, 8 August 2007
Author:yaron
Status:old
Tags:
Comment:
Updated: input for the 'semantic property' is now a dropdown, not a text
field; template format is settable; link to 'create property' form, other
related changes
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php
@@ -15,30 +15,58 @@
1616
1717 SpecialPage::addPage( new SpecialPage('CreateTemplate','',true,'doSpecialCreateTemplate',false) );
1818
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+}
2029 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;
2951 }
3052
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);
3266 $text = ' <div class="field_box">' . "\n";
3367 $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";
3670
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";
4371 $text .= "&nbsp;&nbsp;\n\n";
4472
4573 if ($id != "new") {
@@ -53,10 +81,13 @@
5482 }
5583
5684 function doSpecialCreateTemplate() {
57 - global $wgOut, $wgRequest;
 85+ global $wgOut, $wgRequest, $wgUser;
 86+
 87+ $all_properties = getSemanticProperties();
 88+
5889 # cycle through the query values, setting the appropriate local variables
5990 $template_name = $wgRequest->getVal('template_name');
60 - $type_name = $wgRequest->getVal('type_name');
 91+ $category = $wgRequest->getVal('category');
6192 $cur_id = 1;
6293 $fields = array();
6394 foreach ($wgRequest->getValues() as $var => $val) {
@@ -67,14 +98,14 @@
6899 # do nothing - this field won't get added to the new list
69100 } else {
70101 $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);
74104 $fields[] = $field;
75105 }
76106 }
77107 }
78108 }
 109+ $template_format = $wgRequest->getVal('template_format');
79110
80111 $preview_button_text = wfMsg('preview');
81112 if ($wgRequest->getVal('preview') == $preview_button_text) {
@@ -85,7 +116,9 @@
86117 # redirect to wiki interface
87118 $title = Title::newFromText($template_name, NS_TEMPLATE);
88119 $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('"', '&quot;', $full_text);
90123 $text .= <<<END
91124 <form id="editform" name="editform" method="post" action="$submit_url">
92125 <input type="hidden" name="wpTextbox1" id="wpTextbox1" value="$full_text" />
@@ -102,21 +135,29 @@
103136 // set 'title' field, in case there's no URL niceness
104137 $text .= ' <input type="hidden" name="title" value="Special:CreateTemplate">' . "\n";
105138 $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";
107140 $text .= " <fieldset>\n";
108141 $text .= ' <legend>' . wfMsg('sf_createtemplate_templatefields') . "</legend>\n";
109142 $text .= ' <p>' . wfMsg('sf_createtemplate_fieldsdesc') . "</p>\n";
110143
111144 foreach ($fields as $i => $field) {
112 - $text .= printFieldEntryBox($i + 1, $field);
 145+ $text .= printFieldEntryBox($i + 1, $field, $all_properties);
113146 }
114147 $new_field = new SFTemplateField();
115 - $text .= printFieldEntryBox("new", $new_field);
 148+ $text .= printFieldEntryBox("new", $new_field, $all_properties);
116149
117150 $text .= ' <p><input type="submit" value="' . wfMsg('sf_createtemplate_addfield') . '"></p>' . "\n";
118151 $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";
119155 $text .= ' <p><input type="submit" name="preview" value="' . wfMsg('preview') . '"></p>' . "\n";
120156 $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";
121162
122163 $wgOut->addLink( array(
123164 'rel' => 'stylesheet',

Status & tagging log