Tobias Gritschacher has uploaded a new change for review.

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


Change subject: Remove unused Autocomment class
......................................................................

Remove unused Autocomment class

Change-Id: I03212dfca8172d5a71b0acc6c8c2739a8fe6cc9b
---
M repo/Wikibase.classes.php
M repo/Wikibase.hooks.php
M repo/Wikibase.php
D repo/includes/Autocomment.php
D repo/tests/phpunit/includes/AutocommentTest.php
5 files changed, 60 insertions(+), 431 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/88/78088/1

diff --git a/repo/Wikibase.classes.php b/repo/Wikibase.classes.php
index 36b6968..038e13b 100644
--- a/repo/Wikibase.classes.php
+++ b/repo/Wikibase.classes.php
@@ -32,7 +32,6 @@
                'Wikibase\RepoHooks' => 'Wikibase.hooks.php',
 
                // includes
-               'Wikibase\Autocomment' => 'includes/Autocomment.php',
                'Wikibase\ClaimSaver' => 'includes/ClaimSaver.php',
                'Wikibase\ClaimSummaryBuilder' => 
'includes/ClaimSummaryBuilder.php',
                'Wikibase\DataTypeSelector' => 'includes/DataTypeSelector.php',
diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index 040d96e..bfc0cd8 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -960,4 +960,62 @@
 
                return false;
        }
+
+       /**
+        * Pretty formatting of autocomments.
+        *
+        * Note that this function does _not_ use $title and $local but
+        * could use them if links should be created that points to something.
+        * Typically this could be links that moves to and highlight some
+        * section within the item itself.
+        *
+        * @param $data
+        * @param string $comment reference to the finalized autocomment
+        * @param string $pre the string before the autocomment
+        * @param string $auto the autocomment unformatted
+        * @param string $post the string after the autocomment
+        * @param \Title $title use for further information
+        * @param boolean $local shall links be generated locally or globally
+        *
+        * @return boolean
+        */
+       public static function onFormat( $data, &$comment, $pre, $auto, $post, 
$title, $local ) {
+               global $wgLang, $wgTitle;
+
+               list( $model, $root ) = $data;
+
+               // If it is possible to avoid loading the whole page then the 
code will be lighter on the server.
+               $title = $title === null ? $wgTitle : $title;
+
+               if ( $title->getContentModel() !== $model ) {
+                       return true;
+               }
+
+               if ( preg_match( '/^([\-a-z]+?)\s*(:\s*(.*?))?\s*$/', $auto, 
$matches ) ) {
+
+                       // turn the args to the message into an array
+                       $args = ( 3 < count( $matches ) ) ? explode( '|', 
$matches[3] ) : array();
+
+                       // look up the message
+                       $msg = wfMessage( $root . '-summary-' . $matches[1] );
+                       if ( !$msg->isDisabled() ) {
+                               // parse the autocomment
+                               $auto = $msg->params( $args )->parse();
+
+                               // add pre and post fragments
+                               if ( $pre ) {
+                                       // written summary $presep autocomment 
(summary /* section */)
+                                       $pre .= wfMessage( 'autocomment-prefix' 
)->escaped();
+                               }
+                               if ( $post ) {
+                                       // autocomment $postsep written summary 
(/* section */ summary)
+                                       $auto .= wfMessage( 'colon-separator' 
)->escaped();
+                               }
+
+                               $auto = '<span class="autocomment">' . $auto . 
'</span>';
+                               $comment = $pre . $wgLang->getDirMark() . 
'<span dir="auto">' . $auto . $post . '</span>';
+                       }
+               }
+               return true;
+       }
 }
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index f6a1d00..a208162 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -168,8 +168,8 @@
        $wgHooks['LinkBegin'][]                                                 
        = 'Wikibase\RepoHooks::onLinkBegin';
        $wgHooks['OutputPageBodyAttributes'][]                          = 
'Wikibase\RepoHooks::onOutputPageBodyAttributes';
        //FIXME: handle other types of entities with autocomments too!
-       $wgHooks['FormatAutocomments'][]                                        
= array( 'Wikibase\Autocomment::onFormat', array( CONTENT_MODEL_WIKIBASE_ITEM, 
"wikibase-item" ) );
-       $wgHooks['FormatAutocomments'][]                                        
= array( 'Wikibase\Autocomment::onFormat', array( 
CONTENT_MODEL_WIKIBASE_PROPERTY, "wikibase-property" ) );
+       $wgHooks['FormatAutocomments'][]                                        
= array( 'Wikibase\RepoHooks::onFormat', array( CONTENT_MODEL_WIKIBASE_ITEM, 
"wikibase-item" ) );
+       $wgHooks['FormatAutocomments'][]                                        
= array( 'Wikibase\RepoHooks::onFormat', array( 
CONTENT_MODEL_WIKIBASE_PROPERTY, "wikibase-property" ) );
        $wgHooks['PageHistoryLineEnding'][]                                     
= 'Wikibase\RepoHooks::onPageHistoryLineEnding';
        $wgHooks['WikibaseRebuildData'][]                                       
= 'Wikibase\RepoHooks::onWikibaseRebuildData';
        $wgHooks['WikibaseDeleteData'][]                                        
= 'Wikibase\RepoHooks::onWikibaseDeleteData';
diff --git a/repo/includes/Autocomment.php b/repo/includes/Autocomment.php
deleted file mode 100644
index 54cebef..0000000
--- a/repo/includes/Autocomment.php
+++ /dev/null
@@ -1,185 +0,0 @@
-<?php
-
-namespace Wikibase;
-/**
- * File defining the handler for autocomments and additional utility functions
- *
- * @since 0.1
- *
- * @file
- * @ingroup WikibaseRepo
- *
- * @licence GNU GPL v2+
- * @author John Erling Blad
- *
- * @deprecated use the Summary class to build summaries instead
- * @note before removing this class once it's phased out, make sure the 
doFormat hook handler
- *       gets rescued to a new location.
- */
-final class Autocomment {
-
-       /**
-        * @see Summary::formatAutoComment
-        *
-        * @since 0.1
-        * @deprecated this is a B/C stub for Summary::formatAutoComment
-        *
-        * @return string
-        */
-       public static function formatAutoComment( $messageKey, array $parts ) {
-               return Summary::formatAutoComment( $messageKey, $parts );
-       }
-
-       /**
-        * @see Summary::formatAutoSummary
-        *
-        * @since 0.1
-        * @deprecated this is a B/C stub for Summary::formatAutoSummary
-        *
-        * @return array
-        */
-       public static function formatAutoSummary( $parts, \Language $lang = 
null ) {
-               global $wgContLang;
-
-               return array(
-                       count( $parts ),
-                       Summary::formatAutoSummary( $parts ),
-                       $lang ? $lang : $wgContLang );
-       }
-
-       /**
-        * @see Summary::formatTotalSummary
-        *
-        * @since 0.1
-        * @deprecated this is a B/C stub for Summary::formatTotalSummary
-        *
-        * @return string
-        */
-       public static function formatTotalSummary( $comment, $summary, $lang = 
false, $length = SUMMARY_MAX_LENGTH ) {
-               return Summary::formatTotalSummary( $comment, $summary, $length 
);
-       }
-
-       /**
-        * Pretty formatting of autocomments.
-        *
-        * Note that this function does _not_ use $title and $local but
-        * could use them if links should be created that points to something.
-        * Typically this could be links that moves to and highlight some
-        * section within the item itself.
-        *
-        * @todo: move this elsewhere, it doesn't really belong in this class
-        *
-        * @param $data
-        * @param string $comment reference to the finalized autocomment
-        * @param string $pre the string before the autocomment
-        * @param string $auto the autocomment unformatted
-        * @param string $post the string after the autocomment
-        * @param \Title $title use for further information
-        * @param boolean $local shall links be generated locally or globally
-        *
-        * @return boolean
-        */
-       public static function onFormat( $data, &$comment, $pre, $auto, $post, 
$title, $local ) {
-               global $wgLang, $wgTitle;
-
-               list( $model, $root ) = $data;
-
-               // If it is possible to avoid loading the whole page then the 
code will be lighter on the server.
-               $title = $title === null ? $wgTitle : $title;
-
-               if ( $title->getContentModel() !== $model ) {
-                       return true;
-               }
-
-               if ( preg_match( '/^([\-a-z]+?)\s*(:\s*(.*?))?\s*$/', $auto, 
$matches ) ) {
-
-                       // turn the args to the message into an array
-                       $args = ( 3 < count( $matches ) ) ? explode( '|', 
$matches[3] ) : array();
-
-                       // look up the message
-                       $msg = wfMessage( $root . '-summary-' . $matches[1] );
-                       if ( !$msg->isDisabled() ) {
-                               // parse the autocomment
-                               $auto = $msg->params( $args )->parse();
-
-                               // add pre and post fragments
-                               if ( $pre ) {
-                                       // written summary $presep autocomment 
(summary /* section */)
-                                       $pre .= wfMessage( 'autocomment-prefix' 
)->escaped();
-                               }
-                               if ( $post ) {
-                                       // autocomment $postsep written summary 
(/* section */ summary)
-                                       $auto .= wfMessage( 'colon-separator' 
)->escaped();
-                               }
-
-                               $auto = '<span class="autocomment">' . $auto . 
'</span>';
-                               $comment = $pre . $wgLang->getDirMark() . 
'<span dir="auto">' . $auto . $post . '</span>';
-                       }
-               }
-               return true;
-       }
-
-       /**
-        * Pick values from a params array and collect them in a array
-        *
-        * This takes a call with a vararg list and reduce that list to the
-        * entries that has values in the params array, possibly also flattening
-        * any arrays.
-        *
-        * @since 0.1
-        *
-        * @param $params array with parameters from the call to the module
-        * @param array|string... $sequence array or variant number of strings
-        * @return array of found items
-        */
-       public static function pickValuesFromParams( array $params ) {
-
-               $sequence = func_get_args();
-               array_shift( $sequence );
-
-               if ( 1 === count( $sequence ) && is_array( $sequence[0] ) ) {
-                       $sequence = $sequence[0];
-               }
-
-               $common = array_intersect_key( array_flip( $sequence ), $params 
);
-               $filtered = array_merge( $common, array_intersect_key( $params, 
$common ) );
-
-               $values = array();
-               foreach ( $filtered as $v ) {
-                       if ( is_string( $v ) && $v !== '' ) {
-                               $values[] = $v;
-                       }
-                       elseif ( is_array( $v ) && $v !== array() ) {
-                               $values = array_merge( $values, $v );
-                       }
-               }
-               return array_unique( $values );
-       }
-
-       /**
-        * Pick keys from a params array and string them together
-        *
-        * This takes a call with a vararg list and reduce that list to the
-        * entries that is also keys in the params array.
-        *
-        * @since 0.1
-        *
-        * @param array $params parameters from the call to the containg module
-        * @param array|string... $sequence array or variant number of strings
-        * @return array of found items
-        */
-       public static function pickKeysFromParams( array $params ) {
-               $sequence = func_get_args();
-               array_shift( $sequence );
-
-               if ( 1 === count( $sequence ) && is_array( $sequence[0] ) ) {
-                       $sequence = $sequence[0];
-               }
-
-               $common = array_filter(
-                       $sequence,
-                       function( $key ) use ( $params ) { return isset( 
$params[$key] ); }
-               );
-               return $common;
-       }
-}
diff --git a/repo/tests/phpunit/includes/AutocommentTest.php 
b/repo/tests/phpunit/includes/AutocommentTest.php
deleted file mode 100644
index d6a3104..0000000
--- a/repo/tests/phpunit/includes/AutocommentTest.php
+++ /dev/null
@@ -1,243 +0,0 @@
-<?php
-
-namespace Wikibase\Test;
-use Wikibase\Autocomment;
-
-/**
- * Test Autocomment.
- *
- * @file
- * @since 0.1
- *
- * @ingroup WikibaseRepoTest
- * @ingroup Test
- *
- * @group Wikibase
- * @group Autocomment
- *
- * @licence GNU GPL v2+
- * @author John Erling Blad < [email protected] >
- *
- */
-class AutocommentTest extends \MediaWikiTestCase {
-
-       /**
-        * @dataProvider providerOnFormat
-        */
-       public function testOnFormat( $model, $root, $pre, $auto, $post, 
$title, $local, $expected ) {
-               $itemTitle = $this->getMock( $title );
-               $itemTitle->expects( $this->once() )->method( 'getContentModel' 
)->will( $this->returnValue( $model ) );
-               $comment = null;
-               Autocomment::onFormat( array($model, $root), $comment, $pre, 
$auto, $post, $itemTitle, $local );
-               if ( is_null( $expected ) ) {
-                       $this->assertEquals( $expected, $comment, "Didn't find 
the expected null" );
-               }
-               else {
-                       $this->assertRegExp( $expected, $comment, "Didn't find 
the expected final comment" );
-               }
-       }
-
-       public static function providerOnFormat() {
-               return array( //@todo: test other types of entities too!
-                       array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
-                               "wikibase-item",
-                               '', '', '',
-                               'Title',
-                               false,
-                               null
-                       ),
-                       array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
-                               "wikibase-item",
-                               'foo', '', 'bar',
-                               'Title',
-                               false,
-                               null
-                       ),
-                       array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
-                               "wikibase-item",
-                               'foo', 'wbeditentity', 'bar',
-                               'Title',
-                               false,
-                               '!foo‎<span dir="auto"><span 
class="autocomment">.*?</span>bar</span>!'
-                       ),
-                       array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
-                               "wikibase-item",
-                               'foo', 'wbsetlabel-set:1|en', 'bar',
-                               'Title',
-                               false,
-                               '!foo‎<span dir="auto"><span 
class="autocomment">.*?\[en\].*?</span>bar</span>!'
-                       ),
-                       array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
-                               "wikibase-item",
-                               'foo', 'wbsetlabel-set:1|<>', 'bar',
-                               'Title',
-                               false,
-                               '!foo‎<span dir="auto"><span 
class="autocomment">.*?\[&lt;&gt;\].*?</span>bar</span>!'
-                       ),
-                       array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
-                               "wikibase-item",
-                               'foo', 'wbsetlabel-set:1|&lt;&gt;', 'bar',
-                               'Title',
-                               false,
-                               '!foo‎<span dir="auto"><span 
class="autocomment">.*?\[&lt;&gt;\].*?</span>bar</span>!'
-                       ),
-                       array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
-                               "wikibase-item",
-                               'foo', 'wbsetlabel-set:1|&', 'bar',
-                               'Title',
-                               false,
-                               '!foo‎<span dir="auto"><span 
class="autocomment">.*?\[&amp;\].*?</span>bar</span>!'
-                       ),
-                       array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
-                               "wikibase-item",
-                               'foo', 'wbsetlabel-set:1|…', 'bar',
-                               'Title',
-                               false,
-                               '!foo‎<span dir="auto"><span 
class="autocomment">.*?\[…\].*?</span>bar</span>!'
-                       )
-               );
-       }
-
-       /**
-        * @dataProvider providerPickValuesFromParams
-        */
-       public function testPickValuesFromParams( array $params, array 
$sequence, array $expected ) {
-               $result = Autocomment::pickValuesFromParams( $params, $sequence 
);
-               $this->assertEquals( $expected, $result, 'Not the expected 
result' );
-       }
-
-       public static function providerPickValuesFromParams() {
-               return array(
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array(),
-                               array()
-                       ),
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array( 'one' ),
-                               array( 'one-value' )
-                       ),
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array( 'one', 'two' ),
-                               array( 'one-value', 'two-value' )
-                       ),
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array( 'one', 'two', 'three' ),
-                               array( 'one-value', 'two-value', 'three-value' )
-                       ),
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array( 'one', 'three', 'four' ),
-                               array( 'one-value', 'three-value' )
-                       ),
-               );
-       }
-
-       /**
-        * @dataProvider providerPickKeysFromParams
-        */
-       public function testPickKeysFromParams( array $params, array $sequence, 
array $expected ) {
-               $result = Autocomment::pickKeysFromParams( $params, $sequence );
-               $this->assertEquals( $expected, $result, 'Not the expected 
result' );
-       }
-
-       public static function providerPickKeysFromParams() {
-               return array(
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array(),
-                               array()
-                       ),
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array( 'one' ),
-                               array( 'one' )
-                       ),
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array( 'one', 'two' ),
-                               array( 'one', 'two' )
-                       ),
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array( 'one', 'two', 'three' ),
-                               array( 'one', 'two', 'three' )
-                       ),
-                       array(
-                               array( 'one' => 'one-value', 'two' => 
'two-value', 'three' => 'three-value' ),
-                               array( 'one', 'three', 'four' ),
-                               array( 'one', 'three' )
-                       ),
-               );
-       }
-
-       /**
-        * @dataProvider providerFormatAutoComment
-        */
-       public function testFormatAutoComment( $msg, $parts, $expected ) {
-               $result = Autocomment::formatAutoComment( $msg, $parts );
-               $this->assertEquals( $expected, $result, 'Not the expected 
result' );
-       }
-
-       public static function providerFormatAutoComment() {
-               return array(
-                       array( '', array(), '' ),
-                       array( 'msgkey', array(), 'msgkey' ),
-                       array( 'msgkey', array( 'one' ), 'msgkey:one' ),
-                       array( 'msgkey', array( 'one', 'two' ), 
'msgkey:one|two' ),
-                       array( 'msgkey', array( 'one', 'two', 'three' ), 
'msgkey:one|two|three' ),
-               );
-       }
-
-       /**
-        * @dataProvider providerFormatAutoSummary
-        */
-       public function testFormatAutoSummary( $parts, $lang, $expected ) {
-               $result = Autocomment::formatAutoSummary( $parts, $lang );
-               $this->assertEquals( $expected, $result, 'Not the expected 
result' );
-       }
-
-       public static function providerFormatAutoSummary() {
-               $lang = \Language::factory( 'en' );
-               return array(
-                       array( array(), $lang, array( 0, '', $lang ) ),
-                       array( array( 'one' ), $lang, array( 1, 'one', $lang ) 
),
-                       array( array( 'one', 'two' ), $lang, array( 2, 'one, 
two', $lang ) ),
-                       array( array( 'one', 'two', 'three' ), $lang, array( 3, 
'one, two, three', $lang ) ),
-               );
-       }
-
-       /**
-        * @dataProvider providerFormatTotalSummary
-        */
-       public function testFormatTotalSummary( $comment, $summary, $lang, 
$expected ) {
-               $result = Autocomment::formatTotalSummary( $comment, $summary, 
$lang );
-               $this->assertEquals( $expected, $result, 'Not the expected 
result' );
-       }
-
-       public static function providerFormatTotalSummary() {
-               $lang = \Language::factory( 'en' );
-               return array(
-                       array( '', '', $lang, '' ),
-                       array( 'foobar', 'This is a test…', $lang, '/* foobar 
*/This is a test…' ),
-                       array( 'foobar:one', 'This is a test…', $lang, '/* 
foobar:one */This is a test…' ),
-                       array( 'foobar:one|two', 'This is a test…', $lang, '/* 
foobar:one|two */This is a test…' ),
-                       array( 'foobar:one|two|three', 'This is a test…', 
$lang, '/* foobar:one|two|three */This is a test…' ),
-                       array( 'foobar:one|two|three|…', 'This is a test…', 
$lang, '/* foobar:one|two|three|… */This is a test…' ),
-                       array( 'foobar:one|two|three|<>', 'This is a test…', 
$lang, '/* foobar:one|two|three|<> */This is a test…' ),
-                       array( 'foobar:one|two|three|&lt;&gt;', 'This is a 
test…', $lang, '/* foobar:one|two|three|&lt;&gt; */This is a test…' ),
-                       array(  '', str_repeat( 'a', 2*SUMMARY_MAX_LENGTH ), 
$lang, str_repeat( 'a', SUMMARY_MAX_LENGTH-3 ) . '...' ),
-               );
-       }
-}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I03212dfca8172d5a71b0acc6c8c2739a8fe6cc9b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Tobias Gritschacher <[email protected]>

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

Reply via email to