r98108 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98107‎ | r98108 | r98109 >
Date:02:38, 26 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Saved XML now gets pretty-printed, via new prettyPrintXML() method
Modified paths:
  • /trunk/extensions/PageSchemas/specials/PS_EditSchema.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php
@@ -110,6 +110,22 @@
111111 }
112112
113113 /**
 114+ * Returns a nicely-formatted version of the XML passed in.
 115+ *
 116+ * Code based on
 117+ * http://coffeecoders.de/2011/03/how-to-pretty-print-a-simplexmlobject-in-php/
 118+ */
 119+ static function prettyPrintXML( $xml ){
 120+ // Turn the XML string into a DOMDocument object, and then
 121+ // back again, to have it displayed nicely.
 122+ $domDocument = new DOMDocument('1.0');
 123+ $domDocument->preserveWhiteSpace = false;
 124+ $domDocument->formatOutput = true;
 125+ $domDocument->loadXML( $xml );
 126+ return $domDocument->saveXML( $domDocument->documentElement );
 127+ }
 128+
 129+ /**
114130 * Creates full <PageSchema> XML text, based on what was passed in by
115131 * the form.
116132 */
@@ -179,6 +195,7 @@
180196 }
181197 }
182198 $psXML .= '</PageSchema>';
 199+ $psXML = self::prettyPrintXML( $psXML );
183200 return $psXML;
184201 }
185202
@@ -222,10 +239,10 @@
223240 */
224241 static function printFormSection( $label, $topColor, $html, $bgColor = 'white', $isCollapsible = false, $hasExistingValues = true ) {
225242 $className = $isCollapsible ? 'sectionBox' : '';
226 - $text = "<div class=\"$className\" style=\"background: $bgColor; border: 1px #999 solid; padding: 0px; margin-bottom: 10px; margin-top: 10px;\">\n";
 243+ $text = "<div class=\"$className\" style=\"background: $bgColor; border: 1px #999 solid; padding: 0px; margin-bottom: 10px; margin-top: 10px;\">\n";
227244 $text .= "<div style=\"font-weight: bold; background: $topColor; padding: 4px 7px; border-bottom: 1px #bbb solid;\">";
228245 if ( $isCollapsible ) {
229 - $checkboxAttrs = array( 'class' => 'sectionCheckbox' );
 246+ $checkboxAttrs = array( 'class' => 'sectionCheckbox' );
230247 if ( $hasExistingValues ) {
231248 $checkboxAttrs['checked'] = true;
232249 }

Status & tagging log