r93396 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93395‎ | r93396 | r93397 >
Date:16:51, 28 July 2011
Author:ankitgarg833
Status:deferred
Tags:
Comment:
1_ Added code to create Category page, from EditSchema form.
2_ added jQuery to dynamically create delimiter input
Modified paths:
  • /trunk/extensions/PageSchemas/specials/PS_EditSchema.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php
@@ -32,6 +32,7 @@
3333 .fadeOut('fast', function() { jQuery(this).remove(); });
3434 });
3535 jQuery('#fieldsList_'+template_num).append(newField);
 36+ addjQueryToCheckbox();
3637 }
3738 function createAddTemplate() {
3839 templateNum++;
@@ -45,7 +46,16 @@
4647 });
4748 jQuery('#templatesList').append(newField);
4849 }
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+}
5060 jQuery(document).ready(function() {
5161 jQuery(".deleteField").click( function() {
5262 // Remove the encompassing div for this instance.
@@ -57,17 +67,7 @@
5868 jQuery(this).closest(".templateBox")
5969 .fadeOut('fast', function() { jQuery(this).remove(); });
6070 });
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();
7272 });
7373
7474 </script>
@@ -76,57 +76,12 @@
7777 $wgOut->addScript( $jsText );
7878 }
7979 function execute( $category ) {
80 - global $wgRequest, $wgOut;
 80+ global $wgRequest, $wgOut, $wgUser;
8181 global $wgSkin;
8282 $this->setHeaders();
8383 $text_1 = '<p>This category does not exist yet. Create this category and its page schema: </p>';
8484 $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>';
13186 self::addJavascript();
13287 $text = "";
13388 $text .= '<p>This category does not exist yet. Create this category and its page schema: </p>';
@@ -153,10 +108,10 @@
154109 <p>Additional XML:
155110 <textarea rows=4 style="width: 100%" name="f_add_xml_1"></textarea>
156111 </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+ ';
161116 $add_field_button = Xml::element( 'input',
162117 array(
163118 'type' => 'button',
@@ -204,25 +159,109 @@
205160 <hr /> ';
206161 $text .= '<div class="fieldBox" id="starterField" style="display: none">
207162 <fieldset style="background: #bbb;"><legend>Field</legend>
 163+ <p>
208164 <input size="15" name="f_name_starter">
209165 Display label: <input size="15" name="f_label_starter">
210166 </p>
211 - <p><input type="checkbox" name="f_is_list_starter" /> This field can hold a list of values, separated by commas
212 - &#160;&#160;
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+ &#160;&#160;</p>
 169+ <div class="delimiterInput" style="display: none" ><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_starter" /> </p></div>
214170 <p>Additional XML:
215171 <textarea rows=4 style="width: 100%" name="f_add_xml_starter"></textarea>
216172 </p>
217173 <input type="button" value="Remove field" class="deleteField" />
218 -</p>
219174 </fieldset>
220175 </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;
221257 $wgOut->addHTML( $text );
222258 }else{
223259 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);
225263 }else{
226 - $wgOut->addHTML($text_2);
 264+ $text .= $text_2;
 265+ $wgOut->addHTML($text);
227266 }
228267 }
229268 }else {

Status & tagging log