Kji has uploaded a new change for review.

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

Change subject: Implemented titleicons for hierarchySelect.
......................................................................

Implemented titleicons for hierarchySelect.

Initial titleicon implementation for hierarchySelect

Change-Id: Ib7b8db48580341dab36720905ea82b221ab4fc62

Finished implementing titleicons for hierarchySelect.

Refactored php wikitext to HTML parsing into a shared HierarchyBuilder utility 
function.

Change-Id: Ia6faaa1fa8e938b63043ee720e5945e1ef811bfb

Php codesniffer fixes.

Change-Id: Id2f774aade4f2414fb98f3094738f3e003eced07
---
M HierarchyBuilder.hooks.php
M HierarchyBuilder.php
M HierarchyBuilder_body.php
M extension.json
M includes/HierarchyFormInput.php
M includes/HierarchySelectFormInput.php
M includes/HierarchyTree.php
M includes/TreeNode.php
M includes/editHierarchy.css
M includes/editHierarchy.js
M includes/renderHierarchy.css
M includes/renderHierarchySelected.js
M includes/selectFromHierarchy.css
M includes/selectFromHierarchy.js
14 files changed, 256 insertions(+), 176 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/HierarchyBuilder 
refs/changes/53/269453/1

diff --git a/HierarchyBuilder.hooks.php b/HierarchyBuilder.hooks.php
index 221ac3f..950a8dc 100644
--- a/HierarchyBuilder.hooks.php
+++ b/HierarchyBuilder.hooks.php
@@ -1,5 +1,5 @@
 <?php
- 
+
 class HierarchyBuilderHooks {
 
        public static function onRegistration () {
@@ -30,7 +30,7 @@
         * @return bool
         */
        public static function efHierarchyBuilderSetup ( & $parser ) {
-               $parser->setFunctionHook( 'hierarchyBreadcrumb', 
+               $parser->setFunctionHook( 'hierarchyBreadcrumb',
                        'HierarchyBuilder::hierarchyBreadcrumb' );
                $parser->setFunctionHook( 'hierarchySectionNumber', 
'HierarchyBuilder::hierarchySectionNumber' );
                $parser->setFunctionHook( 'hierarchyParent', 
'HierarchyBuilder::hierarchyParent' );
@@ -46,4 +46,4 @@
                return true;
        }
 
-}
\ No newline at end of file
+}
diff --git a/HierarchyBuilder.php b/HierarchyBuilder.php
index 25e9a6f..e589547 100644
--- a/HierarchyBuilder.php
+++ b/HierarchyBuilder.php
@@ -29,8 +29,9 @@
        $wgExtensionMessagesFiles['HierarchyBuilder'] = __DIR__ . 
'/HierarchyBuilder.i18n.php';
        $wgExtensionMessagesFiles['HierarchyBuilderMagic'] = __DIR__ . 
'/HierarchyBuilder.i18n.magic.php';
        wfWarn(
-               'Deprecated PHP entry point used for HierarchyBuilder 
extension. Please use wfLoadExtension instead, ' .
-               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+               'Deprecated PHP entry point used for HierarchyBuilder 
extension. ' .
+               'Please use wfLoadExtension instead, see ' .
+               'https://www.mediawiki.org/wiki/Extension_registration for more 
details.'
        );
        return;
 }
diff --git a/HierarchyBuilder_body.php b/HierarchyBuilder_body.php
index 3c8489b..796abbb 100644
--- a/HierarchyBuilder_body.php
+++ b/HierarchyBuilder_body.php
@@ -180,7 +180,7 @@
                                                                } else {
                                                                        return 
"{{" . $template . "|[[$child]]}}";
                                                                }
-                                                       } ,
+                                                       },
                                                        $children
                                                ),
                                                "$delimiter\n"
@@ -191,7 +191,7 @@
                                                array_map(
                                                        function( $child ) use 
( $link ) {
                                                                return $link == 
'none' ? $child : "[[$child]]";
-                                                       } ,
+                                                       },
                                                        $children
                                                ),
                                                $delimiter
@@ -411,7 +411,7 @@
                                                                } else {
                                                                        return 
"{{" . $template . "|[[$parent]]}}";
                                                                }
-                                                       } ,
+                                                       },
                                                        $parents
                                                ),
                                                "$delimiter\n"
@@ -422,7 +422,7 @@
                                                array_map(
                                                        function( $parent ) use 
( $link ) {
                                                                return $link == 
'none' ? $parent : "[[$parent]]";
-                                                       } ,
+                                                       },
                                                        $parents
                                                ),
                                                $delimiter
@@ -531,7 +531,9 @@
                                $displayMode = 'pruned';
                        }
 
-                       $wikitextHierarchy = 
HierarchyBuilder::getPropertyFromPage( $hierarchyPageName, 
$hierarchyPropertyName );
+                       $wikitextHierarchy = 
HierarchyBuilder::getPropertyFromPage(
+                               $hierarchyPageName, $hierarchyPropertyName
+                       );
                        // this is where we ask HierarchyBuilder class to 
actually do the work for us.
                        $hierarchyTree = HierarchyTree::fromWikitext( 
$wikitextHierarchy );
 
@@ -546,7 +548,7 @@
                                        },
                                        explode( ',', $selectedPages )
                                );
-               
+
                        $mst = $hierarchyTree->getMST( $normalizedSelectedPages 
);
 
                        // output formatting
@@ -566,9 +568,15 @@
 
                        $output = '';
                        if ( $displayMode == 'collapsed') {
-                               $output = "<hierarchySelected collapsed 
selected=$selected>" . (string)$mst . '</hierarchySelected>';
+                               $output =
+                                       "<hierarchySelected collapsed 
selected=$selected>" .
+                                       (string)$mst .
+                                       '</hierarchySelected>';
                        } else {
-                               $output = "<hierarchySelected 
selected=$selected>" . (string)$mst . '</hierarchySelected>';
+                               $output =
+                                       "<hierarchySelected 
selected=$selected>" .
+                                       (string)$mst .
+                                       '</hierarchySelected>';
                        }
 
                        $output = $parser->recursiveTagParse( $output );
@@ -602,7 +610,6 @@
         */
        public static function hierarchyBreadcrumb( $parser ) {
                $params = func_get_args();
-
 
                if ( count( $params ) < 4 ) {
                        $output = "";
@@ -699,7 +706,7 @@
                $breadcrumb = "{| width='100%'" . PHP_EOL;
                if ( $previous != null ) {
                        if ( $previous == $parent ) {
-                   $arrow = "&uarr;";
+                               $arrow = "&uarr;";
                        } else {
                                $arrow = "&larr;";
                        }
@@ -708,7 +715,7 @@
                } else {
                        $breadcrumb .= "| width='33%' | &nbsp;" . PHP_EOL;
                }
-        if ( $parent != null  && $parent != $previous ) {
+               if ( $parent != null && $parent != $previous ) {
                        $breadcrumb .= "| align='center' width='33%' | &uarr; 
[[" . $parent .
                                "| " . HierarchyBuilder::getPageDisplayName( 
$parent ) . "]]" . PHP_EOL;
                } else {
@@ -814,7 +821,9 @@
         *  rows from the hierarchy and not a list of page names extracted from 
those
         *  rows.
         */
-       private static function getHierarchyRowsByDepth( $depth, 
$hierarchyPageName, $hierarchyPropertyName ) {
+       private static function getHierarchyRowsByDepth(
+               $depth, $hierarchyPageName,     $hierarchyPropertyName
+       ) {
                $hierarchy = self::getPropertyFromPage( $hierarchyPageName, 
$hierarchyPropertyName );
                $hierarchyRows = preg_split( '/\n/', $hierarchy );
 
@@ -954,14 +963,14 @@
                                json_encode( explode( ',', urldecode( 
$attributes['selected'] ) ) );
 
                        $selectedPages =
-                                       json_encode(
-                                               array_map(
-                                                       function ($pageName){
-                                                               return 
HierarchyBuilder::getPageDisplayName( $pageName );
-                                                       },
-                                                       explode( ',', 
urldecode( $attributes['selected'] ) )            
-                                               )
-                                       );
+                               json_encode(
+                                       array_map(
+                                               function ($pageName){
+                                                       return 
HierarchyBuilder::getPageDisplayName( $pageName );
+                                               },
+                                               explode( ',', urldecode( 
$attributes['selected'] ) )
+                                       )
+                               );
                } else  {
                        $selectedPages = '';
                }
@@ -1093,10 +1102,13 @@
                                return $strings;
                        }
                } catch (Exception $e) {
-                       
wfLogWarning("[HierarchyBuilder.class.php][getPropertyFromPage] Something 
broke. Returning an empty string.");
+                       wfLogWarning(
+                               
"[HierarchyBuilder.class.php][getPropertyFromPage] " .
+                               "Something broke. Returning an empty string."
+                       );
                        return '';
-               }               
-               
+               }
+
        }
 
        /**
@@ -1112,23 +1124,23 @@
 
                $title = Title::newFromText( $page );
                if ($title) {
-               $id = $title->getArticleID();
+                       $id = $title->getArticleID();
 
-               $dbr = wfGetDB( DB_SLAVE );
-               $result = $dbr->select(
-                       'page_props',
-                       array( 'pp_value' ),
-                       array(
-                               'pp_page' => $id,
-                               'pp_propname' => 'displaytitle'
-                       ),
-                       __METHOD__
-               );
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $result = $dbr->select(
+                               'page_props',
+                               array( 'pp_value' ),
+                               array(
+                                       'pp_page' => $id,
+                                       'pp_propname' => 'displaytitle'
+                               ),
+                               __METHOD__
+                       );
 
-               if ( $result->numRows() > 0 ) {
-                       $row = $result->fetchRow();
-                       $displayname = $row['pp_value'];
-               }
+                       if ( $result->numRows() > 0 ) {
+                               $row = $result->fetchRow();
+                               $displayname = $row['pp_value'];
+                       }
                }
 
                // note that if anything fails in the pipeline we return the 
pagename
@@ -1255,7 +1267,7 @@
         *  we cannot find the page within the hierarchy, then the empty string 
is
         *  returned instead.
         */
-       private static function getSectionNumberFromHierarchyHelper( 
+       private static function getSectionNumberFromHierarchyHelper(
                $wikiTextHierarchy,
                $depth,
                $sectionNumber,
@@ -1321,18 +1333,24 @@
        }
 
        /**
-        * This parser function will return the subhierarchy that is rooted at 
the specified
-        * node within a hierarchy.
+        * This parser function will return the subhierarchy that is rooted at 
the
+        * specified node within a hierarchy.
         *
         * The three required arguments are (in order):
-        *   - The root node of the subhierarchy within the overall hierarchy. 
If this
-        *     argument is empty, then the entire hierarchy is returned.
+        *   - The root node of the subhierarchy within the overall hierarchy. 
If
+        *     this argument is empty, then the entire hierarchy is returned.
         *   - Full page name of the page containing the hierarchy
         *   - Property name of the property containing the hierarchy data
         *
-        * The optional argument is:
-        *   - Format to specify if the results should be returned as a 
bulleted list as
-        *     opposed to the default striped format.
+        * The optional arguments are:
+        *   - Format to specify if the results should be returned as a bulleted
+        *     list as opposed to the default striped format.
+        *   - titleiconproperty to specify the property containing the 
titleicons
+        *         that should be displayed for each page in the hierarchy.
+        *   - showroot to specify if the root of the subhierarchy should be
+        *     included in the display.
+        *   - collapsed to specify whether or not the subhierarchy should be
+        *     initialized in collapsed mode.
         *
         * Example invokation:
         * @code
@@ -1340,6 +1358,7 @@
         * {{#hierarchySubtree:Hierarchy Builder|Main Page|Hierarchy Data}}
         * {{#hierarchySubtree:Hierarchy Builder|Main Page|Hierarchy Data}}
         * {{#hierarchySubtree:Hierarchy Builder|Main Page|Hierarchy 
Data|format=ul}}
+        * {{#hierarchySubtree:Hierarchy Builder|Main Page|Hierarchy 
Data|showroot|collapsed|titleiconproperty=Logo Link}}
         * @endcode
         *
         * @param $parser: Parser
@@ -1443,7 +1462,7 @@
                if ( $root == '' ) {
                        return $hierarchy;
                } else {
-                       return HierarchyBuilder::getSubhierarchyHelper( 
+                       return HierarchyBuilder::getSubhierarchyHelper(
                                $root,
                                "[[Hierarchy_Root]]\n" . $hierarchy,
                                ''
@@ -1482,7 +1501,9 @@
                        $subHierarchyRows = preg_split( '/\n/', $subHierarchy );
                        $subHierarchyRoot = 
HierarchyBuilder::getPageNameFromHierarchyRow( $subHierarchyRows[0] );
                        if ( $subHierarchyRoot == $root ) {
-                               $subHierarchyRows[0] = str_repeat( '*', strlen( 
$depth ) + 1 ) . $subHierarchyRows[0]; // put the stars on the root row to start
+                               // put the stars on the root row to start
+                               $subHierarchyRows[0] =
+                                       str_repeat( '*', strlen( $depth ) + 1 ) 
. $subHierarchyRows[0];
                                $result = array_reduce( $subHierarchyRows,
                                        function( $carry, $item ) use ( $depth 
) {
                                                if ( $carry != '' ) {
@@ -1495,7 +1516,9 @@
                                );
                                return $result;
                        } else {
-                               $subHierarchyCandidate = 
HierarchyBuilder::getSubhierarchyHelper( $root, $subHierarchy, $depth . '*' );
+                               $subHierarchyCandidate = 
HierarchyBuilder::getSubhierarchyHelper(
+                                       $root, $subHierarchy, $depth . '*'
+                               );
                                if ( $subHierarchyCandidate != '' ) {
                                        return $subHierarchyCandidate;
                                }
@@ -1503,6 +1526,97 @@
                }
 
                return '';
+       }
+
+       /**
+        * Parse a standard wikitext formatted hierarchy into HTML.
+        * 
+        * The wikitext hierarchy is assumed to be in the standard format 
without
+        * specified displaynames. (eg: [[pagename]] not 
[[pagename|displayname]])
+        * The parsing will correctly handle displaynames and titleicons 
(assuming
+        * the titleiconproperty is specified as an argument).
+        *
+        * This parser is utilized by the both the HierarchyFormInput for 
formedits
+        * and the HierarchySelectFormInput for "select from hierarchy".
+        *
+        * @param string $hierarchy: The wikitext formatted hieararchy to be 
parsed.
+        * @param string $titleiconpropery: (Optional) The name of the property 
+        *  containing the titleicons to be displayed for pages in the 
hierarchy.
+        *
+        * @return string: The HTML formatted hierarchy with both displaynames 
and
+        *  titleicons properly handled.
+        */
+       public static function parseWikitext2Html($hierarchy, 
$titleiconproperty = '') {
+               $rootedhierarchy = "[[".wfMessage( 
'hierarchybuilder-hierarchyroot' )->text()."]]\n" . $hierarchy;
+               return
+                       "<ul>" .
+                       
HierarchyBuilder::parseWikitext2HtmlHelper($rootedhierarchy, 0, 
$titleiconproperty) .
+                       "</ul>";
+       }
+
+       /**
+        * Helper function for parsing wikitext hierarchies to HTML.
+        *
+        * @param string $subhierarchy: The current subhierarchy being 
processed.
+        * @param number $depth: The depth of the current subhierarchy within 
the
+        *  original overall hierarchy being parsed.
+        * @param string $titleiconproperty: The name of the property containing
+        *  the titleicons to be displayed for pages in the hierarchy.
+        *
+        * @return string: The HTML formatted subhierarchy hierarchy with both
+        *  displaynames and titleicons properly handled.
+        */
+       private static function parseWikitext2HtmlHelper($subhierarchy, $depth, 
$titleiconproperty) {
+               $depthpattern = '/^' . '\*'.'{'.$depth.'}' . '([^\*]+)' . '/m';
+               $nummatches = preg_match_all( $depthpattern, $subhierarchy, 
$matches );
+               if ($nummatches < 1) {
+                       return '';
+               }
+               $rootrow = $matches[1][0];
+
+               $childdepth = $depth + 1;
+               $childdepthpattern = '/^' . '\*'.'{'.$childdepth.'}' . 
'([^\*]+)' . '/m';
+               $nummatches = preg_match_all( $childdepthpattern, 
$subhierarchy, $matches );
+               $childrows = $nummatches > 0 ? $matches[0] : array();
+               $childsubhierarchies = array_slice(
+                       preg_split( $childdepthpattern, $subhierarchy ), 1
+               ); // chop off element 0 which is the root
+               $numchildren = count($childrows);
+
+               //extract the root pagename
+               $numMatches = preg_match_all( 
HierarchyBuilder::PAGENAMEPATTERN, $rootrow, $matches );
+               $rootpagename = $matches[1][0]; // this is just the pagename 
excluding the [[]] formatting
+               if ($depth == 0) {
+                       $rootHtml = "<a>$rootpagename<span 
style=display:none>$rootpagename</span></a>";
+               } else {
+
+                       if ($titleiconproperty != '') {
+                               $roottitleiconshtml = 
HierarchyBuilder::getPageTitleIconsHtml(
+                                       $rootpagename, $titleiconproperty
+                               );
+                       } else {
+                               $roottitleiconshtml = '';
+                       }
+                       $rootdisplayname = 
HierarchyBuilder::getPageDisplayName($rootpagename);
+                       $roottexthtml = "$rootdisplayname<span 
style=display:none>$rootpagename</span>";
+                       $rootHtml = "<a>" . $roottitleiconshtml . $roottexthtml 
. "</a>";
+               }
+
+               $html = $depth == 0 ? "<li class='hierarchy_root'>" : '<li>';
+               $html .= $rootHtml;
+               if ( $numchildren > 0 ) {
+                       $html .= '<ul>';
+                       for ( $i = 0; $i < $numchildren; $i++ ) {
+                               $childhierarchy = $childrows[$i] . "\n" . 
$childsubhierarchies[$i];
+                               $html .= 
HierarchyBuilder::parseWikitext2HtmlHelper(
+                                       $childhierarchy, $depth+1, 
$titleiconproperty
+                               );
+                       }
+                       $html .= '</ul>';
+               }
+               $html .= '</li>';
+
+               return $html;
        }
 
        /**
@@ -1526,12 +1640,13 @@
                        if ( $imagefile !== false ) {
 
                                $tooltip = $page;
-                               
+
                                $frameParams = array();
                                //$frameParams['link-title'] = $page;
                                $frameParams['alt'] = $tooltip;
                                $frameParams['title'] = $tooltip;
-                               $handlerParams = array(); // this is where we 
might specify default height and width but that's not helping us
+                               // this is where we might specify default 
height and width
+                               $handlerParams = array();
 
                                $iconhtmls[] = Linker::makeImageLink( 
$GLOBALS['wgParser'],
                                        $filetitle, $imagefile, $frameParams, 
$handlerParams );
@@ -1544,12 +1659,12 @@
                        //extract just the guts of just the img part of the html
                        $imgpattern = '/\<img (.*) \/\>/';
                        $numMatches = preg_match_all( $imgpattern, $iconhtml, 
$matches );
-                       
+
                        // build the new image html thing
                        $finaliconshtml .= '<img 
class="hierarchy_row_titleicon" ' . $matches[1][0] . '/>';
 
                }
-               
+
                return $finaliconshtml;
        }
 
@@ -1647,7 +1762,10 @@
        }
 
        public static function hbLog($className, $methodName, $message) {
-               wfErrorLog( "[".date("c")."]" . 
"[".$className."][".$methodName."] " . $message . "\n", 
'/home/kji/hierarchyBuilder.log' );
+               wfErrorLog(
+                       "[".date("c")."]" . "[".$className."][".$methodName."] 
" . $message . "\n",
+                       '/home/kji/hierarchyBuilder.log'
+               );
        }
 
 }
diff --git a/extension.json b/extension.json
index 006fd10..2bba7e7 100644
--- a/extension.json
+++ b/extension.json
@@ -1,6 +1,6 @@
 {
        "name": "HierarchyBuilder",
-       "version": "3.0.1",
+       "version": "3.1.0",
        "author": [
                "[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy 
Cicalese]",
                "[https://www.mediawiki.org/wiki/User:Kevin.ji Kevin Ji]"
diff --git a/includes/HierarchyFormInput.php b/includes/HierarchyFormInput.php
index 5a005a0..5dc889b 100644
--- a/includes/HierarchyFormInput.php
+++ b/includes/HierarchyFormInput.php
@@ -1,5 +1,5 @@
 <?php
- 
+
 /*
  * Copyright (c) 2013 The MITRE Corporation
  *
@@ -95,7 +95,7 @@
                        foreach ( $pages as $key => $value ) {
                                $name = $value;
                                $namehtml = "<a>$name<span 
style=display:none>$key</span></a>";
-                               
+
                                if ($titleiconProperty != '') {
                                        $pagetitleiconshtml = 
HierarchyBuilder::getPageTitleIconsHtml( $key, $titleiconProperty );
                                } else {
@@ -109,7 +109,7 @@
                }
                $unusedpages .= "</li></ul>";
 
-               $hierarchy = $this->wikitext2Html($this->mCurrentValue, 
$titleiconProperty);
+               $hierarchy 
=HierarchyBuilder::parseWikitext2Html($this->mCurrentValue, $titleiconProperty);
 
                global $sfgFieldNum;
                $this->mDivId = "hierarchy_$sfgFieldNum";
@@ -135,58 +135,6 @@
                return json_encode( $jsattribs );
        }
 
-       public function wikitext2Html($hierarchy, $titleiconproperty) {
-               $rootedhierarchy = "[[".wfMessage( 
'hierarchybuilder-hierarchyroot' )->text()."]]\n" . $hierarchy;
-               return "<ul>" . $this->wikitext2HtmlHelper($rootedhierarchy, 0, 
$titleiconproperty) . "</ul>";  
-       }
-
-       public function wikitext2HtmlHelper($subhierarchy, $depth, 
$titleiconproperty) {
-               $depthpattern = '/^' . '\*'.'{'.$depth.'}' . '([^\*]+)' . '/m';
-               $nummatches = preg_match_all( $depthpattern, $subhierarchy, 
$matches );
-               if ($nummatches < 1) {
-                       return '';
-               }
-               $rootrow = $matches[1][0];
-               
-               $childdepth = $depth + 1;
-               $childdepthpattern = '/^' . '\*'.'{'.$childdepth.'}' . 
'([^\*]+)' . '/m';
-               $nummatches = preg_match_all( $childdepthpattern, 
$subhierarchy, $matches );
-               $childrows = $nummatches > 0 ? $matches[0] : array();
-               $childsubhierarchies = array_slice( preg_split( 
$childdepthpattern, $subhierarchy ), 1 ); // chop off element 0 which is the 
root
-               $numchildren = count($childrows);
-               
-               //extract the root pagename 
-               $numMatches = preg_match_all( 
HierarchyBuilder::PAGENAMEPATTERN, $rootrow, $matches );
-               $rootpagename = $matches[1][0]; // this is just the pagename 
excluding the [[]] formatting
-               if ($depth == 0) {
-                       $rootHtml = "<a>$rootpagename<span 
style=display:none>$rootpagename</span></a>";
-               } else {
-
-                       if ($titleiconproperty != '') {
-                               $roottitleiconshtml = 
HierarchyBuilder::getPageTitleIconsHtml( $rootpagename, $titleiconproperty );
-                       } else {
-                               $roottitleiconshtml = '';
-                       }
-                       $rootdisplayname = 
HierarchyBuilder::getPageDisplayName($rootpagename);
-                       $rootrowhtml = "<a>$rootdisplayname<span 
style=display:none>$rootpagename</span></a>";
-                       $rootHtml = $roottitleiconshtml . $rootrowhtml;
-               }
-               
-               $html = $depth == 0 ? "<li class='hierarchy_root'>" : '<li>';
-               $html .= $rootHtml;
-               if ( $numchildren > 0 ) {
-                       $html .= '<ul>';
-                       for ( $i = 0; $i < $numchildren; $i++ ) {
-                               $childhierarchy = $childrows[$i] . "\n" . 
$childsubhierarchies[$i];
-                               $html .= 
$this->wikitext2HtmlHelper($childhierarchy, $depth+1, $titleiconproperty);
-                       }
-                       $html .= '</ul>';
-               }
-               $html .= '</li>';
-                       
-               return $html;
-       }
-       
        /**
         * Get error messages for display.
         *
diff --git a/includes/HierarchySelectFormInput.php 
b/includes/HierarchySelectFormInput.php
index ed46db0..6327791 100644
--- a/includes/HierarchySelectFormInput.php
+++ b/includes/HierarchySelectFormInput.php
@@ -59,8 +59,17 @@
                        return;
                }
 
+               if ( array_key_exists( 'titleiconproperty', $this->mOtherArgs ) 
) {
+                       $this->titleiconProperty = 
$this->mOtherArgs['titleiconproperty'];
+               } else {
+                       $this->titleiconProperty = null;
+               }
+
                if ( array_key_exists( 'collapsed', $this->mOtherArgs ) ) {
                        $this->mCollapsed = $this->mOtherArgs['collapsed'];
+                       if ( $this->mCollapsed ) {
+                               $this->mCollapsed = 'true';
+                       }
                        if ( $this->mCollapsed !== 'true' && $this->mCollapsed 
!== 'false' ) {
                                $this->mCollapsed = null;
                                return;
@@ -94,9 +103,14 @@
                        $this->mHeight = '';
                }
 
-               $hierarchy = HierarchyBuilder::getPropertyFromPage( 
$this->mPageName,
-                       $this->mPropertyName );
-               $hierarchy = HierarchyBuilder::updateHierarchyWithDisplayNames( 
$hierarchy );
+               $hierarchy = HierarchyBuilder::getPropertyFromPage(
+                       $this->mPageName,
+                       $this->mPropertyName
+               );
+               $hierarchy = HierarchyBuilder::parseWikitext2Html(
+                       $hierarchy,
+                       $this->titleiconProperty
+               );
 
                $selectedItems = array_map( 'trim', explode( ',', 
$this->mCurrentValue ) );
 
@@ -134,11 +148,6 @@
                                wfMessage( 
'hierarchybuilder-missing-property-name' )->text() );
                }
 
-               if ( $this->mCollapsed == null ) {
-                       return Html::element( 'b', array(),
-                               wfMessage( 'hierarchybuilder-invalid-collapsed' 
)->text() );
-               }
-
                return Html::element( 'input', array(
                        'type' => 'hidden',
                        'id' => $this->mInputId,
@@ -160,12 +169,6 @@
                        'type' => 'string',
                        'description' =>
                                wfMessage( 'hierarchybuilder-propertyname-desc' 
)->text()
-               );
-               $params['collapsed'] = array(
-                       'name' => 'collapsed',
-                       'type' => 'string',
-                       'description' =>
-                               wfMessage( 'hierarchybuilder-collapsed-desc' 
)->text()
                );
        }
 
diff --git a/includes/HierarchyTree.php b/includes/HierarchyTree.php
index 8f4e380..e31bb79 100644
--- a/includes/HierarchyTree.php
+++ b/includes/HierarchyTree.php
@@ -1,5 +1,5 @@
 <?php
- 
+
 /*
  * Copyright (c) 2014 The MITRE Corporation
  *
@@ -140,10 +140,16 @@
                }
 
                // if children are in $rows or self is in rows then return the 
copy
-               if ( $clone->getChildren() != null || in_array( 
HierarchyBuilder::getPageNameFromHierarchyRow( $node->getValue() ), $rows ) ) {
+               if (
+                       $clone->getChildren() != null ||
+                       in_array(
+                               HierarchyBuilder::getPageNameFromHierarchyRow( 
$node->getValue() ),
+                               $rows
+                       )
+               ) {
                        return $clone;
                } else { // otherwise this whole branch gets cut
                        return null;
                }
        }
-}
\ No newline at end of file
+}
diff --git a/includes/TreeNode.php b/includes/TreeNode.php
index 35976f7..188357d 100644
--- a/includes/TreeNode.php
+++ b/includes/TreeNode.php
@@ -1,5 +1,5 @@
 <?php
- 
+
 /*
  * Copyright (c) 2014 The MITRE Corporation
  *
@@ -23,39 +23,39 @@
  */
 
 class TreeNode {
-       protected $value = null; // this is the actuall row value like 
"***[[Hierarchy Builder]]"
-       protected $parent = null; // this is a pointer to the parent node 
within the tree
-       protected $children = null; // an array of pointers to children
+       protected $value = null; // this is the actuall row value like 
"***[[Hierarchy Builder]]"
+       protected $parent = null; // this is a pointer to the parent node 
within the tree
+       protected $children = null; // an array of pointers to children
 
-       function __construct( $text ) {
-       $this->value = $text;
+       function __construct( $text ) {
+               $this->value = $text;
        }
 
-       public function getValue() {
-               return $this->value;
-       }
+       public function getValue() {
+               return $this->value;
+       }
 
-       public function getParent() {
-               return $this->parent;
-       }
+       public function getParent() {
+               return $this->parent;
+       }
 
-       public function getChildren() {
-               return $this->children;
-       }
+       public function getChildren() {
+               return $this->children;
+       }
 
-       public function setValue( $text ) {
-               $this->value = $text;
-       }
+       public function setValue( $text ) {
+               $this->value = $text;
+       }
 
-       public function setParent( TreeNode $node ) {
-               $this->parent = $node;
-       }
+       public function setParent( TreeNode $node ) {
+               $this->parent = $node;
+       }
 
-       public function addChild( TreeNode $node ) {
-               if ( $this->children == null ) {
-                       $this->children = array( $node );
-               } else {
-                       array_push( $this->children, $node );   
-               }
-       }
-}
\ No newline at end of file
+       public function addChild( TreeNode $node ) {
+               if ( $this->children == null ) {
+                       $this->children = array( $node );
+               } else {
+                       array_push( $this->children, $node );
+               }
+       }
+}
diff --git a/includes/editHierarchy.css b/includes/editHierarchy.css
index f3a1274..71b7c80 100644
--- a/includes/editHierarchy.css
+++ b/includes/editHierarchy.css
@@ -43,4 +43,4 @@
 
 #showinfo {
        cursor: pointer;
-}
\ No newline at end of file
+}
diff --git a/includes/editHierarchy.js b/includes/editHierarchy.js
index 34e148e..1a3d33d 100644
--- a/includes/editHierarchy.js
+++ b/includes/editHierarchy.js
@@ -123,7 +123,7 @@
                                }
                                if ( params.hideinfo == "true" ) {
                                        var button = $("#showinfo")[0];
-                                       button.onclick = function() { 
+                                       button.onclick = function() {
                                                if ($("#info").css("display") 
== "none") {
                                                        $("#info").slideDown();
                                                } else {
diff --git a/includes/renderHierarchy.css b/includes/renderHierarchy.css
index caf93fd..bbd5692 100644
--- a/includes/renderHierarchy.css
+++ b/includes/renderHierarchy.css
@@ -24,4 +24,4 @@
        max-height:15px;
        max-width:15px;
        padding-right:5px;
-}
\ No newline at end of file
+}
diff --git a/includes/renderHierarchySelected.js 
b/includes/renderHierarchySelected.js
index 3415065..142fb2e 100644
--- a/includes/renderHierarchySelected.js
+++ b/includes/renderHierarchySelected.js
@@ -20,7 +20,6 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-
 ( function( $ ) {
        /**
         * Gobal function to display a hierarchy.
@@ -75,7 +74,6 @@
                                                selectedComponents[i] = 
selectedComponents[i].replace("%20", " ");
                                        }
                                }
-                       
 
                                var obj = this;
 
@@ -87,7 +85,7 @@
                                        .css( "list-style-image", "none" );
                                $( jqDivId )
                                        .bind( "loaded.jstree", function( 
event, data ) {
-                                               obj.initializeTree( jqDivId, 
selectedComponents, true, collapsed );                                     
+                                               obj.initializeTree( jqDivId, 
selectedComponents, true, collapsed );
                                        } );
                                $( jqDivId )
                                        .bind( "refresh.jstree", function( 
event, data ) {
diff --git a/includes/selectFromHierarchy.css b/includes/selectFromHierarchy.css
index 5b6c8d4..6b722d6 100644
--- a/includes/selectFromHierarchy.css
+++ b/includes/selectFromHierarchy.css
@@ -24,22 +24,28 @@
     font-style: italic;
     color: green;
 }
-                
+
 li > a.unselectedHierarchyRow {
        font-style: normal;
     color: black;
 }*/
 
 li.jstree-checked > a {
-    font-style: italic;
-    color: green;
+       font-style: italic;
+       color: green;
 }
-                
+
 li.jstree-undetermined li.jstree-unchecked > a {
        font-style: normal;
-    color: black;
+       color: black;
 }
 
 .scrollableHierarchy {
        overflow: scroll;
-}
\ No newline at end of file
+}
+
+.hierarchy_row_titleicon {
+       max-height:15px;
+       max-width:15px;
+       padding-right:5px;
+}
diff --git a/includes/selectFromHierarchy.js b/includes/selectFromHierarchy.js
index e70bbd0..54caa97 100644
--- a/includes/selectFromHierarchy.js
+++ b/includes/selectFromHierarchy.js
@@ -106,7 +106,8 @@
 
                                var hierarchy = params.hierarchy;
                                var html = hierarchy;
-                               html = this.parseWikiTextToHtml( html );
+                               //html = this.parseWikiTextToHtml( html );
+                               console.log("[selectFromHierarchy.js][init] 
html = " + html);
 
                                var jqDivId = "#" + params.divId;
                                $( jqDivId )
@@ -190,7 +191,6 @@
                                                },
                                                "plugins": [ "themes", 
"html_data", "checkbox", "types" ]
                                        } );
-
 
                                /*$html = $( jqDivId ).html();
                                $( jqDivId )
@@ -550,4 +550,4 @@
                } )
                .init( inputId, params );
        };
-}( jQuery ) );
\ No newline at end of file
+}( jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id2f774aade4f2414fb98f3094738f3e003eced07
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/HierarchyBuilder
Gerrit-Branch: master
Gerrit-Owner: Kji <[email protected]>

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

Reply via email to