3 * A License class for use on Special:Upload
7 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
8 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
9 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
24 var $licenses = array();
35 * @param $str String: the string to build the licenses member from, will use
36 * wfMsgForContent( 'licenses' ) if null (default: null)
38 function __construct( $str = null ) {
39 // PHP sucks, this should be possible in the constructor
40 $this->msg
= is_null( $str ) ?
wfMsgForContent( 'licenses' ) : $str;
43 $this->makeLicenses();
44 $tmp = $this->getLicenses();
45 $this->makeHtml( $tmp );
51 function makeLicenses() {
53 $lines = explode( "\n", $this->msg
);
55 foreach ( $lines as $line ) {
56 if ( strpos( $line, '*' ) !== 0 )
59 list( $level, $line ) = $this->trimStars( $line );
61 if ( strpos( $line, '|' ) !== false ) {
62 $obj = new License( $line );
63 $this->stackItem( $this->licenses
, $levels, $obj );
65 if ( $level < count( $levels ) ) {
66 $levels = array_slice( $levels, 0, $level );
68 if ( $level == count( $levels ) ) {
69 $levels[$level - 1] = $line;
70 } else if ( $level > count( $levels ) ) {
78 function trimStars( $str ) {
82 while ($str[$i++
] == '*')
86 return array( $count, ltrim( $str, '* ' ) );
89 function stackItem( &$list, $path, $item ) {
92 foreach( $path as $key )
93 $position =& $position[$key];
97 function makeHtml( &$tagset, $depth = 0 ) {
98 foreach ( $tagset as $key => $val )
99 if ( is_array( $val ) ) {
100 $this->html
.= $this->outputOption(
104 'disabled' => 'disabled',
105 'style' => 'color: GrayText', // for MSIE
109 $this->makeHtml( $val, $depth +
1 );
111 $this->html
.= $this->outputOption(
112 $this->msg( $val->text
),
114 'value' => $val->template
,
115 'title' => '{{' . $val->template
. '}}'
122 function outputOption( $val, $attribs = null, $depth ) {
123 $val = str_repeat( /*   */ "\xc2\xa0", $depth * 2 ) . $val;
124 return str_repeat( "\t", $depth ) . Xml
::element( 'option', $attribs, $val ) . "\n";
127 function msg( $str ) {
128 $out = wfMsg( $str );
129 return wfEmptyMsg( $str, $out ) ?
$str : $out;
135 * Accessor for $this->licenses
139 function getLicenses() { return $this->licenses
; }
142 * Accessor for $this->html
146 function getHtml() { return $this->html
; }
150 * A License class for use on Special:Upload (represents a single type of license).
166 * @param $str String: license name??
168 function License( $str ) {
169 list( $text, $template ) = explode( '|', strrev( $str ), 2 );
171 $this->template
= strrev( $template );
172 $this->text
= strrev( $text );