OOUI
Object-Oriented User Interface
Loading...
Searching...
No Matches
OOUI\Tag Class Reference
+ Inheritance diagram for OOUI\Tag:

Public Member Functions

 __construct ( $tag='div')
 Create element.
 
 hasClass ( $class)
 Check for CSS class.
 
 addClasses (array $classes)
 Add CSS classes.
 
 removeClasses (array $classes)
 Remove CSS classes.
 
 toggleClasses (array $classes, $toggle=null)
 Toggle CSS classes.
 
 getTag ()
 
 getAttribute ( $key)
 Get HTML attribute value.
 
 setAttributes (array $attributes)
 Add HTML attributes.
 
 setValue ( $value)
 Set value of input element ('value' attribute for most, element content for textarea).
 
 removeAttributes (array $keys)
 Remove HTML attributes.
 
 removeContent (... $content)
 Remove any items that match by reference.
 
 appendContent (... $content)
 Add content to the end.
 
 prependContent (... $content)
 Add content to the beginning.
 
 clearContent ()
 Remove all content.
 
 getElementGroup ()
 Get group element is in.
 
 setElementGroup ( $group)
 Set group element is in.
 
 setInfusable ( $infusable)
 Enable widget for client-side infusion.
 
 isInfusable ()
 Get client-side infusability.
 
 ensureInfusableId ()
 Ensure that this given Tag is infusable and has a unique id attribute.
 
 toString ()
 Render element into HTML.
 
 __toString ()
 Magic method implementation.
 

Static Public Member Functions

static generateElementId ()
 Generate a unique ID for element.
 
static resetElementId ()
 Reset the unique ID, for consistent test output.
 
static isSafeUrl ( $url)
 Check whether user-supplied URL is safe, that is, whether outputting it will not result in XSS vulnerability.
 

Protected Member Functions

 getGeneratedAttributes ()
 Return an augmented attributes array, including synthetic attributes which are created from other properties (like the classes array) but which shouldn't be retained in the user-visible attributes.
 

Protected Attributes

string $tag = ''
 Tag name for this instance.
 
array $attributes = []
 Attributes.
 
array $classes = []
 Classes.
 
array $content = []
 Content.
 
GroupElement null $elementGroup = null
 Group.
 
bool $infusable = false
 Infusion support.
 

Constructor & Destructor Documentation

◆ __construct()

OOUI\Tag::__construct ( $tag = 'div')

Create element.

Parameters
string$tagHTML tag name

Member Function Documentation

◆ __toString()

OOUI\Tag::__toString ( )

Magic method implementation.

It was not possible to throw an exception from within a __toString() method prior to PHP 7.4.0. Doing so will result in a fatal error. This is a wrapper around the real toString() to convert them to errors instead.

Returns
string

◆ addClasses()

OOUI\Tag::addClasses ( array $classes)

Add CSS classes.

Parameters
array$classesList of classes to add
Returns
$this

◆ appendContent()

OOUI\Tag::appendContent ( $content)

Add content to the end.

Strings will be HTML-escaped, use HtmlSnippet to prevent that.

Accepts either variadic arguments (the $content argument can be repeated any number of times) or an array of arguments.

For example, these uses are valid:

  • $tag->appendContent( [ $element1, $element2 ] );
  • $tag->appendContent( $element1, $element2 ); This, however, is not acceptable
  • $tag->appendContent( [ $element1, $element2 ], $element3 );

Objects that are already in $this->content will be moved to the end of the list, not duplicated.

Parameters
string|Tag|HtmlSnippet|array...$content Content to append
Returns
$this

◆ clearContent()

OOUI\Tag::clearContent ( )

Remove all content.

Returns
$this

◆ ensureInfusableId()

OOUI\Tag::ensureInfusableId ( )

Ensure that this given Tag is infusable and has a unique id attribute.

Returns
$this

◆ generateElementId()

static OOUI\Tag::generateElementId ( )
static

Generate a unique ID for element.

Returns
string ID

◆ getAttribute()

OOUI\Tag::getAttribute ( $key)

Get HTML attribute value.

Parameters
string$keyHTML attribute name
Returns
string|null

◆ getElementGroup()

OOUI\Tag::getElementGroup ( )

Get group element is in.

Returns
GroupElement|null Group element, null if none

◆ getGeneratedAttributes()

OOUI\Tag::getGeneratedAttributes ( )
protected

Return an augmented attributes array, including synthetic attributes which are created from other properties (like the classes array) but which shouldn't be retained in the user-visible attributes.

Returns
string[]

Reimplemented in OOUI\Element.

◆ getTag()

OOUI\Tag::getTag ( )
Returns
string

◆ hasClass()

OOUI\Tag::hasClass ( $class)

Check for CSS class.

Parameters
string$classCSS class name
Returns
bool

◆ isInfusable()

OOUI\Tag::isInfusable ( )

Get client-side infusability.

Returns
bool If this tag/element/widget can be referenced client-side.

◆ isSafeUrl()

static OOUI\Tag::isSafeUrl ( $url)
static

Check whether user-supplied URL is safe, that is, whether outputting it will not result in XSS vulnerability.

(Note that URLs must be HTML-escaped regardless of this check.)

The point is to disallow 'javascript:' URLs (there are no good reasons to ever use them anyway), but there's no good way to prohibit them because of very lax parsing in browsers.

An URL is safe if:

  • it is empty, or
  • it starts with an allowed protocol, followed by a colon (absolute URL), or
  • it starts with two slashes // (protocol-relative URL), or
  • it starts with a single slash /, or dot and slash ./ (relative URL), or
  • it starts with a question mark ? (replace query part in current URL), or
  • it starts with a pound sign # (replace fragment part in current URL)

Plain relative URLs (like index.php) are not allowed, since it's pretty much impossible to distinguish them from malformed absolute ones (again, very lax rules for parsing protocols).

Parameters
string$urlURL
Returns
bool [description]

◆ prependContent()

OOUI\Tag::prependContent ( $content)

Add content to the beginning.

Accepts either variadic arguments (the $content argument can be repeated any number of times) or an array of arguments.

Objects that are already in $this->content will be moved to the end of the list, not duplicated.

For example, these uses are valid:

  • $tag->prependContent( [ $element1, $element2 ] );
  • $tag->prependContent( $element1, $element2 ); This, however, is not acceptable
  • $tag->prependContent( [ $element1, $element2 ], $element3 );
Parameters
string|Tag|HtmlSnippet|array...$content Content to prepend. Strings will be HTML-escaped for output, use a HtmlSnippet instance to prevent that.
Returns
$this

◆ removeAttributes()

OOUI\Tag::removeAttributes ( array $keys)

Remove HTML attributes.

Parameters
array$keysList of attribute keys to remove
Returns
$this

◆ removeClasses()

OOUI\Tag::removeClasses ( array $classes)

Remove CSS classes.

Parameters
array$classesList of classes to remove
Returns
$this

◆ removeContent()

OOUI\Tag::removeContent ( $content)

Remove any items that match by reference.

String items should never match by reference so will not be removed.

Parameters
string|Tag|HtmlSnippet|array...$content Content to remove.
Returns
$this

◆ resetElementId()

static OOUI\Tag::resetElementId ( )
static

Reset the unique ID, for consistent test output.

Warning: Do not use this function outside of tests!

See also
https://phabricator.wikimedia.org/T345515

◆ setAttributes()

OOUI\Tag::setAttributes ( array $attributes)

Add HTML attributes.

Parameters
array$attributesList of attribute key/value pairs to add
Returns
$this

◆ setElementGroup()

OOUI\Tag::setElementGroup ( $group)

Set group element is in.

Parameters
GroupElement | null$groupGroup element, null if none
Returns
$this

◆ setInfusable()

OOUI\Tag::setInfusable ( $infusable)

Enable widget for client-side infusion.

Parameters
bool$infusableTrue to allow tag/element/widget to be referenced client-side.
Returns
$this

◆ setValue()

OOUI\Tag::setValue ( $value)

Set value of input element ('value' attribute for most, element content for textarea).

Parameters
mixed$valueNew value should usually be a string
Returns
$this

Reimplemented in OOUI\ButtonInputWidget, OOUI\CheckboxMultiselectInputWidget, OOUI\DropdownInputWidget, OOUI\InputWidget, OOUI\RadioSelectInputWidget, OOUI\ToggleSwitchWidget, and OOUI\ToggleWidget.

◆ toggleClasses()

OOUI\Tag::toggleClasses ( array $classes,
$toggle = null )

Toggle CSS classes.

Parameters
array$classesList of classes to add
bool | null$toggleAdd classes
Returns
$this

◆ toString()

OOUI\Tag::toString ( )

Render element into HTML.

Returns
string HTML serialization

Reimplemented in OOUI\Element.

Member Data Documentation

◆ $attributes

array OOUI\Tag::$attributes = []
protected

Attributes.

HTML attributes

◆ $classes

array OOUI\Tag::$classes = []
protected

Classes.

CSS classes

◆ $content

array OOUI\Tag::$content = []
protected

Content.

Content text and elements

◆ $elementGroup

GroupElement null OOUI\Tag::$elementGroup = null
protected

Group.

Group element is in

◆ $infusable

bool OOUI\Tag::$infusable = false
protected

Infusion support.

Whether to serialize tag/element/widget state for client-side use.

◆ $tag

string OOUI\Tag::$tag = ''
protected

Tag name for this instance.

HTML tag name


The documentation for this class was generated from the following file: