Index: trunk/extensions/PageSchemas/PS_Tabs.php |
— | — | @@ -1,76 +1,74 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - |
6 | | -* @file PSTabs.php |
7 | | - * @ingroup |
| 5 | + * @file PSTabs.php |
| 6 | + * @ingroup |
8 | 7 | * |
9 | 8 | * @author ankit |
10 | 9 | */ |
11 | 10 | final class PSTabs { |
12 | | - |
| 11 | + |
13 | 12 | public static function displayTabs( $obj, &$content_actions ) { |
14 | 13 | global $wgUser; |
15 | | - |
| 14 | + |
16 | 15 | $title = $obj->getTitle(); |
17 | | - if ( |
18 | | - $title->getNamespace() == NS_CATEGORY |
19 | | - && $title->exists() ){ |
20 | | - global $wgRequest; |
21 | | - |
22 | | - $category = $title->getText(); |
23 | | - $pageSchemaObj = new PSSchema( $category ); |
24 | | - if( $pageSchemaObj->isPSDefined() ){ |
25 | | - $content_actions['editschema'] = array( |
26 | | - 'text' => wfMsg( 'editschema' ), |
27 | | - 'class' => $wgRequest->getVal( 'action' ) == 'editschema' ? 'selected' : '', |
28 | | - 'href' => $title->getLocalURL( 'action=editschema' ) |
29 | | - ); |
30 | | - $content_actions['generatepages'] = array( |
| 16 | + if ( $title->getNamespace() != NS_CATEGORY || !$title->exists() ){ |
| 17 | + return true; |
| 18 | + } |
| 19 | + |
| 20 | + global $wgRequest; |
| 21 | + |
| 22 | + $content_actions['editschema'] = array( |
| 23 | + 'text' => wfMsg( 'editschema' ), |
| 24 | + 'class' => $wgRequest->getVal( 'action' ) == 'editschema' ? 'selected' : '', |
| 25 | + 'href' => $title->getLocalURL( 'action=editschema' ) |
| 26 | + ); |
| 27 | + |
| 28 | + $category = $title->getText(); |
| 29 | + $pageSchemaObj = new PSSchema( $category ); |
| 30 | + if ( $pageSchemaObj->isPSDefined() ) { |
| 31 | + $content_actions['generatepages'] = array( |
31 | 32 | 'text' => wfMsg( 'generatepages' ), |
32 | 33 | 'class' => $wgRequest->getVal( 'action' ) == 'generatepages' ? 'selected' : '', |
33 | 34 | 'href' => $title->getLocalURL( 'action=generatepages' ) |
34 | | - ); |
35 | | - }else{ |
36 | | - $content_actions['editschema'] = array( |
37 | | - 'text' => wfMsg( 'createpages' ), |
38 | | - 'class' => $wgRequest->getVal( 'action' ) == 'editschema' ? 'selected' : '', |
39 | | - 'href' => $title->getLocalURL( 'action=editschema' ) |
40 | | - ); |
41 | | - } |
| 35 | + ); |
42 | 36 | } |
43 | | - |
| 37 | + |
44 | 38 | return true; |
45 | 39 | } |
46 | 40 | |
47 | 41 | /** |
48 | | - * Function currently called only for the 'Vector' skin, added in |
49 | | - * MW 1.16 - will possibly be called for additional skins later |
| 42 | + * Function called for some skins, most notably 'Vector'. |
50 | 43 | */ |
51 | 44 | public static function displayTabs2( $obj, &$links ) { |
52 | 45 | // The old '$content_actions' array is thankfully just a sub-array of this one |
53 | 46 | $views_links = $links['actions']; |
54 | 47 | self::displayTabs( $obj, $views_links ); |
55 | | - $links['actions'] = $views_links; |
| 48 | + $links['actions'] = $views_links; |
56 | 49 | return true; |
57 | 50 | } |
58 | 51 | |
59 | | - /** |
60 | | - * |
61 | | - * @return true |
| 52 | + /** |
| 53 | + * Adds handling for the tabs 'generatepages' and 'editschema'. |
62 | 54 | */ |
63 | 55 | public static function onUnknownAction( $action, Article $article ) { |
64 | 56 | $title = $article->getTitle(); |
65 | | - $category = $title->getText(); |
66 | | - if ( $action == 'generatepages' ) { |
67 | | - $gen_page = new GeneratePages(); |
68 | | - $gen_page->execute($category); |
69 | | - return false; |
70 | | - } elseif ( $action == 'editschema' ) { |
71 | | - $edit_schema = new EditSchema(); |
72 | | - $edit_schema->execute($category); |
73 | | - return false; |
74 | | - } |
| 57 | + |
| 58 | + // These tabs should only exist for category pages |
| 59 | + if ( $title->getNamespace() != NS_CATEGORY ) { |
| 60 | + return false; |
| 61 | + } |
| 62 | + |
| 63 | + $categoryName = $title->getText(); |
| 64 | + if ( $action == 'generatepages' ) { |
| 65 | + $gen_page = new GeneratePages(); |
| 66 | + $gen_page->execute( $categoryName ); |
| 67 | + return false; |
| 68 | + } elseif ( $action == 'editschema' ) { |
| 69 | + $edit_schema = new EditSchema(); |
| 70 | + $edit_schema->execute( $categoryName ); |
| 71 | + return false; |
| 72 | + } |
75 | 73 | return true; |
76 | 74 | } |
77 | | -} |
\ No newline at end of file |
| 75 | +} |
Index: trunk/extensions/PageSchemas/PageSchemas.classes.php |
— | — | @@ -8,30 +8,17 @@ |
9 | 9 | |
10 | 10 | class PageSchemas { |
11 | 11 | |
12 | | - /* Functions */ |
13 | | - //Copied from SFUtils |
14 | | - public static function loadJavascriptAndCSS( $parser = null ) { |
15 | | - // Handling depends on whether or not this form is embedded |
16 | | - // in another page. |
17 | | - if ( !is_null( $parser ) ) { |
18 | | - $output = $parser->getOutput(); |
19 | | - } else { |
20 | | - global $wgOut; |
21 | | - $output = $wgOut; |
22 | | - } |
23 | | - $output->addModules( 'jquery' ); |
24 | | - } |
25 | 12 | public static function getCategoriesWithPSDefined(){ |
26 | | - $cat_titles = array(); |
| 13 | + $cat_titles = array(); |
27 | 14 | $dbr = wfGetDB( DB_SLAVE ); |
28 | 15 | //get the result set, query : slect page_props |
29 | 16 | $res = $dbr->select( 'page_props', |
30 | 17 | array( |
31 | 18 | 'pp_page', |
32 | 19 | 'pp_propname', |
33 | | - 'pp_value' |
| 20 | + 'pp_value' |
34 | 21 | ), |
35 | | - array( |
| 22 | + array( |
36 | 23 | 'pp_propname' => 'PageSchema' |
37 | 24 | ) |
38 | 25 | ); |
— | — | @@ -51,7 +38,7 @@ |
52 | 39 | /** |
53 | 40 | * Includes the necessary Javascript and CSS files for the form |
54 | 41 | * to display and work correctly. |
55 | | - * |
| 42 | + * |
56 | 43 | * Accepts an optional Parser instance, or uses $wgOut if omitted. |
57 | 44 | */ |
58 | 45 | public static function addJavascriptAndCSS( $parser = null ) { |
— | — | @@ -59,13 +46,17 @@ |
60 | 47 | |
61 | 48 | if ( !$parser ) { |
62 | 49 | $wgOut->addMeta( 'robots', 'noindex,nofollow' ); |
63 | | - } |
| 50 | + } |
64 | 51 | |
65 | | - // MW 1.17 + |
66 | | - if ( class_exists( 'ResourceLoader' ) ) { |
67 | | - self::loadJavascriptAndCSS( $parser ); |
68 | | - return; |
69 | | - } |
| 52 | + // Handling depends on whether or not this page is embedded |
| 53 | + // in another page. |
| 54 | + if ( !is_null( $parser ) ) { |
| 55 | + $output = $parser->getOutput(); |
| 56 | + } else { |
| 57 | + global $wgOut; |
| 58 | + $output = $wgOut; |
| 59 | + } |
| 60 | + $output->addModules( 'jquery' ); |
70 | 61 | } |
71 | 62 | |
72 | 63 | public static function titleString( $title ) { |
— | — | @@ -80,20 +71,12 @@ |
81 | 72 | return $namespace . $title->getText(); |
82 | 73 | } |
83 | 74 | } |
| 75 | + |
84 | 76 | public static function isCapitalized( $title ) { |
85 | | - // Method was added in MW 1.16. |
86 | | - $realFunction = array( 'MWNamespace', 'isCapitalized' ); |
87 | | - if ( is_callable( $realFunction ) ) { |
88 | | - return MWNamespace::isCapitalized( $title->getNamespace() ); |
89 | | - } else { |
90 | | - global $wgCapitalLinks; |
91 | | - return $wgCapitalLinks; |
92 | | - } |
| 77 | + return MWNamespace::isCapitalized( $title->getNamespace() ); |
| 78 | + } |
93 | 79 | |
94 | | - } |
95 | 80 | public static function validateXML( $xml, &$error_msg ) { |
96 | | - |
97 | | - |
98 | 81 | $xmlDTD =<<<END |
99 | 82 | <?xml version="1.0" encoding="utf-8"?> |
100 | 83 | <!DOCTYPE PageSchema [ |
— | — | @@ -107,6 +90,7 @@ |
108 | 91 | ]> |
109 | 92 | |
110 | 93 | END; |
| 94 | + |
111 | 95 | // we are using the SimpleXML library to do the XML validation |
112 | 96 | // for now - this may change later |
113 | 97 | // hide parsing warnings |
— | — | @@ -138,29 +122,30 @@ |
139 | 123 | return $text; |
140 | 124 | } |
141 | 125 | |
142 | | - static function parsePageSchemas($class_schema_xml) { |
| 126 | + static function parsePageSchemas($class_schema_xml) { |
143 | 127 | global $wgTitle; |
144 | | - if($wgTitle->getNamespace() == NS_CATEGORY){ |
145 | | - $text = "<p>Schema description:</p>\n"; |
146 | | - $text .= "<table class=\"pageSchema\">\n"; |
147 | | - $name = $class_schema_xml->attributes()->name; |
148 | | - $text .= self::tableRowHTML('paramGroup', 'PageSchema', $name); |
149 | | - foreach ( $class_schema_xml->children() as $tag => $child ) { |
150 | | - if ( $tag == 'semanticforms_Form' ){ |
| 128 | + |
| 129 | + if ( $wgTitle->getNamespace() == NS_CATEGORY ){ |
| 130 | + $text = "<p>Schema description:</p>\n"; |
| 131 | + $text .= "<table class=\"pageSchema\">\n"; |
| 132 | + $name = $class_schema_xml->attributes()->name; |
| 133 | + $text .= self::tableRowHTML('paramGroup', 'PageSchema', $name); |
| 134 | + foreach ( $class_schema_xml->children() as $tag => $child ) { |
| 135 | + if ( $tag == 'semanticforms_Form' ) { |
151 | 136 | $text .= self::parseFormElem($child); |
152 | | - } |
153 | | - else if ($tag == 'Template') { |
| 137 | + } elseif ($tag == 'Template') { |
154 | 138 | $text .= self::parseTemplate($child); |
155 | | - } else{ |
156 | | - echo "Code to be added by other extension\n"; |
| 139 | + } else { |
| 140 | + //echo "Code to be added by other extension\n"; |
157 | 141 | } |
158 | 142 | } |
159 | | - $text .= "</table>\n"; |
160 | | - }else{ |
161 | | - $text = ""; |
| 143 | + $text .= "</table>\n"; |
| 144 | + } else { |
| 145 | + $text = ""; |
162 | 146 | } |
163 | | - return $text; |
| 147 | + return $text; |
164 | 148 | } |
| 149 | + |
165 | 150 | static function parseFormElem( $form_xml ) { |
166 | 151 | $name = $form_xml->attributes()->name; |
167 | 152 | $text = self::tableRowHTML('param', 'Form', $name); |
— | — | @@ -169,7 +154,8 @@ |
170 | 155 | } |
171 | 156 | return $text; |
172 | 157 | } |
173 | | - static function parseTemplate ( $template_xml ) { |
| 158 | + |
| 159 | + static function parseTemplate ( $template_xml ) { |
174 | 160 | $name = $template_xml->attributes()->name; |
175 | 161 | $text = self::tableRowHTML('param', 'Template', $name); |
176 | 162 | foreach ($template_xml->children() as $child) { |
— | — | @@ -181,7 +167,7 @@ |
182 | 168 | $name = $field_xml->attributes()->name; |
183 | 169 | $text = self::tableRowHTML('paramAttr', 'Field', $name); |
184 | 170 | $text_object = array(); //different extensions will fill the html parsed text in this array via hooks |
185 | | - wfRunHooks( 'PSParseFieldElements', array( $field_xml, &$text_object ) ); |
| 171 | + wfRunHooks( 'PSParseFieldElements', array( $field_xml, &$text_object ) ); |
186 | 172 | foreach( $text_object as $key => $value ) { |
187 | 173 | $text .= $value; |
188 | 174 | } |
— | — | @@ -189,64 +175,62 @@ |
190 | 176 | } |
191 | 177 | } |
192 | 178 | |
193 | | -/*class holds the PageScheme tag equivalent object */ |
| 179 | +/*class holds the PageSchema tag equivalent object */ |
194 | 180 | |
195 | 181 | class PSSchema { |
196 | | - public $categoryName=""; |
197 | | - public $pageId=0; |
198 | | - public $pageXml=null; |
199 | | - public $pageXmlstr= ""; |
200 | | - //public $pageName=""; |
201 | | - public $formName=""; |
202 | | - public $formArray = array(); |
203 | | - /* Stores the templte objects */ |
| 182 | + public $categoryName = ""; |
| 183 | + public $pageID = 0; |
| 184 | + public $pageXML = null; |
| 185 | + public $pageXMLstr = ""; |
| 186 | + public $formName = ""; |
| 187 | + public $formArray = array(); |
| 188 | + /* Stores the template objects */ |
204 | 189 | public $PSTemplates = array(); |
205 | | - public $isPSDefined = true; |
| 190 | + public $isPSDefined = true; |
206 | 191 | public $pp_value = ""; |
| 192 | + |
207 | 193 | function __construct ( $category_name ) { |
208 | | - $this->categoryName = $category_name; |
| 194 | + $this->categoryName = $category_name; |
209 | 195 | $title = Title::newFromText( $category_name, NS_CATEGORY ); |
210 | | - $this->pageId = $title->getArticleID(); |
| 196 | + $this->pageID = $title->getArticleID(); |
211 | 197 | $dbr = wfGetDB( DB_SLAVE ); |
212 | | - //get the result set, query : slect page_props |
213 | 198 | $res = $dbr->select( 'page_props', |
214 | | - array( |
215 | | - 'pp_page', |
216 | | - 'pp_propname', |
217 | | - 'pp_value' |
218 | | - ), |
219 | | - array( |
220 | | - 'pp_page' => $this->pageId, |
221 | | - 'pp_propname' => 'PageSchema' |
222 | | - ) |
| 199 | + array( |
| 200 | + 'pp_page', |
| 201 | + 'pp_propname', |
| 202 | + 'pp_value' |
| 203 | + ), |
| 204 | + array( |
| 205 | + 'pp_page' => $this->pageID, |
| 206 | + 'pp_propname' => 'PageSchema' |
| 207 | + ) |
223 | 208 | ); |
224 | | - //first row of the result set |
| 209 | + // first row of the result set |
225 | 210 | $row = $dbr->fetchRow( $res ); |
226 | | - if( $row == null){ |
| 211 | + if ( $row == null) { |
227 | 212 | $this->isPSDefined = false; |
228 | | - }else{ |
229 | | - //retrievimg the third attribute which is pp_value |
230 | | - $pageXmlstr = $row[2]; |
231 | | - $this->pageXml = simplexml_load_string ( $pageXmlstr ); |
232 | | - //$this->pageName = (string)$this->pageXml->attributes()->name; |
233 | | - /* index for template objects */ |
| 213 | + } else { |
| 214 | + // retrieve the third attribute, which is pp_value |
| 215 | + $pageXMLstr = $row[2]; |
| 216 | + $this->pageXML = simplexml_load_string ( $pageXMLstr ); |
| 217 | + /* index for template objects */ |
234 | 218 | $i = 0; |
235 | 219 | $inherited_templates = null ; |
236 | | - foreach ( $this->pageXml->children() as $tag => $child ) { |
| 220 | + foreach ( $this->pageXML->children() as $tag => $child ) { |
237 | 221 | if ( $tag == 'InheritsFrom ' ) { |
238 | 222 | $schema_to_inherit = (string) $child->attributes()->schema; |
239 | 223 | if( $schema_to_inherit !=null ){ |
240 | 224 | $inheritedSchemaObj = new PSSchema( $schema_to_inherit ); |
241 | | - $inherited_templates = $inheritedSchemaObj->getTemplates(); |
| 225 | + $inherited_templates = $inheritedSchemaObj->getTemplates(); |
242 | 226 | } |
243 | 227 | } |
244 | 228 | if ( $tag == 'Template' ) { |
245 | 229 | $ignore = (string) $child->attributes()->ignore; |
246 | | - if( count($child->children()) > 0 ){ |
247 | | - $templateObj = new PSTemplate($child); |
| 230 | + if ( count($child->children()) > 0 ) { |
| 231 | + $templateObj = new PSTemplate($child); |
248 | 232 | $this->PSTemplates[$i++]= $templateObj; |
249 | | - }else if( $ignore != "true" ) { |
250 | | - //Code to Add Templates from Inherited templates |
| 233 | + } elseif ( $ignore != "true" ) { |
| 234 | + // Code to add templates from inherited templates |
251 | 235 | $temp_name = (string) $child->attributes()->name; |
252 | 236 | foreach( $inherited_templates as $inherited_template ) { |
253 | 237 | if( $temp_name == $inherited_template->getName() ){ |
— | — | @@ -254,80 +238,87 @@ |
255 | 239 | } |
256 | 240 | } |
257 | 241 | } |
258 | | - } |
| 242 | + } |
259 | 243 | } |
260 | 244 | } |
261 | 245 | } |
262 | | - /* function to generate all pages based on the Xml contained in the page */ |
| 246 | + |
| 247 | + /* function to generate all pages based on the XML contained in the page */ |
263 | 248 | function generateAllPages ( $toGenPageList ) { |
264 | | - wfRunHooks( 'PageSchemasGeneratePages', array( $this, $toGenPageList )); |
| 249 | + wfRunHooks( 'PageSchemasGeneratePages', array( $this, $toGenPageList )); |
265 | 250 | } |
| 251 | + |
266 | 252 | /*return an array of PSTemplate Objects */ |
267 | 253 | function getFormArray () { |
268 | 254 | $obj = $this->getObject('semanticforms_Form'); |
269 | 255 | return $obj['sf']; |
270 | 256 | } |
| 257 | + |
271 | 258 | /*return an array of PSTemplate Objects */ |
272 | 259 | function isPSDefined () { |
273 | | - return $this->isPSDefined; |
274 | | - } |
| 260 | + return $this->isPSDefined; |
| 261 | + } |
| 262 | + |
275 | 263 | /*return an array of PSTemplate Objects */ |
276 | 264 | function getTemplates () { |
277 | | - return $this->PSTemplates; |
278 | | - } |
| 265 | + return $this->PSTemplates; |
| 266 | + } |
| 267 | + |
279 | 268 | function getFormName(){ |
280 | 269 | $form_array = $this->getFormArray(); |
281 | 270 | return $form_array['name']; |
282 | 271 | } |
| 272 | + |
283 | 273 | function getObject( $objectName ) { |
284 | 274 | $object = array(); |
285 | | - wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->pageXml, &$object ) ); |
| 275 | + wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->pageXML, &$object ) ); |
286 | 276 | return $object; |
287 | 277 | } |
288 | | - function getCategoryName(){ |
| 278 | + |
| 279 | + function getCategoryName() { |
289 | 280 | return $this->categoryName; |
290 | | - } |
| 281 | + } |
291 | 282 | } |
292 | | -class PSTemplate { |
| 283 | +class PSTemplate { |
293 | 284 | /* Stores the field objects */ |
294 | | - public $PSFields = array(); |
| 285 | + public $PSFields = array(); |
295 | 286 | public $templateName =""; |
296 | | - public $templateXml = null; |
| 287 | + public $templateXML = null; |
297 | 288 | public $multiple_allowed = false; |
298 | 289 | private $label_name = null; |
| 290 | + |
299 | 291 | function __construct( $template_xml ) { |
300 | | - $this->templateXml = $template_xml; |
| 292 | + $this->templateXML = $template_xml; |
301 | 293 | $this->templateName = (string) $template_xml->attributes()->name; |
302 | 294 | if( ((string) $template_xml->attributes()->multiple) == "multiple" ) { |
303 | 295 | $this->multiple_allowed = true; |
304 | 296 | } |
305 | 297 | /*index for template objects */ |
306 | 298 | $i = 0 ; |
307 | | - $inherited_fields = null ; |
308 | | - foreach ($template_xml->children() as $child) { |
309 | | - if ( $child->getName() == 'InheritsFrom' ) { |
| 299 | + $inherited_fields = array(); |
| 300 | + foreach ($template_xml->children() as $child) { |
| 301 | + if ( $child->getName() == 'InheritsFrom' ) { |
310 | 302 | $schema_to_inherit = (string) $child->attributes()->schema; |
311 | | - $template_to_inherit = (string) $child->attributes()->template; |
| 303 | + $template_to_inherit = (string) $child->attributes()->template; |
312 | 304 | if( $schema_to_inherit !=null && $template_to_inherit != null ) { |
313 | 305 | $inheritedSchemaObj = new PSSchema( $schema_to_inherit ); |
314 | | - $inherited_templates = $inheritedSchemaObj->getTemplates(); |
| 306 | + $inherited_templates = $inheritedSchemaObj->getTemplates(); |
315 | 307 | foreach( $inherited_templates as $inherited_template ) { |
316 | 308 | if( $template_to_inherit == $inherited_template->getName() ){ |
317 | | - $inherited_fields = $inherited_template->getFields(); |
| 309 | + $inherited_fields = $inherited_template->getFields(); |
318 | 310 | } |
319 | 311 | } |
320 | 312 | } |
321 | | - } |
322 | | - else if( $child->getName() == "Label" ) { //@TODO Label => sf:Label |
| 313 | + } elseif ( $child->getName() == "Label" ) { //@TODO Label => sf:Label |
323 | 314 | $this->label_name = (string)$child; |
324 | | - } else if ( $child->getName() == "Field" ){ |
| 315 | + } elseif ( $child->getName() == "Field" ){ |
325 | 316 | $ignore = (string) $child->attributes()->ignore; |
326 | | - if( count($child->children()) > 0 ){ //@TODO :Can be dealt more efficiently |
327 | | - $fieldObj = new PSTemplateField($child); |
| 317 | + if( count($child->children()) > 0 ){ //@TODO :Can be dealt more efficiently |
| 318 | + $fieldObj = new PSTemplateField($child); |
328 | 319 | $this->PSFields[$i++]= $fieldObj; |
329 | | - }else if( $ignore != "true" ) { |
330 | | - //Code to Add Templates from Inherited templates |
331 | | - $field_name = (string) $child->attributes()->name; |
| 320 | + } elseif ( $ignore != "true" ) { |
| 321 | + //Code to Add Templates from Inherited templates |
| 322 | + $field_name = (string) $child->attributes()->name; |
332 | 323 | foreach( $inherited_fields as $inherited_field ) { |
333 | 324 | if( $field_name == $inherited_field->getName() ){ |
334 | 325 | $this->PSFields[$i++]= $inherited_field; |
— | — | @@ -337,57 +328,66 @@ |
338 | 329 | } |
339 | 330 | } |
340 | 331 | } |
341 | | - function getName(){ |
342 | | - return $this->templateName; |
| 332 | + |
| 333 | + function getName() { |
| 334 | + return $this->templateName; |
343 | 335 | } |
344 | | - function isMultiple(){ |
345 | | - return $this->multiple_allowed; |
| 336 | + |
| 337 | + function isMultiple() { |
| 338 | + return $this->multiple_allowed; |
346 | 339 | } |
347 | | - public function getLabel(){ |
348 | | - return $this->label_name; |
349 | | - } |
350 | | - function getFields(){ |
351 | | - return $this->PSFields; |
| 340 | + |
| 341 | + public function getLabel() { |
| 342 | + return $this->label_name; |
352 | 343 | } |
| 344 | + |
| 345 | + function getFields() { |
| 346 | + return $this->PSFields; |
| 347 | + } |
353 | 348 | } |
354 | 349 | |
355 | 350 | class PSTemplateField { |
356 | | - |
357 | 351 | public $fieldName =""; |
358 | | - public $fieldXml= null; |
359 | | - public $fieldLabel = ""; |
| 352 | + public $fieldXML = null; |
| 353 | + public $fieldLabel = ""; |
360 | 354 | private $list_values = false; |
361 | | - private $delimiter=null; |
| 355 | + private $delimiter = null; |
| 356 | + |
362 | 357 | function __construct( $field_xml ) { |
363 | | - $this->fieldXml = $field_xml; |
364 | | - $this->fieldName = (string)$this->fieldXml->attributes()->name; |
365 | | - if( ((string)$this->fieldXml->attributes()->list) == "list") { |
| 358 | + $this->fieldXML = $field_xml; |
| 359 | + $this->fieldName = (string)$this->fieldXML->attributes()->name; |
| 360 | + if( ((string)$this->fieldXML->attributes()->list) == "list") { |
366 | 361 | $this->list_values = true; |
367 | 362 | } |
368 | | - if( ((string)$this->fieldXml->attributes()->delimiter) != null || ((string)$this->fieldXml->attributes()->delimiter) != '' ){ |
369 | | - $this->delimiter = (string)$this->fieldXml->attributes()->delimiter; |
| 363 | + if( ((string)$this->fieldXML->attributes()->delimiter) != null || ((string)$this->fieldXML->attributes()->delimiter) != '' ){ |
| 364 | + $this->delimiter = (string)$this->fieldXML->attributes()->delimiter; |
370 | 365 | } |
371 | | - foreach ($this->fieldXml->children() as $tag => $child ) { |
| 366 | + foreach ($this->fieldXML->children() as $tag => $child ) { |
372 | 367 | if ( $tag == 'Label' ) { |
373 | 368 | $this->fieldLabel = (string)$child; |
374 | | - } |
375 | | - } |
| 369 | + } |
| 370 | + } |
376 | 371 | } |
| 372 | + |
377 | 373 | public function getDelimiter(){ |
378 | 374 | return $this->delimiter; |
379 | | - } |
| 375 | + } |
| 376 | + |
380 | 377 | function getName(){ |
381 | 378 | return $this->fieldName; |
382 | 379 | } |
| 380 | + |
383 | 381 | function getLabel(){ |
384 | 382 | return $this->fieldLabel; |
385 | 383 | } |
| 384 | + |
386 | 385 | public function isList(){ |
387 | 386 | return $this->list_values; |
388 | 387 | } |
| 388 | + |
389 | 389 | function getObject( $objectName ) { |
390 | 390 | $object = array(); |
391 | | - wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->fieldXml, &$object ) ); |
| 391 | + wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->fieldXML, &$object ) ); |
392 | 392 | return $object; |
393 | 393 | } |
394 | 394 | } |
Index: trunk/extensions/PageSchemas/PS_CreatePageJob.php |
— | — | @@ -23,12 +23,12 @@ |
24 | 24 | wfProfileOut( __METHOD__ ); |
25 | 25 | return false; |
26 | 26 | } |
27 | | - $article = new Article( $this->title ); |
28 | | - if ( !$article ) { |
29 | | - $this->error = 'createPage: Article not found "' . $this->title->getPrefixedDBkey() . '"'; |
30 | | - wfProfileOut( __METHOD__ ); |
31 | | - return false; |
32 | | - } |
| 27 | + $article = new Article( $this->title ); |
| 28 | + if ( !$article ) { |
| 29 | + $this->error = 'createPage: Article not found "' . $this->title->getPrefixedDBkey() . '"'; |
| 30 | + wfProfileOut( __METHOD__ ); |
| 31 | + return false; |
| 32 | + } |
33 | 33 | |
34 | 34 | $page_text = $this->params['page_text']; |
35 | 35 | // change global $wgUser variable to the one |
Index: trunk/extensions/PageSchemas/specials/PS_GeneratePages.php |
— | — | @@ -1,65 +1,77 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Displays an interface to let users create all pages based on xml |
| 4 | + * Displays an interface to let users create all pages based on the Page Schemas XML |
5 | 5 | * |
6 | 6 | * @author Ankit Garg |
7 | 7 | */ |
8 | 8 | |
9 | 9 | class GeneratePages extends IncludableSpecialPage { |
10 | | - function __construct() { |
11 | | - parent::__construct( 'GeneratePages' ); |
12 | | - wfLoadExtensionMessages('GeneratePages'); |
13 | | - } |
14 | | - |
15 | | - function execute( $category ) { |
| 10 | + function __construct() { |
| 11 | + parent::__construct( 'GeneratePages' ); |
| 12 | + wfLoadExtensionMessages('GeneratePages'); |
| 13 | + } |
| 14 | + |
| 15 | + function execute( $category ) { |
16 | 16 | global $wgRequest, $wgOut; |
17 | 17 | global $wgSkin; |
18 | | - $this->setHeaders(); |
19 | | - $generate_page_text = wfMsg( 'ps-generatepages' ); |
20 | | - $generate_page_desc = wfMsg( 'ps-generatepages-desc' ); |
| 18 | + |
| 19 | + $this->setHeaders(); |
21 | 20 | $param = $wgRequest->getText('param'); |
22 | | - $text_1 = '<p>All pages will be generated! </p>'; |
23 | | - if ( $param != "" && $category != "" ) { |
24 | | - $this->generate_pages( $param, $_POST['page'] ); |
25 | | - $wgOut->addHTML($text_1); |
26 | | - }else { |
27 | | - if( $category == ""){ |
28 | | - $text = ""; |
29 | | - $cat_titles = PageSchemas::getCategoriesWithPSDefined(); |
30 | | - foreach( $cat_titles as $cat_text ) { |
31 | | - $generatePagesPage = SpecialPage::getTitleFor( 'GeneratePages' ); |
32 | | - $url = $generatePagesPage ->getFullURL() . '/' . $cat_text; |
33 | | - $text .= '<a href='.$url.'>'.$cat_text.' </a> <br /> '; |
34 | | - } |
35 | | - $wgOut->addHTML( $text ); |
36 | | - }else { |
37 | | - //this is when Special:GeneratePages/Category is accessed first time |
38 | | - //Here check for the valid Category name and allow for generating pages |
39 | | - $pageSchemaObj = new PSSchema( $category ); |
40 | | - if(!$pageSchemaObj->isPSDefined()){ |
41 | | - $text = "<p>Error: there is no psssage schema defined for that category in the wiki. </p>"; |
42 | | - $wgOut->addHTML( $text ); |
43 | | - }else{ |
44 | | - $text_2 = '<p>'.$generate_page_desc.'</p> <form method="post"> <input type="hidden" name="param" value="'.$category.'" /><br /> '; |
45 | | - //add code to generate a list of check-box for pages to be generated. |
46 | | - $pageList = array(); |
47 | | - wfRunHooks( 'PageSchemasGetPageList', array( $pageSchemaObj, &$pageList )); //will return an array of string, with each value as a title of the page to be created. |
48 | | - foreach( $pageList as $page ){ |
49 | | - //$page_link = $wgSkin->link( $page ); |
50 | | - $page_link = $page->getFullUrl(); |
51 | | - $page_val = PageSchemas::titleString( $page ); |
52 | | - $text_2 .= '<input type="checkbox" name="page[]" value="'.$page_val.'" /> '.$page_link.' <br />'; |
53 | | - } |
54 | | - $text_2 .= '<br /> <input type="submit" value="'.$generate_page_text.'" /> <br /> <br /></form>'; |
55 | | - $wgOut->addHTML($text_2); |
| 21 | + if ( $param != "" && $category != "" ) { |
| 22 | + $this->generatePages( $param, $_POST['page'] ); |
| 23 | + $text = '<p>All pages will be generated! </p>'; |
| 24 | + $wgOut->addHTML( $text ); |
| 25 | + return true; |
| 26 | + } |
| 27 | + |
| 28 | + if ( $category == "") { |
| 29 | + // No category listed - show a list of links to all categories with a page |
| 30 | + // schema defined. |
| 31 | + $text = ""; |
| 32 | + $cat_titles = PageSchemas::getCategoriesWithPSDefined(); |
| 33 | + foreach( $cat_titles as $cat_text ) { |
| 34 | + $generatePagesPage = SpecialPage::getTitleFor( 'GeneratePages' ); |
| 35 | + $url = $generatePagesPage->getFullURL() . '/' . $cat_text; |
| 36 | + $text .= '<a href="' . $url . '">' . $cat_text . '</a> <br /> '; |
56 | 37 | } |
57 | | - } |
| 38 | + $wgOut->addHTML( $text ); |
| 39 | + return true; |
58 | 40 | } |
| 41 | + |
| 42 | + // Standard "generate pages" form, with category name set. |
| 43 | + // Check for a valid category, with a page schema defined. |
| 44 | + $pageSchemaObj = new PSSchema( $category ); |
| 45 | + if ( !$pageSchemaObj->isPSDefined() ) { |
| 46 | + $text = "<p>Error: there is no page schema defined for that category in the wiki. </p>"; |
| 47 | + $wgOut->addHTML( $text ); |
| 48 | + return true; |
| 49 | + } |
| 50 | + |
| 51 | + $generate_page_desc = wfMsg( 'ps-generatepages-desc' ); |
| 52 | + $text = "<p>$generate_page_desc</p>\n"; |
| 53 | + $text = '<form method="post"><input type="hidden" name="param" value="'.$category.'" /><br />'; |
| 54 | + //add code to generate a list of check-box for pages to be generated. |
| 55 | + $pageList = array(); |
| 56 | + |
| 57 | + // This hook will return an array of strings, with each value as a title of |
| 58 | + // the page to be created. |
| 59 | + wfRunHooks( 'PageSchemasGetPageList', array( $pageSchemaObj, &$pageList ) ); |
| 60 | + foreach( $pageList as $page ){ |
| 61 | + //$page_link = $wgSkin->link( $page ); |
| 62 | + $pageURL = $page->getFullUrl(); |
| 63 | + $pageName = PageSchemas::titleString( $page ); |
| 64 | + $pageLink = Html::element( 'a', array( 'href' => $pageURL ), $pageName ); |
| 65 | + $text .= '<input type="checkbox" name="page[]" value="' . $pageName . '" checked="checked" />' . $pageLink . ' <br />'; |
| 66 | + } |
| 67 | + $generate_page_text = wfMsg( 'ps-generatepages' ); |
| 68 | + $text .= '<br /> <input type="submit" value="'.$generate_page_text.'" /> <br /> <br /></form>'; |
| 69 | + $wgOut->addHTML( $text ); |
59 | 70 | return true; |
60 | | - } |
61 | | - function generate_pages ( $categoryName, $toGenPageList ) { |
| 71 | + } |
| 72 | + |
| 73 | + function generatePages ( $categoryName, $toGenPageList ) { |
62 | 74 | global $wgRequest, $wgOut; |
63 | | - $pageSchema = new PSSchema( $categoryName ); |
| 75 | + $pageSchema = new PSSchema( $categoryName ); |
64 | 76 | $pageSchema->generateAllPages( $toGenPageList ); |
65 | 77 | } |
66 | 78 | } |
Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php |
— | — | @@ -6,13 +6,14 @@ |
7 | 7 | */ |
8 | 8 | |
9 | 9 | class EditSchema extends IncludableSpecialPage { |
10 | | - function __construct() { |
11 | | - parent::__construct( 'EditSchema' ); |
12 | | - wfLoadExtensionMessages('EditSchema'); |
13 | | - } |
14 | | - public static function addJavascript() { |
| 10 | + function __construct() { |
| 11 | + parent::__construct( 'EditSchema' ); |
| 12 | + wfLoadExtensionMessages('EditSchema'); |
| 13 | + } |
| 14 | + |
| 15 | + public static function addJavascript() { |
15 | 16 | global $wgOut; |
16 | | - |
| 17 | + |
17 | 18 | PageSchemas::addJavascriptAndCSS(); |
18 | 19 | |
19 | 20 | // TODO - this should be in a JS file |
— | — | @@ -34,6 +35,7 @@ |
35 | 36 | jQuery('#fieldsList_'+template_num).append(newField); |
36 | 37 | addjQueryToCheckbox(); |
37 | 38 | } |
| 39 | + |
38 | 40 | function createAddTemplate() { |
39 | 41 | templateNum++; |
40 | 42 | newField = jQuery('#starterTemplate').clone().css('display', '').removeAttr('id'); |
— | — | @@ -46,20 +48,21 @@ |
47 | 49 | }); |
48 | 50 | jQuery('#templatesList').append(newField); |
49 | 51 | } |
50 | | -function updateFieldNum(field_num){ |
| 52 | + |
| 53 | +function updateFieldNum(field_num ) { |
51 | 54 | fieldNum = field_num; |
52 | 55 | } |
53 | 56 | |
54 | | -function addjQueryToCheckbox(){ |
55 | | - jQuery('.isListCheckbox').click(function() { |
56 | | - if (jQuery(this).is(":checked")) |
57 | | - { |
58 | | - jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', ''); |
59 | | - }else{ |
60 | | - jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', 'none'); |
61 | | - } |
| 57 | +function addjQueryToCheckbox( ) { |
| 58 | + jQuery('.isListCheckbox').click(function() { |
| 59 | + if (jQuery(this).is(":checked")) { |
| 60 | + jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', ''); |
| 61 | + } else { |
| 62 | + jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', 'none'); |
| 63 | + } |
62 | 64 | }); |
63 | 65 | } |
| 66 | + |
64 | 67 | jQuery(document).ready(function() { |
65 | 68 | jQuery(".deleteField").click( function() { |
66 | 69 | // Remove the encompassing div for this instance. |
— | — | @@ -73,16 +76,17 @@ |
74 | 77 | }); |
75 | 78 | addjQueryToCheckbox(); |
76 | 79 | }); |
77 | | - |
78 | 80 | </script> |
79 | 81 | |
80 | 82 | END; |
81 | 83 | $wgOut->addScript( $jsText ); |
82 | 84 | } |
83 | | - function execute( $category ) { |
| 85 | + |
| 86 | + function execute( $category ) { |
84 | 87 | global $wgRequest, $wgOut, $wgUser; |
85 | 88 | global $wgSkin; |
86 | | - $this->setHeaders(); |
| 89 | + |
| 90 | + $this->setHeaders(); |
87 | 91 | $text_1 = '<p>'.wfMsg( 'ps-page-desc-cat-not-exist' ).'</p>'; |
88 | 92 | $text_2 = '<p>'.wfMsg( 'ps-page-desc-ps-not-exist' ).'</p>'; |
89 | 93 | $text_3 = '<p>'.wfMsg( 'ps-page-desc-edit-schema' ).'</p>'; |
— | — | @@ -90,75 +94,75 @@ |
91 | 95 | self::addJavascript(); |
92 | 96 | $schema_name_label = wfMsg('ps-schema-name-label'); |
93 | 97 | $add_xml_label = wfMsg('ps-add-xml-label'); |
94 | | - |
| 98 | + |
95 | 99 | $pageSchemaObj = null; |
96 | 100 | $text_extensions = array(); //This var. will save the html text returned by the extensions |
97 | 101 | $js_extensions = array(); |
98 | 102 | wfRunHooks( 'getHtmlTextForFieldInputs', array( &$js_extensions, &$text_extensions )); |
99 | | - $text = ""; |
| 103 | + $text = ""; |
100 | 104 | $text .= ' <form id="createPageSchemaForm" action="" method="post">' . "\n"; |
101 | 105 | //$text .= '<p>'.$schema_name_label.' <input type="text" name="s_name"/> </p> '; |
102 | 106 | $text .= '<p>'.$add_xml_label.' |
103 | | - <textarea rows=4 style="width: 100%" name="ps_add_xml"></textarea> |
104 | | - </p> '; |
105 | | - if($text_extensions['sf_form'] != null){ |
| 107 | + <textarea rows=4 style="width: 100%" name="ps_add_xml"></textarea> |
| 108 | + </p> '; |
| 109 | + if ($text_extensions['sf_form'] != null ) { |
106 | 110 | $text_ex = preg_replace('/starter/', '1', $text_extensions['sf_form']); |
107 | 111 | $text .= $text_ex; |
108 | 112 | } |
109 | 113 | $delimeter_label = wfMsg('ps-delimeter-label'); |
110 | 114 | $multiple_temp_label = wfMsg('ps-multiple-temp-label'); |
111 | | - $field_list_label = wfMsg('ps-field-list-label'); |
112 | | - |
| 115 | + $field_list_label = wfMsg('ps-field-list-label'); |
| 116 | + |
113 | 117 | $text .= '<div id="templatesList">'; |
114 | 118 | $text .= '<div class="templateBox" >'; |
115 | 119 | $text .= '<fieldset style="background: #ddd;"><legend>Template</legend> '; |
116 | | - $text .= '<p>Name: <input type="text" name="t_name_1"/></p> '; |
| 120 | + $text .= '<p>Name: <input type="text" name="t_name_1"/></p> '; |
117 | 121 | $text .= '<p><input type="checkbox" name="is_multiple_1"/> '.$multiple_temp_label.'</p> '; |
118 | 122 | $text .= '<div id="fieldsList_1">'; |
119 | 123 | $text .= '<div class="fieldBox" >'; |
120 | | - $text .= '<fieldset style="background: #bbb;"><legend>Field</legend> |
| 124 | + $text .= '<fieldset style="background: #bbb;"><legend>Field</legend> |
121 | 125 | <p>Field name: <input size="15" name="f_name_1"> |
122 | 126 | Display label: <input size="15" name="f_label_1"> |
123 | | - </p> |
| 127 | + </p> |
124 | 128 | <p><input type="checkbox" name="f_is_list_1" class="isListCheckbox" />'. |
125 | | - $field_list_label.' |
126 | | - </p> |
127 | | - <div class="delimiterInput" style="display: none" ><p>'.$delimeter_label.' <input type="text" name="f_delimiter_1" /> </p></div>'; |
128 | | - if($text_extensions['smw'] != null){ |
| 129 | + $field_list_label . ' |
| 130 | + </p> |
| 131 | + <div class="delimiterInput" style="display: none" ><p>' . $delimeter_label . ' <input type="text" name="f_delimiter_1" /> </p></div>'; |
| 132 | + if ($text_extensions['smw'] != null ) { |
129 | 133 | $text_ex = preg_replace('/starter/', '1', $text_extensions['smw']); |
130 | 134 | $text .= $text_ex; |
131 | | - } |
132 | | - if($text_extensions['sf'] != null){ |
| 135 | + } |
| 136 | + if ($text_extensions['sf'] != null ) { |
133 | 137 | $text_ex = preg_replace('/starter/', '1', $text_extensions['sf']); |
134 | 138 | $text .= $text_ex; |
135 | | - } |
136 | | - if($text_extensions['sd'] != null){ |
| 139 | + } |
| 140 | + if ($text_extensions['sd'] != null ) { |
137 | 141 | $text_ex = preg_replace('/starter/', '1', $text_extensions['sd']); |
138 | 142 | $text .= $text_ex; |
139 | 143 | } |
140 | | - |
141 | | - $text .= '<p>'.$add_xml_label.' |
142 | | - <textarea rows=4 style="width: 100%" name="f_add_xml_1"></textarea> |
143 | | - </p> |
| 144 | + |
| 145 | + $text .= '<p>' . $add_xml_label . ' |
| 146 | + <textarea rows=4 style="width: 100%" name="f_add_xml_1"></textarea> |
| 147 | + </p> |
144 | 148 | <input type="button" value="Remove field" class="deleteField" /></fieldset> |
145 | | - </div> |
146 | | - </div> |
| 149 | + </div> |
| 150 | + </div> |
147 | 151 | '; |
148 | 152 | $add_field_button = Xml::element( 'input', |
149 | | - array( |
150 | | - 'type' => 'button', |
151 | | - 'value' => 'Add field', |
152 | | - 'onclick' => "createTemplateAddField(1)" |
153 | | - ) |
| 153 | + array( |
| 154 | + 'type' => 'button', |
| 155 | + 'value' => 'Add field', |
| 156 | + 'onclick' => "createTemplateAddField(1)" |
| 157 | + ) |
154 | 158 | ); |
155 | 159 | $text .= Xml::tags( 'p', null, $add_field_button ) . "\n"; |
156 | | - $text .= '<hr /> |
| 160 | + $text .= '<hr /> |
157 | 161 | <p>'.$add_xml_label.' |
158 | | - <textarea rows=4 style="width: 100%" name="t_add_xml_1"></textarea> |
159 | | - </p> |
160 | | - <p><input type="button" value="Remove template" class="deleteTemplate" /></p> |
| 162 | + <textarea rows=4 style="width: 100%" name="t_add_xml_1"></textarea> |
| 163 | + </p> |
| 164 | + <p><input type="button" value="Remove template" class="deleteTemplate" /></p> |
161 | 165 | </fieldset> </div></div>'; |
162 | | - |
| 166 | + |
163 | 167 | $add_template_button = Xml::element( 'input', |
164 | 168 | array( |
165 | 169 | 'type' => 'button', |
— | — | @@ -167,123 +171,123 @@ |
168 | 172 | ) |
169 | 173 | ); |
170 | 174 | $text .= Xml::tags( 'p', null, $add_template_button ) . "\n"; |
171 | | - $text .= ' <hr /> |
| 175 | + $text .= ' <hr /> |
172 | 176 | <div class="editButtons"> |
173 | | - <input type="submit" id="wpSave" name="wpSave" value="Save" /> |
| 177 | + <input type="submit" id="wpSave" name="wpSave" value="Save" /> |
174 | 178 | </div>'; |
175 | | - $text .= ' </form>'; |
176 | | - $starter_text = '<div class="templateBox" id="starterTemplate" style="display: none"> |
| 179 | + $text .= ' </form>'; |
| 180 | + $starter_text = '<div class="templateBox" id="starterTemplate" style="display: none"> |
177 | 181 | <fieldset style="background: #ddd;"> |
178 | | -<legend>Template</legend> |
179 | | -<p>Name: <input type="text" name="t_name_starter"/></p> |
180 | | -<p><input type="checkbox" name="is_multiple_starter"/> Allow multiple instances of this template</p> |
| 182 | +<legend>Template</legend> |
| 183 | +<p>Name: <input type="text" name="t_name_starter"/></p> |
| 184 | +<p><input type="checkbox" name="is_multiple_starter"/>Allow multiple instances of this template</p> |
181 | 185 | <div id="fieldsList_starter"> |
182 | 186 | </div> |
183 | 187 | <p><input type="button" value="Add Field" onclick="createTemplateAddField(starter)" /></p> |
184 | 188 | |
185 | | -<hr /> |
| 189 | +<hr /> |
186 | 190 | <p>'.$add_xml_label.' |
187 | | - <textarea rows=4 style="width: 100%" name="t_add_xml_starter"></textarea> |
188 | | - </p> |
189 | | - <p><input type="button" value="Remove template" class="deleteTemplate" /></p> |
| 191 | + <textarea rows=4 style="width: 100%" name="t_add_xml_starter"></textarea> |
| 192 | + </p> |
| 193 | + <p><input type="button" value="Remove template" class="deleteTemplate" /></p> |
190 | 194 | </fieldset> |
191 | | - </div> |
| 195 | + </div> |
192 | 196 | <hr /> '; |
193 | 197 | $starter_text .= '<div class="fieldBox" id="starterField" style="display: none"> |
194 | | - <fieldset style="background: #bbb;"><legend>Field</legend> |
| 198 | + <fieldset style="background: #bbb;"><legend>Field</legend> |
195 | 199 | <p> |
196 | 200 | <input size="15" name="f_name_starter"> |
197 | 201 | Display label: <input size="15" name="f_label_starter"> |
198 | 202 | </p> |
199 | 203 | <p><input type="checkbox" name="f_is_list_starter" class="isListCheckbox" /> This field can hold a list of values |
200 | 204 |   </p> |
201 | | - <div class="delimiterInput" style="display: none" ><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_starter" /> </p></div>'; |
202 | | - if($text_extensions['smw'] != null){ |
203 | | - $starter_text .= $text_extensions['smw']; |
204 | | - } |
205 | | - if($text_extensions['sf'] != null){ |
206 | | - $starter_text .= $text_extensions['sf']; |
207 | | - } |
208 | | - if($text_extensions['sd'] != null){ |
209 | | - $starter_text .= $text_extensions['sd']; |
210 | | - } |
211 | | - $starter_text .= '<p>'.$add_xml_label.' |
212 | | - <textarea rows=4 style="width: 100%" name="f_add_xml_starter"></textarea> |
213 | | - </p> |
| 205 | + <div class="delimiterInput" style="display: none" ><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_starter" /> </p></div>'; |
| 206 | + if ($text_extensions['smw'] != null ) { |
| 207 | + $starter_text .= $text_extensions['smw']; |
| 208 | + } |
| 209 | + if ($text_extensions['sf'] != null ) { |
| 210 | + $starter_text .= $text_extensions['sf']; |
| 211 | + } |
| 212 | + if ($text_extensions['sd'] != null ) { |
| 213 | + $starter_text .= $text_extensions['sd']; |
| 214 | + } |
| 215 | + $starter_text .= '<p>'.$add_xml_label.' |
| 216 | + <textarea rows=4 style="width: 100%" name="f_add_xml_starter"></textarea> |
| 217 | + </p> |
214 | 218 | <input type="button" value="Remove field" class="deleteField" /> |
215 | 219 | </fieldset> |
216 | 220 | </div>'; |
217 | 221 | $text .= $starter_text; |
218 | 222 | $save_page = $wgRequest->getCheck( 'wpSave' ); |
219 | | - if ($save_page) { |
| 223 | + if ( $save_page ) { |
220 | 224 | //Generate the Xml from the Form elements |
221 | | - $Xmltext = ""; |
| 225 | + $XMLtext = ""; |
222 | 226 | //$s_name = $wgRequest->getText('s_name'); |
223 | | - $Xmltext .= '<PageSchema>'; |
| 227 | + $XMLtext .= '<PageSchema>'; |
224 | 228 | $ps_add_xml = $wgRequest->getText('ps_add_xml'); |
225 | | - $Xmltext .= $ps_add_xml; |
| 229 | + $XMLtext .= $ps_add_xml; |
226 | 230 | $fieldName = ""; |
227 | 231 | $fieldNum= -1; |
228 | 232 | $templateNum = -1; |
229 | 233 | $xml_text_extensions = array(); //This var. will save the xml text returned by the extensions |
230 | 234 | $js_extensions = array(); |
231 | 235 | wfRunHooks( 'getXmlTextForFieldInputs', array( $wgRequest, &$xml_text_extensions )); |
232 | | - if( $xml_text_extensions['sf_form'] != null ){ |
233 | | - $Xmltext .= $xml_text_extensions['sf_form']; |
| 236 | + if ( $xml_text_extensions['sf_form'] != null ) { |
| 237 | + $XMLtext .= $xml_text_extensions['sf_form']; |
234 | 238 | } |
235 | | - $indexGlobalField = 0 ; //this variable is use to index the array returned by extensions for XML. |
| 239 | + $indexGlobalField = 0 ; //this variable is use to index the array returned by extensions for XML. |
236 | 240 | foreach ( $wgRequest->getValues() as $var => $val ) { |
237 | | - if(substr($var,0,7) == 't_name_'){ |
| 241 | + if (substr($var,0,7) == 't_name_' ) { |
238 | 242 | $templateNum = substr($var,7,1); |
239 | | - if($wgRequest->getCheck( 'is_multiple_'.$templateNum )){ |
240 | | - $Xmltext .= '<Template name="'.$val.'" multiple="multiple">'; |
241 | | - }else{ |
242 | | - $Xmltext .= '<Template name="'.$val.'">'; |
| 243 | + if ($wgRequest->getCheck( 'is_multiple_'.$templateNum ) ) { |
| 244 | + $XMLtext .= '<Template name="'.$val.'" multiple="multiple">'; |
| 245 | + } else { |
| 246 | + $XMLtext .= '<Template name="'.$val.'">'; |
243 | 247 | } |
244 | | - }else if(substr($var,0,7) == 'f_name_'){ |
| 248 | + } elseif (substr($var,0,7) == 'f_name_' ) { |
245 | 249 | $fieldName = $val; |
246 | 250 | $fieldNum = substr($var,7,1); |
247 | | - if($wgRequest->getCheck( 'f_is_list_'.$fieldNum )){ |
248 | | - if( $wgRequest->getText('f_delimiter_'.$fieldNum) != ''){ |
| 251 | + if ($wgRequest->getCheck( 'f_is_list_'.$fieldNum ) ) { |
| 252 | + if ( $wgRequest->getText('f_delimiter_'.$fieldNum) != '' ) { |
249 | 253 | $delimeter = $wgRequest->getText('f_delimiter_'.$fieldNum); |
250 | | - $Xmltext .= '<Field name="'.$fieldName.'" list="list" delimiter="'.$delimeter.'">'; |
251 | | - }else{ |
252 | | - $Xmltext .= '<Field name="'.$fieldName.'" list="list">'; |
| 254 | + $XMLtext .= '<Field name="'.$fieldName.'" list="list" delimiter="'.$delimeter.'">'; |
| 255 | + } else { |
| 256 | + $XMLtext .= '<Field name="'.$fieldName.'" list="list">'; |
253 | 257 | } |
254 | | - }else{ |
255 | | - $Xmltext .= '<Field name="'.$fieldName.'">'; |
| 258 | + } else { |
| 259 | + $XMLtext .= '<Field name="'.$fieldName.'">'; |
256 | 260 | } |
257 | | - }else if(substr($var,0,8) == 'f_label_'){ |
258 | | - $Xmltext .= '<Label>'.$val.'</Label>'; |
259 | | - //Get Xml parsed from extensions, |
260 | | - if( $xml_text_extensions['smw'] != null ){ |
| 261 | + } elseif (substr($var,0,8) == 'f_label_' ) { |
| 262 | + $XMLtext .= '<Label>'.$val.'</Label>'; |
| 263 | + //Get XML parsed from extensions |
| 264 | + if ( $xml_text_extensions['smw'] != null ) { |
261 | 265 | $xml_ex_array = $xml_text_extensions['smw']; |
262 | | - if($xml_ex_array[$indexGlobalField] != null){ |
263 | | - $Xmltext .= $xml_ex_array[$indexGlobalField] ; |
264 | | - } |
| 266 | + if ($xml_ex_array[$indexGlobalField] != null ) { |
| 267 | + $XMLtext .= $xml_ex_array[$indexGlobalField] ; |
| 268 | + } |
265 | 269 | } |
266 | | - if( $xml_text_extensions['sf'] != null ){ |
| 270 | + if ( $xml_text_extensions['sf'] != null ) { |
267 | 271 | $xml_ex_array = $xml_text_extensions['sf']; |
268 | | - if($xml_ex_array[$indexGlobalField] != null){ |
269 | | - $Xmltext .= $xml_ex_array[$indexGlobalField] ; |
270 | | - } |
| 272 | + if ($xml_ex_array[$indexGlobalField] != null ) { |
| 273 | + $XMLtext .= $xml_ex_array[$indexGlobalField] ; |
| 274 | + } |
271 | 275 | } |
272 | | - if( $xml_text_extensions['sd'] != null ){ |
| 276 | + if ( $xml_text_extensions['sd'] != null ) { |
273 | 277 | $xml_ex_array = $xml_text_extensions['sd']; |
274 | | - if($xml_ex_array[$indexGlobalField] != null){ |
275 | | - $Xmltext .= $xml_ex_array[$indexGlobalField] ; |
| 278 | + if ($xml_ex_array[$indexGlobalField] != null ) { |
| 279 | + $XMLtext .= $xml_ex_array[$indexGlobalField] ; |
276 | 280 | } |
277 | | - } |
| 281 | + } |
278 | 282 | $indexGlobalField++ ; |
279 | | - }else if(substr($var,0,10) == 'f_add_xml_'){ |
280 | | - $Xmltext .= $val; |
281 | | - $Xmltext .= '</Field>'; |
282 | | - }else if(substr($var,0,10) == 't_add_xml_'){ |
283 | | - $Xmltext .= $val; |
284 | | - $Xmltext .= '</Template>'; |
| 283 | + } elseif (substr($var,0,10) == 'f_add_xml_' ) { |
| 284 | + $XMLtext .= $val; |
| 285 | + $XMLtext .= '</Field>'; |
| 286 | + } elseif (substr($var,0,10) == 't_add_xml_' ) { |
| 287 | + $XMLtext .= $val; |
| 288 | + $XMLtext .= '</Template>'; |
285 | 289 | } |
286 | 290 | } |
287 | | - $Xmltext .= '</PageSchema>'; |
| 291 | + $XMLtext .= '</PageSchema>'; |
288 | 292 | $pageSchemaObj = new PSSchema( $category ); |
289 | 293 | $categoryTitle = Title::newFromText( $category, NS_CATEGORY ); |
290 | 294 | $categoryArticle = new Article( $categoryTitle ); |
— | — | @@ -291,197 +295,192 @@ |
292 | 296 | $title = Title::newFromText( $category, NS_CATEGORY ); |
293 | 297 | $jobs = array(); |
294 | 298 | $params = array(); |
295 | | - if( $pageSchemaObj->isPSDefined() ){ |
| 299 | + if ( $pageSchemaObj->isPSDefined() ) { |
296 | 300 | //Do some preg-replace magic |
297 | 301 | $tag = "PageSchema"; |
298 | | - $replaced_text = preg_replace('{<'.$tag.'[^>]*>([^@]*?)</'.$tag.'>'.'}', $Xmltext , $pageText); |
299 | | - $params['user_id'] = $wgUser->getId(); |
| 302 | + $replaced_text = preg_replace('{<'.$tag.'[^>]*>([^@]*?)</'.$tag.'>'.'}', $XMLtext, $pageText); |
300 | 303 | $params['page_text'] = $replaced_text; |
301 | | - $jobs[] = new PSCreatePageJob( $title, $params ); |
302 | | - Job::batchInsert( $jobs ); |
303 | | - }else{ |
304 | | - $params['user_id'] = $wgUser->getId(); |
305 | | - $params['page_text'] = $Xmltext.$pageText; |
306 | | - $jobs[] = new PSCreatePageJob( $title, $params ); |
307 | | - Job::batchInsert( $jobs ); |
| 304 | + } else { |
| 305 | + $params['page_text'] = $XMLtext . $pageText; |
308 | 306 | } |
309 | | - } |
310 | | - else{ |
311 | | - if ( $category != "" ) { |
312 | | - $pageSchemaObj = new PSSchema( $category ); |
313 | | - $title = Title::newFromText( $category, NS_CATEGORY ); |
314 | | - $pageId = $title->getArticleID(); |
315 | | - $dbr = wfGetDB( DB_SLAVE ); |
316 | | - //get the result set, query : slect page_props |
317 | | - $res = $dbr->select( 'page_props', |
318 | | - array( |
319 | | - 'pp_page', |
320 | | - 'pp_propname', |
321 | | - 'pp_value' |
322 | | - ), |
323 | | - array( |
324 | | - 'pp_page' => $pageId, |
325 | | - ) |
326 | | - ); |
327 | | - //first row of the result set |
328 | | - $row = $dbr->fetchRow( $res ); |
329 | | - if( $row == null && !$title->exists() ){ |
330 | | - //Create form here, Cat doesnt exist, create new cat with this text |
331 | | - $text_1 .= $text; |
332 | | - $wgOut->addHTML( $text_1 ); |
333 | | - }else{ |
334 | | - if( ($row[1] == 'PageSchema') && ($row[2] != null )){ |
335 | | - //Populate the form here with autocompleted values |
336 | | - $pageXmlstr = $row[2]; |
337 | | - $pageXml = simplexml_load_string ( $pageXmlstr ); |
338 | | - $ps_add_xml = ""; |
339 | | - //$pageName = (string)$pageXml->attributes()->name; |
340 | | - $text_4 .= ''; |
341 | | - $text_4 .= '<form id="editPageSchemaForm" action="" method="post">' . "\n"; |
342 | | - //$text_4 .= '<p>'.$schema_name_label.' <input type="text" name="s_name" value="'.$pageName.'" /> </p> '; |
343 | | - foreach ( $pageXml->children() as $template_xml ) { |
344 | | - if ( ($template_xml->getName() != 'Template') && ($template_xml->getName() != 'semanticforms_Form') ){ |
345 | | - $ps_add_xml .= (string)$template_xml->asXML(); |
346 | | - } |
347 | | - } |
348 | | - $text_4 .= '<p>'.$add_xml_label.' |
349 | | - <textarea rows=4 style="width: 100%" name="ps_add_xml" >'.$ps_add_xml.'</textarea> |
350 | | - </p> '; |
351 | | - |
352 | | - $filled_html_text_extensions = array(); |
353 | | - wfRunHooks( 'getFilledHtmlTextForFieldInputs', array( $pageSchemaObj, &$filled_html_text_extensions )); |
354 | | - if($filled_html_text_extensions['sf_form'] != null){ |
355 | | - $text_ex = preg_replace('/starter/', '1', $filled_html_text_extensions['sf_form']); |
356 | | - $text_4 .= $text_ex; |
357 | | - } |
358 | | - $text_4 .= '<div id="templatesList">'; |
359 | | - $template_num = 0; |
360 | | - /* index for template objects */ |
361 | | - foreach ( $pageXml->children() as $tag => $template_xml ) { |
362 | | - if ( $tag == 'Template' ){ |
363 | | - $template_add_xml = ""; |
364 | | - $template_num++; |
365 | | - $field_count = 0; |
366 | | - if( count($template_xml->children()) > 0 ){ |
367 | | - $templateName = (string) $template_xml->attributes()->name; |
368 | | - $text_4 .= '<div class="templateBox" >'; |
369 | | - $text_4 .= '<fieldset style="background: #ddd;"><legend>Template</legend> '; |
370 | | - $text_4 .= '<p>Name: <input type="text" name="t_name_'.$template_num.'" value="'.$templateName.'" /></p> '; |
371 | | - if( ((string) $template_xml->attributes()->multiple) == "multiple" ) { |
372 | | - $text_4 .= '<p><input type="checkbox" checked name="is_multiple_'.$template_num.'"/> Allow multiple instances of this template</p> '; |
373 | | - }else{ |
374 | | - $text_4 .= '<p><input type="checkbox" name="is_multiple_'.$template_num.'"/> Allow multiple instances of this template</p> '; |
| 307 | + $params['user_id'] = $wgUser->getId(); |
| 308 | + $jobs[] = new PSCreatePageJob( $title, $params ); |
| 309 | + Job::batchInsert( $jobs ); |
| 310 | + } else { |
| 311 | + if ( $category != "" ) { |
| 312 | + $pageSchemaObj = new PSSchema( $category ); |
| 313 | + $title = Title::newFromText( $category, NS_CATEGORY ); |
| 314 | + $pageId = $title->getArticleID(); |
| 315 | + $dbr = wfGetDB( DB_SLAVE ); |
| 316 | + //get the result set, query : slect page_props |
| 317 | + $res = $dbr->select( 'page_props', |
| 318 | + array( |
| 319 | + 'pp_page', |
| 320 | + 'pp_propname', |
| 321 | + 'pp_value' |
| 322 | + ), |
| 323 | + array( |
| 324 | + 'pp_page' => $pageId, |
| 325 | + ) |
| 326 | + ); |
| 327 | + //first row of the result set |
| 328 | + $row = $dbr->fetchRow( $res ); |
| 329 | + if ( $row == null && !$title->exists() ) { |
| 330 | + //Create form here, Cat doesnt exist, create new cat with this text |
| 331 | + $text_1 .= $text; |
| 332 | + $wgOut->addHTML( $text_1 ); |
| 333 | + } else { |
| 334 | + if ( ($row[1] == 'PageSchema') && ($row[2] != null ) ) { |
| 335 | + //Populate the form here with autocompleted values |
| 336 | + $pageXMLstr = $row[2]; |
| 337 | + $pageXML = simplexml_load_string ( $pageXMLstr ); |
| 338 | + $ps_add_xml = ""; |
| 339 | + //$pageName = (string)$pageXML->attributes()->name; |
| 340 | + $text_4 .= ''; |
| 341 | + $text_4 .= '<form id="editPageSchemaForm" action="" method="post">' . "\n"; |
| 342 | + //$text_4 .= '<p>'.$schema_name_label.' <input type="text" name="s_name" value="'.$pageName.'" /> </p> '; |
| 343 | + foreach ( $pageXML->children() as $template_xml ) { |
| 344 | + if ( ($template_xml->getName() != 'Template') && ($template_xml->getName() != 'semanticforms_Form') ) { |
| 345 | + $ps_add_xml .= (string)$template_xml->asXML(); |
375 | 346 | } |
376 | | - foreach ( $template_xml->children() as $field_xml ) { |
377 | | - if ( $field_xml->getName() != 'Field' ){ |
378 | | - $template_add_xml .= (string)$field_xml->asXML(); |
379 | | - } |
380 | | - } |
381 | | - $text_4 .= '<div id="fieldsList_'.$template_num.'">'; |
382 | | - $list_values = false; |
383 | | - foreach ($template_xml->children() as $field_xml) { |
384 | | - if ( $field_xml->getName() == "Field" ){ |
385 | | - $fieldName = (string)$field_xml->attributes()->name; |
386 | | - $text_4 .= '<div class="fieldBox" >'; |
387 | | - $text_4 .= '<fieldset style="background: #bbb;"><legend>Field</legend> '; |
388 | | - if( ((string)$field_xml->attributes()->list) == "list") { |
389 | | - $list_values = true; |
| 347 | + } |
| 348 | + $text_4 .= '<p>' . $add_xml_label . ' |
| 349 | + <textarea rows=4 style="width: 100%" name="ps_add_xml" >' . $ps_add_xml . '</textarea> |
| 350 | + </p> '; |
| 351 | + |
| 352 | + $filled_html_text_extensions = array(); |
| 353 | + wfRunHooks( 'getFilledHtmlTextForFieldInputs', array( $pageSchemaObj, &$filled_html_text_extensions )); |
| 354 | + if ( $filled_html_text_extensions['sf_form'] != null ) { |
| 355 | + $text_ex = preg_replace('/starter/', '1', $filled_html_text_extensions['sf_form']); |
| 356 | + $text_4 .= $text_ex; |
| 357 | + } |
| 358 | + $text_4 .= '<div id="templatesList">'; |
| 359 | + $template_num = 0; |
| 360 | + /* index for template objects */ |
| 361 | + foreach ( $pageXML->children() as $tag => $template_xml ) { |
| 362 | + if ( $tag == 'Template' ) { |
| 363 | + $template_add_xml = ""; |
| 364 | + $template_num++; |
| 365 | + $field_count = 0; |
| 366 | + if ( count($template_xml->children()) > 0 ) { |
| 367 | + $templateName = (string) $template_xml->attributes()->name; |
| 368 | + $text_4 .= '<div class="templateBox" >'; |
| 369 | + $text_4 .= '<fieldset style="background: #ddd;"><legend>Template</legend> '; |
| 370 | + $text_4 .= '<p>Name: <input type="text" name="t_name_'.$template_num.'" value="'.$templateName.'" /></p> '; |
| 371 | + if ( ((string) $template_xml->attributes()->multiple) == "multiple" ) { |
| 372 | + $text_4 .= '<p><input type="checkbox" checked name="is_multiple_'.$template_num.'"/> Allow multiple instances of this template</p> '; |
| 373 | + } else { |
| 374 | + $text_4 .= '<p><input type="checkbox" name="is_multiple_'.$template_num.'"/> Allow multiple instances of this template</p> '; |
390 | 375 | } |
391 | | - if( ((string)$field_xml->attributes()->delimiter) != null || ((string)$field_xml->attributes()->delimiter) != '' ){ |
392 | | - $delimiter = (string)$field_xml->attributes()->delimiter; |
393 | | - } |
394 | | - foreach ($field_xml->children() as $tag => $child ) { |
395 | | - if ( $tag == 'Label' ) { |
396 | | - $fieldLabel = (string)$child; |
| 376 | + foreach ( $template_xml->children() as $field_xml ) { |
| 377 | + if ( $field_xml->getName() != 'Field' ) { |
| 378 | + $template_add_xml .= (string)$field_xml->asXML(); |
397 | 379 | } |
398 | | - } |
399 | | - $text_4 .= '<p>Field name: <input size="15" name="f_name_'.$field_count.'" value="'.$fieldName.'" >'; |
400 | | - $text_4 .= 'Display label: <input size="15" name="f_label_'.$field_count.'" value="'.$fieldLabel.'" > |
401 | | - </p> '; |
402 | | - if($list_values){ |
403 | | - $text_4 .= '<p><input type="checkbox" name="f_is_list_'.$field_count.'" checked class="isListCheckbox" /> This field can hold a list of values</p> '; |
404 | | - $text_4 .= '<div class="delimiterInput" style="display:" ><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_'.$field_count.'" value="'.$delimiter.'" /> </p></div>'; |
405 | | - }else{ |
406 | | - $text_4 .= '<p><input type="checkbox" name="f_is_list_'.$field_count.'" class="isListCheckbox" /> This field can hold a list of values</p> '; |
407 | | - $text_4 .= '<div class="delimiterInput" style="display: none" ><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_'.$field_count.'" /> </p></div>'; |
408 | 380 | } |
409 | | - //Inserting HTML text from Extensions |
410 | | - |
411 | | - if( $filled_html_text_extensions['smw'] != null ){ |
412 | | - $text_ex_array = $filled_html_text_extensions['smw']; |
413 | | - if( $text_ex_array[$field_count] != null ){ |
414 | | - $text_ex = preg_replace('/starter/', $field_count, $text_ex_array[$field_count]); |
415 | | - $text_4 .= $text_ex; |
416 | | - } |
417 | | - } |
418 | | - if( $filled_html_text_extensions['sf'] != null ){ |
419 | | - $text_ex_array = $filled_html_text_extensions['sf']; |
420 | | - if( $text_ex_array[$field_count] != null ){ |
421 | | - $text_ex = preg_replace('/starter/', $field_count, $text_ex_array[$field_count]); |
422 | | - $text_4 .= $text_ex; |
423 | | - } |
424 | | - } |
425 | | - if( $filled_html_text_extensions['sd'] != null ){ |
426 | | - $text_ex_array = $filled_html_text_extensions['sd']; |
427 | | - if( $text_ex_array[$field_count] != null ){ |
428 | | - $text_ex = preg_replace('/starter/', $field_count, $text_ex_array[$field_count]); |
429 | | - $text_4 .= $text_ex; |
430 | | - } |
431 | | - } |
432 | | - |
433 | | - $text_4 .= '<p>'.$add_xml_label.' |
434 | | - <textarea rows=4 style="width: 100%" name="f_add_xml_'.$field_count.'"></textarea> |
435 | | - </p> |
| 381 | + $text_4 .= '<div id="fieldsList_'.$template_num.'">'; |
| 382 | + $list_values = false; |
| 383 | + foreach ($template_xml->children() as $field_xml) { |
| 384 | + if ( $field_xml->getName() == "Field" ) { |
| 385 | + $fieldName = (string)$field_xml->attributes()->name; |
| 386 | + $text_4 .= '<div class="fieldBox" >'; |
| 387 | + $text_4 .= '<fieldset style="background: #bbb;"><legend>Field</legend> '; |
| 388 | + if ( ((string)$field_xml->attributes()->list) == "list") { |
| 389 | + $list_values = true; |
| 390 | + } |
| 391 | + if ( ((string)$field_xml->attributes()->delimiter) != null || ((string)$field_xml->attributes()->delimiter) != '' ) { |
| 392 | + $delimiter = (string)$field_xml->attributes()->delimiter; |
| 393 | + } |
| 394 | + foreach ($field_xml->children() as $tag => $child ) { |
| 395 | + if ( $tag == 'Label' ) { |
| 396 | + $fieldLabel = (string)$child; |
| 397 | + } |
| 398 | + } |
| 399 | + $text_4 .= '<p>Field name: <input size="15" name="f_name_'.$field_count.'" value="'.$fieldName.'" >'; |
| 400 | + $text_4 .= 'Display label: <input size="15" name="f_label_'.$field_count.'" value="'.$fieldLabel.'" > |
| 401 | + </p> '; |
| 402 | + if ($list_values ) { |
| 403 | + $text_4 .= '<p><input type="checkbox" name="f_is_list_'.$field_count.'" checked class="isListCheckbox" /> This field can hold a list of values</p> '; |
| 404 | + $text_4 .= '<div class="delimiterInput" style="display:"><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_'.$field_count.'" value="'.$delimiter.'" /> </p></div>'; |
| 405 | + } else { |
| 406 | + $text_4 .= '<p><input type="checkbox" name="f_is_list_'.$field_count.'" class="isListCheckbox" /> This field can hold a list of values</p> '; |
| 407 | + $text_4 .= '<div class="delimiterInput" style="display: none" ><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_'.$field_count.'" /> </p></div>'; |
| 408 | + } |
| 409 | + //Inserting HTML text from Extensions |
| 410 | + |
| 411 | + if ( $filled_html_text_extensions['smw'] != null ) { |
| 412 | + $text_ex_array = $filled_html_text_extensions['smw']; |
| 413 | + if ( $text_ex_array[$field_count] != null ) { |
| 414 | + $text_ex = preg_replace('/starter/', $field_count, $text_ex_array[$field_count]); |
| 415 | + $text_4 .= $text_ex; |
| 416 | + } |
| 417 | + } |
| 418 | + if ( $filled_html_text_extensions['sf'] != null ) { |
| 419 | + $text_ex_array = $filled_html_text_extensions['sf']; |
| 420 | + if ( $text_ex_array[$field_count] != null ) { |
| 421 | + $text_ex = preg_replace('/starter/', $field_count, $text_ex_array[$field_count]); |
| 422 | + $text_4 .= $text_ex; |
| 423 | + } |
| 424 | + } |
| 425 | + if ( $filled_html_text_extensions['sd'] != null ) { |
| 426 | + $text_ex_array = $filled_html_text_extensions['sd']; |
| 427 | + if ( $text_ex_array[$field_count] != null ) { |
| 428 | + $text_ex = preg_replace('/starter/', $field_count, $text_ex_array[$field_count]); |
| 429 | + $text_4 .= $text_ex; |
| 430 | + } |
| 431 | + } |
| 432 | + |
| 433 | + $text_4 .= '<p>'.$add_xml_label.' |
| 434 | + <textarea rows=4 style="width: 100%" name="f_add_xml_'.$field_count.'"></textarea> |
| 435 | + </p> |
436 | 436 | <input type="button" value="Remove field" class="deleteField" /></fieldset> |
437 | | - </div> |
438 | | - </div> |
439 | | - '; |
440 | | - $field_count++; |
441 | | - $text_4 .= '<script type="text/javascript"> |
| 437 | + </div> |
| 438 | + </div> |
| 439 | + '; |
| 440 | + $field_count++; |
| 441 | + $text_4 .= '<script type="text/javascript"> |
442 | 442 | updateFieldNum('.$field_count.'); |
443 | | - </script>'; |
444 | | - } |
445 | | - } |
446 | | - $text_4 .= '</div>'; |
447 | | - $add_field_button = Xml::element( 'input', |
448 | | - array( |
449 | | - 'type' => 'button', |
450 | | - 'value' => 'Add field', |
451 | | - 'onclick' => "createTemplateAddField($template_num)" |
452 | | - ) |
453 | | - ); |
454 | | - $text_4 .= Xml::tags( 'p', null, $add_field_button ) . "\n"; |
455 | | - $text_4 .= '<hr /> |
| 443 | + </script>'; |
| 444 | + } |
| 445 | + } |
| 446 | + $text_4 .= '</div>'; |
| 447 | + $add_field_button = Xml::element( 'input', |
| 448 | + array( |
| 449 | + 'type' => 'button', |
| 450 | + 'value' => 'Add field', |
| 451 | + 'onclick' => "createTemplateAddField($template_num)" |
| 452 | + ) |
| 453 | + ); |
| 454 | + $text_4 .= Xml::tags( 'p', null, $add_field_button ) . "\n"; |
| 455 | + $text_4 .= '<hr /> |
456 | 456 | <p>'.$add_xml_label.' |
457 | | - <textarea rows=4 style="width: 100%" name="t_add_xml_'.$template_num.'">'.$template_add_xml.'</textarea> |
458 | | - </p> |
459 | | - <p><input type="button" value="Remove template" class="deleteTemplate" /></p> |
460 | | - </fieldset> </div>'; |
461 | | - |
| 457 | + <textarea rows=4 style="width: 100%" name="t_add_xml_'.$template_num.'">'.$template_add_xml.'</textarea> |
| 458 | + </p> |
| 459 | + <p><input type="button" value="Remove template" class="deleteTemplate" /></p> |
| 460 | + </fieldset> </div>'; |
| 461 | + } |
462 | 462 | } |
463 | | - } |
464 | | - } |
465 | | - $add_template_button = Xml::element( 'input', |
466 | | - array( |
467 | | - 'type' => 'button', |
468 | | - 'value' => 'Add template', |
469 | | - 'onclick' => "createAddTemplate()" |
470 | | - ) |
471 | | - ); |
472 | | - $text_4 .= Xml::tags( 'p', null, $add_template_button ) . "\n"; |
473 | | - $text_4 .= ' <hr /> |
| 463 | + } |
| 464 | + $add_template_button = Xml::element( 'input', |
| 465 | + array( |
| 466 | + 'type' => 'button', |
| 467 | + 'value' => 'Add template', |
| 468 | + 'onclick' => "createAddTemplate()" |
| 469 | + ) |
| 470 | + ); |
| 471 | + $text_4 .= Xml::tags( 'p', null, $add_template_button ) . "\n"; |
| 472 | + $text_4 .= ' <hr /> |
474 | 473 | <div class="editButtons"> |
475 | | - <input type="submit" id="wpSave" name="wpSave" value="Save" /> |
| 474 | + <input type="submit" id="wpSave" name="wpSave" value="Save" /> |
476 | 475 | </div>'; |
477 | | - $text_4 .= ' </form>'; |
478 | | - $text_4 .= $starter_text; |
479 | | - $wgOut->addHTML($text_4); |
480 | | - }else{ |
481 | | - $text_2 .= $text; |
482 | | - $wgOut->addHTML($text_2); |
483 | | - } |
| 476 | + $text_4 .= ' </form>'; |
| 477 | + $text_4 .= $starter_text; |
| 478 | + $wgOut->addHTML($text_4); |
| 479 | + } else { |
| 480 | + $text_2 .= $text; |
| 481 | + $wgOut->addHTML($text_2); |
| 482 | + } |
484 | 483 | } |
485 | | - }else { |
| 484 | + } else { |
486 | 485 | $cat_titles = array(); |
487 | 486 | $count_title = 0; |
488 | 487 | $text = ""; |
— | — | @@ -491,27 +490,27 @@ |
492 | 491 | array( |
493 | 492 | 'pp_page', |
494 | 493 | 'pp_propname', |
495 | | - 'pp_value' |
| 494 | + 'pp_value' |
496 | 495 | ), |
497 | | - array( |
| 496 | + array( |
498 | 497 | 'pp_propname' => 'PageSchema' |
499 | 498 | ) |
500 | 499 | ); |
501 | 500 | while ( $row = $dbr->fetchRow( $res ) ) { |
502 | | - if( $row[2] != null ){ |
| 501 | + if ( $row[2] != null ) { |
503 | 502 | $page_id_cat = $row[0]; |
504 | | - if( Title::newFromId($page_id_cat)->getNamespace() == NS_CATEGORY){ |
| 503 | + if ( Title::newFromId($page_id_cat)->getNamespace() == NS_CATEGORY ) { |
505 | 504 | $cat_text = Title::newFromId($page_id_cat)->getText(); |
506 | 505 | $generatePagesPage = SpecialPage::getTitleFor( 'EditSchema' ); |
507 | 506 | $url = $generatePagesPage ->getFullURL() . '/' . $cat_text; |
508 | | - $text .= '<a href='.$url.'>'.$cat_text.' </a> <br /> '; |
| 507 | + $text .= '<a href='.$url.'>' . $cat_text . '</a> <br /> '; |
509 | 508 | } |
510 | 509 | } |
511 | 510 | } |
512 | 511 | $dbr->freeResult( $res ); |
513 | 512 | $wgOut->addHTML( $text ); |
514 | 513 | } |
515 | | - } |
516 | | - return true; |
517 | 514 | } |
| 515 | + return true; |
| 516 | + } |
518 | 517 | } |
Index: trunk/extensions/PageSchemas/PageSchemas.php |
— | — | @@ -1,17 +1,14 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * PageSchemas extension |
| 4 | + * Page Schemas extension |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @ingroup Extensions |
8 | 8 | * |
9 | | - * This file contains the main include file for the PageSchemas extension of |
10 | | - * MediaWiki. |
| 9 | + * This is the main include file for the Page Schemas MediaWiki extension. |
11 | 10 | * |
12 | 11 | * Usage: Add the following line in LocalSettings.php: |
13 | 12 | * require_once( "$IP/extensions/PageSchemas/PageSchemas.php" ); |
14 | | - * |
15 | | - * @version 0.0.1 |
16 | 13 | */ |
17 | 14 | |
18 | 15 | // Check environment |
— | — | @@ -26,8 +23,8 @@ |
27 | 24 | $wgExtensionCredits['parserhook'][] = array( |
28 | 25 | 'path' => __FILE__, |
29 | 26 | 'name' => 'Page Schemas', |
30 | | - 'author' => array( 'Ankit Garg' ), |
31 | | - 'version' => '0.0.1', |
| 27 | + 'author' => array( 'Ankit Garg', 'Yaron Koren' ), |
| 28 | + 'version' => '0.1', |
32 | 29 | 'url' => 'http://www.mediawiki.org/wiki/Extension:PageSchemas', |
33 | 30 | 'descriptionmsg' => 'pageschemas-desc', |
34 | 31 | ); |
— | — | @@ -60,8 +57,8 @@ |
61 | 58 | $wgHooks['ParserFirstCallInit'][] = 'PageSchemasHooks::register'; |
62 | 59 | |
63 | 60 | // Register page_props usage |
64 | | -$wgPageProps['PageSchema'] = 'Content of <PageSchema> tag'; |
| 61 | +$wgPageProps['PageSchema'] = 'Contents of <PageSchema> tag'; |
65 | 62 | |
66 | 63 | $wgHooks['UnknownAction'][] = 'PSTabs::onUnknownAction'; |
67 | 64 | $wgHooks['SkinTemplateTabs'][] = 'PSTabs::displayTabs'; |
68 | | -$wgHooks['SkinTemplateNavigation'][] = 'PSTabs::displayTabs2'; |
\ No newline at end of file |
| 65 | +$wgHooks['SkinTemplateNavigation'][] = 'PSTabs::displayTabs2'; |
Index: trunk/extensions/PageSchemas/PageSchemas.hooks.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Hooks for PageSchemas extension |
| 4 | + * Hook functions for the Page Schemas extension |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @ingroup Extensions |
— | — | @@ -8,8 +8,6 @@ |
9 | 9 | |
10 | 10 | class PageSchemasHooks { |
11 | 11 | |
12 | | - /* Functions */ |
13 | | - |
14 | 12 | // Initialization |
15 | 13 | public static function register( &$parser ) { |
16 | 14 | // Register the hook with the parser |
— | — | @@ -17,7 +15,6 @@ |
18 | 16 | // add the CSS |
19 | 17 | global $wgOut, $wgScriptPath; |
20 | 18 | $wgOut->addStyle($wgScriptPath . '/extensions/PageSchemas/PageSchemas.css'); |
21 | | - // Continue |
22 | 19 | return true; |
23 | 20 | } |
24 | 21 | |
— | — | @@ -28,8 +25,7 @@ |
29 | 26 | // or if the input is empty, display nothing |
30 | 27 | if ( !$frame->title->equals( $parser->getTitle() ) || $input == '' ) |
31 | 28 | return; |
32 | | - |
33 | | - |
| 29 | + |
34 | 30 | // TODO: Do processing here, like parse to an array |
35 | 31 | $error_msg = null; |
36 | 32 | |
— | — | @@ -37,25 +33,25 @@ |
38 | 34 | // attributes it contained, because that was actually a tag- |
39 | 35 | // function call, as opposed to a real XML tag |
40 | 36 | $input = Xml::tags('PageSchema', $args, $input); |
41 | | - |
| 37 | + |
42 | 38 | // if 'type=' was specified, and it wasn't set to one of the |
43 | | - // allowed values (currently just 'auto'), don't validate - |
| 39 | + // allowed values (currently just 'auto'), don't validate - |
44 | 40 | // just display the XML |
45 | | - if (array_key_exists('type', $args) && $args['type'] != 'auto') { |
| 41 | + if ( array_key_exists( 'type', $args ) && $args['type'] != 'auto' ) { |
46 | 42 | // Store XML in the page_props table - the Javascript |
47 | 43 | // can figure out on its own whether or not to handle it |
48 | 44 | $parser->getOutput()->setProperty( 'PageSchema', $input ); |
49 | 45 | // TODO - a hook should be called here, to allow other |
50 | 46 | // XML handlers to parse and display this |
51 | | - $text = Html::element('p', null, "The (unhandled) XML definition for this Schema is:") . "\n"; |
| 47 | + $text = Html::element('p', null, "The (unhandled) XML definition for this schema is:") . "\n"; |
52 | 48 | $text .= Html::element('pre', null, $input); |
53 | 49 | return $text; |
54 | 50 | } |
55 | 51 | |
56 | 52 | if ( $xml_object = PageSchemas::validateXML( $input, $error_msg ) ) { |
57 | 53 | // Store XML in the page_props table |
58 | | - $parser->getOutput()->setProperty( 'PageSchema', $input ); |
59 | | - $text = PageSchemas::parsePageSchemas($xml_object); |
| 54 | + $parser->getOutput()->setProperty( 'PageSchema', $input ); |
| 55 | + $text = PageSchemas::parsePageSchemas( $xml_object ); |
60 | 56 | } else { |
61 | 57 | // Store error message in the page_props table |
62 | 58 | $parser->getOutput()->setProperty( 'PageSchema', $error_msg ); |
— | — | @@ -65,5 +61,5 @@ |
66 | 62 | |
67 | 63 | // return output |
68 | 64 | return $text; |
69 | | - } |
| 65 | + } |
70 | 66 | } |