MediaWiki  1.23.13
Licenses.php
Go to the documentation of this file.
1 <?php
30 class Licenses extends HTMLFormField {
34  protected $msg;
35 
39  protected $licenses = array();
40 
44  protected $html;
52  public function __construct( $params ) {
53  parent::__construct( $params );
54 
55  $this->msg = empty( $params['licenses'] ) ? wfMessage( 'licenses' )->inContentLanguage()->plain() : $params['licenses'];
56  $this->selected = null;
57 
58  $this->makeLicenses();
59  }
60 
64  protected function makeLicenses() {
65  $levels = array();
66  $lines = explode( "\n", $this->msg );
67 
68  foreach ( $lines as $line ) {
69  if ( strpos( $line, '*' ) !== 0 ) {
70  continue;
71  } else {
72  list( $level, $line ) = $this->trimStars( $line );
73 
74  if ( strpos( $line, '|' ) !== false ) {
75  $obj = new License( $line );
76  $this->stackItem( $this->licenses, $levels, $obj );
77  } else {
78  if ( $level < count( $levels ) ) {
79  $levels = array_slice( $levels, 0, $level );
80  }
81  if ( $level == count( $levels ) ) {
82  $levels[$level - 1] = $line;
83  } elseif ( $level > count( $levels ) ) {
84  $levels[] = $line;
85  }
86  }
87  }
88  }
89  }
90 
95  protected function trimStars( $str ) {
96  $numStars = strspn( $str, '*' );
97  return array( $numStars, ltrim( substr( $str, $numStars ), ' ' ) );
98  }
99 
105  protected function stackItem( &$list, $path, $item ) {
106  $position =& $list;
107  if ( $path ) {
108  foreach ( $path as $key ) {
109  $position =& $position[$key];
110  }
111  }
112  $position[] = $item;
113  }
114 
119  protected function makeHtml( $tagset, $depth = 0 ) {
120  foreach ( $tagset as $key => $val ) {
121  if ( is_array( $val ) ) {
122  $this->html .= $this->outputOption(
123  $key, '',
124  array(
125  'disabled' => 'disabled',
126  'style' => 'color: GrayText', // for MSIE
127  ),
128  $depth
129  );
130  $this->makeHtml( $val, $depth + 1 );
131  } else {
132  $this->html .= $this->outputOption(
133  $val->text, $val->template,
134  array( 'title' => '{{' . $val->template . '}}' ),
135  $depth
136  );
137  }
138  }
139  }
140 
148  protected function outputOption( $message, $value, $attribs = null, $depth = 0 ) {
149  $msgObj = $this->msg( $message );
150  $text = $msgObj->exists() ? $msgObj->text() : $message;
151  $attribs['value'] = $value;
152  if ( $value === $this->selected ) {
153  $attribs['selected'] = 'selected';
154  }
155 
156  $val = str_repeat( /* &nbsp */ "\xc2\xa0", $depth * 2 ) . $text;
157  return str_repeat( "\t", $depth ) . Xml::element( 'option', $attribs, $val ) . "\n";
158  }
159 
167  public function getLicenses() {
168  return $this->licenses;
169  }
170 
178  public function getInputHTML( $value ) {
179  $this->selected = $value;
180 
181  $this->html = $this->outputOption( wfMessage( 'nolicense' )->text(), '',
182  (bool)$this->selected ? null : array( 'selected' => 'selected' ) );
183  $this->makeHtml( $this->getLicenses() );
184 
185  $attribs = array(
186  'name' => $this->mName,
187  'id' => $this->mID
188  );
189  if ( !empty( $this->mParams['disabled'] ) ) {
190  $attibs['disabled'] = 'disabled';
191  }
192 
193  return Html::rawElement( 'select', $attribs, $this->html );
194  }
195 }
196 
200 class License {
205 
209  var $text;
210 
216  function __construct( $str ) {
217  list( $text, $template ) = explode( '|', strrev( $str ), 2 );
218 
219  $this->template = strrev( $template );
220  $this->text = strrev( $text );
221  }
222 }
Licenses\trimStars
trimStars( $str)
Definition: Licenses.php:92
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
Licenses\stackItem
stackItem(&$list, $path, $item)
Definition: Licenses.php:102
$params
$params
Definition: styleTest.css.php:40
Licenses\$html
string $html
Definition: Licenses.php:41
Licenses\$licenses
array $licenses
Definition: Licenses.php:37
Licenses\getInputHTML
getInputHTML( $value)
Accessor for $this->html.
Definition: Licenses.php:175
Licenses
A License class for use on Special:Upload.
Definition: Licenses.php:30
Licenses\$msg
string $msg
Definition: Licenses.php:33
Licenses\getLicenses
getLicenses()
#-
Definition: Licenses.php:164
Licenses\makeHtml
makeHtml( $tagset, $depth=0)
Definition: Licenses.php:116
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
wfMessage
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
$lines
$lines
Definition: router.php:65
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
License\$text
string $text
Definition: Licenses.php:204
Licenses\outputOption
outputOption( $message, $value, $attribs=null, $depth=0)
Definition: Licenses.php:145
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
License\$template
string $template
Definition: Licenses.php:200
Licenses\makeLicenses
makeLicenses()
Definition: Licenses.php:61
$line
$line
Definition: cdb.php:57
$value
$value
Definition: styleTest.css.php:45
License
A License class for use on Special:Upload (represents a single type of license).
Definition: Licenses.php:197
HTMLFormField\msg
msg()
Get a translated interface message.
Definition: HTMLFormField.php:51
Licenses\__construct
__construct( $params)
#-
Definition: Licenses.php:49
$path
$path
Definition: NoLocalSettings.php:35
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:124
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1530
License\__construct
__construct( $str)
Constructor.
Definition: Licenses.php:211