r98106 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98105‎ | r98106 | r98107 >
Date:02:35, 26 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Improved some code, including removing unused code copied from the TemplateInfo extension
Modified paths:
  • /trunk/extensions/PageSchemas/PageSchemas.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/PageSchemas.hooks.php
@@ -10,21 +10,22 @@
1111
1212 // Initialization
1313 public static function register( &$parser ) {
 14+ global $wgOut, $wgScriptPath;
 15+
1416 // Register the hook with the parser
1517 $parser->setHook( 'PageSchema', array( 'PageSchemasHooks', 'render' ) );
1618 // add the CSS
17 - global $wgOut, $wgScriptPath;
18 - $wgOut->addStyle($wgScriptPath . '/extensions/PageSchemas/PageSchemas.css');
 19+ $wgOut->addStyle( $wgScriptPath . '/extensions/PageSchemas/PageSchemas.css' );
1920 return true;
2021 }
2122
22 -
2323 // Render the displayed XML, if any
2424 public static function render( $input, $args, $parser, $frame ) {
25 - // if this call is contained in a transcluded page or template,
26 - // or if the input is empty, display nothing
27 - if ( !$frame->title->equals( $parser->getTitle() ) || $input == '' )
 25+ // If this call is contained in a transcluded page or template,
 26+ // or if the input is empty, display nothing.
 27+ if ( !$frame->title->equals( $parser->getTitle() ) || $input == '' ) {
2828 return;
 29+ }
2930
3031 // TODO: Do processing here, like parse to an array
3132 $error_msg = null;
@@ -32,31 +33,17 @@
3334 // recreate the top-level <PageSchema> tag, with whatever
3435 // attributes it contained, because that was actually a tag-
3536 // function call, as opposed to a real XML tag
36 - $input = Xml::tags('PageSchema', $args, $input);
 37+ $input = Xml::tags( 'PageSchema', $args, $input );
3738
38 - // if 'type=' was specified, and it wasn't set to one of the
39 - // allowed values (currently just 'auto'), don't validate -
40 - // just display the XML
41 - if ( array_key_exists( 'type', $args ) && $args['type'] != 'auto' ) {
42 - // Store XML in the page_props table - the Javascript
43 - // can figure out on its own whether or not to handle it
44 - $parser->getOutput()->setProperty( 'PageSchema', $input );
45 - // TODO - a hook should be called here, to allow other
46 - // XML handlers to parse and display this
47 - $text = Html::element('p', null, "The (unhandled) XML definition for this schema is:") . "\n";
48 - $text .= Html::element('pre', null, $input);
49 - return $text;
50 - }
51 -
5239 if ( $xml_object = PageSchemas::validateXML( $input, $error_msg ) ) {
53 - // Store XML in the page_props table
 40+ // Store the XML in the page_props table
5441 $parser->getOutput()->setProperty( 'PageSchema', $input );
5542 $text = PageSchemas::parsePageSchemas( $xml_object );
5643 } else {
5744 // Store error message in the page_props table
5845 $parser->getOutput()->setProperty( 'PageSchema', $error_msg );
59 - $text = Html::element('p', null, "The (incorrect) XML definition for this template is:") . "\n";
60 - $text .= Html::element('pre', null, $input);
 46+ $text = Html::element( 'p', null, "The (incorrect) XML definition for this template is:" ) . "\n";
 47+ $text .= Html::element( 'pre', null, $input );
6148 }
6249
6350 // return output

Status & tagging log