Orbartal has uploaded a new change for review.

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


Change subject: Any file type gets its own Tag in extension: page schema
......................................................................

Any file type gets its own Tag in extension: page schema

The change in extensions\semantic form\ include\SF_TemplateField.php allows the 
user to view each file type with its ow
n Tag. Pages created from forms and templates defines using the page schema 
extension. Mapping between file type (exten
sion) type and Tag are done using the global array variable , which is set in 
Local
Settings.php.
Change-Id: I2c37894c0e5435cb3e1fbc65b8cb3f9ae4b72831
---
M includes/SF_TemplateField.php
1 file changed, 66 insertions(+), 29 deletions(-)


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

diff --git a/includes/SF_TemplateField.php b/includes/SF_TemplateField.php
index 15ff8ac..624870e 100644
--- a/includes/SF_TemplateField.php
+++ b/includes/SF_TemplateField.php
@@ -152,6 +152,33 @@
        }
 
        /**
+        * Creates the text in the template for a link to a file.
+        * Each file type(extension) in the gloabl 
$wgPageSchemaMapTagsToFilesExtension
+        * receive a diffrent tag, and using a diffrent extension. For example:
+        *              $wgPageSchemaMapTagsToFilesExtension = array(
+        *              "jpg" => "gallery",
+        *                      "png" => "gallery",
+        *                      "wmv" => "video",
+        *                      "wma" => "audio",
+        *              );
+        */
+       static function displayFileWikiCode($field)
+       {
+       
+                       global $wgPageSchemaMapTagsToFilesExtension;
+                       $tableText = "";
+                       $tableText .="{{#switch: {{#explode:" . "{{{" . 
$field->mFieldName . "}}}|.|-1}}" . PHP_EOL;
+                       foreach($wgPageSchemaMapTagsToFilesExtension as 
$key=>$value)
+                       {
+                               $tableText .= "|". $key ." = " . PHP_EOL . 
"{{#tag:" . $value ."|" . "{{{" . $field->mFieldName . "}}}". "}}" . PHP_EOL;
+                               $tableText .= "{{#set:". 
$field->mSemanticProperty . "=file:{{{" . $field->mFieldName . "|}}}  }}" . 
PHP_EOL;
+                       }
+                       $tableText .="|#default = " . "[[" . 
$field->mSemanticProperty . "::{{{" . $field->mFieldName . "}}}]]" . PHP_EOL;
+                       $tableText .="}}" . PHP_EOL;
+                       return $tableText;
+       }
+       
+       /**
         * Creates the text of a template, when called from
         * Special:CreateTemplate, Special:CreateClass or the Page Schemas
         * extension.
@@ -162,6 +189,7 @@
        public static function createTemplateText( $template_name, 
$template_fields, $internal_obj_property, $category,
                                                                                
           $aggregating_property, $aggregating_label, $template_format, 
$template_options = null ) {
                $template_header = wfMessage( 'sf_template_docu', 
$template_name )->inContentLanguage()->text();
+               // The noinclude part of the template. Only for display in the 
template page itself. Has no effect on pages that use the template. 
                $text = <<<END
 <noinclude>
 $template_header
@@ -215,6 +243,7 @@
                }
 
                foreach ( $template_fields as $i => $field ) {
+                       // Fix or skip fields with missing details
                        if ( $field->mFieldName == '' ) continue;
                        $separator = '|';
 
@@ -239,26 +268,26 @@
                        if ( is_null( $field->mDisplay ) ) {
                                if ( $template_format == 'standard' || 
$template_format == 'infobox' ) {
                                        if ( $i > 0 ) {
-                                               $tableText .= "|-\n";
+                                               $tableText .= 
PHP_EOL."|-".PHP_EOL;
                                        }
-                                       $tableText .= '! ' . $field->mLabel . 
"\n";
+                                       $tableText .= '! ' . $field->mLabel . 
PHP_EOL;
                                } elseif ( $template_format == 'plain' ) {
                                        $tableText .= "\n'''" .  $field->mLabel 
. ":''' ";
                                } elseif ( $template_format == 'sections' ) {
-                                       $tableText .= "\n==" .  $field->mLabel 
. "==\n";
+                                       $tableText .= PHP_EOL . "==" .  
$field->mLabel . "==".PHP_EOL;
                                }
                        } elseif ( $field->mDisplay == 'nonempty' ) {
                                $tableText .= '{{#if:{{{' . $field->mFieldName 
. '|}}}|';
                                if ( $template_format == 'standard' || 
$template_format == 'infobox' ) {
                                        if ( $i > 0 ) {
-                                               $tableText .= "\n{{!}}-\n";
+                                               $tableText .= PHP_EOL . 
"{{!}}-" . PHP_EOL;
                                        }
-                                       $tableText .= '! ' . $field->mLabel . 
"\n";
+                                       $tableText .= '! ' . $field->mLabel .  
PHP_EOL;
                                        $separator = '{{!}}';
                                } elseif ( $template_format == 'plain' ) {
                                        $tableText .= "'''" .  $field->mLabel . 
"''' ";
                                } elseif ( $template_format == 'sections' ) {
-                                       $tableText .= '==' .  $field->mLabel . 
"==\n";
+                                       $tableText .= '==' .  $field->mLabel . 
"==" .  PHP_EOL;
                                }
                        } // If it's 'hidden', do nothing
                        // Value column
@@ -275,9 +304,9 @@
                                if ( $field->mDisplay == 'nonempty' ) {
                                        $tableText .= " }}";
                                }
-                               $tableText .= "\n";
+                               $tableText .=  PHP_EOL;
                        } elseif ( !is_null( $setInternalText ) ) {
-                               $tableText .= "$separator $fieldBefore {{{" . 
$field->mFieldName . "|}}} $fieldAfter\n";
+                               $tableText .= "$separator $fieldBefore {{{" . 
$field->mFieldName . "|}}} $fieldAfter". PHP_EOL;
                                if ( $field->mIsList ) {
                                        $setInternalText .= '|' . 
$field->mSemanticProperty . '#list={{{' . $field->mFieldName . '|}}}';
                                } else {
@@ -290,7 +319,7 @@
                                        $setText .= $field->mSemanticProperty . 
'={{{' . $field->mFieldName . '|}}}|';
                                }
                        } elseif ( $field->mDisplay == 'nonempty' ) {
-                               $tableText .= '{{!}} ' . $fieldBefore . ' [[' . 
$field->mSemanticProperty . '::{{{' . $field->mFieldName . "|}}}]]}} 
$fieldAfter\n";
+                               $tableText .= '{{!}} ' . $fieldBefore . ' [[' . 
$field->mSemanticProperty . '::{{{' . $field->mFieldName . "|}}}]]}} 
$fieldAfter". PHP_EOL;
                        } elseif ( $field->mIsList ) {
                                // If this field is meant to contain a list,
                                // add on an 'arraymap' function, that will
@@ -298,19 +327,27 @@
                                // element in the list.
                                // Find a string that's not in the semantic
                                // field call, to be used as the variable.
-                               $var = "x"; // default - use this if all the 
attempts fail
-                               if ( strstr( $field->mSemanticProperty, $var ) 
) {
-                                       $var_options = array( 'y', 'z', 'xx', 
'yy', 'zz', 'aa', 'bb', 'cc' );
-                                       foreach ( $var_options as $option ) {
-                                               if ( ! strstr( 
$field->mSemanticProperty, $option ) ) {
-                                                       $var = $option;
-                                                       break;
-                                               }
-                                       }
-                               }
-                               $tableText .= "{{#arraymap:{{{" . 
$field->mFieldName . "|}}}|" . $field->mDelimiter . "|$var|[[" . 
$field->mSemanticProperty . "::$var]]}}\n";
+                               
+                       
+                                $letter = 'a';
+                                while (strstr( $field->mSemanticProperty,  
$letter ))
+                                {
+                                       $letter++;
+                                }
+                                $tableText .="{{!}}" . PHP_EOL ;
+                                $tableText .=  "{{#arraymap:{{{" . 
$field->mFieldName . "|}}}|" . $field->mDelimiter . "|". $letter. "|[[" . 
$field->mSemanticProperty . "::".$letter."]]}}". PHP_EOL;
                        } else {
-                               $tableText .= "" . $fieldBefore . " [[" . 
$field->mSemanticProperty . "::{{{" . $field->mFieldName . "|}}}]] 
$fieldAfter\n";
+                               $tableText .= "{{!}}" . PHP_EOL;
+
+                               if ($field->mPropertyType=='_wpg')
+                               {
+                                       $tableText .= $fieldBefore .  
self::displayFileWikiCode($field) . $fieldAfter . PHP_EOL;
+                               }
+                               else
+                               {
+                                       $tableText .= "" .$fieldBefore .  "[[" 
. $field->mSemanticProperty . "::{{{" . $field->mFieldName . "}}}]]" . 
$fieldAfter. PHP_EOL;
+                               }
+                       //      $tableText .= "" . $fieldBefore . " [[" . 
$field->mSemanticProperty . "::{{{" . $field->mFieldName . "|}}}]] 
$fieldAfter". PHP_EOL;
                        }
                }
 
@@ -319,18 +356,18 @@
                if ( !is_null( $aggregating_property ) && $aggregating_property 
!== '' ) {
                        if ( $template_format == 'standard' || $template_format 
== 'infobox' ) {
                                if ( count( $template_fields ) > 0 ) {
-                                       $tableText .= "|-\n";
+                                       $tableText .= "|-" . PHP_EOL;
                                }
                                $tableText .= <<<END
 ! $aggregating_label
 | 
 END;
                        } elseif ( $template_format == 'plain' ) {
-                               $tableText .= "\n'''$aggregating_label:''' ";
+                               $tableText .= PHP_EOL . 
"'''$aggregating_label:''' ";
                        } elseif ( $template_format == 'sections' ) {
-                               $tableText .= "\n==$aggregating_label==\n";
+                               $tableText .= PHP_EOL . 
"==$aggregating_label==" . PHP_EOL;
                        }
-                       $tableText .= 
"{{#ask:[[$aggregating_property::{{SUBJECTPAGENAME}}]]|format=list}}\n";
+                       $tableText .= 
"{{#ask:[[$aggregating_property::{{SUBJECTPAGENAME}}]]|format=list}}" . PHP_EOL;
                }
                if ( $template_format == 'standard' || $template_format == 
'infobox' ) {
                        $tableText .= "|}";
@@ -340,7 +377,7 @@
                // multiple instances of this template.)
                if ( is_null( $setInternalText ) ) {
                        if ( $template_format == 'standard' || $template_format 
== 'infobox' ) {
-                               $tableText .= "\n";
+                               $tableText .= PHP_EOL;
                        }
                } else {
                        $setInternalText .= "}}";
@@ -349,7 +386,7 @@
 
                // Add a call to #set, if necessary
                if ( $setText !== '' ) {
-                       $setText = '{{#set:' . $setText . "}}\n";
+                       $setText = '{{#set:' . $setText . "}}".PHP_EOL;
                        $text .= $setText;
                }
 
@@ -358,7 +395,7 @@
                        global $wgContLang;
                        $namespace_labels = $wgContLang->getNamespaces();
                        $category_namespace = $namespace_labels[NS_CATEGORY];
-                       $text .= "\n[[$category_namespace:$category]]\n";
+                       $text .= PHP_EOL . 
"[[$category_namespace:$category]]".PHP_EOL;
                }
 
                //After text
@@ -366,7 +403,7 @@
                        $text .= $template_options['afterText'];
                }
 
-               $text .= "</includeonly>\n";
+               $text .= "</includeonly>".PHP_EOL;
 
                return $text;
        }

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

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

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

Reply via email to