Go to the documentation of this file.
39 public static function element( $element,
$attribs =
null, $contents =
'', $allowShortTag =
true ) {
40 $out =
'<' . $element;
44 if ( is_null( $contents ) ) {
47 if ( $allowShortTag && $contents ===
'' ) {
50 $out .=
'>' . htmlspecialchars( $contents ) .
"</$element>";
75 throw new MWException(
'Expected attribute array, got something else in ' . __METHOD__ );
119 return "</$element>";
145 public static function namespaceSelector( $selected =
'', $all =
null, $element_name =
'namespace', $label =
null ) {
148 'selected' => $selected,
152 'name' => $element_name,
154 'class' =>
'namespaceselector',
166 public static function monthSelector( $selected =
'', $allmonths =
null, $id =
'month' ) {
169 if ( is_null( $selected ) ) {
172 if ( !is_null( $allmonths ) ) {
175 for ( $i = 1; $i < 13; $i++ ) {
178 return self::openElement(
'select',
array(
'id' => $id,
'name' =>
'month',
'class' =>
'mw-month-selector' ) )
189 # Offset overrides year/month selection
190 if ( $month && $month !== -1 ) {
191 $encMonth = intval( $month );
196 $encYear = intval( $year );
197 } elseif ( $encMonth ) {
199 $thisMonth = intval(
$timestamp->format(
'n' ) );
200 $thisYear = intval(
$timestamp->format(
'Y' ) );
201 if ( intval( $encMonth ) > $thisMonth ) {
204 $encYear = $thisYear;
208 $inputAttribs =
array(
'id' =>
'year',
'maxlength' => 4,
'size' => 7 );
210 Html::input(
'year', $encYear,
'number', $inputAttribs ) .
' ' .
225 public static function languageSelector( $selected, $customisedOnly =
true, $inLanguage =
null, $overrideAttrs =
array(), Message $msg =
null ) {
228 $include = $customisedOnly ?
'mwfile' :
'mw';
233 if ( !array_key_exists( $wgLanguageCode,
$languages ) ) {
234 $languages[$wgLanguageCode] = $wgLanguageCode;
244 $selected = isset(
$languages[$selected] ) ? $selected : $wgLanguageCode;
250 $attrs =
array(
'id' =>
'wpUserLanguage',
'name' =>
'wpUserLanguage' );
251 $attrs = array_merge( $attrs, $overrideAttrs );
253 if ( $msg ===
null ) {
298 $attributes[
'size'] =
$size;
302 $attributes[
'value'] =
$value;
343 'type' =>
'checkbox',
345 self::attrib(
'checked', $checked ),
361 'value' =>
$value ) + self::attrib(
'checked', $checked ) +
$attribs );
375 $a =
array(
'for' => $id );
377 # FIXME avoid copy pasting below:
400 return $label .
' ' . $input;
475 public static function option( $text,
$value =
null, $selected =
false,
477 if ( !is_null(
$value ) ) {
502 foreach ( explode(
"\n", $list )
as $option ) {
506 } elseif ( substr(
$value, 0, 1 ) ==
'*' && substr(
$value, 1, 1 ) !=
'*' ) {
514 } elseif ( substr(
$value, 0, 2 ) ==
'**' ) {
570 if ( $content !==
false ) {
571 $s .= $content .
"\n";
622 # To avoid any complaints about bad entity refs
626 # Encode certain Unicode formatting chars
so affected
627 # versions
of Gecko don
't misinterpret our strings;
628 # this is a common problem with Farsi text.
629 "\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER
630 "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER
633 return strtr( $string, $pairs );
647 public static function encodeJsVar( $value, $pretty = false ) {
648 if ( $value instanceof XmlJsCode ) {
649 return $value->value;
651 return FormatJson::encode( $value, $pretty, FormatJson::UTF8_OK );
665 public static function encodeJsCall( $name, $args, $pretty = false ) {
666 foreach ( $args as &$arg ) {
667 $arg = Xml::encodeJsVar( $arg, $pretty );
668 if ( $arg === false ) {
673 return "$name(" . ( $pretty
674 ? ( ' ' . implode( ',
', $args ) . ' ' )
675 : implode( ',
', $args )
688 public static function isWellFormed( $text ) {
689 $parser = xml_parser_create( "UTF-8" );
691 # case folding violates XML standard, turn it off
692 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, false );
694 if ( !xml_parse( $parser, $text, true ) ) {
695 //$err = xml_error_string( xml_get_error_code( $parser ) );
696 //$position = xml_get_current_byte_index( $parser );
697 //$fragment = $this->extractFragment( $html, $position );
698 //$this->mXmlError = "$err at byte $position:\n$fragment";
699 xml_parser_free( $parser );
703 xml_parser_free( $parser );
716 public static function isWellFormedXmlFragment( $text ) {
718 Sanitizer::hackDocType() .
723 return Xml::isWellFormed( $html );
733 public static function escapeTagsOnly( $in ) {
735 array( '"', '>', '<' ),
736 array( '"', '>', '<' ),
748 public static function buildForm( $fields, $submitLabel = null, $submitAttribs = array() ) {
750 $form .= "<
table><tbody>
";
752 foreach ( $fields as $labelmsg => $input ) {
753 $id = "mw-$labelmsg
";
754 $form .= Xml::openElement( 'tr', array( 'id' => $id ) );
756 // TODO use a <label> here for accessibility purposes - will need
757 // to either not use a table to build the form, or find the ID of
758 // the input somehow.
760 $form .= Xml::tags( 'td', array( 'class' => 'mw-label' ), wfMessage( $labelmsg )->parse() );
761 $form .= Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . $input . Xml::closeElement( 'td' );
762 $form .= Xml::closeElement( 'tr' );
765 if ( $submitLabel ) {
766 $form .= Xml::openElement( 'tr' );
767 $form .= Xml::tags( 'td', array(), '' );
768 $form .= Xml::openElement( 'td', array( 'class' => 'mw-submit' ) ) . Xml::submitButton( wfMessage( $submitLabel )->text(), $submitAttribs ) . Xml::closeElement( 'td' );
769 $form .= Xml::closeElement( 'tr' );
772 $form .= "</tbody></
table>
";
784 public static function buildTable( $rows, $attribs = array(), $headers = null ) {
785 $s = Xml::openElement( 'table', $attribs );
787 if ( is_array( $headers ) ) {
788 $s .= Xml::openElement( 'thead', $attribs );
790 foreach ( $headers as $id => $header ) {
793 if ( is_string( $id ) ) {
794 $attribs['id'] = $id;
797 $s .= Xml::element( 'th', $attribs, $header );
799 $s .= Xml::closeElement( 'thead' );
802 foreach ( $rows as $id => $row ) {
805 if ( is_string( $id ) ) {
806 $attribs['id'] = $id;
809 $s .= Xml::buildTableRow( $attribs, $row );
812 $s .= Xml::closeElement( 'table' );
823 public static function buildTableRow( $attribs, $cells ) {
824 $s = Xml::openElement( 'tr', $attribs );
826 foreach ( $cells as $id => $cell ) {
829 if ( is_string( $id ) ) {
830 $attribs['id'] = $id;
833 $s .= Xml::element( 'td', $attribs, $cell );
836 $s .= Xml::closeElement( 'tr' );
843 protected $options = array();
844 protected $default = false;
845 protected $attributes = array();
847 public function __construct( $name = false, $id = false, $default = false ) {
849 $this->setAttribute( 'name', $name );
853 $this->setAttribute( 'id', $id );
856 if ( $default !== false ) {
857 $this->default = $default;
864 public function setDefault( $default ) {
865 $this->default = $default;
872 public function setAttribute( $name, $value ) {
873 $this->attributes[$name] = $value;
880 public function getAttribute( $name ) {
881 if ( isset( $this->attributes[$name] ) ) {
882 return $this->attributes[$name];
892 public function addOption( $name, $value = false ) {
894 $value = $value !== false ? $value : $name;
896 $this->options[] = array( $name => $value );
906 public function addOptions( $options ) {
907 $this->options[] = $options;
919 static function formatOptions( $options, $default = false ) {
922 foreach ( $options as $label => $value ) {
923 if ( is_array( $value ) ) {
924 $contents = self::formatOptions( $value, $default );
925 $data .= Html::rawElement( 'optgroup', array( 'label' => $label ), $contents ) . "\
n";
927 $data .= Xml::option( $label, $value, $value === $default ) . "\
n";
937 public function getHTML() {
940 foreach ( $this->options as $options ) {
941 $contents .= self::formatOptions( $options, $this->default );
944 return Html::rawElement( 'select', $this->attributes, rtrim( $contents ) );
968 function __construct( $value ) {
969 $this->value = $value;
static checkLabel( $label, $name, $id, $checked=false, $attribs=array())
Convenience function to build an HTML checkbox with a label.
static escapeJsString( $string)
Returns an escaped string suitable for inclusion in a string literal for JavaScript source code.
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
static expandAttributes( $attribs)
Given an array of ('attributename' => 'value'), it generates the code to set the XML attributes : att...
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
static tags( $element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
static elementClean( $element, $attribs=array(), $contents='')
Format an XML element as with self::element(), but run text through the $wgContLang->normalize() vali...
static option( $text, $value=null, $selected=false, $attribs=array())
Convenience function to build an HTML drop-down list item.
wfProfileIn( $functionname)
Begin profiling of a function.
if(! $in) print Initializing normalization quick check tables n
static languageSelector( $selected, $customisedOnly=true, $inLanguage=null, $overrideAttrs=array(), Message $msg=null)
Construct a language selector appropriate for use in a form or preferences.
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 content language as $wgContLang
in this case you re responsible for computing and outputting the entire conflict i the difference between revisions and your text headers and sections and Diff & $tabindex
static openElement( $element, $attribs=null)
This opens an XML element.
static radioLabel( $label, $name, $value, $id, $checked=false, $attribs=array())
Convenience function to build an HTML radio button with a label.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
static fetchLanguageNames( $inLanguage=null, $include='mw')
Get an array of language names, indexed by code.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs table
I won t presume to tell you how to I m just describing the methods I chose to use for myself If you do choose to follow these it will probably be easier for you to collaborate with others on the but if you want to contribute without by all means do so(and don 't be surprised if I reformat your code). - I have the code indented with tabs to save file size and so that users can set their tab stops to any depth they like. I use 4-space tab stops
static element( $element, $attribs=array(), $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
wfProfileOut( $functionname='missing')
Stop profiling of a function.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<
static encodeAttribute( $text)
Encode an attribute value for HTML output.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
static getInstance( $ts=false)
Get a timestamp instance in GMT.
static inputLabel( $label, $name, $id, $size=false, $value=false, $attribs=array())
Convenience function to build an HTML text input field with a label.
when a variable name is used in a it is silently declared as a new masking the global
static input( $name, $value='', $type='text', $attribs=array())
Convenience function to produce an "<input>" element.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
static span( $text, $class, $attribs=array())
Shortcut to make a span element.
Allows to change the fields on the form that will be generated $name
static check( $name, $checked=false, $attribs=array())
Convenience function to build an HTML checkbox.
static inputLabelSep( $label, $name, $id, $size=false, $value=false, $attribs=array())
Same as Xml::inputLabel() but return input and label in an array.
static attrib( $name, $present=true)
Internal function for use in checkboxes and radio buttons and such.
static textarea( $name, $content, $cols=40, $rows=5, $attribs=array())
Shortcut for creating textareas.
static namespaceSelector( $selected='', $all=null, $element_name='namespace', $label=null)
Build a drop-down box for selecting a namespace.
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 $wgLang
static closeElement( $element)
Shortcut to close an XML element.
static listDropDown( $name='', $list='', $other='', $selected='', $class='', $tabindex=null)
Build a drop-down box from a textual list.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at https
static radio( $name, $value, $checked=false, $attribs=array())
Convenience function to build an HTML radio button.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
static dateMenu( $year, $month)
static namespaceSelector(array $params=array(), array $selectAttribs=array())
Build a drop-down box for selecting a namespace.
static submitButton( $value, $attribs=array())
Convenience function to build an HTML submit button.
static monthSelector( $selected='', $allmonths=null, $id='month')
Create a date selector.
static input( $name, $size=false, $value=false, $attribs=array())
Convenience function to build an HTML text input field.
static label( $label, $id, $attribs=array())
Convenience function to build an HTML form label.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
static wrapClass( $text, $class, $tag='span', $attribs=array())
Shortcut to make a specific element with a class attribute.
static password( $name, $size=false, $value=false, $attribs=array())
Convenience function to build an HTML password input field.
Module of static functions for generating XML.
static fieldset( $legend=false, $content=false, $attribs=array())
Shortcut for creating fieldsets.