TitleInputWidget.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace MediaWiki\Widget;
  3. /**
  4. * Title input widget.
  5. *
  6. * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
  7. * @license MIT
  8. */
  9. class TitleInputWidget extends \OOUI\TextInputWidget {
  10. protected $namespace = null;
  11. protected $relative = null;
  12. protected $suggestions = null;
  13. protected $highlightFirst = null;
  14. protected $validateTitle = null;
  15. /**
  16. * @param array $config Configuration options
  17. * - int|null $config['namespace'] Namespace to prepend to queries
  18. * - bool|null $config['relative'] If a namespace is set,
  19. * return a title relative to it (default: true)
  20. * - bool|null $config['suggestions'] Display search suggestions (default: true)
  21. * - bool|null $config['highlightFirst'] Automatically highlight
  22. * the first result (default: true)
  23. * - bool|null $config['validateTitle'] Whether the input must
  24. * be a valid title (default: true)
  25. */
  26. public function __construct( array $config = [] ) {
  27. parent::__construct(
  28. array_merge( [ 'maxLength' => 255 ], $config )
  29. );
  30. // Properties, which are ignored in PHP and just shipped back to JS
  31. if ( isset( $config['namespace'] ) ) {
  32. $this->namespace = $config['namespace'];
  33. }
  34. if ( isset( $config['relative'] ) ) {
  35. $this->relative = $config['relative'];
  36. }
  37. if ( isset( $config['suggestions'] ) ) {
  38. $this->suggestions = $config['suggestions'];
  39. }
  40. if ( isset( $config['highlightFirst'] ) ) {
  41. $this->highlightFirst = $config['highlightFirst'];
  42. }
  43. if ( isset( $config['validateTitle'] ) ) {
  44. $this->validateTitle = $config['validateTitle'];
  45. }
  46. // Initialization
  47. $this->addClasses( [ 'mw-widget-titleInputWidget' ] );
  48. }
  49. protected function getJavaScriptClassName() {
  50. return 'mw.widgets.TitleInputWidget';
  51. }
  52. public function getConfig( &$config ) {
  53. if ( $this->namespace !== null ) {
  54. $config['namespace'] = $this->namespace;
  55. }
  56. if ( $this->relative !== null ) {
  57. $config['relative'] = $this->relative;
  58. }
  59. if ( $this->suggestions !== null ) {
  60. $config['suggestions'] = $this->suggestions;
  61. }
  62. if ( $this->highlightFirst !== null ) {
  63. $config['highlightFirst'] = $this->highlightFirst;
  64. }
  65. if ( $this->validateTitle !== null ) {
  66. $config['validateTitle'] = $this->validateTitle;
  67. }
  68. $config['$overlay'] = true;
  69. return parent::getConfig( $config );
  70. }
  71. }