r73291 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73290‎ | r73291 | r73292 >
Date:14:20, 18 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Add checker for balanced html
Modified paths:
  • /trunk/extensions/Translate/MessageChecks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageChecks.php
@@ -358,4 +358,34 @@
359359 }
360360 }
361361
 362+ protected function balancedTagsCheck( $messages, $code, &$warnings ) {
 363+ foreach ( $messages as $message ) {
 364+ $key = $message->key();
 365+ $translation = $message->translation();
 366+
 367+ libxml_use_internal_errors( true );
 368+ libxml_clear_errors();
 369+ $doc = simplexml_load_string( Xml::tags( 'root', null, $translation ));
 370+ if ($doc) continue;
 371+
 372+ $errors = libxml_get_errors();
 373+ $params = array();
 374+ foreach ( $errors as $error ) {
 375+ if ( $error->code !== 76 && $error->code !== 73 ) continue;
 376+ $params[] = "<br />• [{$error->code}] $error->message";
 377+ }
 378+
 379+ if ( !count( $params ) ) continue;
 380+
 381+ $warnings[$key][] = array(
 382+ array( 'tags', 'balance', $key, $code ),
 383+ 'translate-checks-format',
 384+ array( 'PARAMS', $params ),
 385+ array( 'COUNT', count( $params ) ),
 386+ );
 387+ }
 388+
 389+ libxml_clear_errors();
 390+ }
 391+
362392 }

Status & tagging log