X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FXml.php;h=8f18046f5fc414864c3b04d3c807f6af36f3298f;hb=7d3cd26340de92dcd4768e7a82824c0f5d438fe2;hp=e124c38b75521b3551fc36dcd10831a7cc8844be;hpb=e968a1f431ad058dcb14adb2757bde5664b99a79;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Xml.php b/includes/Xml.php index e124c38b75..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. *