Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php |
— | — | @@ -32,6 +32,7 @@ |
33 | 33 | .fadeOut('fast', function() { jQuery(this).remove(); }); |
34 | 34 | }); |
35 | 35 | jQuery('#fieldsList_'+template_num).append(newField); |
| 36 | + addjQueryToCheckbox(); |
36 | 37 | } |
37 | 38 | function createAddTemplate() { |
38 | 39 | templateNum++; |
— | — | @@ -45,7 +46,16 @@ |
46 | 47 | }); |
47 | 48 | jQuery('#templatesList').append(newField); |
48 | 49 | } |
49 | | - |
| 50 | +function addjQueryToCheckbox(){ |
| 51 | + jQuery('.isListCheckbox').click(function() { |
| 52 | + if (jQuery(this).is(":checked")) |
| 53 | + { |
| 54 | + jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', ''); |
| 55 | + }else{ |
| 56 | + jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', 'none'); |
| 57 | + } |
| 58 | + }); |
| 59 | +} |
50 | 60 | jQuery(document).ready(function() { |
51 | 61 | jQuery(".deleteField").click( function() { |
52 | 62 | // Remove the encompassing div for this instance. |
— | — | @@ -57,17 +67,7 @@ |
58 | 68 | jQuery(this).closest(".templateBox") |
59 | 69 | .fadeOut('fast', function() { jQuery(this).remove(); }); |
60 | 70 | }); |
61 | | - jQuery('.isListCheckbox').click(function() { |
62 | | - if (jQuery(this).is(":checked")) |
63 | | - { |
64 | | - alert("checked"); |
65 | | - jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', ''); |
66 | | - }else{ |
67 | | - alert("unchecked"); |
68 | | - jQuery(this).siblings('.delimiterInput').css('display', 'none'); |
69 | | - } |
70 | | - }); |
71 | | - |
| 71 | + addjQueryToCheckbox(); |
72 | 72 | }); |
73 | 73 | |
74 | 74 | </script> |
— | — | @@ -76,57 +76,12 @@ |
77 | 77 | $wgOut->addScript( $jsText ); |
78 | 78 | } |
79 | 79 | function execute( $category ) { |
80 | | - global $wgRequest, $wgOut; |
| 80 | + global $wgRequest, $wgOut, $wgUser; |
81 | 81 | global $wgSkin; |
82 | 82 | $this->setHeaders(); |
83 | 83 | $text_1 = '<p>This category does not exist yet. Create this category and its page schema: </p>'; |
84 | 84 | $text_2 = '<p>This category exists, but does not have a page schema. Create schema:" </p>'; |
85 | | - $save_page = $wgRequest->getCheck( 'wpSave' ); |
86 | | - if ($save_page) { |
87 | | - //Generate the Xml from the Form elements |
88 | | - $Xmltext = ""; |
89 | | - $s_name = $wgRequest->getText('s_name'); |
90 | | - $Xmltext .= '<PageSchema name="'.$s_name.'">'; |
91 | | - $ps_add_xml = $wgRequest->getText('ps_add_xml'); |
92 | | - $Xmltext .= $ps_add_xml; |
93 | | - foreach ( $wgRequest->getValues() as $var => $val ) { |
94 | | - if(substr($var,0,7) == 't_name_'){ |
95 | | - $Xmltext .= '<Template name="'.$val.'">'; |
96 | | - }else if(substr($var,0,7) == 'f_name_'){ |
97 | | - $Xmltext .= '<Field name="'.$val.'">'; |
98 | | - }else if(substr($var,0,8) == 'f_label_'){ |
99 | | - $Xmltext .= '<Label>'.$val.'</Label>'; |
100 | | - }else if(substr($var,0,10) == 'f_add_xml_'){ |
101 | | - $Xmltext .= $val; |
102 | | - $Xmltext .= '</Field>'; |
103 | | - }else if(substr($var,0,10) == 't_add_xml_'){ |
104 | | - $Xmltext .= $val; |
105 | | - $Xmltext .= '</Template>'; |
106 | | - } |
107 | | - } |
108 | | - $Xmltext .= '</PageSchema>'; |
109 | | - } |
110 | | - else{ |
111 | | - if ( $category != "" ) { |
112 | | - |
113 | | - $title = Title::newFromText( $category, NS_CATEGORY ); |
114 | | - $pageId = $title->getArticleID(); |
115 | | - $dbr = wfGetDB( DB_SLAVE ); |
116 | | - //get the result set, query : slect page_props |
117 | | - $res = $dbr->select( 'page_props', |
118 | | - array( |
119 | | - 'pp_page', |
120 | | - 'pp_propname', |
121 | | - 'pp_value' |
122 | | - ), |
123 | | - array( |
124 | | - 'pp_page' => $pageId, |
125 | | - ) |
126 | | - ); |
127 | | - //first row of the result set |
128 | | - $row = $dbr->fetchRow( $res ); |
129 | | - if( $row == null ){ |
130 | | - //Create form here |
| 85 | + $text_3 = '<p>This category exists,have a page schema. Edit schema:" </p>'; |
131 | 86 | self::addJavascript(); |
132 | 87 | $text = ""; |
133 | 88 | $text .= '<p>This category does not exist yet. Create this category and its page schema: </p>'; |
— | — | @@ -153,10 +108,10 @@ |
154 | 109 | <p>Additional XML: |
155 | 110 | <textarea rows=4 style="width: 100%" name="f_add_xml_1"></textarea> |
156 | 111 | </p> |
157 | | - <input type="button" value="Remove field" class="deleteField" /> </div> |
158 | | - |
159 | | -</div> |
160 | | - </fieldset> '; |
| 112 | + <input type="button" value="Remove field" class="deleteField" /></fieldset> |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + '; |
161 | 116 | $add_field_button = Xml::element( 'input', |
162 | 117 | array( |
163 | 118 | 'type' => 'button', |
— | — | @@ -204,25 +159,109 @@ |
205 | 160 | <hr /> '; |
206 | 161 | $text .= '<div class="fieldBox" id="starterField" style="display: none"> |
207 | 162 | <fieldset style="background: #bbb;"><legend>Field</legend> |
| 163 | + <p> |
208 | 164 | <input size="15" name="f_name_starter"> |
209 | 165 | Display label: <input size="15" name="f_label_starter"> |
210 | 166 | </p> |
211 | | - <p><input type="checkbox" name="f_is_list_starter" /> This field can hold a list of values, separated by commas |
212 | | -    |
213 | | - <p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_starter" /> </p> |
| 167 | + <p><input type="checkbox" name="f_is_list_starter" class="isListCheckbox" /> This field can hold a list of values |
| 168 | +   </p> |
| 169 | + <div class="delimiterInput" style="display: none" ><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_starter" /> </p></div> |
214 | 170 | <p>Additional XML: |
215 | 171 | <textarea rows=4 style="width: 100%" name="f_add_xml_starter"></textarea> |
216 | 172 | </p> |
217 | 173 | <input type="button" value="Remove field" class="deleteField" /> |
218 | | -</p> |
219 | 174 | </fieldset> |
220 | 175 | </div>'; |
| 176 | + $save_page = $wgRequest->getCheck( 'wpSave' ); |
| 177 | + if ($save_page) { |
| 178 | + //Generate the Xml from the Form elements |
| 179 | + $Xmltext = ""; |
| 180 | + $s_name = $wgRequest->getText('s_name'); |
| 181 | + $Xmltext .= '<PageSchema name="'.$s_name.'">'; |
| 182 | + $ps_add_xml = $wgRequest->getText('ps_add_xml'); |
| 183 | + $Xmltext .= $ps_add_xml; |
| 184 | + $fieldName = ""; |
| 185 | + $fieldNum= -1; |
| 186 | + $templateNum = -1; |
| 187 | + foreach ( $wgRequest->getValues() as $var => $val ) { |
| 188 | + if(substr($var,0,7) == 't_name_'){ |
| 189 | + $templateNum = substr($var,7,1); |
| 190 | + if($wgRequest->getCheck( 'is_multiple_'.$templateNum )){ |
| 191 | + $Xmltext .= '<Template name="'.$val.'" multiple="multiple">'; |
| 192 | + }else{ |
| 193 | + $Xmltext .= '<Template name="'.$val.'">'; |
| 194 | + } |
| 195 | + }else if(substr($var,0,7) == 'f_name_'){ |
| 196 | + $fieldName = $val; |
| 197 | + $fieldNum = substr($var,7,1); |
| 198 | + if($wgRequest->getCheck( 'f_is_list_'.$fieldNum )){ |
| 199 | + if( $wgRequest->getText('f_delimiter_'.$fieldNum) != ''){ |
| 200 | + $delimeter = $wgRequest->getText('f_delimiter_'.$fieldNum); |
| 201 | + $Xmltext .= '<Field name="'.$fieldName.'" list="list" delimiter="'.$delimeter.'">'; |
| 202 | + }else{ |
| 203 | + $Xmltext .= '<Field name="'.$fieldName.'" list="list">'; |
| 204 | + } |
| 205 | + }else{ |
| 206 | + $Xmltext .= '<Field name="'.$fieldName.'">'; |
| 207 | + } |
| 208 | + }else if(substr($var,0,8) == 'f_label_'){ |
| 209 | + $Xmltext .= '<Label>'.$val.'</Label>'; |
| 210 | + }else if(substr($var,0,10) == 'f_add_xml_'){ |
| 211 | + $Xmltext .= $val; |
| 212 | + $Xmltext .= '</Field>'; |
| 213 | + }else if(substr($var,0,10) == 't_add_xml_'){ |
| 214 | + $Xmltext .= $val; |
| 215 | + $Xmltext .= '</Template>'; |
| 216 | + } |
| 217 | + } |
| 218 | + $Xmltext .= '</PageSchema>'; |
| 219 | + |
| 220 | + $categoryTitle = Title::newFromText( $category, NS_CATEGORY ); |
| 221 | + $categoryArticle = new Article( $categoryTitle ); |
| 222 | + $pageText = $categoryArticle->getContent(); |
| 223 | + $jobs = array(); |
| 224 | + if( $wgRequest->getText('is_edit')=='true' ){ |
| 225 | + //Do some preg-replace magic |
| 226 | + }else{ |
| 227 | + $title = Title::newFromText( $category, NS_CATEGORY ); |
| 228 | + $params = array(); |
| 229 | + $params['user_id'] = $wgUser->getId(); |
| 230 | + $params['page_text'] = $pageText.$Xmltext; |
| 231 | + $jobs[] = new PSCreatePageJob( $title, $params ); |
| 232 | + Job::batchInsert( $jobs ); |
| 233 | + } |
| 234 | + } |
| 235 | + else{ |
| 236 | + if ( $category != "" ) { |
| 237 | + |
| 238 | + $title = Title::newFromText( $category, NS_CATEGORY ); |
| 239 | + $pageId = $title->getArticleID(); |
| 240 | + $dbr = wfGetDB( DB_SLAVE ); |
| 241 | + //get the result set, query : slect page_props |
| 242 | + $res = $dbr->select( 'page_props', |
| 243 | + array( |
| 244 | + 'pp_page', |
| 245 | + 'pp_propname', |
| 246 | + 'pp_value' |
| 247 | + ), |
| 248 | + array( |
| 249 | + 'pp_page' => $pageId, |
| 250 | + ) |
| 251 | + ); |
| 252 | + //first row of the result set |
| 253 | + $row = $dbr->fetchRow( $res ); |
| 254 | + if( $row == null ){ |
| 255 | + //Create form here, Cat doesnt exist, create new cat with this text |
| 256 | + $text .= $text_1; |
221 | 257 | $wgOut->addHTML( $text ); |
222 | 258 | }else{ |
223 | 259 | if( ($row[1] == 'PageSchema') && ($row[2] != null )){ |
224 | | - |
| 260 | + //Populate the form here with autocompleted values |
| 261 | + $pageXml = $row[2]; |
| 262 | + $wgOut->addHTML($text_3); |
225 | 263 | }else{ |
226 | | - $wgOut->addHTML($text_2); |
| 264 | + $text .= $text_2; |
| 265 | + $wgOut->addHTML($text); |
227 | 266 | } |
228 | 267 | } |
229 | 268 | }else { |