Index: trunk/phase3/includes/Linker.php |
— | — | @@ -1938,9 +1938,9 @@ |
1939 | 1939 | } |
1940 | 1940 | |
1941 | 1941 | /** |
1942 | | - * @deprecated Returns raw bits of HTML, use titleAttrib() and accesskey() |
| 1942 | + * Returns the attributes for the tooltip and access key |
1943 | 1943 | */ |
1944 | | - public function tooltipAndAccesskey( $name ) { |
| 1944 | + public function tooltipAndAccesskeyAttribs( $name ) { |
1945 | 1945 | global $wgEnableTooltipsAndAccesskeys; |
1946 | 1946 | if ( !$wgEnableTooltipsAndAccesskeys ) |
1947 | 1947 | return ''; |
— | — | @@ -1957,8 +1957,15 @@ |
1958 | 1958 | if ( $attribs['accesskey'] === false ) { |
1959 | 1959 | unset( $attribs['accesskey'] ); |
1960 | 1960 | } |
1961 | | - return Xml::expandAttributes( $attribs ); |
| 1961 | + return $attribs; |
1962 | 1962 | } |
| 1963 | + /** |
| 1964 | + * @deprecated Returns raw bits of HTML, use titleAttrib() and accesskey() |
| 1965 | + */ |
| 1966 | + public function tooltipAndAccesskey( $name ) { |
| 1967 | + return Xml::expandAttributes( $this->tooltipAndAccesskeyAttribs( $name ) ); |
| 1968 | + } |
| 1969 | + |
1963 | 1970 | |
1964 | 1971 | /** @deprecated Returns raw bits of HTML, use titleAttrib() */ |
1965 | 1972 | public function tooltip( $name, $options = null ) { |
Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | 'selectorother' => 'HTMLSelectOrOtherField', |
65 | 65 | 'submit' => 'HTMLSubmitField', |
66 | 66 | 'hidden' => 'HTMLHiddenField', |
| 67 | + 'edittools' => 'HTMLEditTools', |
67 | 68 | |
68 | 69 | # HTMLTextField will output the correct type="" attribute automagically. |
69 | 70 | # There are about four zillion other HTML 5 input types, like url, but |
— | — | @@ -83,11 +84,15 @@ |
84 | 85 | protected $mPre = ''; |
85 | 86 | protected $mHeader = ''; |
86 | 87 | protected $mPost = ''; |
| 88 | + protected $mId; |
87 | 89 | |
88 | 90 | protected $mSubmitID; |
| 91 | + protected $mSubmitName; |
89 | 92 | protected $mSubmitText; |
| 93 | + protected $mSubmitTooltip; |
90 | 94 | protected $mTitle; |
91 | 95 | |
| 96 | + protected $mUseMultipart = false; |
92 | 97 | protected $mHiddenFields = array(); |
93 | 98 | protected $mButtons = array(); |
94 | 99 | |
— | — | @@ -112,6 +117,9 @@ |
113 | 118 | |
114 | 119 | $info['name'] = $fieldname; |
115 | 120 | |
| 121 | + if ( isset( $info['type'] ) && $info['type'] == 'file' ) |
| 122 | + $this->mUseMultipart = true; |
| 123 | + |
116 | 124 | $field = self::loadInputFromParameters( $info ); |
117 | 125 | $field->mParent = $this; |
118 | 126 | |
— | — | @@ -287,8 +295,8 @@ |
288 | 296 | $this->mHiddenFields[ $name ] = $value; |
289 | 297 | } |
290 | 298 | |
291 | | - public function addButton( $name, $value, $id=null ){ |
292 | | - $this->mButtons[] = compact( 'name', 'value', 'id' ); |
| 299 | + public function addButton( $name, $value, $id=null, $attribs=null ){ |
| 300 | + $this->mButtons[] = compact( 'name', 'value', 'id', 'attribs' ); |
293 | 301 | } |
294 | 302 | |
295 | 303 | /** |
— | — | @@ -327,19 +335,24 @@ |
328 | 336 | function wrapForm( $html ) { |
329 | 337 | |
330 | 338 | # Include a <fieldset> wrapper for style, if requested. |
331 | | - if( $this->mWrapperLegend !== false ){ |
| 339 | + if ( $this->mWrapperLegend !== false ){ |
332 | 340 | $html = Xml::fieldset( $this->mWrapperLegend, $html ); |
333 | 341 | } |
334 | | - |
335 | | - return Html::rawElement( |
336 | | - 'form', |
337 | | - array( |
338 | | - 'action' => $this->getTitle()->getFullURL(), |
339 | | - 'method' => 'post', |
340 | | - 'class' => 'visualClear', |
341 | | - ), |
342 | | - $html |
| 342 | + # Use multipart/form-data |
| 343 | + $encType = $this->mUseMultipart |
| 344 | + ? 'multipart/form-data' |
| 345 | + : 'application/x-www-form-urlencoded'; |
| 346 | + # Attributes |
| 347 | + $attribs = array( |
| 348 | + 'action' => $this->getTitle()->getFullURL(), |
| 349 | + 'method' => 'post', |
| 350 | + 'class' => 'visualClear', |
| 351 | + 'enctype' => $encType, |
343 | 352 | ); |
| 353 | + if ( !empty( $this->mId ) ) |
| 354 | + $attribs['id'] = $this->mId; |
| 355 | + |
| 356 | + return Html::rawElement( 'form', $attribs, $html ); |
344 | 357 | } |
345 | 358 | |
346 | 359 | /** |
— | — | @@ -350,7 +363,7 @@ |
351 | 364 | global $wgUser; |
352 | 365 | $html = ''; |
353 | 366 | |
354 | | - $html .= Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n"; |
| 367 | + $html .= Html::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n"; |
355 | 368 | $html .= Html::hidden( 'title', $this->getTitle() ) . "\n"; |
356 | 369 | |
357 | 370 | foreach( $this->mHiddenFields as $name => $value ){ |
— | — | @@ -371,6 +384,12 @@ |
372 | 385 | |
373 | 386 | if ( isset( $this->mSubmitID ) ) |
374 | 387 | $attribs['id'] = $this->mSubmitID; |
| 388 | + if ( isset( $this->mSubmitName ) ) |
| 389 | + $attribs['name'] = $this->mSubmitName; |
| 390 | + if ( isset( $this->mSubmitTooltip ) ) { |
| 391 | + global $wgUser; |
| 392 | + $attribs += $wgUser->getSkin()->tooltipAndAccessKeyAttribs( $this->mSubmitTooltip ); |
| 393 | + } |
375 | 394 | |
376 | 395 | $attribs['class'] = 'mw-htmlform-submit'; |
377 | 396 | |
— | — | @@ -392,6 +411,8 @@ |
393 | 412 | 'name' => $button['name'], |
394 | 413 | 'value' => $button['value'] |
395 | 414 | ); |
| 415 | + if ( $button['attribs'] ) |
| 416 | + $attrs += $button['attribs']; |
396 | 417 | if( isset( $button['id'] ) ) |
397 | 418 | $attrs['id'] = $button['id']; |
398 | 419 | $html .= Html::element( 'input', $attrs ); |
— | — | @@ -467,7 +488,16 @@ |
468 | 489 | ? $this->mSubmitText |
469 | 490 | : wfMsg( 'htmlform-submit' ); |
470 | 491 | } |
| 492 | + |
| 493 | + public function setSubmitName( $name ) { |
| 494 | + $this->mSubmitName = $name; |
| 495 | + } |
| 496 | + |
| 497 | + public function setSubmitTooltip( $name ) { |
| 498 | + $this->mSubmitTooltip = $name; |
| 499 | + } |
471 | 500 | |
| 501 | + |
472 | 502 | /** |
473 | 503 | * Set the id for the submit button. |
474 | 504 | * @param $t String. FIXME: Integrity is *not* validated |
— | — | @@ -476,6 +506,9 @@ |
477 | 507 | $this->mSubmitID = $t; |
478 | 508 | } |
479 | 509 | |
| 510 | + public function setId( $id ) { |
| 511 | + $this->mId = $id; |
| 512 | + } |
480 | 513 | /** |
481 | 514 | * Prompt the whole form to be wrapped in a <fieldset>, with |
482 | 515 | * this text as its <legend> element. |
— | — | @@ -514,7 +547,7 @@ |
515 | 548 | * TODO: Document |
516 | 549 | * @param $fields |
517 | 550 | */ |
518 | | - function displaySection( $fields ) { |
| 551 | + function displaySection( $fields, $sectionName = '' ) { |
519 | 552 | $tableHtml = ''; |
520 | 553 | $subsectionHtml = ''; |
521 | 554 | $hasLeftColumn = false; |
— | — | @@ -529,7 +562,7 @@ |
530 | 563 | if( $value->getLabel() != ' ' ) |
531 | 564 | $hasLeftColumn = true; |
532 | 565 | } elseif ( is_array( $value ) ) { |
533 | | - $section = $this->displaySection( $value ); |
| 566 | + $section = $this->displaySection( $value, $key ); |
534 | 567 | $legend = wfMsg( "{$this->mMessagePrefix}-$key" ); |
535 | 568 | $subsectionHtml .= Xml::fieldset( $legend, $section ) . "\n"; |
536 | 569 | } |
— | — | @@ -538,9 +571,13 @@ |
539 | 572 | $classes = array(); |
540 | 573 | if( !$hasLeftColumn ) // Avoid strange spacing when no labels exist |
541 | 574 | $classes[] = 'mw-htmlform-nolabel'; |
542 | | - $classes = implode( ' ', $classes ); |
| 575 | + $attribs = array( |
| 576 | + 'classes' => implode( ' ', $classes ), |
| 577 | + ); |
| 578 | + if ( $sectionName ) |
| 579 | + $attribs['id'] = Sanitizer::escapeId( "mw-htmlform-$sectionName" ); |
543 | 580 | |
544 | | - $tableHtml = Html::rawElement( 'table', array( 'class' => $classes ), |
| 581 | + $tableHtml = Html::rawElement( 'table', $attribs, |
545 | 582 | Html::rawElement( 'tbody', array(), "\n$tableHtml\n" ) ) . "\n"; |
546 | 583 | |
547 | 584 | return $subsectionHtml . "\n" . $tableHtml; |
— | — | @@ -791,7 +828,20 @@ |
792 | 829 | return null; |
793 | 830 | } |
794 | 831 | } |
| 832 | + |
| 833 | + /** |
| 834 | + * Returns the attributes required for the tooltip and accesskey. |
| 835 | + * |
| 836 | + * @return array Attributes |
| 837 | + */ |
| 838 | + public function getTooltipAndAccessKey() { |
| 839 | + if ( empty( $this->mParams['tooltip'] ) ) |
| 840 | + return array(); |
795 | 841 | |
| 842 | + global $wgUser; |
| 843 | + return $wgUser->getSkin()->tooltipAndAccessKeyAttribs(); |
| 844 | + } |
| 845 | + |
796 | 846 | /** |
797 | 847 | * flatten an array of options to a single array, for instance, |
798 | 848 | * a set of <options> inside <optgroups>. |
— | — | @@ -812,6 +862,7 @@ |
813 | 863 | |
814 | 864 | return $flatOpts; |
815 | 865 | } |
| 866 | + |
816 | 867 | } |
817 | 868 | |
818 | 869 | class HTMLTextField extends HTMLFormField { |
— | — | @@ -829,7 +880,7 @@ |
830 | 881 | 'name' => $this->mName, |
831 | 882 | 'size' => $this->getSize(), |
832 | 883 | 'value' => $value, |
833 | | - ); |
| 884 | + ) + $this->getTooltipAndAccessKey(); |
834 | 885 | |
835 | 886 | if ( isset( $this->mParams['maxlength'] ) ) { |
836 | 887 | $attribs['maxlength'] = $this->mParams['maxlength']; |
— | — | @@ -908,7 +959,7 @@ |
909 | 960 | 'name' => $this->mName, |
910 | 961 | 'cols' => $this->getCols(), |
911 | 962 | 'rows' => $this->getRows(), |
912 | | - ); |
| 963 | + ) + $this->getTooltipAndAccessKey(); |
913 | 964 | |
914 | 965 | |
915 | 966 | if ( !empty( $this->mParams['disabled'] ) ) { |
— | — | @@ -996,7 +1047,8 @@ |
997 | 1048 | if ( !empty( $this->mParams['invert'] ) ) |
998 | 1049 | $value = !$value; |
999 | 1050 | |
1000 | | - $attr = array( 'id' => $this->mID ); |
| 1051 | + $attr = $this->getTooltipAndAccessKey(); |
| 1052 | + $attr['id'] = $this->mID; |
1001 | 1053 | if( !empty( $this->mParams['disabled'] ) ) { |
1002 | 1054 | $attr['disabled'] = 'disabled'; |
1003 | 1055 | } |
— | — | @@ -1329,9 +1381,22 @@ |
1330 | 1382 | $this->mParent->addButton( |
1331 | 1383 | $this->mParams['name'], |
1332 | 1384 | $this->mParams['default'], |
1333 | | - isset($this->mParams['id']) ? $this->mParams['id'] : null |
| 1385 | + isset($this->mParams['id']) ? $this->mParams['id'] : null, |
| 1386 | + $this->getTooltipAndAccessKey() |
1334 | 1387 | ); |
1335 | 1388 | } |
1336 | 1389 | |
1337 | 1390 | public function getInputHTML( $value ){ return ''; } |
| 1391 | +} |
| 1392 | + |
| 1393 | +class HTMLEditTools extends HTMLFormField { |
| 1394 | + public function getInputHTML( $value ) { |
| 1395 | + return ''; |
| 1396 | + } |
| 1397 | + public function getTableRow( $value ) { |
| 1398 | + return "<tr><td></td><td class=\"mw-input\">" |
| 1399 | + . '<div class="mw-editTools">' |
| 1400 | + . wfMsgForContent( 'edittools' ) |
| 1401 | + . "</div></td></tr>\n"; |
| 1402 | + } |
1338 | 1403 | } |
\ No newline at end of file |