Yaron Koren has submitted this change and it was merged.
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, 215 insertions(+), 4 deletions(-)
Approvals:
Yaron Koren: Verified; Looks good to me, approved
diff --git a/PS_ExtensionHandler.php b/PS_ExtensionHandler.php
index cac6c88..6ac32f4 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 getPageSectionDisplayString() {
+ 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;
}
@@ -106,4 +117,11 @@
public static function getFieldDisplayValues( $fieldXML ) {
return null;
}
+
+ /**
+ * Displays form details for one page section in the Page Schemas XML.
+ */
+ public static function getPageSectionDisplayValues( $pageSectionXML ) {
+ return null;
+ }
}
diff --git a/PageSchemas.classes.php b/PageSchemas.classes.php
index 636a89b..a04a01a 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 );
@@ -202,7 +204,7 @@
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 );
@@ -235,6 +237,31 @@
return $text;
}
+ static function displayPageSection( $pageSectionXML ) {
+ global $wgPageSchemasHandlerClasses;
+
+ $name = $pageSectionXML->attributes()->name;
+ $level = $pageSectionXML->attributes()->level;
+ $text = self::tableRowHTML( 'templateRow', wfMsg( 'ps-section'
), $name );
+ $text .= self::attrRowHTML( 'schemaAttrRow', wfMsg( 'ps-level'
), $level );
+
+ foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) {
+ $returnVals = call_user_func( array( $psHandlerClass,
'getPageSectionDisplayValues' ), $pageSectionXML );
+ if ( count( $returnVals ) != 2 ) {
+ continue;
+ }
+ list( $elementName, $values ) = $returnVals;
+ $label = call_user_func( array( $psHandlerClass,
'getPageSectionDisplayString' ) );
+ $bgColor = call_user_func( array( $psHandlerClass,
'getDisplayColor' ) );
+ $text .= self::tableRowHTML( 'fieldExtensionRow',
$label, $elementName, $bgColor );
+ foreach ( $values as $fieldName => $value ) {
+ $text .= self::attrRowHTML( 'fieldAttrRow',
$fieldName, $value );
+ }
+ }
+
+ return $text;
+ }
+
public static function getValueFromObject( $object, $key ) {
if ( is_null( $object ) ) {
return null;
@@ -254,6 +281,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 +310,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 +334,12 @@
}
}
}
+ } elseif ( $tag == 'Section' ) {
+ if ( count( $child->children() ) > 0 ) {
+ $pageSectionObj = new
PSPageSection( $child );
+
$this->mPageSections[$pageSectionCount] = $pageSectionObj;
+ }
+ $pageSectionCount++;
}
}
}
@@ -336,6 +372,10 @@
*/
public function getTemplates() {
return $this->mTemplates;
+ }
+
+ public function getPageSections() {
+ return $this->mPageSections;
}
public function getObject( $objectName ) {
@@ -488,3 +528,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..e43bca0 100644
--- a/PageSchemas.i18n.php
+++ b/PageSchemas.i18n.php
@@ -42,6 +42,13 @@
'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-removepagesection' => 'Remove section',
+ 'ps-sectionname' => 'Section name:',
+ 'ps-sectionlevel' => 'Section level:',
+ 'ps-section' => 'Section',
+ 'ps-level' => 'Level',
+ 'ps-otherparams' => 'Other parameters',
);
/** Message documentation (Message documentation)
@@ -71,6 +78,13 @@
'createschema' => 'Tab name',
'right-generatepages' => '{{doc-right|generatepages}}',
'action-generatepages' => '{{doc-action|generatepages}}',
+ 'ps-add-section' => '{{Identical|Add section}}',
+ 'ps-removepagesection' => 'The text on the button that removes the
current section',
+ 'ps-sectionname' => 'Used as label for "Section name" input box',
+ 'ps-sectionlevel' => 'Used as label for "Section level" select box',
+ 'ps-section' => 'A page section. {{Identical|Section}}',
+ 'ps-level' => 'The level, or number of \'=\'s, in a section\'s header',
+ 'ps-otherparams' => '{{Identical|Other parameters}}',
);
/** Afrikaans (Afrikaans)
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..ac83cac 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 = '<p>' . 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 />' . 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 .= '  ' . Html::rawElement( 'select',
array( 'name' => "s_level_" . $section_num ), $header_options ) . "</p>\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-section' ),
'#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: merged
Gerrit-Change-Id: I67f7a50ea7811f72f25ee36e6f513dd0187fe063
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/PageSchemas
Gerrit-Branch: master
Gerrit-Owner: Himeshi <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits