Kji has submitted this change and it was merged.

Change subject: Added ability to specify pages by property value for 
HierarchyFormInput.
......................................................................


Added ability to specify pages by property value for HierarchyFormInput.

Change-Id: Ib0ace149ee6bd0b61c845f8fc1c48c1bfac0b6bc
---
M HierarchyBuilder.php
M HierarchyBuilder_body.php
M extension.json
M includes/HierarchyFormInput.php
4 files changed, 65 insertions(+), 16 deletions(-)

Approvals:
  Kji: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/HierarchyBuilder.php b/HierarchyBuilder.php
index 2ad7ae1..dbdf0e6 100644
--- a/HierarchyBuilder.php
+++ b/HierarchyBuilder.php
@@ -56,7 +56,7 @@
                ' Semantic Forms 2.5.2 or above.' );
 }
 
-define( 'HB_VERSION', '3.1.0' );
+define( 'HB_VERSION', '3.2.0' );
 
 # credits
 $wgExtensionCredits['parserhook'][] = array (
diff --git a/HierarchyBuilder_body.php b/HierarchyBuilder_body.php
index 4b3aaf4..53bfcc1 100644
--- a/HierarchyBuilder_body.php
+++ b/HierarchyBuilder_body.php
@@ -52,6 +52,7 @@
        const CATEGORY = 'category';
        const NUMBERED = 'numbered';
        const SELECTED = 'selected';
+       const PROPERTYVALUE = 'propertyvalue';
 
        /**
         * This parser function will give the section number of a page in a 
hierarchy.
@@ -712,7 +713,7 @@
         *
         * @return string: Formatted wikitext which renders breadcrumbs on a 
page.
         */
-       private function formatBreadcrumb( $previous, $parent, $next ) {
+       private static function formatBreadcrumb( $previous, $parent, $next ) {
                $breadcrumb = "{| width='100%'" . PHP_EOL;
                if ( $previous != null ) {
                        if ( $previous == $parent ) {
diff --git a/extension.json b/extension.json
index 2bba7e7..3fa8519 100644
--- a/extension.json
+++ b/extension.json
@@ -1,6 +1,6 @@
 {
        "name": "HierarchyBuilder",
-       "version": "3.1.0",
+       "version": "3.2.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 ce800dd..fb960fe 100644
--- a/includes/HierarchyFormInput.php
+++ b/includes/HierarchyFormInput.php
@@ -62,21 +62,17 @@
                        $this->mCategory = null;
                }
 
-               $params = array();
-               $params[] = "[[Category:$this->mCategory]]";
-               $params[] = "link=none";
-               $params[] = "limit=1000";
+               if ( array_key_exists( HierarchyBuilder::PROPERTYVALUE, 
$this->mOtherArgs ) ) {
+                       $propertyValue = 
$this->mOtherArgs[HierarchyBuilder::PROPERTYVALUE];
+               } else {
+                       $propertyValue = null;
+               }
 
-               $output = SMWQueryProcessor::getResultFromFunctionParams( 
$params,
-                       SMW_OUTPUT_WIKI ); // this can wait for a another 
approach
-// 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 ) );
+               $pageArray = self::getUnusedPages($this->mCategory, 
$propertyValue);
 
                $pages = array();
                foreach ( $pageArray as $key => $value ) {
-                       $pages[$value] =
-                               HierarchyBuilder::getPageDisplayName( $value );
+                       $pages[$value] = HierarchyBuilder::getPageDisplayName( 
$value );
                }
 
                // This loop will removed pages from the unselected pages list 
if we can
@@ -136,16 +132,68 @@
        }
 
        /**
+        * Find and return all of the pages that we wish to have available for 
use
+        * when creating/updating a hierarchy using the edit form.
+        *
+        * Pages are collected based on the provided category and 
property/value.
+        * Only those pages that satisfy BOTH parameters will be returned. 
+        * Specifically, if only one of category and property/value is provided,
+        * then all pages that satisfy the one provided argument will be 
returned.
+        * However, if both a category and a property/value are provided, then 
only
+        * those pages that belong to the specified category and have the 
property
+        * set with the correct value will be returned.
+        *
+        * @param string $category: The name of the category from which pages 
will
+        *  be drawn.
+        * @param string $propertyValue: The propertyname::value that pages must
+        *  contain to be returned. (eg: Display Name::A Cool Name)
+        *
+        * @return array: List of qualified pages that should be available when
+        *  editing the hierarchy.
+        */
+       private function getUnusedPages($category, $propertyValue) {
+               $categoryPageArray = array();
+               if ($category != null) {
+                       $params = array();
+                       $params[] = "[[Category:$this->mCategory]]";
+                       $params[] = "link=none";
+                       $params[] = "limit=1000";
+                       $output = 
SMWQueryProcessor::getResultFromFunctionParams( $params,
+                               SMW_OUTPUT_WIKI );
+                       $categoryPageArray = $output === "" ? array() : 
array_map( 'trim', explode( ',', $output ) );
+               }
+               
+               $propertyValuePageArray = array();
+               if ($propertyValue != null) {
+                       $params = array();
+                       $params[] = "[[$propertyValue]]";
+                       $params[] = "link=none";
+                       $params[] = "limit=1000";
+                       $output = 
SMWQueryProcessor::getResultFromFunctionParams( $params,
+                               SMW_OUTPUT_WIKI );
+                       $propertyValuePageArray = $output === "" ? array() : 
array_map( 'trim', explode( ',', $output ) );
+               }
+
+               if ($category != null && $propertyValue != null) {
+                       $pageArray = array_intersect($categoryPageArray, 
$propertyValuePageArray);
+               } else {
+                       $pageArray = array_merge($categoryPageArray, 
$propertyValuePageArray);
+               }
+
+               return $pageArray;
+       }
+
+       /**
         * Get error messages for display.
         *
         * @return HTML::element: HTML formatted message for display.
         */
        public function getHtmlText() {
 
-               if ( $this->mCategory == null ) {
+               /*if ( $this->mCategory == null ) {
                        return Html::element( 'b', array(),
                                wfMessage( 'hierarchybuilder-missing-category' 
)->text() );
-               }
+               }*/
 
                return Html::element( 'input', array(
                        'type' => 'hidden',

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib0ace149ee6bd0b61c845f8fc1c48c1bfac0b6bc
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

Reply via email to