http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99689
Revision: 99689
Author: yaron
Date: 2011-10-13 16:24:11 +0000 (Thu, 13 Oct 2011)
Log Message:
-----------
Version 2.0-alpha: overhaul of extension, with changes to Javascript, HTML and
display, along with bug fixes
Modified Paths:
--------------
trunk/extensions/PageSchemas/PageSchemas.classes.php
trunk/extensions/PageSchemas/PageSchemas.css
trunk/extensions/PageSchemas/PageSchemas.hooks.php
trunk/extensions/PageSchemas/PageSchemas.php
trunk/extensions/PageSchemas/specials/PS_EditSchema.php
Added Paths:
-----------
trunk/extensions/PageSchemas/PageSchemas.js
Modified: trunk/extensions/PageSchemas/PageSchemas.classes.php
===================================================================
--- trunk/extensions/PageSchemas/PageSchemas.classes.php 2011-10-13
16:13:13 UTC (rev 99688)
+++ trunk/extensions/PageSchemas/PageSchemas.classes.php 2011-10-13
16:24:11 UTC (rev 99689)
@@ -56,7 +56,7 @@
global $wgOut;
$output = $wgOut;
}
- $output->addModules( 'jquery' );
+ $output->addModules( 'ext.pageschemas.main' );
}
public static function titleString( $title ) {
@@ -98,43 +98,59 @@
return $xml_success;
}
- static function tableRowHTML($css_class, $data_type, $value = null) {
- $data_type = htmlspecialchars($data_type);
- if ( is_null( $value ) ) {
+ static function tableRowHTML( $css_class, $data_type, $value = null,
$bgColor = null ) {
+ $data_type = htmlspecialchars( $data_type );
+ if ( !is_null( $bgColor ) ) {
+ // We don't actually use the passed-in background
color, except as an indicator
+ // that this is a header row for extension data, and
thus should have special
+ // display.
+ // In the future, the background color may get used,
though.
+ $data_type = HTML::element( 'span', array( 'style' =>
"color: #993333;" ), $data_type );
+ }
+ if ( $value == '' ) {
$content = $data_type;
} else {
- $content = "$data_type: " . HTML::element('span',
array('class' => 'rowValue'), $value);
+ $content = "$data_type: " . HTML::element( 'span',
array( 'class' => 'rowValue' ), $value );
}
- $cell = HTML::rawElement('td', array('colspan' => 2, 'class' =>
$css_class), $content);
- $text = HTML::rawElement('tr', null, $cell);
+ $cellAttrs = array( 'colspan' => 2, 'class' => $css_class );
+ $cell = HTML::rawElement( 'td', $cellAttrs, $content );
+ //$cell = "<td colspan=2><span style=\"background: white;
min-width; 20px;\">.</span><span style=\"background:
$bgColor;\">$content</span></td>";
+ $text = HTML::rawElement( 'tr', array( 'style' => 'border: 1px
black solid; margin: 10px;' ), $cell );
$text .= "\n";
return $text;
}
- static function tableMessageRowHTML( $css_class, $name, $value ) {
- $cell1 = HTML::element('td', array('class' => $css_class),
$name);
- $cell2 = HTML::element('td', array('class' => 'msg'), $value);
- $text = HTML::rawElement('tr', null, $cell1 . "\n" . $cell2);
+ static function attrRowHTML( $cssClass, $fieldName, $value ) {
+ $fieldNameAttrs = array( 'class' => $cssClass, 'style' =>
'font-weight: normal;' );
+ $fieldNameCell = HTML::rawElement( 'td', $fieldNameAttrs,
$fieldName );
+ $valueCell = HTML::element( 'td', array( 'class' => 'msg',
'style' => 'font-weight: bold;' ), $value );
+ $text = HTML::rawElement( 'tr', null, $fieldNameCell . "\n" .
$valueCell );
$text .= "\n";
return $text;
}
- static function parsePageSchemas($class_schema_xml) {
+ static function displaySchema($schema_xml) {
global $wgTitle;
if ( $wgTitle->getNamespace() == NS_CATEGORY ) {
- $text = Html::element( 'p', null, wfMsg(
'ps-schema-description' ) ) . "\n";
- $text .= "<table class=\"pageSchema\">\n";
- $name = $class_schema_xml->attributes()->name;
- $text .= self::tableRowHTML('paramGroup', 'PageSchema',
$name);
- foreach ( $class_schema_xml->children() as $tag =>
$child ) {
- // TODO - need a hook call right here
- if ( $tag == 'semanticforms_Form' ) {
- $text .= self::parseFormElem($child);
- } elseif ($tag == 'Template') {
- $text .= self::parseTemplate($child);
+ //$text = Html::element( 'p', null, wfMsg(
'ps-schema-description' ) ) . "\n";
+ $text = "<table class=\"pageSchema mw-collapsible
mw-collapsed\">\n";
+ $name = $schema_xml->attributes()->name;
+ $text .= self::tableRowHTML( 'pageSchemaHeader', 'Page
schema' );
+ $displayInfoFromExtensions = array();
+ wfRunHooks( 'PageSchemasGetSchemaDisplayInfo', array(
$schema_xml, &$displayInfoFromExtensions ) );
+ foreach( $displayInfoFromExtensions as $displayInfo ) {
+ list( $label, $elementName, $bgColor, $values )
= $displayInfo;
+ $text .= self::tableRowHTML(
'schemaExtensionRow', $label, $elementName, $bgColor );
+ foreach ( $values as $fieldName => $value ) {
+ $text .= self::attrRowHTML(
'schemaAttrRow', $fieldName, $value );
}
}
+ foreach ( $schema_xml->children() as $tag => $child ) {
+ if ( $tag == 'Template') {
+ $text .= self::displayTemplate($child);
+ }
+ }
$text .= "</table>\n";
} else {
$text = "";
@@ -142,34 +158,52 @@
return $text;
}
- /**
- * @TODO - this should move into Semantic Forms, via a hook
- */
- static function parseFormElem( $form_xml ) {
- $name = $form_xml->attributes()->name;
- $text = self::tableRowHTML('param', 'Form', $name);
- foreach ($form_xml->children() as $key => $value ) {
- $text .= self::tableMessageRowHTML( "paramAttrMsg",
(string)$key, (string)$value );
+ static function displayTemplate ( $templateXML ) {
+ $name = $templateXML->attributes()->name;
+ $text = self::tableRowHTML( 'templateRow', 'Template', $name );
+ $multiple = $templateXML->attributes()->multiple;
+ if ( $multiple == 'multiple' ) {
+ $text .= self::attrRowHTML( 'schemaAttrRow',
'multiple', null );
}
+ $displayInfoFromExtensions = array();
+ wfRunHooks( 'PageSchemasGetTemplateDisplayInfo', array(
$templateXML, &$displayInfoFromExtensions ) );
+ foreach( $displayInfoFromExtensions as $displayInfo ) {
+ list( $label, $elementName, $bgColor, $values ) =
$displayInfo;
+ $text .= self::tableRowHTML( 'fieldExtensionRow',
$label, $elementName, $bgColor );
+ foreach ( $values as $fieldName => $value ) {
+ $text .= self::attrRowHTML( 'fieldAttrRow',
$fieldName, $value );
+ }
+ }
+ foreach ( $templateXML->children() as $child ) {
+ $text .= self::displayField( $child );
+ }
return $text;
}
- static function parseTemplate ( $template_xml ) {
- $name = $template_xml->attributes()->name;
- $text = self::tableRowHTML( 'param', 'Template', $name );
- foreach ( $template_xml->children() as $child ) {
- $text .= self::parseField( $child );
+ static function displayField ( $fieldXML ) {
+ $name = $fieldXML->attributes()->name;
+ $text = self::tableRowHTML( 'fieldRow', 'Field', $name );
+
+ if( ((string) $fieldXML->attributes()->list) == "list" ) {
+ $text .= self::attrRowHTML( 'fieldAttrRow', 'List',
null );
}
- return $text;
- }
- static function parseField ( $field_xml ) {
- $name = $field_xml->attributes()->name;
- $text = self::tableRowHTML( 'paramAttr', 'Field', $name );
- $text_object = array(); //different extensions will fill the
html parsed text in this array via hooks
- wfRunHooks( 'PSParseFieldElements', array( $field_xml,
&$text_object ) );
- foreach( $text_object as $key => $value ) {
- $text .= $value;
+ foreach ( $fieldXML->children() as $tag => $child ) {
+ if ( $tag == 'Label' ) {
+ $text .= self::attrRowHTML( 'fieldAttrRow',
'Label', $child );
+ }
}
+
+ // Let extensions that store data within the Page Schemas XML
each
+ // handle displaying their data, by adding to this array.
+ $displayInfoFromExtensions = array();
+ wfRunHooks( 'PageSchemasGetFieldDisplayInfo', array( $fieldXML,
&$displayInfoFromExtensions ) );
+ foreach( $displayInfoFromExtensions as $displayInfo ) {
+ list( $label, $elementName, $bgColor, $values ) =
$displayInfo;
+ $text .= self::tableRowHTML( 'fieldExtensionRow',
$label, $elementName, $bgColor );
+ foreach ( $values as $fieldName => $value ) {
+ $text .= self::attrRowHTML( 'fieldAttrRow',
$fieldName, $value );
+ }
+ }
return $text;
}
}
@@ -213,7 +247,7 @@
$this->pageXML = simplexml_load_string ( $pageXMLstr );
/* index for template objects */
$i = 0;
- $inherited_templates = null ;
+ $inherited_templates = array();
foreach ( $this->pageXML->children() as $tag => $child
) {
if ( $tag == 'InheritsFrom ' ) {
$schema_to_inherit = (string)
$child->attributes()->schema;
@@ -266,13 +300,13 @@
return $this->categoryName;
}
}
+
class PSTemplate {
/* Stores the field objects */
public $PSFields = array();
public $templateName ="";
public $templateXML = null;
public $multiple_allowed = false;
- private $label_name = null;
function __construct( $template_xml ) {
$this->templateXML = $template_xml;
@@ -296,15 +330,13 @@
}
}
}
- } elseif ( $child->getName() == "Label" ) { //@TODO
Label => sf:Label
- $this->label_name = (string)$child;
} elseif ( $child->getName() == "Field" ) {
$ignore = (string) $child->attributes()->ignore;
if ( count($child->children()) > 0 ) { //@TODO
:Can be dealt more efficiently
$fieldObj = new PSTemplateField($child);
$this->PSFields[$i++]= $fieldObj;
} elseif ( $ignore != "true" ) {
- //Code to Add Templates from Inherited
templates
+ // Code to add fields from inherited
templates
$field_name = (string)
$child->attributes()->name;
foreach( $inherited_fields as
$inherited_field ) {
if( $field_name ==
$inherited_field->getName() ){
@@ -324,8 +356,10 @@
return $this->multiple_allowed;
}
- public function getLabel() {
- return $this->label_name;
+ function getObject( $objectName ) {
+ $object = array();
+ wfRunHooks( 'PageSchemasGetObject', array( $objectName,
$this->templateXML, &$object ) );
+ return $object;
}
function getFields() {
Modified: trunk/extensions/PageSchemas/PageSchemas.css
===================================================================
--- trunk/extensions/PageSchemas/PageSchemas.css 2011-10-13 16:13:13 UTC
(rev 99688)
+++ trunk/extensions/PageSchemas/PageSchemas.css 2011-10-13 16:24:11 UTC
(rev 99689)
@@ -1,4 +1,11 @@
-.pageSchema td {
+/**
+ * Used to display page schema information directly on the category page.
+ */
+table.pageSchema {
+ border: 1px solid #ccc;
+}
+
+table.pageSchema td {
padding-right: 5px;
}
@@ -7,96 +14,92 @@
padding-left: 5px;
}
-.pageSchema .paramGroup {
- background: #bbaa88;
+table.pageSchema .pageSchemaHeader {
padding-left: 5px;
}
-body.rtl .pageSchema .paramGroup {
+body.rtl .pageSchema .pageSchemaHeader {
padding-left: auto;
padding-right: 5px;
}
-.pageSchema .paramGroup span.rowValue {
+table.pageSchema .pageSchemaHeader span.rowValue {
font-weight: bold;
}
-.pageSchema .param {
- background: #d3c2a0;
- padding-left: 20px;
+.pageSchema .schemaExtensionRow {
+ padding-left: 5px;
}
-body.rtl .pageSchema .param {
+body.rtl .pageSchema .schemaExtensionRow {
padding-left: auto;
- padding-right: 20px;
+ padding-right: 5px;
}
-.pageSchema .param span.rowValue {
+.pageSchema .schemaAttrRow {
+ padding-left: 25px;
+ background: white;
font-weight: bold;
}
-.pageSchema .paramAttr {
- background: #eeddbb;
- padding-left: 35px;
-}
-
-body.rtl .pageSchema .paramAttr {
+body.rtl .pageSchema .schemaAttrRow {
padding-left: auto;
- padding-right: 35px;
+ padding-left: 25px;
}
-.pageSchema .paramAttrMsg {
- background: #ffeecc;
- padding-left: 50px;
+table.pageSchema .templateRow {
+ background: #d3c2a0;
+ padding-left: 5px;
}
-body.rtl .pageSchema .paramAttrMsg {
+body.rtl .pageSchema .templaterow {
padding-left: auto;
- padding-right: 50px;
+ padding-right: 5px;
}
-.pageSchema .paramOptions {
- padding-left: 20px;
- background: #ffff77;
+.pageSchema span.rowValue {
+ font-weight: bold;
}
-body.rtl .pageSchema .paramOptions {
+.pageSchema .fieldRow {
+ background: #eeddbb;
+ padding-left: 25px;
+}
+
+body.rtl .pageSchema .fieldRow {
padding-left: auto;
- padding-right: 20px;
+ padding-right: 25px;
}
-.pageSchema .paramOption {
- padding-left: 35px;
- background: #ffff99;
+.pageSchema .fieldExtensionRow {
+ padding-left: 26px;
+ border-top: 1px solid #ddd;
}
-body.rtl .pageSchema .paramOption {
+body.rtl .pageSchema .fieldExtensionRow {
padding-left: auto;
- padding-right: 35px;
+ padding-right: 26px;
}
-.pageSchema .paramOption span.rowValue {
+.pageSchema .fieldAttrRow {
+ padding-left: 45px;
+ background: white;
font-weight: bold;
}
-.pageSchema .paramOptionMsg {
- padding-left: 50px;
- background: #ffffbb;
-}
-
-body.rtl .pageSchema .paramOptionMsg {
+body.rtl .pageSchema .fieldAttrRow {
padding-left: auto;
- padding-right: 50px;
+ padding-left: 45px;
}
.pageSchema .paramData {
- padding-left: 20px;
+ padding-left: 5px;
background: #77dd77;
}
body.rtl .pageSchema .paramData {
padding-left: auto;
- padding-right: 20px;
+ padding-right: 5px;
}
.pageSchema .paramData span.rowValue {
@@ -122,3 +125,28 @@
padding-left: auto;
padding-right: 5px;
}
+
+/**
+ * Used in Special:EditSchema
+ */
+div.editSchemaSection {
+ border: 1px #999 solid;
+ background: white;
+ padding: 0px;
+ margin-bottom: 10px;
+ margin-top: 10px;
+}
+div.editSchemaTemplateSection {
+ background: #EEE;
+}
+div.editSchemaFieldSection {
+ background: #CCC;
+}
+div.editSchemaSection .sectionHeader {
+ font-weight: bold;
+ padding: 4px 7px;
+ border-bottom: 1px #bbb solid;
+}
+div.editSchemaSection .sectionBody {
+ padding: 5px 15px;
+}
Modified: trunk/extensions/PageSchemas/PageSchemas.hooks.php
===================================================================
--- trunk/extensions/PageSchemas/PageSchemas.hooks.php 2011-10-13 16:13:13 UTC
(rev 99688)
+++ trunk/extensions/PageSchemas/PageSchemas.hooks.php 2011-10-13 16:24:11 UTC
(rev 99689)
@@ -10,17 +10,16 @@
// Initialization
public static function register( &$parser ) {
- global $wgOut, $wgScriptPath;
-
// Register the hook with the parser
$parser->setHook( 'PageSchema', array( 'PageSchemasHooks',
'render' ) );
- // add the CSS
- $wgOut->addStyle( $wgScriptPath .
'/extensions/PageSchemas/PageSchemas.css' );
return true;
}
// Render the displayed XML, if any
public static function render( $input, $args, $parser, $frame ) {
+ // Disable cache so that CSS will get loaded
+ $parser->disableCache();
+
// If this call is contained in a transcluded page or template,
// or if the input is empty, display nothing.
if ( !$frame->title->equals( $parser->getTitle() ) || $input ==
'' ) {
@@ -38,7 +37,10 @@
if ( $xml_object = PageSchemas::validateXML( $input, $error_msg
) ) {
// Store the XML in the page_props table
$parser->getOutput()->setProperty( 'PageSchema', $input
);
- $text = PageSchemas::parsePageSchemas( $xml_object );
+ // Display the schema on the screen
+ global $wgOut, $wgScriptPath;
+ $wgOut->addStyle( $wgScriptPath .
'/extensions/PageSchemas/PageSchemas.css' );
+ $text = PageSchemas::displaySchema( $xml_object );
} else {
// Store error message in the page_props table
$parser->getOutput()->setProperty( 'PageSchema',
$error_msg );
Added: trunk/extensions/PageSchemas/PageSchemas.js
===================================================================
--- trunk/extensions/PageSchemas/PageSchemas.js (rev 0)
+++ trunk/extensions/PageSchemas/PageSchemas.js 2011-10-13 16:24:11 UTC (rev
99689)
@@ -0,0 +1,106 @@
+/**
+ * Javascript for the Page Schemas extension.
+ *
+ * @author Ankit Garg
+ * @author Yaron Koren
+ */
+
+
+var fieldNum = jQuery('.fieldBox:visible').length;
+var templateNum = jQuery('.templateBox:visible').length;
+
+jQuery.fn.editSchemaMakeTemplateDeleter = function() {
+ jQuery(this).click( function() {
+ // Remove the encompassing div for this instance.
+ jQuery(this).closest(".templateBox")
+ .fadeOut('fast', function() { jQuery(this).remove(); });
+ });
+}
+
+jQuery.fn.editSchemaMakeFieldDeleter = function() {
+ jQuery(this).click( function() {
+ // Remove the encompassing div for this instance.
+ jQuery(this).closest(".fieldBox")
+ .fadeOut('fast', function() { jQuery(this).remove(); });
+ });
+}
+
+jQuery.fn.editSchemaMakeFieldAdder = function() {
+ jQuery(this).click( function() {
+ newField = jQuery('#starterField').clone().css('display',
'').removeAttr('id');
+ newHTML = newField.html().replace(/fnum/g, fieldNum);
+ newField.html(newHTML);
+ newField.find(".deleteField").editSchemaMakeFieldDeleter();
+
jQuery(this).closest('.templateBox').find('.fieldsList').append(newField);
+ // TODO - have this apply only to the added field, instead of
all fields.
+ jQuery(".deleteField").editSchemaMakeFieldDeleter();
+ jQuery('.sectionCheckbox').click(function() {
+ jQuery(this).editSchemaToggleSectionDisplay();
+ });
+ jQuery('.isListCheckbox').click(function() {
+ jQuery(this).editSchemaToggleDelimiterInput();
+ });
+ fieldNum++;
+ } );
+}
+
+jQuery.fn.editSchemaMakeTemplateAdder = function() {
+ jQuery(this).click( function() {
+ newField = jQuery('#starterTemplate').clone().css('display',
'').remove('#starterField').removeAttr('id');
+ newHTML = newField.html().replace(/tnum/g, templateNum);
+ newField.html(newHTML);
+
newField.find(".deleteTemplate").editSchemaMakeTemplateDeleter();
+ jQuery('#templatesList').append(newField);
+ // TODO - have this apply only to the added template, instead
of all templates.
+ jQuery(".editSchemaAddField").editSchemaMakeFieldAdder();
+ jQuery('.sectionCheckbox').click(function() {
+ jQuery(this).editSchemaToggleSectionDisplay();
+ });
+ jQuery('.isListCheckbox').click(function() {
+ jQuery(this).editSchemaToggleDelimiterInput();
+ });
+ templateNum++;
+ } );
+}
+
+jQuery.fn.editSchemaToggleDelimiterInput = function() {
+ if (this.is(":checked")) {
+
this.closest('.fieldBox').find('.delimiterInput').css('display', '');
+ } else {
+
this.closest('.fieldBox').find('.delimiterInput').css('display', 'none');
+ }
+}
+
+jQuery.fn.editSchemaToggleSectionDisplay = function() {
+ if (this.is(":checked")) {
+
this.closest('.editSchemaSection').find('.sectionBody').css('display',
'').removeClass('hiddenSection');
+ } else {
+
this.closest('.editSchemaSection').find('.sectionBody').css('display',
'none').addClass('hiddenSection');
+ }
+}
+
+jQuery(document).ready(function() {
+ // Add and delete buttons
+ jQuery(".deleteTemplate").editSchemaMakeTemplateDeleter();
+ jQuery(".editSchemaAddTemplate").editSchemaMakeTemplateAdder();
+ jQuery(".deleteField").editSchemaMakeFieldDeleter();
+ jQuery(".editSchemaAddField").editSchemaMakeFieldAdder();
+
+ // Checkboxes
+ jQuery('.isListCheckbox').each(function() {
+ jQuery(this).editSchemaToggleDelimiterInput();
+ });
+ jQuery('.isListCheckbox').click(function() {
+ jQuery(this).editSchemaToggleDelimiterInput();
+ });
+ jQuery('.sectionCheckbox').each(function() {
+ jQuery(this).editSchemaToggleSectionDisplay();
+ });
+ jQuery('.sectionCheckbox').click(function() {
+ jQuery(this).editSchemaToggleSectionDisplay();
+ });
+ jQuery('#editSchemaForm').submit( function() {
+ jQuery(':hidden').find("input, select,
textarea").attr('disabled', 'disabled');
+ return true;
+ } );
+});
Modified: trunk/extensions/PageSchemas/PageSchemas.php
===================================================================
--- trunk/extensions/PageSchemas/PageSchemas.php 2011-10-13 16:13:13 UTC
(rev 99688)
+++ trunk/extensions/PageSchemas/PageSchemas.php 2011-10-13 16:24:11 UTC
(rev 99689)
@@ -24,7 +24,7 @@
'path' => __FILE__,
'name' => 'Page Schemas',
'author' => array( 'Ankit Garg', 'Yaron Koren' ),
- 'version' => '0.1',
+ 'version' => '0.2-alpha',
'url' =>
'http://www.mediawiki.org/wiki/Extension:PageSchemas',
'descriptionmsg' => 'ps-desc',
);
@@ -36,10 +36,9 @@
$wgExtensionMessagesFiles['PageSchemas'] = $dir . 'PageSchemas.i18n.php';
//Job classes
-$wgJobClasses['createPage'] = 'PSCreatePageJob';
+$wgJobClasses['pageSchemasCreatePage'] = 'PSCreatePageJob';
$wgAutoloadClasses['PSCreatePageJob'] = $dir . 'PS_CreatePageJob.php';
-
// Register auto load for the special page class
$wgAutoloadClasses['PageSchemasHooks'] = $dir . 'PageSchemas.hooks.php';
$wgAutoloadClasses['PageSchemas'] = $dir . 'PageSchemas.classes.php';
@@ -62,3 +61,25 @@
$wgHooks['UnknownAction'][] = 'PSTabs::onUnknownAction';
$wgHooks['SkinTemplateTabs'][] = 'PSTabs::displayTabs';
$wgHooks['SkinTemplateNavigation'][] = 'PSTabs::displayTabs2';
+
+// Register client-side modules
+$pageSchemasResourceTemplate = array(
+ 'localBasePath' => $dir,
+ 'remoteExtPath' => 'PageSchemas'
+);
+$wgResourceModules += array(
+ 'ext.pageschemas.main' => $pageSchemasResourceTemplate + array(
+ 'scripts' => array(
+ 'PageSchemas.js',
+ ),
+ 'styles' => array(
+ 'PageSchemas.css',
+ ),
+ 'dependencies' => array(
+ 'jquery',
+ ),
+ ),
+);
+
+// Page Schemas global variables
+$wgPageSchemasFieldNum = 0;
Modified: trunk/extensions/PageSchemas/specials/PS_EditSchema.php
===================================================================
--- trunk/extensions/PageSchemas/specials/PS_EditSchema.php 2011-10-13
16:13:13 UTC (rev 99688)
+++ trunk/extensions/PageSchemas/specials/PS_EditSchema.php 2011-10-13
16:24:11 UTC (rev 99689)
@@ -11,104 +11,6 @@
parent::__construct( 'EditSchema' );
}
- public static function addJavascript() {
- global $wgOut;
-
- PageSchemas::addJavascriptAndCSS();
-
- // TODO - this should be in a JS file
- $template_name_error_str = wfMsg( 'sf_blank_error' );
- $jsText =<<<END
-<script type="text/javascript">
-var fieldNum = 0;
-var templateNum = 0;
-// TODO - this function should be a jQuery 'fn' instead
-function psAddField(template_num) {
- fieldNum++;
- newField = jQuery('#starterField').clone().css('display',
'').removeAttr('id');
- newHTML = newField.html().replace(/fnum/g, fieldNum);
- newField.html(newHTML);
- newField.find(".deleteField").click( function() {
- // Remove the encompassing div for this instance.
- jQuery(this).closest(".fieldBox")
- .fadeOut('fast', function() { jQuery(this).remove(); });
- });
- jQuery('#fieldsList_'+template_num).append(newField);
- addjQueryToCheckboxes();
-}
-
-function psAddTemplate() {
- templateNum++;
- newField = jQuery('#starterTemplate').clone().css('display',
'').removeAttr('id');
- newHTML = newField.html().replace(/tnum/g, templateNum);
- newField.html(newHTML);
- newField.find(".deleteTemplate").click( function() {
- // Remove the encompassing div for this instance.
- jQuery(this).closest(".templateBox")
- .fadeOut('fast', function() { jQuery(this).remove(); });
- });
- jQuery('#templatesList').append(newField);
-}
-
-function updateFieldNum(field_num) {
- fieldNum = field_num;
-}
-
-function addjQueryToCheckboxes() {
- jQuery('.isListCheckbox').each(function() {
- if (jQuery(this).is(":checked")) {
-
jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', '');
- } else {
-
jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display',
'none');
- }
- });
- jQuery('.isListCheckbox').click(function() {
- if (jQuery(this).is(":checked")) {
-
jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', '');
- } else {
-
jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display',
'none');
- }
- });
- jQuery('.sectionCheckbox').each(function() {
- if (jQuery(this).is(":checked")) {
-
jQuery(this).closest('.sectionBox').find('.extensionInputs').css('display',
'').removeClass('hiddenSection');
- } else {
-
jQuery(this).closest('.sectionBox').find('.extensionInputs').css('display',
'none').addClass('hiddenSection');
- }
- });
- jQuery('.sectionCheckbox').click(function() {
- if (jQuery(this).is(":checked")) {
-
jQuery(this).closest('.sectionBox').find('.extensionInputs').css('display',
'').removeClass('hiddenSection');
- } else {
-
jQuery(this).closest('.sectionBox').find('.extensionInputs').css('display',
'none').addClass('hiddenSection');
- }
- });
-}
-
-jQuery(document).ready(function() {
- jQuery(".deleteField").click( function() {
- // Remove the encompassing div for this instance.
- jQuery(this).closest(".fieldBox")
- .fadeOut('fast', function() { jQuery(this).remove(); });
- });
- jQuery(".deleteTemplate").click( function() {
- // Remove the encompassing div for this instance.
- jQuery(this).closest(".templateBox")
- .fadeOut('fast', function() { jQuery(this).remove(); });
- });
- addjQueryToCheckboxes();
- jQuery('#editPageSchemaForm').submit( function() {
- jQuery('#starterTemplate').find("input, select,
textarea").attr('disabled', 'disabled');
- jQuery('.hiddenSection').find("input, select,
textarea").attr('disabled', 'disabled');
- return true;
- } );
-});
-</script>
-
-END;
- $wgOut->addScript( $jsText );
- }
-
/**
* Returns a nicely-formatted version of the XML passed in.
*
@@ -132,8 +34,7 @@
static function pageSchemaXMLFromRequest() {
global $wgRequest;
- //Generate the XML from the Form elements
- //$s_name = $wgRequest->getText('s_name');
+ // Generate the XML from the form elements.
$psXML = '<PageSchema>';
$additionalXML = $wgRequest->getText( 'ps_add_xml' );
$psXML .= $additionalXML;
@@ -142,17 +43,17 @@
$templateNum = -1;
// Arrays to store the extension-specific XML entered in the
form
$schemaXMLFromExtensions = array();
+ $templateXMLFromExtensions = array();
$fieldXMLFromExtensions = array();
wfRunHooks( 'PageSchemasGetSchemaXML', array( $wgRequest,
&$schemaXMLFromExtensions ));
+ wfRunHooks( 'PageSchemasGetTemplateXML', array( $wgRequest,
&$templateXMLFromExtensions ));
wfRunHooks( 'PageSchemasGetFieldXML', array( $wgRequest,
&$fieldXMLFromExtensions ));
foreach ( $schemaXMLFromExtensions as $extensionName => $xml ) {
if ( !empty( $xml ) ) {
$psXML .= $xml;
}
}
- $indexGlobalField = 0 ; //this variable is use to index the
array returned by extensions for XML.
foreach ( $wgRequest->getValues() as $var => $val ) {
- $suffix = substr( $var, -3 );
// Ignore fields from the hidden/starter div
if ( substr( $var, 0, 7 ) == 't_name_' ) {
$templateNum = substr( $var, 7 );
@@ -161,6 +62,13 @@
} else {
$psXML .= '<Template name="'.$val.'">';
}
+
+ // Get XML created by extensions for this
template
+ foreach ( $templateXMLFromExtensions as
$extensionName => $xmlPerTemplate ) {
+ if ( !empty(
$xmlPerTemplate[$templateNum] ) ) {
+ $psXML .=
$xmlPerTemplate[$templateNum];
+ }
+ }
} elseif ( substr( $var, 0, 7 ) == 'f_name_' ) {
$fieldNum = substr( $var, 7 );
$fieldName = $val;
@@ -179,13 +87,12 @@
$psXML .= '<Label>' . $val . '</Label>';
}
- // Get XML created by extensions
+ // Get XML created by extensions for this field
foreach ( $fieldXMLFromExtensions as
$extensionName => $xmlPerField ) {
- if ( !empty(
$xmlPerField[$indexGlobalField] ) ) {
- $psXML .=
$xmlPerField[$indexGlobalField];
+ if ( !empty( $xmlPerField[$fieldNum] )
) {
+ $psXML .=
$xmlPerField[$fieldNum];
}
}
- $indexGlobalField++ ;
} elseif ( substr( $var, 0, 10 ) == 'f_add_xml_' ) {
$psXML .= $val;
$psXML .= '</Field>';
@@ -220,16 +127,23 @@
)
);
$editSchemaPage = SpecialPage::getTitleFor( 'EditSchema' );
+ $text .= "<ul>\n";
while ( $row = $dbr->fetchRow( $res ) ) {
- if ( $row[2] != null ) {
- $page_id_cat = $row[0];
- if ( Title::newFromId( $page_id_cat
)->getNamespace() == NS_CATEGORY ) {
- $cat_text = Title::newFromId(
$page_id_cat )->getText();
- $url = $editSchemaPage ->getFullURL() .
'/' . $cat_text;
- $text .= Html::element( 'a', array(
'href' => $url ), $cat_text ) . '<br />';
- }
+ if ( $row[2] == null ) {
+ continue;
}
+ $catTitle = Title::newFromID( $row[0] );
+ if ( $catTitle->getNamespace() !== NS_CATEGORY ) {
+ continue;
+ }
+ $catName = $catTitle->getText();
+ $url = $catTitle->getFullURL( 'action=editschema' );
+ $text .= Html::rawElement( 'li',
+ null,
+ Html::element( 'a', array( 'href' => $url ),
$catName )
+ );
}
+ $text .= "</ul>\n";
$dbr->freeResult( $res );
return $text;
}
@@ -237,19 +151,28 @@
/*
* Returns the HTML for one section of the EditSchema form.
*/
- static function printFormSection( $label, $topColor, $html, $bgColor =
'white', $isCollapsible = false, $hasExistingValues = true ) {
- $className = $isCollapsible ? 'sectionBox' : '';
- $text = "<div class=\"$className\" style=\"background:
$bgColor; border: 1px #999 solid; padding: 0px; margin-bottom: 10px;
margin-top: 10px;\">\n";
- $text .= "<div style=\"font-weight: bold; background:
$topColor; padding: 4px 7px; border-bottom: 1px #bbb solid;\">";
- if ( $isCollapsible ) {
+ static function printFormSection( $label, $headerColor, $mainHTML,
$sectionClass, $hasExistingValues = true ) {
+ // Section header
+ $headerContents = '';
+ if ( empty( $sectionClass ) ) {
$checkboxAttrs = array( 'class' => 'sectionCheckbox' );
if ( $hasExistingValues ) {
$checkboxAttrs['checked'] = true;
}
- $text .= " " . Html::input( 'show_section', null,
'checkbox', $checkboxAttrs );
+ $headerContents .= "\n\t\t" . Html::input(
'show_section', null, 'checkbox', $checkboxAttrs ) . ' ';
}
- $className = $isCollapsible ? 'extensionInputs' : '';
- $text .= "$label</div>" . "<div class=\"$className\"
style=\"padding: 5px 15px;\">$html</div>\n" . "</div>\n";
+ $headerContents .= $label . "\n";
+ $sectionHTML = "\n\t\t\t\t\t" . Html::rawElement( 'div', array(
+ 'class' => 'sectionHeader',
+ 'style' => "background: $headerColor;"
+ ), $headerContents );
+
+ // Body of section, with all the inputs.
+ $sectionHTML .= "\n\t" . Html::rawElement( 'div', array(
'class' => 'sectionBody' ), "\n" . $mainHTML );
+
+ // Wrapper around the whole thing.
+ $className = "editSchemaSection $sectionClass";
+ $text = "\n\t\t\t\t" . Html::rawElement( 'div', array( 'class'
=> $className ), $sectionHTML ) . "\n";
return $text;
}
@@ -258,23 +181,32 @@
*/
static function printFieldHTMLForExtension( $valuesFromExtension ) {
list( $label, $color, $html, $hasExistingValues ) =
$valuesFromExtension;
- return self::printFormSection( $label, $color, $html, 'white',
true, $hasExistingValues );
+ return self::printFormSection( $label, $color, $html, null,
$hasExistingValues );
}
/**
* Returns the HTML for a section of the form comprising one
* template field.
*/
- static function printFieldSection( $field_xml = null, $pageSchemaField
= null, $field_count = 'fnum' ) {
+ static function printFieldSection( $field_xml = null, $pageSchemaField
= null ) {
+ if ( is_null( $field_xml ) ) {
+ $fieldNum = 'fnum';
+ } else {
+ global $wgPageSchemasFieldNum;
+ $fieldNum = $wgPageSchemasFieldNum;
+ $wgPageSchemasFieldNum++;
+ }
+
$fieldName = '';
$delimiter = '';
$fieldLabel = '';
$isListAttrs = array( 'class' => 'isListCheckbox' );
$delimiterAttrs = array( 'class' => 'delimiterInput' );
+ $text = "\n\t\t\t";
if ( is_null( $field_xml ) ) {
- $text = '<div class="fieldBox" id="starterField"
style="display: none" >';
+ $text .= '<div class="fieldBox" id="starterField"
style="display: none" >';
} else {
- $text = '<div class="fieldBox" >';
+ $text .= '<div class="fieldBox" >';
$fieldName = (string)$field_xml->attributes()->name;
if ( ((string)$field_xml->attributes()->delimiter) !=
null || ((string)$field_xml->attributes()->delimiter) != '' ) {
$delimiter =
(string)$field_xml->attributes()->delimiter;
@@ -288,15 +220,15 @@
$isListAttrs['checked'] = 'checked';
}
}
- $fieldHTML = '<p>Field name: ';
- $fieldHTML .= Html::input( 'f_name_' . $field_count,
$fieldName, 'text', array( 'size' => 15 ) ) . ' ';
+ $fieldHTML = wfMsg( 'ps-namelabel' ) . ' ';
+ $fieldHTML .= Html::input( 'f_name_' . $fieldNum, $fieldName,
'text', array( 'size' => 15 ) ) . ' ';
$fieldHTML .= wfMsg( 'ps-displaylabel' ) . ' ';
- $fieldHTML .= Html::input( 'f_label_' . $field_count,
$fieldLabel, 'text', array( 'size' => 15 ) );
- $fieldHTML .= "\t\t</p>\n";
- $fieldIsListInput = Html::input( 'f_is_list_' . $field_count,
null, 'checkbox', $isListAttrs );
+ $fieldHTML .= Html::input( 'f_label_' . $fieldNum, $fieldLabel,
'text', array( 'size' => 15 ) );
+ $fieldHTML = Html::rawElement( 'p', null, $fieldHTML ) . "\n";
+ $fieldIsListInput = Html::input( 'f_is_list_' . $fieldNum,
null, 'checkbox', $isListAttrs );
$fieldHTML .= Html::rawElement( 'p', null, $fieldIsListInput .
' ' . wfMsg( 'ps-field-list-label' ) );
- $fieldDelimiterInput = Html::input ( 'f_delimiter_' .
$field_count, $delimiter, 'text', array( 'size' => 3 ) );
- $fieldHTML .= Html::rawElement( 'p', $delimiterAttrs, wfMsg(
'ps-delimiter-label' ) . ' ' . $fieldDelimiterInput );
+ $fieldDelimiterInput = Html::input ( 'f_delimiter_' .
$fieldNum, $delimiter, 'text', array( 'size' => 3 ) );
+ $fieldHTML .= "\n" . Html::rawElement( 'p', $delimiterAttrs,
wfMsg( 'ps-delimiter-label' ) . ' ' . $fieldDelimiterInput );
// Insert HTML text from extensions
$htmlFromExtensions = array();
@@ -308,20 +240,17 @@
// their number set via Javascript) and field names from
// other extensions (which get their number set via
PHP).
// Is this important to do? Probably not.
- $fieldHTML .= str_replace( 'num', $field_count, $html );
+ $fieldHTML .= str_replace( 'num', $fieldNum, $html );
}
- $add_xml_label = wfMsg('ps-add-xml-label');
- $fieldHTML .= <<<END
- <p>$add_xml_label
- <textarea rows=4 style="width: 100%"
name="f_add_xml_$field_count"></textarea>
- </p>
-
-END;
+ // TODO - this needs to get set.
+ $field_add_xml = null;
+ $additionalXMLInput = "\n\t\t\t\t" . Html::textarea(
"f_add_xml_$fieldNum", $field_add_xml, array( 'rows' => 4, 'style' => 'width:
100%;' ) );
+ $fieldHTML .= "<p>" . wfMsg('ps-add-xml-label') .
$additionalXMLInput . "</p>\n";
$fieldHTML .= Html::input( 'remove-field', wfMsg(
'ps-remove-field' ), 'button',
array( 'class' => 'deleteField' )
);
- $text .= self::printFormSection( wfMsg( 'ps-field' ), '#AAA',
$fieldHTML, '#CCC' );
+ $text .= "\n" . self::printFormSection( wfMsg( 'ps-field' ),
'#AAA', $fieldHTML, 'editSchemaFieldSection' );
$text .= "\t</div><!-- fieldBox -->\n";
return $text;
}
@@ -336,63 +265,72 @@
$pageSchemaTemplateFields =
$pageSchemaTemplate->getFields();
}
$attrs = array();
+ $templateXMLElements = array();
+ $text = "\t";
if ( is_null( $template_xml ) ) {
- $text = '<div class="templateBox" id="starterTemplate"
style="display: none">';
+ $text .= '<div class="templateBox" id="starterTemplate"
style="display: none">' . "\n";
$templateName = '';
- $fields_xml_array = array( null );
} else {
- $text = '<div class="templateBox" >';
+ $text .= '<div class="templateBox" >' . "\n";
$templateName = (string)
$template_xml->attributes()->name;
if ( ( (string)$template_xml->attributes()->multiple )
== "multiple" ) {
$attrs['checked'] = 'checked';
}
- $fields_xml_array = $template_xml->children();
+ $templateXMLElements = $template_xml->children();
}
- $templateNameInput = Html::input( 't_name_' . $template_num,
$templateName, 'text' );
- $templateHTML = '<p>Name: ' . $templateNameInput . '</p> ';
+ $templateNameInput = wfMsg( 'ps-namelabel' ) . ' ';
+ $templateNameInput .= Html::input( 't_name_' . $template_num,
$templateName, 'text' );
+ $templateHTML = "\t\t" . Html::rawElement( 'p', null,
$templateNameInput ) . "\n";
$templateIsMultipleInput = Html::input( 'is_multiple_' .
$template_num, null, 'checkbox', $attrs );
- $templateHTML .= Html::rawElement( 'p', null,
$templateIsMultipleInput . ' ' . wfMsg( 'ps-multiple-temp-label' ) );
+ $templateHTML .= "\t\t" . Html::rawElement( 'p', null,
$templateIsMultipleInput . ' ' . wfMsg( 'ps-multiple-temp-label' ) );
$template_add_xml = "";
- foreach ( $fields_xml_array as $field_xml ) {
- if ( !empty( $field_xml ) && $field_xml->getName() !=
'Field' ) {
- $template_add_xml .=
(string)$field_xml->asXML();
+ // TODO - set this correctly.
+ /*
+ foreach ( $templateXMLElements as $templateXMLElement ) {
+ if ( !empty( $templateXMLElement ) &&
$templateXMLElement->getName() != 'Field' ) {
+ $template_add_xml .=
(string)$templateXMLElement->asXML();
}
}
- $templateHTML .= '<div id="fieldsList_'.$template_num.'">';
- $field_count = 0;
- foreach ( $fields_xml_array as $field_xml ) {
- if ( empty( $field_xml ) ) {
- $templateHTML .= self::printFieldSection();
- } elseif ( $field_xml->getName() == "Field" ) {
- $pageSchemaField =
$pageSchemaTemplateFields[$field_count];
- $templateHTML .= self::printFieldSection(
$field_xml, $pageSchemaField, $field_count );
- $field_count++;
+ */
+
+ $htmlForTemplate = array();
+ wfRunHooks( 'PageSchemasGetTemplateHTML', array(
$pageSchemaTemplate, &$htmlForTemplate ) );
+ foreach ( $htmlForTemplate as $valuesFromExtension ) {
+ $html = self::printFieldHTMLForExtension(
$valuesFromExtension );
+ $templateHTML .= str_replace( 'num', $template_num,
$html );
+ }
+
+ $templateHTML .= "\n\t\t" . '<div class="fieldsList">';
+ $fieldNumInTemplate = 0;
+ // If this is a "starter" template, create the starter
+ // field HTML.
+ if ( is_null( $pageSchemaTemplate ) ) {
+ $templateHTML .= self::printFieldSection();
+ }
+ foreach ( $templateXMLElements as $templateXMLElement ) {
+ if ( empty( $templateXMLElement ) ) {
+ // Do nothing (?)
+ } elseif ( $templateXMLElement->getName() == "Field" ) {
+ $pageSchemaField =
$pageSchemaTemplateFields[$fieldNumInTemplate];
+ $templateHTML .= self::printFieldSection(
$templateXMLElement, $pageSchemaField );
+ $fieldNumInTemplate++;
}
}
$templateHTML .= "\t</div><!-- fieldsList -->\n";
- $templateHTML .=<<<END
-<script type="text/javascript">
- $(document).ready(function() {
- updateFieldNum($field_count);
- });
-</script>
-
-END;
$add_field_button = Xml::element( 'input',
array(
'type' => 'button',
+ 'class' => 'editSchemaAddField',
'value' => wfMsg( 'ps-add-field' ),
- 'onclick' => "psAddField($template_num)"
)
);
$templateHTML .= Xml::tags( 'p', null, $add_field_button ) .
"\n";
- $templateHTML .= '<hr />
- <p>'. wfMsg('ps-add-xml-label') .'
- <textarea rows=4 style="width:
100%" name="t_add_xml_'.$template_num.'">'.$template_add_xml.'</textarea>
- </p>';
+ $templateHTML .= "<hr />\n";
+ $additionalXMLInput = "\n\t\t\t\t" . Html::textarea(
"t_add_xml_$template_num", $template_add_xml, array( 'rows' => 4, 'style' =>
'width: 100%;' ) );
+ $templateHTML .= "\n<p>" . wfMsg('ps-add-xml-label') .
"\n\t\t\t\t" . $additionalXMLInput . "\n\t\t\t</p>";
$templateHTML .= '<p>' . Html::input( 'remove-template',
'Remove template', 'button', array( 'class' => 'deleteTemplate' ) ) . "</p>\n";
- $text .= self::printFormSection( wfMsg( 'ps-template' ),
'#CCC', $templateHTML, '#EEE' );
- $text .= " </div><!-- templateBox-->";
+ $text .= self::printFormSection( wfMsg( 'ps-template' ),
'#CCC', $templateHTML, 'editSchemaTemplateSection' );
+ $text .= "\t</div><!-- templateBox-->\n";
return $text;
}
@@ -416,22 +354,24 @@
}
$ps_add_xml = '';
+ // TODO - set this correctly.
+ /*
foreach ( $pageXMLChildren as $template_xml ) {
- if ( ( $template_xml->getName() != 'Template') && (
$template_xml->getName() != 'semanticforms_Form' ) ) {
+ if ( $template_xml->getName() != 'Template') {
$ps_add_xml .= (string)$template_xml->asXML();
}
}
+ */
- $text = '<form id="editPageSchemaForm" action=""
method="post">' . "\n";
- $text .= '<p>' . wfMsg('ps-add-xml-label') . '
- <textarea rows=4 style="width: 100%"
name="ps_add_xml" >' . $ps_add_xml . '</textarea>
- </p> ';
+ $text = '<form id="editSchemaForm" action="" method="post">' .
"\n";
+ $additionalXMLInput = "\n\t\t\t\t" . Html::textarea(
'ps_add_xml', $ps_add_xml, array( 'rows' => 4, 'style' => 'width: 100%;' ) );
+ $text .= '<p>' . wfMsg('ps-add-xml-label') .
$additionalXMLInput . "\n</p>";
foreach ( $htmlForSchema as $valuesFromExtension ) {
$text .= self::printFieldHTMLForExtension(
$valuesFromExtension );
}
- $text .= '<div id="templatesList">';
+ $text .= '<div id="templatesList">' . "\n";
$template_num = 0;
@@ -448,8 +388,8 @@
$add_template_button = Xml::element( 'input',
array(
'type' => 'button',
+ 'class' => 'editSchemaAddTemplate',
'value' => wfMsg( 'ps-add-template' ),
- 'onclick' => "psAddTemplate()"
)
);
$text .= "\t</div><!-- templatesList -->\n";
@@ -482,7 +422,7 @@
$this->setHeaders();
$text = '<p>' . wfMsg( 'ps-page-desc-edit-schema' ) . '</p>';
- self::addJavascript();
+ PageSchemas::addJavascriptAndCSS();
$save_page = $wgRequest->getCheck( 'wpSave' );
if ( $save_page ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs