r95679 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95678‎ | r95679 | r95680 >
Date:17:16, 29 August 2011
Author:yaron
Status:deferred
Tags:
Comment:
Improved formatting, layout and comments in code
Modified paths:
  • /trunk/extensions/PageSchemas/PS_CreatePageJob.php (modified) (history)
  • /trunk/extensions/PageSchemas/PS_Tabs.php (modified) (history)
  • /trunk/extensions/PageSchemas/PageSchemas.classes.php (modified) (history)
  • /trunk/extensions/PageSchemas/PageSchemas.hooks.php (modified) (history)
  • /trunk/extensions/PageSchemas/PageSchemas.php (modified) (history)
  • /trunk/extensions/PageSchemas/specials/PS_EditSchema.php (modified) (history)
  • /trunk/extensions/PageSchemas/specials/PS_GeneratePages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/PS_Tabs.php
@@ -1,76 +1,74 @@
22 <?php
33
44 /**
5 -
6 -* @file PSTabs.php
7 - * @ingroup
 5+ * @file PSTabs.php
 6+ * @ingroup
87 *
98 * @author ankit
109 */
1110 final class PSTabs {
12 -
 11+
1312 public static function displayTabs( $obj, &$content_actions ) {
1413 global $wgUser;
15 -
 14+
1615 $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(
3132 'text' => wfMsg( 'generatepages' ),
3233 'class' => $wgRequest->getVal( 'action' ) == 'generatepages' ? 'selected' : '',
3334 '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+ );
4236 }
43 -
 37+
4438 return true;
4539 }
4640
4741 /**
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'.
5043 */
5144 public static function displayTabs2( $obj, &$links ) {
5245 // The old '$content_actions' array is thankfully just a sub-array of this one
5346 $views_links = $links['actions'];
5447 self::displayTabs( $obj, $views_links );
55 - $links['actions'] = $views_links;
 48+ $links['actions'] = $views_links;
5649 return true;
5750 }
5851
59 - /**
60 - *
61 - * @return true
 52+ /**
 53+ * Adds handling for the tabs 'generatepages' and 'editschema'.
6254 */
6355 public static function onUnknownAction( $action, Article $article ) {
6456 $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+ }
7573 return true;
7674 }
77 -}
\ No newline at end of file
 75+}
Index: trunk/extensions/PageSchemas/PageSchemas.classes.php
@@ -8,30 +8,17 @@
99
1010 class PageSchemas {
1111
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 - }
2512 public static function getCategoriesWithPSDefined(){
26 - $cat_titles = array();
 13+ $cat_titles = array();
2714 $dbr = wfGetDB( DB_SLAVE );
2815 //get the result set, query : slect page_props
2916 $res = $dbr->select( 'page_props',
3017 array(
3118 'pp_page',
3219 'pp_propname',
33 - 'pp_value'
 20+ 'pp_value'
3421 ),
35 - array(
 22+ array(
3623 'pp_propname' => 'PageSchema'
3724 )
3825 );
@@ -51,7 +38,7 @@
5239 /**
5340 * Includes the necessary Javascript and CSS files for the form
5441 * to display and work correctly.
55 - *
 42+ *
5643 * Accepts an optional Parser instance, or uses $wgOut if omitted.
5744 */
5845 public static function addJavascriptAndCSS( $parser = null ) {
@@ -59,13 +46,17 @@
6047
6148 if ( !$parser ) {
6249 $wgOut->addMeta( 'robots', 'noindex,nofollow' );
63 - }
 50+ }
6451
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' );
7061 }
7162
7263 public static function titleString( $title ) {
@@ -80,20 +71,12 @@
8172 return $namespace . $title->getText();
8273 }
8374 }
 75+
8476 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+ }
9379
94 - }
9580 public static function validateXML( $xml, &$error_msg ) {
96 -
97 -
9881 $xmlDTD =<<<END
9982 <?xml version="1.0" encoding="utf-8"?>
10083 <!DOCTYPE PageSchema [
@@ -107,6 +90,7 @@
10891 ]>
10992
11093 END;
 94+
11195 // we are using the SimpleXML library to do the XML validation
11296 // for now - this may change later
11397 // hide parsing warnings
@@ -138,29 +122,30 @@
139123 return $text;
140124 }
141125
142 - static function parsePageSchemas($class_schema_xml) {
 126+ static function parsePageSchemas($class_schema_xml) {
143127 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' ) {
151136 $text .= self::parseFormElem($child);
152 - }
153 - else if ($tag == 'Template') {
 137+ } elseif ($tag == 'Template') {
154138 $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";
157141 }
158142 }
159 - $text .= "</table>\n";
160 - }else{
161 - $text = "";
 143+ $text .= "</table>\n";
 144+ } else {
 145+ $text = "";
162146 }
163 - return $text;
 147+ return $text;
164148 }
 149+
165150 static function parseFormElem( $form_xml ) {
166151 $name = $form_xml->attributes()->name;
167152 $text = self::tableRowHTML('param', 'Form', $name);
@@ -169,7 +154,8 @@
170155 }
171156 return $text;
172157 }
173 - static function parseTemplate ( $template_xml ) {
 158+
 159+ static function parseTemplate ( $template_xml ) {
174160 $name = $template_xml->attributes()->name;
175161 $text = self::tableRowHTML('param', 'Template', $name);
176162 foreach ($template_xml->children() as $child) {
@@ -181,7 +167,7 @@
182168 $name = $field_xml->attributes()->name;
183169 $text = self::tableRowHTML('paramAttr', 'Field', $name);
184170 $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 ) );
186172 foreach( $text_object as $key => $value ) {
187173 $text .= $value;
188174 }
@@ -189,64 +175,62 @@
190176 }
191177 }
192178
193 -/*class holds the PageScheme tag equivalent object */
 179+/*class holds the PageSchema tag equivalent object */
194180
195181 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 */
204189 public $PSTemplates = array();
205 - public $isPSDefined = true;
 190+ public $isPSDefined = true;
206191 public $pp_value = "";
 192+
207193 function __construct ( $category_name ) {
208 - $this->categoryName = $category_name;
 194+ $this->categoryName = $category_name;
209195 $title = Title::newFromText( $category_name, NS_CATEGORY );
210 - $this->pageId = $title->getArticleID();
 196+ $this->pageID = $title->getArticleID();
211197 $dbr = wfGetDB( DB_SLAVE );
212 - //get the result set, query : slect page_props
213198 $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+ )
223208 );
224 - //first row of the result set
 209+ // first row of the result set
225210 $row = $dbr->fetchRow( $res );
226 - if( $row == null){
 211+ if ( $row == null) {
227212 $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 */
234218 $i = 0;
235219 $inherited_templates = null ;
236 - foreach ( $this->pageXml->children() as $tag => $child ) {
 220+ foreach ( $this->pageXML->children() as $tag => $child ) {
237221 if ( $tag == 'InheritsFrom ' ) {
238222 $schema_to_inherit = (string) $child->attributes()->schema;
239223 if( $schema_to_inherit !=null ){
240224 $inheritedSchemaObj = new PSSchema( $schema_to_inherit );
241 - $inherited_templates = $inheritedSchemaObj->getTemplates();
 225+ $inherited_templates = $inheritedSchemaObj->getTemplates();
242226 }
243227 }
244228 if ( $tag == 'Template' ) {
245229 $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);
248232 $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
251235 $temp_name = (string) $child->attributes()->name;
252236 foreach( $inherited_templates as $inherited_template ) {
253237 if( $temp_name == $inherited_template->getName() ){
@@ -254,80 +238,87 @@
255239 }
256240 }
257241 }
258 - }
 242+ }
259243 }
260244 }
261245 }
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 */
263248 function generateAllPages ( $toGenPageList ) {
264 - wfRunHooks( 'PageSchemasGeneratePages', array( $this, $toGenPageList ));
 249+ wfRunHooks( 'PageSchemasGeneratePages', array( $this, $toGenPageList ));
265250 }
 251+
266252 /*return an array of PSTemplate Objects */
267253 function getFormArray () {
268254 $obj = $this->getObject('semanticforms_Form');
269255 return $obj['sf'];
270256 }
 257+
271258 /*return an array of PSTemplate Objects */
272259 function isPSDefined () {
273 - return $this->isPSDefined;
274 - }
 260+ return $this->isPSDefined;
 261+ }
 262+
275263 /*return an array of PSTemplate Objects */
276264 function getTemplates () {
277 - return $this->PSTemplates;
278 - }
 265+ return $this->PSTemplates;
 266+ }
 267+
279268 function getFormName(){
280269 $form_array = $this->getFormArray();
281270 return $form_array['name'];
282271 }
 272+
283273 function getObject( $objectName ) {
284274 $object = array();
285 - wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->pageXml, &$object ) );
 275+ wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->pageXML, &$object ) );
286276 return $object;
287277 }
288 - function getCategoryName(){
 278+
 279+ function getCategoryName() {
289280 return $this->categoryName;
290 - }
 281+ }
291282 }
292 -class PSTemplate {
 283+class PSTemplate {
293284 /* Stores the field objects */
294 - public $PSFields = array();
 285+ public $PSFields = array();
295286 public $templateName ="";
296 - public $templateXml = null;
 287+ public $templateXML = null;
297288 public $multiple_allowed = false;
298289 private $label_name = null;
 290+
299291 function __construct( $template_xml ) {
300 - $this->templateXml = $template_xml;
 292+ $this->templateXML = $template_xml;
301293 $this->templateName = (string) $template_xml->attributes()->name;
302294 if( ((string) $template_xml->attributes()->multiple) == "multiple" ) {
303295 $this->multiple_allowed = true;
304296 }
305297 /*index for template objects */
306298 $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' ) {
310302 $schema_to_inherit = (string) $child->attributes()->schema;
311 - $template_to_inherit = (string) $child->attributes()->template;
 303+ $template_to_inherit = (string) $child->attributes()->template;
312304 if( $schema_to_inherit !=null && $template_to_inherit != null ) {
313305 $inheritedSchemaObj = new PSSchema( $schema_to_inherit );
314 - $inherited_templates = $inheritedSchemaObj->getTemplates();
 306+ $inherited_templates = $inheritedSchemaObj->getTemplates();
315307 foreach( $inherited_templates as $inherited_template ) {
316308 if( $template_to_inherit == $inherited_template->getName() ){
317 - $inherited_fields = $inherited_template->getFields();
 309+ $inherited_fields = $inherited_template->getFields();
318310 }
319311 }
320312 }
321 - }
322 - else if( $child->getName() == "Label" ) { //@TODO Label => sf:Label
 313+ } elseif ( $child->getName() == "Label" ) { //@TODO Label => sf:Label
323314 $this->label_name = (string)$child;
324 - } else if ( $child->getName() == "Field" ){
 315+ } elseif ( $child->getName() == "Field" ){
325316 $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);
328319 $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;
332323 foreach( $inherited_fields as $inherited_field ) {
333324 if( $field_name == $inherited_field->getName() ){
334325 $this->PSFields[$i++]= $inherited_field;
@@ -337,57 +328,66 @@
338329 }
339330 }
340331 }
341 - function getName(){
342 - return $this->templateName;
 332+
 333+ function getName() {
 334+ return $this->templateName;
343335 }
344 - function isMultiple(){
345 - return $this->multiple_allowed;
 336+
 337+ function isMultiple() {
 338+ return $this->multiple_allowed;
346339 }
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;
352343 }
 344+
 345+ function getFields() {
 346+ return $this->PSFields;
 347+ }
353348 }
354349
355350 class PSTemplateField {
356 -
357351 public $fieldName ="";
358 - public $fieldXml= null;
359 - public $fieldLabel = "";
 352+ public $fieldXML = null;
 353+ public $fieldLabel = "";
360354 private $list_values = false;
361 - private $delimiter=null;
 355+ private $delimiter = null;
 356+
362357 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") {
366361 $this->list_values = true;
367362 }
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;
370365 }
371 - foreach ($this->fieldXml->children() as $tag => $child ) {
 366+ foreach ($this->fieldXML->children() as $tag => $child ) {
372367 if ( $tag == 'Label' ) {
373368 $this->fieldLabel = (string)$child;
374 - }
375 - }
 369+ }
 370+ }
376371 }
 372+
377373 public function getDelimiter(){
378374 return $this->delimiter;
379 - }
 375+ }
 376+
380377 function getName(){
381378 return $this->fieldName;
382379 }
 380+
383381 function getLabel(){
384382 return $this->fieldLabel;
385383 }
 384+
386385 public function isList(){
387386 return $this->list_values;
388387 }
 388+
389389 function getObject( $objectName ) {
390390 $object = array();
391 - wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->fieldXml, &$object ) );
 391+ wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->fieldXML, &$object ) );
392392 return $object;
393393 }
394394 }
Index: trunk/extensions/PageSchemas/PS_CreatePageJob.php
@@ -23,12 +23,12 @@
2424 wfProfileOut( __METHOD__ );
2525 return false;
2626 }
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+ }
3333
3434 $page_text = $this->params['page_text'];
3535 // change global $wgUser variable to the one
Index: trunk/extensions/PageSchemas/specials/PS_GeneratePages.php
@@ -1,65 +1,77 @@
22 <?php
33 /**
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
55 *
66 * @author Ankit Garg
77 */
88
99 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 ) {
1616 global $wgRequest, $wgOut;
1717 global $wgSkin;
18 - $this->setHeaders();
19 - $generate_page_text = wfMsg( 'ps-generatepages' );
20 - $generate_page_desc = wfMsg( 'ps-generatepages-desc' );
 18+
 19+ $this->setHeaders();
2120 $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 /> ';
5637 }
57 - }
 38+ $wgOut->addHTML( $text );
 39+ return true;
5840 }
 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 );
5970 return true;
60 - }
61 - function generate_pages ( $categoryName, $toGenPageList ) {
 71+ }
 72+
 73+ function generatePages ( $categoryName, $toGenPageList ) {
6274 global $wgRequest, $wgOut;
63 - $pageSchema = new PSSchema( $categoryName );
 75+ $pageSchema = new PSSchema( $categoryName );
6476 $pageSchema->generateAllPages( $toGenPageList );
6577 }
6678 }
Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php
@@ -6,13 +6,14 @@
77 */
88
99 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() {
1516 global $wgOut;
16 -
 17+
1718 PageSchemas::addJavascriptAndCSS();
1819
1920 // TODO - this should be in a JS file
@@ -34,6 +35,7 @@
3536 jQuery('#fieldsList_'+template_num).append(newField);
3637 addjQueryToCheckbox();
3738 }
 39+
3840 function createAddTemplate() {
3941 templateNum++;
4042 newField = jQuery('#starterTemplate').clone().css('display', '').removeAttr('id');
@@ -46,20 +48,21 @@
4749 });
4850 jQuery('#templatesList').append(newField);
4951 }
50 -function updateFieldNum(field_num){
 52+
 53+function updateFieldNum(field_num ) {
5154 fieldNum = field_num;
5255 }
5356
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+ }
6264 });
6365 }
 66+
6467 jQuery(document).ready(function() {
6568 jQuery(".deleteField").click( function() {
6669 // Remove the encompassing div for this instance.
@@ -73,16 +76,17 @@
7477 });
7578 addjQueryToCheckbox();
7679 });
77 -
7880 </script>
7981
8082 END;
8183 $wgOut->addScript( $jsText );
8284 }
83 - function execute( $category ) {
 85+
 86+ function execute( $category ) {
8487 global $wgRequest, $wgOut, $wgUser;
8588 global $wgSkin;
86 - $this->setHeaders();
 89+
 90+ $this->setHeaders();
8791 $text_1 = '<p>'.wfMsg( 'ps-page-desc-cat-not-exist' ).'</p>';
8892 $text_2 = '<p>'.wfMsg( 'ps-page-desc-ps-not-exist' ).'</p>';
8993 $text_3 = '<p>'.wfMsg( 'ps-page-desc-edit-schema' ).'</p>';
@@ -90,75 +94,75 @@
9195 self::addJavascript();
9296 $schema_name_label = wfMsg('ps-schema-name-label');
9397 $add_xml_label = wfMsg('ps-add-xml-label');
94 -
 98+
9599 $pageSchemaObj = null;
96100 $text_extensions = array(); //This var. will save the html text returned by the extensions
97101 $js_extensions = array();
98102 wfRunHooks( 'getHtmlTextForFieldInputs', array( &$js_extensions, &$text_extensions ));
99 - $text = "";
 103+ $text = "";
100104 $text .= ' <form id="createPageSchemaForm" action="" method="post">' . "\n";
101105 //$text .= '<p>'.$schema_name_label.' <input type="text" name="s_name"/> </p> ';
102106 $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 ) {
106110 $text_ex = preg_replace('/starter/', '1', $text_extensions['sf_form']);
107111 $text .= $text_ex;
108112 }
109113 $delimeter_label = wfMsg('ps-delimeter-label');
110114 $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+
113117 $text .= '<div id="templatesList">';
114118 $text .= '<div class="templateBox" >';
115119 $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> ';
117121 $text .= '<p><input type="checkbox" name="is_multiple_1"/> '.$multiple_temp_label.'</p> ';
118122 $text .= '<div id="fieldsList_1">';
119123 $text .= '<div class="fieldBox" >';
120 - $text .= '<fieldset style="background: #bbb;"><legend>Field</legend>
 124+ $text .= '<fieldset style="background: #bbb;"><legend>Field</legend>
121125 <p>Field name: <input size="15" name="f_name_1">
122126 Display label: <input size="15" name="f_label_1">
123 - </p>
 127+ </p>
124128 <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 ) {
129133 $text_ex = preg_replace('/starter/', '1', $text_extensions['smw']);
130134 $text .= $text_ex;
131 - }
132 - if($text_extensions['sf'] != null){
 135+ }
 136+ if ($text_extensions['sf'] != null ) {
133137 $text_ex = preg_replace('/starter/', '1', $text_extensions['sf']);
134138 $text .= $text_ex;
135 - }
136 - if($text_extensions['sd'] != null){
 139+ }
 140+ if ($text_extensions['sd'] != null ) {
137141 $text_ex = preg_replace('/starter/', '1', $text_extensions['sd']);
138142 $text .= $text_ex;
139143 }
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>
144148 <input type="button" value="Remove field" class="deleteField" /></fieldset>
145 - </div>
146 - </div>
 149+ </div>
 150+ </div>
147151 ';
148152 $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+ )
154158 );
155159 $text .= Xml::tags( 'p', null, $add_field_button ) . "\n";
156 - $text .= '<hr />
 160+ $text .= '<hr />
157161 <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>
161165 </fieldset> </div></div>';
162 -
 166+
163167 $add_template_button = Xml::element( 'input',
164168 array(
165169 'type' => 'button',
@@ -167,123 +171,123 @@
168172 )
169173 );
170174 $text .= Xml::tags( 'p', null, $add_template_button ) . "\n";
171 - $text .= ' <hr />
 175+ $text .= ' <hr />
172176 <div class="editButtons">
173 - <input type="submit" id="wpSave" name="wpSave" value="Save" />
 177+ <input type="submit" id="wpSave" name="wpSave" value="Save" />
174178 </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">
177181 <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>
181185 <div id="fieldsList_starter">
182186 </div>
183187 <p><input type="button" value="Add Field" onclick="createTemplateAddField(starter)" /></p>
184188
185 -<hr />
 189+<hr />
186190 <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>
190194 </fieldset>
191 - </div>
 195+ </div>
192196 <hr /> ';
193197 $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>
195199 <p>
196200 <input size="15" name="f_name_starter">
197201 Display label: <input size="15" name="f_label_starter">
198202 </p>
199203 <p><input type="checkbox" name="f_is_list_starter" class="isListCheckbox" /> This field can hold a list of values
200204 &#160;&#160;</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>
214218 <input type="button" value="Remove field" class="deleteField" />
215219 </fieldset>
216220 </div>';
217221 $text .= $starter_text;
218222 $save_page = $wgRequest->getCheck( 'wpSave' );
219 - if ($save_page) {
 223+ if ( $save_page ) {
220224 //Generate the Xml from the Form elements
221 - $Xmltext = "";
 225+ $XMLtext = "";
222226 //$s_name = $wgRequest->getText('s_name');
223 - $Xmltext .= '<PageSchema>';
 227+ $XMLtext .= '<PageSchema>';
224228 $ps_add_xml = $wgRequest->getText('ps_add_xml');
225 - $Xmltext .= $ps_add_xml;
 229+ $XMLtext .= $ps_add_xml;
226230 $fieldName = "";
227231 $fieldNum= -1;
228232 $templateNum = -1;
229233 $xml_text_extensions = array(); //This var. will save the xml text returned by the extensions
230234 $js_extensions = array();
231235 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'];
234238 }
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.
236240 foreach ( $wgRequest->getValues() as $var => $val ) {
237 - if(substr($var,0,7) == 't_name_'){
 241+ if (substr($var,0,7) == 't_name_' ) {
238242 $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.'">';
243247 }
244 - }else if(substr($var,0,7) == 'f_name_'){
 248+ } elseif (substr($var,0,7) == 'f_name_' ) {
245249 $fieldName = $val;
246250 $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) != '' ) {
249253 $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">';
253257 }
254 - }else{
255 - $Xmltext .= '<Field name="'.$fieldName.'">';
 258+ } else {
 259+ $XMLtext .= '<Field name="'.$fieldName.'">';
256260 }
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 ) {
261265 $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+ }
265269 }
266 - if( $xml_text_extensions['sf'] != null ){
 270+ if ( $xml_text_extensions['sf'] != null ) {
267271 $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+ }
271275 }
272 - if( $xml_text_extensions['sd'] != null ){
 276+ if ( $xml_text_extensions['sd'] != null ) {
273277 $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] ;
276280 }
277 - }
 281+ }
278282 $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>';
285289 }
286290 }
287 - $Xmltext .= '</PageSchema>';
 291+ $XMLtext .= '</PageSchema>';
288292 $pageSchemaObj = new PSSchema( $category );
289293 $categoryTitle = Title::newFromText( $category, NS_CATEGORY );
290294 $categoryArticle = new Article( $categoryTitle );
@@ -291,197 +295,192 @@
292296 $title = Title::newFromText( $category, NS_CATEGORY );
293297 $jobs = array();
294298 $params = array();
295 - if( $pageSchemaObj->isPSDefined() ){
 299+ if ( $pageSchemaObj->isPSDefined() ) {
296300 //Do some preg-replace magic
297301 $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);
300303 $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;
308306 }
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();
375346 }
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> ';
390375 }
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();
397379 }
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>';
408380 }
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>
436436 <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">
442442 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 />
456456 <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+ }
462462 }
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 />
474473 <div class="editButtons">
475 - <input type="submit" id="wpSave" name="wpSave" value="Save" />
 474+ <input type="submit" id="wpSave" name="wpSave" value="Save" />
476475 </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+ }
484483 }
485 - }else {
 484+ } else {
486485 $cat_titles = array();
487486 $count_title = 0;
488487 $text = "";
@@ -491,27 +490,27 @@
492491 array(
493492 'pp_page',
494493 'pp_propname',
495 - 'pp_value'
 494+ 'pp_value'
496495 ),
497 - array(
 496+ array(
498497 'pp_propname' => 'PageSchema'
499498 )
500499 );
501500 while ( $row = $dbr->fetchRow( $res ) ) {
502 - if( $row[2] != null ){
 501+ if ( $row[2] != null ) {
503502 $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 ) {
505504 $cat_text = Title::newFromId($page_id_cat)->getText();
506505 $generatePagesPage = SpecialPage::getTitleFor( 'EditSchema' );
507506 $url = $generatePagesPage ->getFullURL() . '/' . $cat_text;
508 - $text .= '<a href='.$url.'>'.$cat_text.' </a> <br /> ';
 507+ $text .= '<a href='.$url.'>' . $cat_text . '</a> <br /> ';
509508 }
510509 }
511510 }
512511 $dbr->freeResult( $res );
513512 $wgOut->addHTML( $text );
514513 }
515 - }
516 - return true;
517514 }
 515+ return true;
 516+ }
518517 }
Index: trunk/extensions/PageSchemas/PageSchemas.php
@@ -1,17 +1,14 @@
22 <?php
33 /**
4 - * PageSchemas extension
 4+ * Page Schemas extension
55 *
66 * @file
77 * @ingroup Extensions
88 *
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.
1110 *
1211 * Usage: Add the following line in LocalSettings.php:
1312 * require_once( "$IP/extensions/PageSchemas/PageSchemas.php" );
14 - *
15 - * @version 0.0.1
1613 */
1714
1815 // Check environment
@@ -26,8 +23,8 @@
2724 $wgExtensionCredits['parserhook'][] = array(
2825 'path' => __FILE__,
2926 'name' => 'Page Schemas',
30 - 'author' => array( 'Ankit Garg' ),
31 - 'version' => '0.0.1',
 27+ 'author' => array( 'Ankit Garg', 'Yaron Koren' ),
 28+ 'version' => '0.1',
3229 'url' => 'http://www.mediawiki.org/wiki/Extension:PageSchemas',
3330 'descriptionmsg' => 'pageschemas-desc',
3431 );
@@ -60,8 +57,8 @@
6158 $wgHooks['ParserFirstCallInit'][] = 'PageSchemasHooks::register';
6259
6360 // Register page_props usage
64 -$wgPageProps['PageSchema'] = 'Content of &lt;PageSchema&gt; tag';
 61+$wgPageProps['PageSchema'] = 'Contents of &lt;PageSchema&gt; tag';
6562
6663 $wgHooks['UnknownAction'][] = 'PSTabs::onUnknownAction';
6764 $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 @@
22 <?php
33 /**
4 - * Hooks for PageSchemas extension
 4+ * Hook functions for the Page Schemas extension
55 *
66 * @file
77 * @ingroup Extensions
@@ -8,8 +8,6 @@
99
1010 class PageSchemasHooks {
1111
12 - /* Functions */
13 -
1412 // Initialization
1513 public static function register( &$parser ) {
1614 // Register the hook with the parser
@@ -17,7 +15,6 @@
1816 // add the CSS
1917 global $wgOut, $wgScriptPath;
2018 $wgOut->addStyle($wgScriptPath . '/extensions/PageSchemas/PageSchemas.css');
21 - // Continue
2219 return true;
2320 }
2421
@@ -28,8 +25,7 @@
2926 // or if the input is empty, display nothing
3027 if ( !$frame->title->equals( $parser->getTitle() ) || $input == '' )
3128 return;
32 -
33 -
 29+
3430 // TODO: Do processing here, like parse to an array
3531 $error_msg = null;
3632
@@ -37,25 +33,25 @@
3834 // attributes it contained, because that was actually a tag-
3935 // function call, as opposed to a real XML tag
4036 $input = Xml::tags('PageSchema', $args, $input);
41 -
 37+
4238 // 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 -
4440 // just display the XML
45 - if (array_key_exists('type', $args) && $args['type'] != 'auto') {
 41+ if ( array_key_exists( 'type', $args ) && $args['type'] != 'auto' ) {
4642 // Store XML in the page_props table - the Javascript
4743 // can figure out on its own whether or not to handle it
4844 $parser->getOutput()->setProperty( 'PageSchema', $input );
4945 // TODO - a hook should be called here, to allow other
5046 // 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";
5248 $text .= Html::element('pre', null, $input);
5349 return $text;
5450 }
5551
5652 if ( $xml_object = PageSchemas::validateXML( $input, $error_msg ) ) {
5753 // 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 );
6056 } else {
6157 // Store error message in the page_props table
6258 $parser->getOutput()->setProperty( 'PageSchema', $error_msg );
@@ -65,5 +61,5 @@
6662
6763 // return output
6864 return $text;
69 - }
 65+ }
7066 }

Status & tagging log