9 public function register() {
13 'unstrip' => [ $this,
'textUnstrip' ],
14 'unstripNoWiki' => [ $this,
'textUnstripNoWiki' ],
15 'killMarkers' => [ $this,
'killMarkers' ],
16 'getEntityTable' => [ $this,
'getEntityTable' ],
17 'jsonEncode' => [ $this,
'jsonEncode' ],
18 'jsonDecode' => [ $this,
'jsonDecode' ],
21 'comma' =>
wfMessage(
'comma-separator' )->inContentLanguage()->text(),
22 'and' =>
wfMessage(
'and' )->inContentLanguage()->text() .
23 wfMessage(
'word-separator' )->inContentLanguage()->text(),
24 'ellipsis' =>
wfMessage(
'ellipsis' )->inContentLanguage()->text(),
25 'nowiki_protocols' => [],
29 if ( substr( $prot, -1 ) ===
':' ) {
33 $prot = preg_replace_callback(
'/([a-zA-Z])|([()^$%.\[\]*+?-])/',
function ( $m ) {
35 return '[' . strtoupper( $m[1] ) . strtolower( $m[1] ) .
']';
39 }, substr( $prot, 0, -1 ) );
40 $opts[
'nowiki_protocols'][
"($prot):"] =
'%1:';
44 return $this->
getEngine()->registerInterface(
'mw.text.lua', $lib, $opts );
55 $stripState = $this->
getParser()->mStripState;
56 return [ $stripState->killMarkers( $stripState->unstripNoWiki(
$s ) ) ];
66 $this->
checkType(
'unstripNoWiki', 1,
$s,
'string' );
67 return [ $this->
getParser()->mStripState->unstripNoWiki(
$s ) ];
78 return [ $this->
getParser()->mStripState->killMarkers(
$s ) ];
88 get_html_translation_table( HTML_ENTITIES, ENT_QUOTES | ENT_HTML5,
"UTF-8" )
102 $flags = (int)$flags;
103 if ( !( $flags & self::JSON_PRESERVE_KEYS ) && is_array( $value ) ) {
107 if ( $ret ===
false ) {
121 $this->
checkType(
'mw.text.jsonDecode', 1,
$s,
'string' );
123 $flags = (int)$flags;
125 if ( $flags & self::JSON_TRY_FIXING ) {
133 if ( !( $flags & self::JSON_PRESERVE_KEYS ) && is_array( $val ) ) {
146 ksort( $arr, SORT_NUMERIC );
152 foreach ( $arr as $k => &$v ) {
153 if ( is_array( $v ) ) {
158 if ( is_int( $k ) ) {
159 $isSequence = $next++ === $k;
160 } elseif ( $isEncoding && ctype_digit( $k ) ) {
162 $isSequence = $next++ === (int)$k;
170 return array_values( $arr );
172 return $arr ? array_combine( range( 1, count( $arr ) ), $arr ) : $arr;