Himeshi has uploaded a new change for review.

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


Change subject: Added handling for page sections
......................................................................

Added handling for page sections

Implemented the handling of page sections for the "Edit Schema" special page.

Change-Id: I67f7a50ea7811f72f25ee36e6f513dd0187fe063
---
M PS_ExtensionHandler.php
M PageSchemas.classes.php
M PageSchemas.css
M PageSchemas.i18n.php
M PageSchemas.js
M specials/PS_EditSchema.php
6 files changed, 203 insertions(+), 10 deletions(-)


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

diff --git a/PS_ExtensionHandler.php b/PS_ExtensionHandler.php
index cac6c88..49cba5d 100644
--- a/PS_ExtensionHandler.php
+++ b/PS_ExtensionHandler.php
@@ -39,6 +39,10 @@
                return null;
        }
 
+       public static function createPageSectionXMLFromForm() {
+               return null;
+       }
+
        public static function getDisplayColor() {
                return 'white';
        }
@@ -63,11 +67,18 @@
                return null;
        }
 
+       public static function getSectionDisplayString() {
+               return null;
+       }
        /**
         * Returns the HTML for inputs to define a single form field,
         * within the Page Schemas 'edit schema' page.
         */
        public static function getFieldEditingHTML( $psField ) {
+               return null;
+       }
+
+       public static function getPageSectionEditingHTML( $psPageSection ) {
                return null;
        }
 
@@ -103,7 +114,7 @@
        /**
         * Displays data on a single form input in the Page Schemas XML.
         */
-       public static function getFieldDisplayValues( $fieldXML ) {
+       public static function getParameterDisplayValues( $fieldXML ) {
                return null;
        }
 }
diff --git a/PageSchemas.classes.php b/PageSchemas.classes.php
index 636a89b..3c8b67f 100644
--- a/PageSchemas.classes.php
+++ b/PageSchemas.classes.php
@@ -159,6 +159,8 @@
                foreach ( $schemaXML->children() as $tag => $child ) {
                        if ( $tag == 'Template') {
                                $text .= self::displayTemplate( $child );
+                       } elseif ( $tag == 'Section' ) {
+                               $text .= self::displayPageSection( $child );
                        }
                }
                $text .= "</table>\n";
@@ -169,7 +171,7 @@
                global $wgPageSchemasHandlerClasses;
 
                $name = $templateXML->attributes()->name;
-               $text = self::tableRowHTML( 'templateRow', 'Template', $name );
+               $text = self::tableRowHTML( 'templateRow', wfMsg( 'ps-template' 
), $name );
                $multiple = $templateXML->attributes()->multiple;
                if ( $multiple == 'multiple' ) {
                        $text .= self::attrRowHTML( 'schemaAttrRow', 
'multiple', null );
@@ -199,10 +201,9 @@
        }
 
        static function displayField ( $fieldXML ) {
-               global $wgPageSchemasHandlerClasses;
 
                $name = $fieldXML->attributes()->name;
-               $text = self::tableRowHTML( 'fieldRow', 'Field', $name );
+               $text = self::tableRowHTML( 'fieldRow', wfMsg( 'ps-field' ), 
$name );
 
                if( ((string) $fieldXML->attributes()->list) == "list" ) {
                        $text .= self::attrRowHTML( 'fieldAttrRow', 'List', 
null );
@@ -217,15 +218,36 @@
                        }
                }
 
-               // Let extensions that store data within the Page Schemas XML
-               // each handle displaying their data, by adding to this array.
+               $text .= self::displayParams( $fieldXML );
+               return $text;
+       }
+
+       static function displayPageSection( $pageSectionXML ) {
+               $name = $pageSectionXML->attributes()->name;
+               $level = $pageSectionXML->attributes()->level;
+               $text = self::tableRowHTML( 'templateRow', wfMsg( 
'ps-pagesection' ), $name );
+               $text .= self::attrRowHTML( 'schemaAttrRow', wfMsg( 'ps-level' 
), $level );
+               $text .= self::displayParams( $pageSectionXML );
+               return $text;
+       }
+
+       // Let extensions that store data within the Page Schemas XML
+       // each handle displaying their data, by adding to this array.
+       static function displayParams( $inputXML ) {
+               global $wgPageSchemasHandlerClasses;
+               $text = "";
+
                foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) {
-                       $returnVals = call_user_func( array( $psHandlerClass, 
'getFieldDisplayValues' ), $fieldXML );
+                       $returnVals = call_user_func( array( $psHandlerClass, 
'getParameterDisplayValues' ), $inputXML );
                        if ( count( $returnVals ) != 2 ) {
                                continue;
                        }
                        list( $elementName, $values ) = $returnVals;
-                       $label = call_user_func( array( $psHandlerClass, 
'getFieldDisplayString' ) );
+                       if ( $inputXML->getName() == 'Field' ) {
+                               $label = call_user_func( array( 
$psHandlerClass, 'getFieldDisplayString' ) );
+                       } elseif ( $inputXML->getName() == 'Section' ) {
+                               $label = call_user_func( array( 
$psHandlerClass, 'getSectionDisplayString' ) );
+                       }
                        $bgColor = call_user_func( array( $psHandlerClass, 
'getDisplayColor' ) );
                        $text .= self::tableRowHTML( 'fieldExtensionRow', 
$label, $elementName, $bgColor );
                        foreach ( $values as $fieldName => $value ) {
@@ -254,6 +276,8 @@
        private $mPageXML = null;
        /* Stores the template objects */
        private $mTemplates = array();
+       // Stores the page sections
+       private $mPageSections = array();
        private $mIsPSDefined = true;
 
        function __construct ( $categoryName ) {
@@ -281,6 +305,7 @@
                        $this->mPageXML = simplexml_load_string ( $pageXMLstr );
                        // index for template objects
                        $i = 0;
+                       $pageSectionCount = 0;
                        $inherited_templates = array();
                        foreach ( $this->mPageXML->children() as $tag => $child 
) {
                                if ( $tag == 'InheritsFrom ' ) {
@@ -304,6 +329,12 @@
                                                        }
                                                }
                                        }
+                               } elseif ( $tag == 'Section' ) {
+                                       if ( count( $child->children() ) > 0 ) {
+                                               $pageSectionObj = new 
PSPageSection( $child );
+                                               
$this->mPageSections[$pageSectionCount] = $pageSectionObj;
+                                       }
+                                       $pageSectionCount++;
                                }
                        }
                }
@@ -336,6 +367,10 @@
         */
        public function getTemplates() {
                return $this->mTemplates;
+       }
+
+       public function getPageSections() {
+               return $this->mPageSections;
        }
 
        public function getObject( $objectName ) {
@@ -488,3 +523,30 @@
                return null;
        }
 }
+
+class PSPageSection{
+
+       private $mPageSectionXML = null;
+       private $mSectionName = "";
+
+       function __construct( $pageSectionXML ) {
+               $this->mPageSectionXML = $pageSectionXML;
+               $this->mSectionName = 
(string)$pageSectionXML->attributes()->name;
+       }
+
+       public function getSectionName() {
+               return $this->mSectionName;
+       }
+
+       public function getObject( $objectName ) {
+               global $wgPageSchemasHandlerClasses;
+
+               foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) {
+                       $object = call_user_func( array( $psHandlerClass, 
'createPageSchemasObject' ), $objectName, $this->mPageSectionXML );
+                       if ( !is_null( $object ) ) {
+                               return $object;
+                       }
+               }
+               return null;
+       }
+}
diff --git a/PageSchemas.css b/PageSchemas.css
index 55a0872..4cfbd2f 100644
--- a/PageSchemas.css
+++ b/PageSchemas.css
@@ -142,6 +142,12 @@
 div.editSchemaFieldSection {
        background: #CCC;
 }
+div.pageSection {
+       background: #D0DAE6;
+}
+div.editSchemaPageSection {
+       background: #FFFFFF;
+}
 div.editSchemaSection .sectionHeader {
        font-weight: bold;
        padding: 4px 7px;
diff --git a/PageSchemas.i18n.php b/PageSchemas.i18n.php
index 6510265..4be4567 100644
--- a/PageSchemas.i18n.php
+++ b/PageSchemas.i18n.php
@@ -42,6 +42,14 @@
        'createschema' => 'Create schema',
        'right-generatepages' => 'View "Generate pages" tab and page',
        'action-generatepages' => 'view the "{{int:Generatepages}}" tab and 
page',
+       'ps-add-section' => 'Add section',
+       'ps-pagesection' => 'Page section',
+       'ps-removepagesection' => 'Remove page section',
+       'ps-sectionname' => 'Section name',
+       'ps-sectionlevel' => 'Section level:',
+       'ps-pagesection' => 'Section',
+       'ps-level' => 'Level',
+       'ps-otherparams' => 'Other Parameters',
 );
 
 /** Message documentation (Message documentation)
diff --git a/PageSchemas.js b/PageSchemas.js
index 1921037..6979e35 100644
--- a/PageSchemas.js
+++ b/PageSchemas.js
@@ -8,6 +8,7 @@
 
 var fieldNum;
 var templateNum;
+var pageSectionNum;
 
 jQuery.fn.editSchemaMakeTemplateDeleter = function() {
        jQuery(this).click( function() {
@@ -21,6 +22,14 @@
        jQuery(this).click( function() {
                // Remove the encompassing div for this instance.
                jQuery(this).closest(".fieldBox")
+                       .fadeOut('fast', function() { jQuery(this).remove(); });
+       });
+}
+
+jQuery.fn.editSchemaMakePageSectionDeleter = function() {
+       jQuery(this).click( function() {
+               // Remove the encompassing div for this instance.
+               jQuery(this).closest(".pageSectionBox")
                        .fadeOut('fast', function() { jQuery(this).remove(); });
        });
 }
@@ -63,6 +72,17 @@
        } );
 }
 
+jQuery.fn.editSchemaMakePageSectionAdder = function() {
+       jQuery(this).click( function() {
+               newField = jQuery('#starterPageSection').clone().css('display', 
'').removeAttr('id');
+               newHTML = newField.html().replace(/snum/g, pageSectionNum);
+               newField.html(newHTML);
+               
newField.find(".deletePageSection").editSchemaMakePageSectionDeleter();
+               jQuery('#templatesList').append(newField);
+               pageSectionNum++;
+       });
+}
+
 jQuery.fn.editSchemaToggleDelimiterInput = function() {
        if (this.is(":checked")) {
                
this.closest('.fieldBox').find('.delimiterInput').css('display', '');
@@ -82,12 +102,15 @@
 jQuery(document).ready(function() {
        fieldNum = jQuery('.fieldBox:visible').length;
        templateNum = jQuery('.templateBox:visible').length;
+       pageSectionNum = jQuery('.pageSectionBox:visible').length;
 
        // Add and delete buttons
        jQuery(".deleteTemplate").editSchemaMakeTemplateDeleter();
        jQuery(".editSchemaAddTemplate").editSchemaMakeTemplateAdder();
        jQuery(".deleteField").editSchemaMakeFieldDeleter();
        jQuery(".editSchemaAddField").editSchemaMakeFieldAdder();
+       jQuery(".deletePageSection").editSchemaMakePageSectionDeleter();
+       jQuery(".editSchemaAddSection").editSchemaMakePageSectionAdder();
 
        // Checkboxes
        jQuery('.isListCheckbox').each(function() {
diff --git a/specials/PS_EditSchema.php b/specials/PS_EditSchema.php
index 15677c6..da9b464 100644
--- a/specials/PS_EditSchema.php
+++ b/specials/PS_EditSchema.php
@@ -42,14 +42,17 @@
                $fieldName = "";
                $fieldNum = -1;
                $templateNum = -1;
+               $pageSectionNum = -1;
                // Arrays to store the extension-specific XML entered in the 
form
                $schemaXMLFromExtensions = array();
                $templateXMLFromExtensions = array();
                $fieldXMLFromExtensions = array();
+               $pageSectionXMLFromExtensions = array();
                foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) {
                        $schemaXMLFromExtensions[] = call_user_func( array( 
$psHandlerClass, 'createSchemaXMLFromForm' ) );
                        $templateXMLFromExtensions[] = call_user_func( array( 
$psHandlerClass, 'createTemplateXMLFromForm' ) );
                        $fieldXMLFromExtensions[] = call_user_func( array( 
$psHandlerClass, 'createFieldXMLFromForm' ) );
+                       $pageSectionXMLFromExtensions[] = call_user_func( 
array( $psHandlerClass, 'createPageSectionXMLFromForm' ) );
                }
                foreach ( $schemaXMLFromExtensions as $xml ) {
                        if ( !empty( $xml ) ) {
@@ -108,6 +111,17 @@
                        } elseif ( substr( $var, 0, 10 ) == 't_add_xml_' ) {
                                $psXML .= $val;
                                $psXML .= '</Template>';
+                       } elseif ( substr( $var, 0, 7 ) == 's_name_' ) {
+                               $pageSectionNum = substr( $var, 7 );
+                               $sectionName = $val;
+                               $sectionLevel = $wgRequest->getVal( "s_level_" 
. $pageSectionNum );
+                               $psXML .= '<Section name="' . $sectionName . '" 
level="' . $sectionLevel . '">';
+                               foreach ( $pageSectionXMLFromExtensions as 
$extensionName => $xmlPerPageSection ) {
+                                       if ( !empty( 
$xmlPerPageSection[$pageSectionNum] ) ) {
+                                               $psXML .= 
$xmlPerPageSection[$pageSectionNum];
+                                       }
+                               }
+                               $psXML .= '</Section>';
                        }
                }
                $psXML .= '</PageSchema>';
@@ -388,6 +402,52 @@
        }
 
        /**
+        * Returns the HTML for a section of the form comprising of one page 
section.
+        */
+       static function printPageSection( $section_num = 'snum', 
$pageSectionXML = null, $psPageSection = null ) {
+               global $wgPageSchemasHandlerClasses;
+
+               $text = "\t";
+               if ( is_null( $pageSectionXML ) ) {
+                       $text .= '<div class="pageSectionBox" 
id="starterPageSection" style="display: none">' . "\n";
+                       $pageSectionName = "";
+                       $section_level = 2;
+               } else {
+                       $text .= '<div class="pageSectionBox" >' . "\n";
+                       $pageSectionName = (string) 
$pageSectionXML->attributes()->name;
+                       $section_level = (string) 
$pageSectionXML->attributes()->level;
+               }
+
+               $pageSectionHTML = Html::rawElement( 'span', null, wfMsg( 
'ps-sectionname' ) ) . "\n";
+               $pageSectionHTML .= '</t>' . Html::input( 's_name_' . 
$section_num, $pageSectionName, 'text', array( 'size' => '30', 'id' => 
'sectionname' ) ) . "\n";
+               $header_options =  '';
+               $pageSectionHTML .= '</br></br>' . Html::rawElement( 'span', 
null, wfMsg( 'ps-sectionlevel' ) ) . "\n";
+               for ( $i = 1; $i < 7; $i++ ) {
+                       if ( $section_level == $i ) {
+                               $header_options .= " " . Html::element( 
'option', array( 'value' => $i, 'selected' ), $i ) . "\n";
+                       } else {
+                               $header_options .= " " . Html::element( 
'option', array( 'value' => $i ), $i ) . "\n";
+                       }
+               }
+               $pageSectionHTML .= '</t></t>' . Html::rawElement( 'select', 
array( 'name' => "s_level_" . $section_num ), $header_options ) . "\n";
+
+               foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) {
+                       $valuesFromExtension = call_user_func( array( 
$psHandlerClass, "getPageSectionEditingHTML" ), $psPageSection );
+                       $label = call_user_func( array( $psHandlerClass, 
"getFieldDisplayString" ) );
+                       $color = call_user_func( array( $psHandlerClass, 
"getDisplayColor" ) );
+                       if ( is_null( $valuesFromExtension ) ) {
+                               continue;
+                       }
+                       $html = self::printFormSection( $label, $color, 
$valuesFromExtension, 'editSchemaPageSection' );
+                       $pageSectionHTML .= str_replace( 'num', $section_num, 
$html );
+               }
+               $pageSectionHTML .= '<p>' . Html::input( 'remove-pageSection', 
wfMsg( 'ps-removepagesection' ), 'button', array( 'class' => 
'deletePageSection' ) ) . "</p>\n";
+               $text .= self::printFormSection( wfMsg( 'ps-pagesection' ), 
'#A6B7CC', $pageSectionHTML, 'pageSection' );
+               $text .= "\t</div><!-- pageSectionBox-->\n";
+               return $text;
+       }
+
+       /**
         * Returns the HTML to display an entire form.
         */
        static function printForm( $pageSchemaObj = null, $pageXML = null ) {
@@ -395,8 +455,10 @@
 
                if ( is_null( $pageSchemaObj ) ) {
                        $psTemplates = array();
+                       $psPageSections = array();
                } else {
                        $psTemplates = $pageSchemaObj->getTemplates();
+                       $psPageSections = $pageSchemaObj->getPageSections();
                }
 
                if ( is_null( $pageXML ) ) {
@@ -432,15 +494,29 @@
                $text .= '<div id="templatesList">' . "\n";
 
                $templateNum = 0;
+               $pageSectionNum = 0;
 
                // Add 'starter', hidden template section.
                $text .= self::printTemplateSection();
+               //Add 'starter', hidden pagesection
+               $text .= self::printPageSection();
+
                /* index for template objects */
                foreach ( $pageXMLChildren as $tag => $pageXMLChild ) {
                        if ( $tag == 'Template' ) {
-                               $psTemplate = $psTemplates[$templateNum];
+                               $psTemplate = null;
+                               if ( array_key_exists( $templateNum, 
$psTemplates ) ) {
+                                       $psTemplate = 
$psTemplates[$templateNum];
+                               }
                                $text .= self::printTemplateSection( 
$templateNum, $pageXMLChild, $psTemplate );
                                $templateNum++;
+                       } elseif ( $tag == 'Section' ) {
+                               $psPageSection = null;
+                               if ( array_key_exists( $pageSectionNum, 
$psPageSections ) ) {
+                                       $psPageSection = 
$psPageSections[$pageSectionNum];
+                               }
+                               $text .= self::printPageSection( 
$pageSectionNum, $pageXMLChild, $psPageSection );
+                               $pageSectionNum++;
                        }
                }
                $add_template_button = Xml::element( 'input',
@@ -450,8 +526,15 @@
                                'value' => wfMsg( 'ps-add-template' ),
                        )
                );
+               $add_section_button = Xml::element( 'input',
+                       array(
+                               'type' => 'button',
+                               'class' => 'editSchemaAddSection',
+                               'value' => wfMsg( 'ps-add-section' ),
+                       )
+               );
                $text .= "\t</div><!-- templatesList -->\n";
-               $text .= Xml::tags( 'p', null, $add_template_button ) . "\n";
+               $text .= Xml::tags( 'p', null, $add_template_button . 
$add_section_button ) . "\n";
                $text .= "\t\t<hr />\n";
                $label = wfMsg( 'summary' );
                $text .= <<<END

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I67f7a50ea7811f72f25ee36e6f513dd0187fe063
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