00001 <?php
00012 class Licenses {
00019 var $msg;
00020
00024 var $licenses = array();
00025
00029 var $html;
00038 function __construct( $str = null ) {
00039
00040 $this->msg = is_null( $str ) ? wfMsgForContent( 'licenses' ) : $str;
00041 $this->html = '';
00042
00043 $this->makeLicenses();
00044 $tmp = $this->getLicenses();
00045 $this->makeHtml( $tmp );
00046 }
00047
00051 function makeLicenses() {
00052 $levels = array();
00053 $lines = explode( "\n", $this->msg );
00054
00055 foreach ( $lines as $line ) {
00056 if ( strpos( $line, '*' ) !== 0 )
00057 continue;
00058 else {
00059 list( $level, $line ) = $this->trimStars( $line );
00060
00061 if ( strpos( $line, '|' ) !== false ) {
00062 $obj = new License( $line );
00063 $this->stackItem( $this->licenses, $levels, $obj );
00064 } else {
00065 if ( $level < count( $levels ) ) {
00066 $levels = array_slice( $levels, 0, $level );
00067 }
00068 if ( $level == count( $levels ) ) {
00069 $levels[$level - 1] = $line;
00070 } else if ( $level > count( $levels ) ) {
00071 $levels[] = $line;
00072 }
00073 }
00074 }
00075 }
00076 }
00077
00078 function trimStars( $str ) {
00079 $i = $count = 0;
00080
00081 wfSuppressWarnings();
00082 while ($str[$i++] == '*')
00083 ++$count;
00084 wfRestoreWarnings();
00085
00086 return array( $count, ltrim( $str, '* ' ) );
00087 }
00088
00089 function stackItem( &$list, $path, $item ) {
00090 $position =& $list;
00091 if ( $path )
00092 foreach( $path as $key )
00093 $position =& $position[$key];
00094 $position[] = $item;
00095 }
00096
00097 function makeHtml( &$tagset, $depth = 0 ) {
00098 foreach ( $tagset as $key => $val )
00099 if ( is_array( $val ) ) {
00100 $this->html .= $this->outputOption(
00101 $this->msg( $key ),
00102 array(
00103 'value' => '',
00104 'disabled' => 'disabled',
00105 'style' => 'color: GrayText',
00106 ),
00107 $depth
00108 );
00109 $this->makeHtml( $val, $depth + 1 );
00110 } else {
00111 $this->html .= $this->outputOption(
00112 $this->msg( $val->text ),
00113 array(
00114 'value' => $val->template,
00115 'title' => '{{' . $val->template . '}}'
00116 ),
00117 $depth
00118 );
00119 }
00120 }
00121
00122 function outputOption( $val, $attribs = null, $depth ) {
00123 $val = str_repeat( "\xc2\xa0", $depth * 2 ) . $val;
00124 return str_repeat( "\t", $depth ) . Xml::element( 'option', $attribs, $val ) . "\n";
00125 }
00126
00127 function msg( $str ) {
00128 $out = wfMsg( $str );
00129 return wfEmptyMsg( $str, $out ) ? $str : $out;
00130 }
00131
00139 function getLicenses() { return $this->licenses; }
00140
00146 function getHtml() { return $this->html; }
00147 }
00148
00152 class License {
00156 var $template;
00157
00161 var $text;
00162
00168 function License( $str ) {
00169 list( $text, $template ) = explode( '|', strrev( $str ), 2 );
00170
00171 $this->template = strrev( $template );
00172 $this->text = strrev( $text );
00173 }
00174 }