jenkins-bot has submitted this change and it was merged.
Change subject: Implemented titleicons for hierarchySelect.
......................................................................
Implemented titleicons for hierarchySelect.
Updated argument parsing across all parser functions and forms.
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, 313 insertions(+), 223 deletions(-)
Approvals:
Kji: Verified; Looks good to me, approved
jenkins-bot: Verified
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..2ad7ae1 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;
}
@@ -55,7 +56,7 @@
' Semantic Forms 2.5.2 or above.' );
}
-define( 'HB_VERSION', '3.0.1' );
+define( 'HB_VERSION', '3.1.0' );
# credits
$wgExtensionCredits['parserhook'][] = array (
diff --git a/HierarchyBuilder_body.php b/HierarchyBuilder_body.php
index 3c8489b..4b3aaf4 100644
--- a/HierarchyBuilder_body.php
+++ b/HierarchyBuilder_body.php
@@ -31,7 +31,9 @@
// in the wikitext hierarchy.
const DEPTHPATTERN = '/^(\**)/';
- // constants for child parser function arg names
+ // constants for arg names
+ const PAGENAME = 'pagename';
+ const PROPERTYNAME = 'propertyname';
const SEPARATOR = 'sep';
const TEMPLATE = 'template';
const INTROTEMPLATE = 'introtemplate';
@@ -42,6 +44,14 @@
const DISPLAYMODE = 'displaymode';
const SHOWROOT = 'showroot';
const COLLAPSED = 'collapsed';
+ const PRUNED = 'pruned';
+ const THREESTATE = 'threestate';
+ const HIDEINFO = 'hideinfo';
+ const WIDTH = 'width';
+ const HEIGHT = 'height';
+ const CATEGORY = 'category';
+ const NUMBERED = 'numbered';
+ const SELECTED = 'selected';
/**
* This parser function will give the section number of a page in a
hierarchy.
@@ -180,7 +190,7 @@
} else {
return
"{{" . $template . "|[[$child]]}}";
}
- } ,
+ },
$children
),
"$delimiter\n"
@@ -191,7 +201,7 @@
array_map(
function( $child ) use
( $link ) {
return $link ==
'none' ? $child : "[[$child]]";
- } ,
+ },
$children
),
$delimiter
@@ -411,7 +421,7 @@
} else {
return
"{{" . $template . "|[[$parent]]}}";
}
- } ,
+ },
$parents
),
"$delimiter\n"
@@ -422,7 +432,7 @@
array_map(
function( $parent ) use
( $link ) {
return $link ==
'none' ? $parent : "[[$parent]]";
- } ,
+ },
$parents
),
$delimiter
@@ -525,13 +535,15 @@
$hierarchyPageName = $params[2];
$hierarchyPropertyName = $params[3];
// if "pruned" is given, then set the displaymode to
pruned. otherwise, "collapsed"
- if ( isset( $params[4] ) && $params[4] == 'collapsed' )
{
+ if ( isset( $params[4] ) && $params[4] ==
HierarchyBuilder::COLLAPSED ) {
$displayMode = 'collapsed';
} else {
$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 +558,7 @@
},
explode( ',', $selectedPages )
);
-
+
$mst = $hierarchyTree->getMST( $normalizedSelectedPages
);
// output formatting
@@ -566,9 +578,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 +620,6 @@
*/
public static function hierarchyBreadcrumb( $parser ) {
$params = func_get_args();
-
if ( count( $params ) < 4 ) {
$output = "";
@@ -699,7 +716,7 @@
$breadcrumb = "{| width='100%'" . PHP_EOL;
if ( $previous != null ) {
if ( $previous == $parent ) {
- $arrow = "↑";
+ $arrow = "↑";
} else {
$arrow = "←";
}
@@ -708,7 +725,7 @@
} else {
$breadcrumb .= "| width='33%' | " . PHP_EOL;
}
- if ( $parent != null && $parent != $previous ) {
+ if ( $parent != null && $parent != $previous ) {
$breadcrumb .= "| align='center' width='33%' | ↑
[[" . $parent .
"| " . HierarchyBuilder::getPageDisplayName(
$parent ) . "]]" . PHP_EOL;
} else {
@@ -814,7 +831,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 );
@@ -854,8 +873,8 @@
$hierarchyName = 'HierarchyDiv' . self::$m_hierarchy_num;
self::$m_hierarchy_num++;
- if ( isset( $attributes['collapsed'] ) ) {
- $collapsed = htmlspecialchars( $attributes['collapsed']
);
+ if ( isset( $attributes[HierarchyBuilder::COLLAPSED] ) ) {
+ $collapsed = htmlspecialchars(
$attributes[HierarchyBuilder::COLLAPSED] );
if ( $collapsed === 'collapsed' ) {
$collapsed = 'true';
}
@@ -863,8 +882,8 @@
$collapsed = 'false';
}
- if ( isset( $attributes['numbered'] ) ) {
- $numbered = htmlspecialchars( $attributes['numbered'] );
+ if ( isset( $attributes[HierarchyBuilder::NUMBERED] ) ) {
+ $numbered = htmlspecialchars(
$attributes[HierarchyBuilder::NUMBERED] );
if ( $numbered === 'numbered' ) {
$numbered = 'true';
}
@@ -872,9 +891,9 @@
$numbered = 'false';
}
- if ( isset( $attributes['titleiconproperty'] ) ) {
+ if ( isset( $attributes[HierarchyBuilder::TITLEICONPROPERTY] )
) {
$titleiconproperty =
- htmlspecialchars(
$attributes['titleiconproperty'] );
+ htmlspecialchars(
$attributes[HierarchyBuilder::TITLEICONPROPERTY] );
} else {
$titleiconproperty = '';
}
@@ -931,8 +950,8 @@
$hierarchyName = 'HierarchyDiv' . self::$m_hierarchy_num;
self::$m_hierarchy_num++;
- if ( isset( $attributes['collapsed'] ) ) {
- $collapsed = htmlspecialchars( $attributes['collapsed']
);
+ if ( isset( $attributes[HierarchyBuilder::COLLAPSED] ) ) {
+ $collapsed = htmlspecialchars(
$attributes[HierarchyBuilder::COLLAPSED] );
if ( $collapsed === 'collapsed' ) {
$collapsed = 'true';
}
@@ -940,8 +959,8 @@
$collapsed = 'false';
}
- if ( isset( $attributes['numbered'] ) ) {
- $numbered = htmlspecialchars( $attributes['numbered'] );
+ if ( isset( $attributes[HierarchyBuilder::NUMBERED] ) ) {
+ $numbered = htmlspecialchars(
$attributes[HierarchyBuilder::NUMBERED] );
if ( $numbered === 'numbered' ) {
$numbered = 'true';
}
@@ -949,19 +968,19 @@
$numbered = 'false';
}
- if ( isset( $attributes['selected'] ) ) {
+ if ( isset( $attributes[HierarchyBuilder::SELECTED] ) ) {
$selectedPages =
- json_encode( explode( ',', urldecode(
$attributes['selected'] ) ) );
+ json_encode( explode( ',', urldecode(
$attributes[HierarchyBuilder::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[HierarchyBuilder::SELECTED] ) )
+ )
+ );
} else {
$selectedPages = '';
}
@@ -1093,10 +1112,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 +1134,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 +1277,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 +1343,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 +1368,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 +1472,7 @@
if ( $root == '' ) {
return $hierarchy;
} else {
- return HierarchyBuilder::getSubhierarchyHelper(
+ return HierarchyBuilder::getSubhierarchyHelper(
$root,
"[[Hierarchy_Root]]\n" . $hierarchy,
''
@@ -1482,7 +1511,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 +1526,9 @@
);
return $result;
} else {
- $subHierarchyCandidate =
HierarchyBuilder::getSubhierarchyHelper( $root, $subHierarchy, $depth . '*' );
+ $subHierarchyCandidate =
HierarchyBuilder::getSubhierarchyHelper(
+ $root, $subHierarchy, $depth . '*'
+ );
if ( $subHierarchyCandidate != '' ) {
return $subHierarchyCandidate;
}
@@ -1503,6 +1536,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 +1650,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 +1669,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 +1772,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..ce800dd 100644
--- a/includes/HierarchyFormInput.php
+++ b/includes/HierarchyFormInput.php
@@ -1,5 +1,5 @@
<?php
-
+
/*
* Copyright (c) 2013 The MITRE Corporation
*
@@ -44,8 +44,20 @@
*/
protected function setupJsInitAttribs() {
- if ( array_key_exists( 'category', $this->mOtherArgs ) ) {
- $this->mCategory = $this->mOtherArgs['category'];
+ if ( array_key_exists( HierarchyBuilder::TITLEICONPROPERTY,
$this->mOtherArgs ) ) {
+ $titleiconProperty =
$this->mOtherArgs[HierarchyBuilder::TITLEICONPROPERTY];
+ } else {
+ $titleiconProperty = '';
+ }
+
+ if ( array_key_exists( HierarchyBuilder::HIDEINFO,
$this->mOtherArgs ) ) {
+ $hideinfoProperty =
$this->mOtherArgs[HierarchyBuilder::HIDEINFO];
+ } else {
+ $hideinfoProperty = 'false';
+ }
+
+ if ( array_key_exists( HierarchyBuilder::CATEGORY,
$this->mOtherArgs ) ) {
+ $this->mCategory =
$this->mOtherArgs[HierarchyBuilder::CATEGORY];
} else {
$this->mCategory = null;
}
@@ -60,18 +72,6 @@
// use the category object to get list of titles in category from which you
can get names
$pageArray = $output === "" ? array() : array_map( 'trim',
explode( ',', $output ) );
-
- if ( array_key_exists( HierarchyBuilder::TITLEICONPROPERTY,
$this->mOtherArgs ) ) {
- $titleiconProperty =
$this->mOtherArgs[HierarchyBuilder::TITLEICONPROPERTY];
- } else {
- $titleiconProperty = '';
- }
-
- if ( array_key_exists( 'hideinfo', $this->mOtherArgs ) ) {
- $hideinfoProperty = $this->mOtherArgs['hideinfo'];
- } else {
- $hideinfoProperty = 'false';
- }
$pages = array();
foreach ( $pageArray as $key => $value ) {
@@ -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.
*
@@ -209,8 +157,8 @@
public static function getParameters() {
$params = parent::getParameters();
- $params['category'] = array(
- 'name' => 'category',
+ $params[HierarchyBuilder::CATEGORY] = array(
+ 'name' => HierarchyBuilder::CATEGORY,
'type' => 'string',
'description' =>
wfMessage( 'hierarchybuilder-category-desc'
)->text()
diff --git a/includes/HierarchySelectFormInput.php
b/includes/HierarchySelectFormInput.php
index ed46db0..62855a6 100644
--- a/includes/HierarchySelectFormInput.php
+++ b/includes/HierarchySelectFormInput.php
@@ -45,22 +45,31 @@
protected function setupJsInitAttribs() {
global $HierarchyBuilder_LegacyMode;
- if ( array_key_exists( 'pagename', $this->mOtherArgs ) ) {
- $this->mPageName = $this->mOtherArgs['pagename'];
+ if ( array_key_exists( HierarchyBuilder::PAGENAME,
$this->mOtherArgs ) ) {
+ $this->mPageName =
$this->mOtherArgs[HierarchyBuilder::PAGENAME];
} else {
$this->mPageName = null;
return;
}
- if ( array_key_exists( 'propertyname', $this->mOtherArgs ) ) {
- $this->mPropertyName =
$this->mOtherArgs['propertyname'];
+ if ( array_key_exists( HierarchyBuilder::PROPERTYNAME,
$this->mOtherArgs ) ) {
+ $this->mPropertyName =
$this->mOtherArgs[HierarchyBuilder::PROPERTYNAME];
} else {
$this->mPropertyName = null;
return;
}
- if ( array_key_exists( 'collapsed', $this->mOtherArgs ) ) {
- $this->mCollapsed = $this->mOtherArgs['collapsed'];
+ if ( array_key_exists( HierarchyBuilder::TITLEICONPROPERTY,
$this->mOtherArgs ) ) {
+ $this->titleiconProperty =
$this->mOtherArgs[HierarchyBuilder::TITLEICONPROPERTY];
+ } else {
+ $this->titleiconProperty = null;
+ }
+
+ if ( array_key_exists( HierarchyBuilder::COLLAPSED,
$this->mOtherArgs ) ) {
+ $this->mCollapsed =
$this->mOtherArgs[HierarchyBuilder::COLLAPSED];
+ if ( $this->mCollapsed ) {
+ $this->mCollapsed = 'true';
+ }
if ( $this->mCollapsed !== 'true' && $this->mCollapsed
!== 'false' ) {
$this->mCollapsed = null;
return;
@@ -69,8 +78,8 @@
$this->mCollapsed = 'false';
}
- if ( array_key_exists( 'threestate', $this->mOtherArgs ) ) {
- $this->mThreestate = $this->mOtherArgs['threestate'];
+ if ( array_key_exists( HierarchyBuilder::THREESTATE,
$this->mOtherArgs ) ) {
+ $this->mThreestate =
$this->mOtherArgs[HierarchyBuilder::THREESTATE];
if ( $this->mThreestate ) {
$this->mThreestate = 'true';
}
@@ -82,21 +91,26 @@
$this->mThreestate = 'false';
}
- if ( array_key_exists( 'width', $this->mOtherArgs ) ) {
- $this->mWidth = $this->mOtherArgs['width'];
+ if ( array_key_exists( HierarchyBuilder::WIDTH,
$this->mOtherArgs ) ) {
+ $this->mWidth =
$this->mOtherArgs[HierarchyBuilder::WIDTH];
} else {
$this->mWidth = '';
}
- if ( array_key_exists( 'height', $this->mOtherArgs ) ) {
- $this->mHeight = $this->mOtherArgs['height'];
+ if ( array_key_exists( HierarchyBuilder::HEIGHT,
$this->mOtherArgs ) ) {
+ $this->mHeight =
$this->mOtherArgs[HierarchyBuilder::HEIGHT];
} else {
$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,
@@ -149,23 +158,17 @@
public static function getParameters() {
$params = parent::getParameters();
- $params['pagename'] = array(
- 'name' => 'pagename',
+ $params[HierarchyBuilder::PAGENAME] = array(
+ 'name' => HierarchyBuilder::PAGENAME,
'type' => 'string',
'description' =>
wfMessage( 'hierarchybuilder-pagename-desc'
)->text()
);
- $params['propertyname'] = array(
- 'name' => 'propertyname',
+ $params[HierarchyBuilder::PROPERTYNAME] = array(
+ 'name' => HierarchyBuilder::PROPERTYNAME,
'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: merged
Gerrit-Change-Id: Id2f774aade4f2414fb98f3094738f3e003eced07
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/HierarchyBuilder
Gerrit-Branch: master
Gerrit-Owner: Kji <[email protected]>
Gerrit-Reviewer: Kji <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits