Index: trunk/extensions/SemanticForms/includes/SF_FormClasses.php |
— | — | @@ -74,19 +74,16 @@ |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * For a field name and its attached property name located in the |
78 | | - * template text, add the two to the $templateFields array, and |
79 | | - * then 'x' them out in the template text to prevent them from being |
80 | | - * parsed twice. |
| 78 | + * template text, create an SFTemplateField object out of it, and |
| 79 | + * add it to the $templateFields array. |
81 | 80 | */ |
82 | | - function handlePropertySettingInTemplate( $fieldName, $propertyName, $isList, &$templateFields, $fullFieldText, &$templateText ) { |
| 81 | + function handlePropertySettingInTemplate( $fieldName, $propertyName, $isList, &$templateFields, $templateText ) { |
83 | 82 | global $wgContLang; |
84 | 83 | $templateField = SFTemplateField::create( $fieldName, $wgContLang->ucfirst( $fieldName ) ); |
85 | 84 | $templateField->setSemanticProperty( $propertyName ); |
86 | 85 | $templateField->is_list = $isList; |
87 | 86 | $cur_pos = stripos( $templateText, $fieldName ); |
88 | 87 | $templateFields[$cur_pos] = $templateField; |
89 | | - $replacement = str_repeat( "x", strlen( $fullFieldText ) ); |
90 | | - $templateText = str_replace( $fullFieldText, $replacement, $templateText ); |
91 | 88 | } |
92 | 89 | |
93 | 90 | /** |
— | — | @@ -101,13 +98,10 @@ |
102 | 99 | // The way this works is that fields are found and then stored |
103 | 100 | // in an array based on their location in the template text, so |
104 | 101 | // that they can be returned in the order in which they appear |
105 | | - // in the template, even though they were found in a different |
106 | | - // order. |
| 102 | + // in the template, not the order in which they were found. |
107 | 103 | // Some fields can be found more than once (especially if |
108 | 104 | // they're part of an "#if" statement), so they're only |
109 | | - // recorded the first time they're found. Also, every field |
110 | | - // gets replaced with a string of x's after being found, so it |
111 | | - // doesn't interfere with future parsing. |
| 105 | + // recorded the first time they're found. |
112 | 106 | $template_title = Title::makeTitleSafe( NS_TEMPLATE, $this->template_name ); |
113 | 107 | $template_article = null; |
114 | 108 | if ( isset( $template_title ) ) $template_article = new Article( $template_title ); |
— | — | @@ -119,30 +113,23 @@ |
120 | 114 | |
121 | 115 | // First, look for "arraymap" parser function calls |
122 | 116 | // that map a property onto a list. |
123 | | - if ( preg_match_all( '/{{#arraymap:{{{([^|}]*:?[^|}]*)[^\[]*\[\[([^:=]*:?[^:=]*)(:[:=])/mis', $templateText, $matches ) ) { |
124 | | - // This is a two-dimensional array; we need |
125 | | - // the last three of the four sub-arrays; we |
126 | | - // also have to remove redundant values. |
| 117 | + if ( preg_match_all( '/{{#arraymap:{{{([^|}]*:?[^|}]*)[^\[]*\[\[([^:]*:?[^:]*)::/mis', $templateText, $matches ) ) { |
127 | 118 | foreach ( $matches[1] as $i => $field_name ) { |
128 | 119 | if ( ! in_array( $field_name, $fieldNamesArray ) ) { |
129 | 120 | $propertyName = $matches[2][$i]; |
130 | | - $full_field_text = $matches[0][$i]; |
131 | | - self::handlePropertySettingInTemplate( $field_name, $propertyName, true, &$templateFields, $full_field_text, &$templateText ); |
| 121 | + self::handlePropertySettingInTemplate( $field_name, $propertyName, true, &$templateFields, $templateText ); |
132 | 122 | $fieldNamesArray[] = $field_name; |
133 | 123 | } |
134 | 124 | } |
135 | 125 | } |
136 | 126 | |
137 | 127 | // Second, look for normal property calls. |
138 | | - if ( preg_match_all( '/\[\[([^:=]*:*?[^:=]*)(:[:=]){{{([^\]\|}]*).*?\]\]/mis', $templateText, $matches ) ) { |
139 | | - // This is a two-dimensional array; we need |
140 | | - // the last three of the four sub-arrays; we |
141 | | - // also have to remove redundant values. |
| 128 | + if ( preg_match_all( '/\[\[([^:|\[\]]*:*?[^:|\[\]]*)::{{{([^\]\|}]*).*?\]\]/mis', $templateText, $matches ) ) { |
142 | 129 | foreach ( $matches[1] as $i => $propertyName ) { |
143 | | - $field_name = $matches[3][$i]; |
| 130 | + $field_name = trim( $matches[2][$i] ); |
144 | 131 | if ( ! in_array( $field_name, $fieldNamesArray ) ) { |
145 | | - $full_field_text = $matches[0][$i]; |
146 | | - self::handlePropertySettingInTemplate( $field_name, $propertyName, false, &$templateFields, $full_field_text, &$templateText ); |
| 132 | + $propertyName = trim( $propertyName ); |
| 133 | + self::handlePropertySettingInTemplate( $field_name, $propertyName, false, &$templateFields, $templateText ); |
147 | 134 | $fieldNamesArray[] = $field_name; |
148 | 135 | } |
149 | 136 | } |
— | — | @@ -152,17 +139,12 @@ |
153 | 140 | // (thankfully, they have basically the same syntax). |
154 | 141 | if ( preg_match_all( '/#(set|set_internal):(.*?}}})\s*}}/mis', $templateText, $matches ) ) { |
155 | 142 | foreach ( $matches[2] as $i => $match ) { |
156 | | - $match = str_replace( '{{{', '', $match ); |
157 | | - $match = str_replace( '}}}', '', $match ); |
158 | | - $setValues = explode( '|', $match ); |
159 | | - foreach( $setValues as $valuePair ) { |
160 | | - $keyAndVal = explode( '=', $valuePair ); |
161 | | - if ( count( $keyAndVal ) == 2) { |
162 | | - $propertyName = trim( $keyAndVal[0] ); |
163 | | - $fieldName = trim( $keyAndVal[1] ); |
| 143 | + if ( preg_match_all( '/([^|{]*?)=\s*{{{([^|}]*)/mis', $match, $matches2 ) ) { |
| 144 | + foreach ( $matches2[1] as $i => $propertyName ) { |
| 145 | + $fieldName = trim( $matches2[2][$i] ); |
164 | 146 | if ( ! in_array( $fieldName, $fieldNamesArray ) ) { |
165 | | - $full_field_text = $matches[0][$i]; |
166 | | - self::handlePropertySettingInTemplate( $fieldName, $propertyName, false, &$templateFields, $full_field_text, &$templateText ); |
| 147 | + $propertyName = trim( $propertyName ); |
| 148 | + self::handlePropertySettingInTemplate( $fieldName, $propertyName, false, &$templateFields, $templateText ); |
167 | 149 | $fieldNamesArray[] = $fieldName; |
168 | 150 | } |
169 | 151 | } |
— | — | @@ -180,8 +162,8 @@ |
181 | 163 | $propertyName = trim( $keyAndVal[0] ); |
182 | 164 | $fieldName = trim( $keyAndVal[1] ); |
183 | 165 | if ( ! in_array( $fieldName, $fieldNamesArray ) ) { |
184 | | - $full_field_text = $matches[0][$i]; |
185 | | - self::handlePropertySettingInTemplate( $fieldName, $propertyName, false, &$templateFields, $full_field_text, &$templateText ); |
| 166 | + self::handlePropertySettingInTemplate( $fieldName, $propertyName, false, &$templateFields, $templateText ); |
| 167 | + $fieldNamesArray[] = $fieldName; |
186 | 168 | } |
187 | 169 | } |
188 | 170 | } |
— | — | @@ -190,12 +172,12 @@ |
191 | 173 | |
192 | 174 | // Finally, get any non-semantic fields defined. |
193 | 175 | if ( preg_match_all( '/{{{([^|}]*)/mis', $templateText, $matches ) ) { |
194 | | - foreach ( $matches[1] as $i => $field_name ) { |
195 | | - $full_field_text = $matches[0][$i]; |
196 | | - if ( ( $full_field_text != '' ) && ( ! in_array( $field_name, $fieldNamesArray ) ) ) { |
197 | | - $cur_pos = stripos( $templateText, $full_field_text ); |
198 | | - $templateFields[$cur_pos] = SFTemplateField::create( $field_name, $wgContLang->ucfirst( $field_name ) ); |
199 | | - $fieldNamesArray[] = $field_name; |
| 176 | + foreach ( $matches[1] as $i => $fieldName ) { |
| 177 | + $fieldName = trim( $fieldName ); |
| 178 | + if ( !empty( $fieldName ) && ( ! in_array( $fieldName, $fieldNamesArray ) ) ) { |
| 179 | + $cur_pos = stripos( $templateText, $fieldName ); |
| 180 | + $templateFields[$cur_pos] = SFTemplateField::create( $fieldName, $wgContLang->ucfirst( $fieldName ) ); |
| 181 | + $fieldNamesArray[] = $fieldName; |
200 | 182 | } |
201 | 183 | } |
202 | 184 | } |