getUserLangObj(); $infoClass = [ 'class' => 'mw-tabular-value-info' ]; $titleHeaders = []; $nameHeaders = []; $typeHeaders = []; $rows = []; $headerAttributes = []; // Helper to add a class value to an array of attributes $addErr = function ( array $attrs, $isValid ) { if ( !$isValid ) { $attrs['class'] = 'mw-tabular-error'; } return $attrs; }; // Helper to create a element out of an array of raw HTML values $makeRow = function ( array $values, array $attrs = [] ) { return Html::rawElement( 'tr', $attrs, implode( '', $values ) ); }; $dataAttrs = [ 'class' => 'mw-tabular sortable' ]; if ( !$content->getValidationData() || $content->getValidationData()->error() ) { $dataAttrs['class'] .= ' mw-tabular-error'; } $flds = $content->getField( [ 'schema', 'fields' ] ); if ( $flds && !$flds->error() ) { foreach ( $flds->getValue() as $fld ) { $name = $content->getField( 'name', $fld ); $nameIsValid = $name && !$name->error(); $name = $nameIsValid ? $name->getValue() : ''; $title = $content->getField( 'title', $fld ); $titleIsValid = $title && !$title->error(); $title = $titleIsValid ? JCUtils::pickLocalizedString( $title->getValue(), $lang, $name ) : ''; $type = $content->getField( 'type', $fld ); $typeIsValid = $type && !$type->error(); $type = $typeIsValid ? $type->getValue() : ''; $thAttr = []; if ( $nameIsValid ) { $thAttr['data-name'] = $name; } if ( $typeIsValid ) { $thAttr['data-type'] = $type; $headerAttributes[] = [ 'data-type' => $type ]; } else { $headerAttributes[] = []; } $nameHeaders[] = Html::element( 'th', $addErr( $thAttr, $nameIsValid ), $name ); $typeHeaders[] = Html::element( 'th', $addErr( $thAttr, $typeIsValid ), $typeIsValid ? wfMessage( 'jsonconfig-type-name-' . $type )->plain() : '' ); $titleHeaders[] = Html::element( 'th', $addErr( $thAttr, $titleIsValid ), $title ); } } $data = $content->getField( 'data' ); if ( $data && !$data->error() ) { foreach ( $data->getValue() as $row ) { $rowIsValid = $row && $row instanceof JCValue && !$row->error(); $row = ( $row && $row instanceof JCValue ) ? $row->getValue() : $row; if ( !is_array( $row ) ) { continue; } $vals = []; foreach ( $row as $column ) { $colIsValid = $column && $column instanceof JCValue && !$column->error(); $column = ( $column && $column instanceof JCValue ) ? $column->getValue() : $column; $header = $headerAttributes[ count( $vals ) ]; if ( !$colIsValid ) { $header['class'] = 'mw-tabular-error'; } if ( is_object( $column ) ) { $valueSize = count( (array)$column ); $column = htmlspecialchars( JCUtils::pickLocalizedString( $column, $lang ) ) . Html::element( 'span', $infoClass, "($valueSize)" ); } elseif ( is_bool( $column ) ) { $column = $column ? '☑' : '☐'; } elseif ( $column === null ) { $header['class'] = 'mw-tabular-value-null'; $column = ''; } $vals[] = Html::rawElement( 'td', $header, $column ); } $rows[] = $makeRow( $vals, $rowIsValid ? [] : [ 'class' => 'mw-tabular-error' ] ); } } $html = $content->renderDescription( $lang ) . Html::rawElement( 'table', $dataAttrs, Html::rawElement( 'thead', [], implode( "\n", [ $makeRow( $nameHeaders, [ 'class' => 'mw-tabular-row-key' ] ), $makeRow( $typeHeaders, [ 'class' => 'mw-tabular-row-type' ] ), $makeRow( $titleHeaders, [ 'class' => 'mw-tabular-row-name' ] ), ] ) ) . Html::rawElement( 'tbody', [], implode( "\n", $rows ) ) ) . $content->renderSources( MediaWikiServices::getInstance()->getParser()->getFreshParser(), $pageTitle, $revId, $options ) . $content->renderLicense(); return $html; } /** * Returns default content for this object * @param string $modelId * @return string */ public function getDefault( $modelId ) { $licenseIntro = JCContentView::getLicenseIntro(); return <<