ComplexTitleInputWidget.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace MediaWiki\Widget;
  3. /**
  4. * Complex title input widget.
  5. *
  6. * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
  7. * @license MIT
  8. */
  9. class ComplexTitleInputWidget extends \OOUI\Widget {
  10. /** @var array */
  11. protected $config;
  12. protected $namespace = null;
  13. protected $title = null;
  14. /**
  15. * Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
  16. *
  17. * @param array $config Configuration options
  18. * - array $config['namespace'] Configuration for the NamespaceInputWidget dropdown
  19. * with list of namespaces
  20. * - array $config['title'] Configuration for the TitleInputWidget text field
  21. * @phan-param array{namespace?:array,title?:array} $config
  22. */
  23. public function __construct( array $config = [] ) {
  24. // Configuration initialization
  25. $config = array_merge(
  26. [
  27. 'namespace' => [],
  28. 'title' => [],
  29. ],
  30. $config
  31. );
  32. parent::__construct( $config );
  33. // Properties
  34. $this->config = $config;
  35. $this->namespace = new NamespaceInputWidget( $config['namespace'] );
  36. $this->title = new TitleInputWidget( array_merge(
  37. $config['title'],
  38. [
  39. 'relative' => true,
  40. 'namespace' => $config['namespace']['value'] ?? null,
  41. ]
  42. ) );
  43. // Initialization
  44. $this
  45. ->addClasses( [ 'mw-widget-complexTitleInputWidget' ] )
  46. ->appendContent( $this->namespace, $this->title );
  47. }
  48. protected function getJavaScriptClassName() {
  49. return 'mw.widgets.ComplexTitleInputWidget';
  50. }
  51. public function getConfig( &$config ) {
  52. $config['namespace'] = $this->config['namespace'];
  53. $config['namespace']['dropdown']['$overlay'] = true;
  54. $config['title'] = $this->config['title'];
  55. $config['title']['$overlay'] = true;
  56. return parent::getConfig( $config );
  57. }
  58. }