Himeshi has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/80863


Change subject: Added generating pages with page sections
......................................................................

Added generating pages with page sections

Added page generation with page sections to the "Generate Pages" special page.

Change-Id: I3eeebff10c3deb23be1db8c48836cb376fc24622
---
M PageSchemas.classes.php
M specials/PS_EditSchema.php
2 files changed, 45 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageSchemas 
refs/changes/63/80863/1

diff --git a/PageSchemas.classes.php b/PageSchemas.classes.php
index a04a01a..9ff69e2 100644
--- a/PageSchemas.classes.php
+++ b/PageSchemas.classes.php
@@ -281,8 +281,8 @@
        private $mPageXML = null;
        /* Stores the template objects */
        private $mTemplates = array();
-       // Stores the page sections
-       private $mPageSections = array();
+       /* Stores the template and page section objects */
+       private $mFormItemList = array();
        private $mIsPSDefined = true;
 
        function __construct ( $categoryName ) {
@@ -309,36 +309,44 @@
                        $pageXMLstr = $row[2];
                        $this->mPageXML = simplexml_load_string ( $pageXMLstr );
                        // index for template objects
-                       $i = 0;
+                       $templateCount = 0;
                        $pageSectionCount = 0;
-                       $inherited_templates = array();
+                       $inherited_template_items = array();
                        foreach ( $this->mPageXML->children() as $tag => $child 
) {
                                if ( $tag == 'InheritsFrom ' ) {
                                        $schema_to_inherit = (string) 
$child->attributes()->schema;
-                                       if( $schema_to_inherit !=null ){
+                                       if( $schema_to_inherit != null ) {
                                                $inheritedSchemaObj = new 
PSSchema( $schema_to_inherit );
-                                               $inherited_templates = 
$inheritedSchemaObj->getTemplates();
+                                               $inherited_template_items = 
$inheritedSchemaObj->getTemplates();
                                        }
                                }
                                if ( $tag == 'Template' ) {
                                        $ignore = (string) 
$child->attributes()->ignore;
-                                       if ( count($child->children()) > 0 ) {
-                                               $templateObj = new 
PSTemplate($child);
-                                               $this->mTemplates[$i++]= 
$templateObj;
+                                       if ( count( $child->children() ) > 0 ) {
+                                               $templateObj = new PSTemplate( 
$child );
+                                               $this->mFormItemList[] = array( 
'type' => $tag,
+                                                       'number' => 
$templateCount,
+                                                       'item' => $templateObj 
);
+                                                       
$this->mTemplates[$templateCount]= $templateObj;
+                                               $templateCount++;
                                        } elseif ( $ignore != "true" ) {
                                                // Code to add templates from 
inherited templates
                                                $temp_name = (string) 
$child->attributes()->name;
-                                               foreach( $inherited_templates 
as $inherited_template ) {
-                                                       if( $temp_name == 
$inherited_template->getName() ){
-                                                               
$this->mTemplates[$i++] = $inherited_template;
+                                               foreach( 
$inherited_template_items as $inherited_template_item ) {
+                                                       if( 
$inherited_template_item['type'] == $tag && $temp_name == 
$inherited_template_item['item']->getName() ) {
+                                                               
$this->mFormItemList[] = array( 'type' => $tag,
+                                                                       
'number' => $templateCount,
+                                                                       'item' 
=> $inherited_template );
+                                                                       
$this->mTemplates[$templateCount] = $inherited_template;
+                                                               
$templateCount++;
                                                        }
                                                }
                                        }
                                } elseif ( $tag == 'Section' ) {
-                                       if ( count( $child->children() ) > 0 ) {
-                                               $pageSectionObj = new 
PSPageSection( $child );
-                                               
$this->mPageSections[$pageSectionCount] = $pageSectionObj;
-                                       }
+                                       $pageSectionObj = new PSPageSection( 
$child );
+                                       $this->mFormItemList[] = array( 'type' 
=> $tag,
+                                                       'number' => 
$pageSectionCount,
+                                                       'item' => 
$pageSectionObj );
                                        $pageSectionCount++;
                                }
                        }
@@ -374,8 +382,11 @@
                return $this->mTemplates;
        }
 
-       public function getPageSections() {
-               return $this->mPageSections;
+       /**
+        * Returns an array of template and page section objects.
+        */
+       public function getFormItemsList() {
+               return $this->mFormItemList;
        }
 
        public function getObject( $objectName ) {
@@ -533,16 +544,22 @@
 
        private $mPageSectionXML = null;
        private $mSectionName = "";
+       private $mSectionLevel = 2;
 
        function __construct( $pageSectionXML ) {
                $this->mPageSectionXML = $pageSectionXML;
                $this->mSectionName = 
(string)$pageSectionXML->attributes()->name;
+               $this->mSectionLevel = 
(string)$pageSectionXML->attributes()->level;
        }
 
        public function getSectionName() {
                return $this->mSectionName;
        }
 
+       public function getSectionLevel() {
+               return $this->mSectionLevel;
+       }
+
        public function getObject( $objectName ) {
                global $wgPageSchemasHandlerClasses;
 
diff --git a/specials/PS_EditSchema.php b/specials/PS_EditSchema.php
index ac83cac..d7a3f52 100644
--- a/specials/PS_EditSchema.php
+++ b/specials/PS_EditSchema.php
@@ -454,11 +454,9 @@
                global $wgPageSchemasHandlerClasses;
 
                if ( is_null( $pageSchemaObj ) ) {
-                       $psTemplates = array();
-                       $psPageSections = array();
+                       $psFormItemList = array();
                } else {
-                       $psTemplates = $pageSchemaObj->getTemplates();
-                       $psPageSections = $pageSchemaObj->getPageSections();
+                       $psFormItemList = $pageSchemaObj->getFormItemsList();
                }
 
                if ( is_null( $pageXML ) ) {
@@ -505,15 +503,19 @@
                foreach ( $pageXMLChildren as $tag => $pageXMLChild ) {
                        if ( $tag == 'Template' ) {
                                $psTemplate = null;
-                               if ( array_key_exists( $templateNum, 
$psTemplates ) ) {
-                                       $psTemplate = 
$psTemplates[$templateNum];
+                               foreach ( $psFormItemList as 
$psFormItemListItem ) {
+                                       if ( $psFormItemListItem['type'] == 
'Template' && $psFormItemListItem['number'] == $templateNum ) {
+                                               $psTemplate = 
$psFormItemListItem['item'];
+                                       }
                                }
                                $text .= self::printTemplateSection( 
$templateNum, $pageXMLChild, $psTemplate );
                                $templateNum++;
                        } elseif ( $tag == 'Section' ) {
                                $psPageSection = null;
-                               if ( array_key_exists( $pageSectionNum, 
$psPageSections ) ) {
-                                       $psPageSection = 
$psPageSections[$pageSectionNum];
+                               foreach ( $psFormItemList as 
$psFormItemListItem ) {
+                                       if ( $psFormItemListItem['type'] == 
'Section' && $psFormItemListItem['number'] == $pageSectionNum ) {
+                                               $psPageSection = 
$psFormItemListItem['item'];
+                                       }
                                }
                                $text .= self::printPageSection( 
$pageSectionNum, $pageXMLChild, $psPageSection );
                                $pageSectionNum++;

-- 
To view, visit https://gerrit.wikimedia.org/r/80863
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3eeebff10c3deb23be1db8c48836cb376fc24622
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageSchemas
Gerrit-Branch: master
Gerrit-Owner: Himeshi <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to