Netbrain has uploaded a new change for review.

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

Change subject: Added "values from subpage" feature If you have the pages:
......................................................................

Added "values from subpage" feature
If you have the pages:

A
A/B
A/B/C

Then this feature will allow you to have these as values as possible
values of an input field.

example:

|values from subpage=A

Change-Id: I4f4543c6510b461864ddfbb6cd4508e65ed48358
---
M i18n/en.json
M includes/SF_FormPrinter.php
M includes/SF_Utils.php
M includes/forminputs/SF_EnumInput.php
M includes/forminputs/SF_TextWithAutocompleteInput.php
5 files changed, 47 insertions(+), 0 deletions(-)


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

diff --git a/i18n/en.json b/i18n/en.json
index 5a98c82..f53f344 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -58,6 +58,7 @@
     "sf_forminputs_valuesfromcategory": "A category whose pages should be this 
input's set of values",
     "sf_forminputs_valuesfromnamespace": "A namespace whose pages should be 
this input's set of values",
     "sf_forminputs_valuesfromconcept": "A Semantic MediaWiki \"concept\" page 
whose pages should be this input's set of values",
+    "sf_forminputs_valuesfromsubpage": "A MediaWiki \"subpage(s)\" of a page 
which would act as this input's set of values",
     "sf_forminputs_valuesfromurl": "A URL holding structured data that should 
be this input's set of values",
     "sf_forminputs_values": "The set of values for this input, separated by 
commas",
     "sf_forminputs_list": "Mark this input as holding a list of values",
diff --git a/includes/SF_FormPrinter.php b/includes/SF_FormPrinter.php
index 4f66828..583c5fc 100644
--- a/includes/SF_FormPrinter.php
+++ b/includes/SF_FormPrinter.php
@@ -976,6 +976,10 @@
                                                                $is_restricted 
= !array_intersect(
                                                                        
$wgUser->getEffectiveGroups(), array_map( 'trim', explode( ',', 
$sub_components[1] ) )
                                                                );
+                                                       }else if 
($sub_components[0] == 'values from subpage'){
+                                                               $title = 
$wgParser->recursiveTagParse( $sub_components[1] );
+                                                               $title = 
Title::newFromText($title);
+                                                               
$possible_values = SFUtils::getAllPagesFromSubpage($title);
                                                        }
                                                        if ( !is_null( 
$possible_values ) && array_key_exists( 'mapping template', $field_args ) ) {
                                                                
$possible_values = SFUtils::getLabels( $possible_values, $field_args['mapping 
template'] );
diff --git a/includes/SF_Utils.php b/includes/SF_Utils.php
index dfb8cf1..e62687a 100644
--- a/includes/SF_Utils.php
+++ b/includes/SF_Utils.php
@@ -1115,6 +1115,40 @@
        }
 
        /**
+        * @param $title \Title
+        * @return array
+        */
+       public static function getAllPagesFromSubpage($title){
+               if ( is_null( $title ) ) {
+                       return array();
+               }
+
+               $subPages = $title->getSubpages();
+               if(empty($subPages)){
+                       return array();
+               }
+               /** @var Title[] $titles */
+               $titles[ ] = $title;
+               while ( $subPages->valid() ) {
+                       $titles[ ] = $subPages->current();
+                       $subPages->next();
+               }
+
+               $result = array();
+               foreach ( $titles as $title ) {
+                       $titleText = $title->getFullText();
+                       $titleTextParts = explode( '/', $titleText );
+                       $titleText = '';
+                       foreach ( $titleTextParts as $part ) {
+                               $titleText .= $part;
+                               $result[ $titleText ] = null;
+                               $titleText .= '/';
+                       }
+               }
+               return array_keys($result);
+       }
+
+       /**
         * Returns a formatted (pseudo) random number
         *
         * @param number $numDigits the min width of the random number
diff --git a/includes/forminputs/SF_EnumInput.php 
b/includes/forminputs/SF_EnumInput.php
index c0a5aa2..2e9f9b7d 100644
--- a/includes/forminputs/SF_EnumInput.php
+++ b/includes/forminputs/SF_EnumInput.php
@@ -46,6 +46,11 @@
                        'type' => 'string',
                        'description' => wfMessage( 
'sf_forminputs_valuesfromconcept' )->text()
                );
+               $params[] = array(
+                       'name' => 'values from subpage',
+                       'type' => 'string',
+                       'description' => wfMessage( 
'sf_forminputs_valuesfromsubpage' )->text()
+               );
                return $params;
        }
 
diff --git a/includes/forminputs/SF_TextWithAutocompleteInput.php 
b/includes/forminputs/SF_TextWithAutocompleteInput.php
index 712a4d7..7c81623 100644
--- a/includes/forminputs/SF_TextWithAutocompleteInput.php
+++ b/includes/forminputs/SF_TextWithAutocompleteInput.php
@@ -56,6 +56,9 @@
                } elseif ( array_key_exists( 'values from concept', $field_args 
) ) {
                        $autocompleteFieldType = 'concept';
                        $autocompletionSource = $field_args['values from 
concept'];
+               } elseif ( array_key_exists( 'values from subpage', $field_args 
) ) {
+                       $autocompleteFieldType = 'subpage';
+                       $autocompletionSource = $field_args['values from 
subpage'];
                } elseif ( array_key_exists( 'values from namespace', 
$field_args ) ) {
                        $autocompleteFieldType = 'namespace';
                        $autocompletionSource = $field_args['values from 
namespace'];

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

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

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

Reply via email to