X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FXml.php;h=8f18046f5fc414864c3b04d3c807f6af36f3298f;hb=e7b57d881a;hp=4c6b0715b0a53edf1329eccdef2bc21592d8ef09;hpb=69ae945e8d39972a07bea89ddb64bc0189b43ac2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Xml.php b/includes/Xml.php index 4c6b0715b0..8f18046f5f 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -563,6 +563,36 @@ class Xml { . Xml::closeElement( 'select' ); } + /** + * Converts textual drop-down list to array + * + * @param string $list Correctly formatted text (newline delimited) to be + * used to generate the options. + * @return array + */ + public static function getArrayFromWikiTextList( $list = '' ) { + $options = []; + + foreach ( explode( "\n", $list ) as $option ) { + $value = trim( $option ); + if ( $value == '' ) { + continue; + } elseif ( substr( $value, 0, 1 ) == '*' && substr( $value, 1, 1 ) != '*' ) { + // A new group is starting ... + $value = trim( substr( $value, 1 ) ); + $options[] = $value; + } elseif ( substr( $value, 0, 2 ) == '**' ) { + // groupmember + $value = trim( substr( $value, 2 ) ); + $options[] = $value; + } else { + // groupless reason list + $options[] = $value; + } + } + return $options; + } + /** * Shortcut for creating fieldsets. * @@ -613,42 +643,6 @@ class Xml { $content, false ); } - /** - * Returns an escaped string suitable for inclusion in a string literal - * for JavaScript source code. - * Illegal control characters are assumed not to be present. - * - * @deprecated since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead - * @param string $string String to escape - * @return string - */ - public static function escapeJsString( $string ) { - // See ECMA 262 section 7.8.4 for string literal format - $pairs = [ - "\\" => "\\\\", - "\"" => "\\\"", - '\'' => '\\\'', - "\n" => "\\n", - "\r" => "\\r", - - # To avoid closing the element or CDATA section - "<" => "\\x3c", - ">" => "\\x3e", - - # To avoid any complaints about bad entity refs - "&" => "\\x26", - - # Work around https://bugzilla.mozilla.org/show_bug.cgi?id=274152 - # Encode certain Unicode formatting chars so affected - # versions of Gecko don't misinterpret our strings; - # this is a common problem with Farsi text. - "\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER - "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER - ]; - - return strtr( $string, $pairs ); - } - /** * Encode a variable of arbitrary type to JavaScript. * If the value is an XmlJsCode object, pass through the object's value verbatim.