Yaron Koren has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/49774


Change subject: Added 'use dropdown' option
......................................................................

Added 'use dropdown' option

Change-Id: I7af0cbbe0038144d35bae195499f8ed2738f7b5c
---
M includes/forminputs/SF_CategoryInput.php
1 file changed, 58 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms 
refs/changes/74/49774/1

diff --git a/includes/forminputs/SF_CategoryInput.php 
b/includes/forminputs/SF_CategoryInput.php
index 6a82631..fe1e520 100644
--- a/includes/forminputs/SF_CategoryInput.php
+++ b/includes/forminputs/SF_CategoryInput.php
@@ -20,6 +20,60 @@
                return array( '_wpg' );
        }
 
+       public static function getHTMLForDropdown( $tree, $input_name, 
$cur_value ) {
+               global $sfgTabIndex;
+
+               // @HACK! Go through the HTML generated by the CategoryTree
+               // extension, getting the category names and the "indicators"
+               // of depth within the HTML, use that to figure out the depth
+               // of each category, and then make a dropdown with that
+               // information.
+               $locations = array();
+               $pos = 0;
+$i = 0;
+               while ( ( $pos = strpos( $tree, 'CategoryTreeChildren', $pos + 
1 ) ) != false ) {
+                       $locations[$pos] = '+';
+               }
+               $pos = 0;
+               while ( ( $pos = strpos( $tree, '</div></div>', $pos + 1 ) ) 
!== false ) {
+                       $locations[$pos] = '-';
+               }
+               $matches = array();
+               $pos = 0;
+               while ( ( $num_matches = preg_match( '/href=".*"\>([^<]*)/', 
$tree, $matches, 0, $pos + 1 ) ) > 0 ) {
+                       $pos = strpos( $tree, $matches[0] );
+                       $locations[$pos] = $matches[1];
+               }
+               ksort( $locations );
+               $depthPerCategory = array();
+               $depth = 0;
+               // Hopefully there aren't any categories named "+" or "-"!
+               foreach( $locations as $string ) {
+                       if ( $string == '+' ) {
+                               $depth++;
+                       } elseif ( $string == '-' ) {
+                               $depth--;
+                       } else {
+                               $depthPerCategory[$string] = $depth;
+                       }
+               }
+               $text = "<select tabindex=\"$sfgTabIndex\" 
name=\"$input_name\">\n";
+               $text .= "<option></option>\n";
+               foreach ( $depthPerCategory as $categoryName => $depth ) {
+                       $text .= "<option value=\"$categoryName\"";
+                       if ( $categoryName == $cur_value ) {
+                               $text .= " selected";
+                       }
+                       $text .= ">";
+                       for ( $i = 0; $i < $depth; $i++ ) {
+                               $text .= "&nbsp;&nbsp;&nbsp;";
+                       }
+                       $text .= "$categoryName</option>\n";
+               }
+               $text .= "</select>\n";
+               return $text;
+       }
+
        public static function getHTML( $cur_value, $input_name, $is_mandatory, 
$is_disabled, $other_args ) {
                // escape if CategoryTree extension isn't included
                if ( !function_exists( 'efCategoryTreeParserHook' ) ) {
@@ -85,6 +139,10 @@
                        $cur_value = $wgContLang->ucfirst( $cur_value );
                }
 
+               if ( array_key_exists( 'use dropdown', $other_args ) ) {
+                       return self::getHTMLForDropdown( $tree, $input_name, 
$cur_value );
+               }
+
                $tree = preg_replace(
                        '/(<a class="CategoryTreeLabel.*>)(.*)(<\/a>)/',
                        '<input tabindex="' . $sfgTabIndex . '" name="' . 
$input_name .

-- 
To view, visit https://gerrit.wikimedia.org/r/49774
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7af0cbbe0038144d35bae195499f8ed2738f7b5c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to