MediaWiki REL1_28
HTMLTitleTextField.php
Go to the documentation of this file.
1<?php
2
4
22 public function __construct( $params ) {
23 $params += [
24 'namespace' => false,
25 'relative' => false,
26 'creatable' => false,
27 'exists' => false,
28 ];
29
30 parent::__construct( $params );
31 }
32
33 public function validate( $value, $alldata ) {
34 if ( $this->mParent->getMethod() === 'get' && $value === '' ) {
35 // If the form is a GET form and has no value, assume it hasn't been
36 // submitted yet, and skip validation
37 return parent::validate( $value, $alldata );
38 }
39 try {
40 if ( !$this->mParams['relative'] ) {
41 $title = Title::newFromTextThrow( $value );
42 } else {
43 // Can't use Title::makeTitleSafe(), because it doesn't throw useful exceptions
45 $namespaceName = $wgContLang->getNsText( $this->mParams['namespace'] );
46 $title = Title::newFromTextThrow( $namespaceName . ':' . $value );
47 }
48 } catch ( MalformedTitleException $e ) {
49 $msg = $this->msg( $e->getErrorMessage() );
50 $params = $e->getErrorMessageParameters();
51 if ( $params ) {
52 $msg->params( $params );
53 }
54 return $msg->parse();
55 }
56
57 $text = $title->getPrefixedText();
58 if ( $this->mParams['namespace'] !== false &&
59 !$title->inNamespace( $this->mParams['namespace'] )
60 ) {
61 return $this->msg( 'htmlform-title-badnamespace', $this->mParams['namespace'], $text )->parse();
62 }
63
64 if ( $this->mParams['creatable'] && !$title->canExist() ) {
65 return $this->msg( 'htmlform-title-not-creatable', $text )->escaped();
66 }
67
68 if ( $this->mParams['exists'] && !$title->exists() ) {
69 return $this->msg( 'htmlform-title-not-exists', $text )->parse();
70 }
71
72 return parent::validate( $value, $alldata );
73 }
74
75 protected function getInputWidget( $params ) {
76 if ( $this->mParams['namespace'] !== false ) {
77 $params['namespace'] = $this->mParams['namespace'];
78 }
79 $params['relative'] = $this->mParams['relative'];
80 return new TitleInputWidget( $params );
81 }
82
83 protected function shouldInfuseOOUI() {
84 return true;
85 }
86
87 protected function getOOUIModules() {
88 // FIXME: TitleInputWidget should be in its own module
89 return [ 'mediawiki.widgets' ];
90 }
91
92 public function getInputHtml( $value ) {
93 // add mw-searchInput class to enable search suggestions for non-OOUI, too
94 $this->mClass .= 'mw-searchInput';
95
96 // return the HTMLTextField html
97 return parent::getInputHTML( $value );
98 }
99
100 protected function getDataAttribs() {
101 return [
102 'data-mw-searchsuggest' => FormatJson::encode( [
103 'wrapAsLink' => false,
104 ] ),
105 ];
106 }
107}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
msg()
Get a translated interface message.
Implements a text input field for page titles.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
getDataAttribs()
Returns an array of data-* attributes to add to the field.
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
shouldInfuseOOUI()
Whether the field should be automatically infused.
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
returning false will NOT prevent logging $e
Definition hooks.txt:2110
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$params