summaryrefslogtreecommitdiff
blob: 58387d14f0ef041a22598b9d1e4d81514c2bc00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

namespace MediaWiki\Extensions\OAuth\Frontend;

use IContextSource;
use Message;
use OOUI\Tag;

/**
 * Static utility class for the special pages
 */
class UIUtils {
	/**
	 * Generate an information table for a consumer. The result will be suitable for use as a
	 * HTMLForm field with no label.
	 * @param array $info fieldname-message => description; description will be escaped (use
	 *   HtmlSnippet to avoid); fields with null value will be ignored; messages will be interpreted
	 *   as plaintext
	 * @param IContextSource $context
	 * @return string
	 */
	public static function generateInfoTable( $info, $context ) {
		$dl = new Tag( 'dl' );
		$dl->addClasses( [ 'mw-mwoauth-infotable' ] );
		foreach ( $info as $fieldname => $description ) {
			if ( $description === null ) {
				continue;
			} elseif ( $description instanceof Message ) {
				$description = $description->plain();
			}
			$dt = new Tag( 'dt' );
			$dd = new Tag( 'dd' );
			$dt->appendContent( $context->msg( $fieldname )->text() );
			$dd->appendContent( $description );
			$dl->appendContent( $dt, $dd );
		}
		return $dl->toString();
	}
}