Dan-nl has uploaded a new change for review.

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

Change subject: Correct the format of the wikitext output
......................................................................

Correct the format of the wikitext output

* allow for empty template parameters
* add =={{int:filedesc}}== to the top of the wiki text
* move gwtoolset parameters out of the artwork template into their own template
* move the categories to the bottom of the wiki text output
* add whitespace between the different sections within the wiki text

another request, that was made that could not be handled here, was to leave
the template parameter order as it is within the actual template; e.g.,
not always alphabetical. this could not be dealt with here because
GWToolset is using templatedata to retrieve the template parameters and
templatedata is alphabetising the parameters. does this need to be dealt
with as a templatedata bug?

Bug: 63168
Change-Id: I4f82c37e8316737c5f8339e2388c1b30143e5204
---
M includes/Handlers/UploadHandler.php
M includes/Models/MediawikiTemplate.php
2 files changed, 47 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GWToolset 
refs/changes/07/121307/1

diff --git a/includes/Handlers/UploadHandler.php 
b/includes/Handlers/UploadHandler.php
index e5a99b7..ff818b3 100644
--- a/includes/Handlers/UploadHandler.php
+++ b/includes/Handlers/UploadHandler.php
@@ -125,6 +125,7 @@
         */
        protected function addMetadata() {
                return
+                       PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL .
                        '<!-- Metadata Mapped -->' . PHP_EOL .
                        '<!-- <metadata_mapped_json>' .
                        json_encode( 
$this->_MediawikiTemplate->mediawiki_template_array ) .
@@ -144,10 +145,11 @@
         * the resulting wiki text is filtered
         */
        protected function addGlobalCategories() {
-               $result = null;
+               $result =
+                       PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL .
+                       '<!-- Categories -->' . PHP_EOL;
 
                if ( !empty( $this->user_options['categories'] ) ) {
-                       $result .= '<!-- Categories -->' . PHP_EOL;
                        $categories = explode( Config::$category_separator, 
$this->user_options['categories'] );
 
                        foreach ( $categories as $category ) {
@@ -155,7 +157,7 @@
                                                '[[' .
                                                        
Utils::getNamespaceName( NS_CATEGORY ) .
                                                        
Utils::stripIllegalCategoryChars( Utils::sanitizeString( $category ) ) .
-                                               ']]';
+                                               ']]' . PHP_EOL;
                        }
                }
 
@@ -353,12 +355,15 @@
         * @return {string}
         * except for the metadata, the resulting wiki text is filtered
         */
-       protected function getText() {
+       protected function getWikiText() {
                return
-                       $this->_MediawikiTemplate->getTemplate( 
$this->user_options ) . PHP_EOL . PHP_EOL .
+                       '=={{int:filedesc}}==' . PHP_EOL . PHP_EOL .
+                       $this->_MediawikiTemplate->getTemplateAsWikiText( 
$this->user_options ) .
+                       PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL .
+                       
$this->_MediawikiTemplate->getGWToolsetTemplateAsWikiText() .
+                       $this->addMetadata() .
                        $this->addGlobalCategories() .
-                       $this->addItemSpecificCategories() . PHP_EOL . PHP_EOL .
-                       $this->addMetadata();
+                       $this->addItemSpecificCategories();
        }
 
        /**
@@ -457,7 +462,7 @@
                        PHP_EOL .
                        trim( $this->user_options['comment'] );
 
-               $options['text'] = $this->getText();
+               $options['text'] = $this->getWikiText();
 
                WikiChecks::increaseHTTPTimeout();
                $this->validatePageOptions( $options );
diff --git a/includes/Models/MediawikiTemplate.php 
b/includes/Models/MediawikiTemplate.php
index f8fd5c6..7ac921b 100644
--- a/includes/Models/MediawikiTemplate.php
+++ b/includes/Models/MediawikiTemplate.php
@@ -128,10 +128,40 @@
        }
 
        /**
+        * creates wiki text for the GWToolset parameters
+        *
+        * @todo move this into a GWToolsetTemplate model
+        *
+        * @return {string}
+        * the result is sanitized
+        */
+       public function getGWToolsetTemplateAsWikiText() {
+               return
+                       '<!-- GWToolset Template -->' . PHP_EOL .
+                       '{{Uploaded with GWtoolset' . PHP_EOL .
+                       ' | gwtoolset-title-|identifier = ' .
+                                       Utils::sanitizeString(
+                                               
$this->mediawiki_template_array['gwtoolset-title-identifier']
+                                       ) . PHP_EOL .
+                       ' | gwtoolset-url-to-the-media-file = ' .
+                                       Utils::sanitizeString(
+                                               
$this->mediawiki_template_array['gwtoolset-url-to-the-media-file']
+                                       ) . PHP_EOL .
+                       '}}'
+               ;
+
+       }
+
+       /**
         * creates wiki text for a given mediawiki template.
         * creates the mediawiki template section of the template.
         * this does not include categories, raw metadata, or raw
         * mapping information, which are added via other methods.
+        *
+        * @todo move the $parameter['gwtoolset-title-identifier']
+        * and $parameter['gwtoolset-url-to-the-media-file'] out of the
+        * $this->mediawiki_template_array and into their own
+        * gwtoolset_template_array
         *
         * @param {array} $user_options
         * an array of user options that was submitted in the html form
@@ -139,13 +169,15 @@
         * @return {string}
         * the resulting wiki text is filtered
         */
-       public function getTemplate( array &$user_options ) {
+       public function getTemplateAsWikiText( array &$user_options ) {
                $result = '<!-- Mediawiki Template -->' . PHP_EOL;
                $sections = null;
                $template = '{{' . $this->mediawiki_template_name . PHP_EOL . 
'%s}}';
 
                foreach ( $this->mediawiki_template_array as $parameter => 
$content ) {
-                       if ( empty( $content ) ) {
+                       if ( $parameter === 'gwtoolset-title-identifier'
+                               || $parameter === 
'gwtoolset-url-to-the-media-file'
+                       ) {
                                continue;
                        }
 
@@ -445,8 +477,6 @@
 
                $this->mediawiki_template_json = 
$result['mediawiki_template_json'];
                $this->mediawiki_template_array = json_decode( 
$this->mediawiki_template_json, true );
-
-               ksort( $this->mediawiki_template_array );
 
                // add aditional mediawiki template fields that the extension 
needs
                $this->mediawiki_template_array['gwtoolset-title-identifier'] = 
null;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f82c37e8316737c5f8339e2388c1b30143e5204
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GWToolset
Gerrit-Branch: master
Gerrit-Owner: Dan-nl <d_ent...@yahoo.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to