Harej has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/340425 )

Change subject: Removing duplicate implementations of 
escape/unescapeForHumanEditable functions
......................................................................

Removing duplicate implementations of escape/unescapeForHumanEditable functions

Change-Id: I03a667fedc638647e5bf2c814d6220c7bb899869
---
M includes/content/CollaborationHubContent.php
M includes/content/CollaborationListContent.php
2 files changed, 14 insertions(+), 53 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit 
refs/changes/25/340425/1

diff --git a/includes/content/CollaborationHubContent.php 
b/includes/content/CollaborationHubContent.php
index 1fb55df..c64666d 100644
--- a/includes/content/CollaborationHubContent.php
+++ b/includes/content/CollaborationHubContent.php
@@ -824,12 +824,12 @@
 
                $out = '';
                foreach ( $this->content as $item ) {
-                       $out .= $this->escapeForHumanEditable( $item['title'] );
+                       $out .= self::escapeForHumanEditable( $item['title'] );
                        if ( isset ( $item['image'] ) ) {
-                               $out .= '|image=' . 
$this->escapeForHumanEditable( $item['image'] );
+                               $out .= '|image=' . 
self::escapeForHumanEditable( $item['image'] );
                        }
                        if ( isset( $item['displayTitle'] ) ) {
-                               $out .= '|display_title=' . 
$this->escapeForHumanEditable( $item['displayTitle'] );
+                               $out .= '|display_title=' . 
self::escapeForHumanEditable( $item['displayTitle'] );
                        }
                        if ( substr( $out, -1 ) === '|' ) {
                                $out = substr( $out, 0, strlen( $out ) - 1 );
@@ -848,7 +848,7 @@
         * @todo Unclear if this is best approach. Alternative might be
         *  to use 
 Or an obscure unicode character like ␊ (U+240A).
         */
-       private function escapeForHumanEditable( $text ) {
+       public static function escapeForHumanEditable( $text ) {
                if ( strpos( $text, '{{!}}' ) !== false ) {
                        // Maybe we should use \| too, but that's not MW like.
                        throw new MWContentSerializationException( "{{!}} in 
content" );
@@ -871,7 +871,7 @@
         * @param string $text
         * @return string Unescaped text
         */
-       private static function unescapeForHumanEditable( $text ) {
+       public static function unescapeForHumanEditable( $text ) {
                $text = strtr( $text, [
                        '\\\\n'=> "\\n",
                        '\n' => "\n",
diff --git a/includes/content/CollaborationListContent.php 
b/includes/content/CollaborationListContent.php
index a3fb1bf..e3f86e7 100644
--- a/includes/content/CollaborationListContent.php
+++ b/includes/content/CollaborationListContent.php
@@ -656,19 +656,19 @@
                        // Use two to separate columns
                        $out .= self::HUMAN_COLUMN_SPLIT;
                        if ( isset( $column->label ) ) {
-                               $out .= $this->escapeForHumanEditable( 
$column->label );
+                               $out .= 
CollaborationHubContent::escapeForHumanEditable( $column->label );
                        } else {
                                $out .= 'column';
                        }
                        if ( isset( $column->notes ) ) {
-                               $out .= '|notes=' . 
$this->escapeForHumanEditable( $column->notes );
+                               $out .= '|notes=' . 
CollaborationHubContent::escapeForHumanEditable( $column->notes );
                        }
                        $out .= self::HUMAN_COLUMN_SPLIT2;
 
                        foreach ( $column->items as $item ) {
-                               $out .= $this->escapeForHumanEditable( 
$item->title );
+                               $out .= 
CollaborationHubContent::escapeForHumanEditable( $item->title );
                                if ( isset ( $item->notes ) ) {
-                                       $out .= '|' . 
$this->escapeForHumanEditable( $item->notes );
+                                       $out .= '|' . 
CollaborationHubContent::escapeForHumanEditable( $item->notes );
                                } else {
                                        $out .= '|';
                                }
@@ -676,19 +676,19 @@
                                        if ( $item->link === false ) {
                                                $out .= '|nolink';
                                        } else {
-                                               $out .= "|link=" . 
$this->escapeForHumanEditable( $item->link );
+                                               $out .= "|link=" . 
CollaborationHubContent::escapeForHumanEditable( $item->link );
                                        }
                                }
                                if ( isset( $item->image ) ) {
                                        if ( $item->image === false ) {
                                                $out .= '|noimage';
                                        } else {
-                                               $out .= '|image=' . 
$this->escapeForHumanEditable( $item->image );
+                                               $out .= '|image=' . 
CollaborationHubContent::escapeForHumanEditable( $item->image );
                                        }
                                }
                                if ( isset( $item->tags ) ) {
                                        foreach ( (array)$item->tags as $tag ) {
-                                               $out .= '|tag=' . 
$this->escapeForHumanEditable( $tag );
+                                               $out .= '|tag=' . 
CollaborationHubContent::escapeForHumanEditable( $tag );
                                        }
                                }
                                if ( substr( $out, -1 ) === '|' ) {
@@ -699,45 +699,6 @@
                        }
                }
                return $out;
-       }
-
-       /**
-        * Escape characters used as separators in human editable mode.
-        *
-        * @param $text
-        * @return string Escaped text
-        * @throws MWContentSerializationException
-        * @todo Unclear if this is best approach. Alternative might be
-        *  to use 
 Or an obscure unicode character like ␊ (U+240A).
-        */
-       private function escapeForHumanEditable( $text ) {
-               if ( strpos( $text, '{{!}}' ) !== false ) {
-                       // Maybe we should use \| too, but that's not MW like.
-                       throw new MWContentSerializationException( "{{!}} in 
content" );
-               }
-               if ( strpos( $text, "\\\n" ) !== false ) {
-                       // @todo We don't currently handle this properly.
-                       throw new MWContentSerializationException( "Line ending 
with a \\" );
-               }
-               $text = strtr( $text, [
-                       "\n" => '\n',
-                       '\n'=> '\\\\n',
-                       '|' => '{{!}}'
-               ] );
-               return $text;
-       }
-
-       /**
-        * @param $text string
-        * @return string
-        */
-       private static function unescapeForHumanEditable( $text ) {
-               $text = strtr( $text, [
-                       '\\\\n'=> "\\n",
-                       '\n' => "\n",
-                       '{{!}}' => '|'
-               ] );
-               return $text;
        }
 
        /**
@@ -824,7 +785,7 @@
 
                $parts = explode( '|', $columnContent[0] );
 
-               $parts = array_map( [ __CLASS__, 'unescapeForHumanEditable' ], 
$parts );
+               $parts = array_map( [ 'CollaborationHubContent', 
'unescapeForHumanEditable' ], $parts );
 
                if ( $parts[0] != 'column' ) {
                        $columnItem['label'] = $parts[0];
@@ -878,7 +839,7 @@
         */
        private static function convertFromHumanEditableItemLine( $line ) {
                $parts = explode( '|', $line );
-               $parts = array_map( [ __CLASS__, 'unescapeForHumanEditable' ], 
$parts );
+               $parts = array_map( [ 'CollaborationHubContent', 
'unescapeForHumanEditable' ], $parts );
                $itemRes = [ 'title' => $parts[0] ];
                if ( count( $parts ) > 1 ) {
                        // If people are using batch editor, they might define 
an image etc. despite lack of a note

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I03a667fedc638647e5bf2c814d6220c7bb899869
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CollaborationKit
Gerrit-Branch: master
Gerrit-Owner: Harej <jamesmh...@gmail.com>

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

Reply via email to