jenkins-bot has submitted this change and it was merged.

Change subject: Support autocomments formatting for all entities
......................................................................


Support autocomments formatting for all entities

Bug: T135618
Change-Id: Id90ef676cfd9a11c9ed5ebc99a948495d867da98
---
M repo/Wikibase.hooks.php
M repo/Wikibase.php
M repo/tests/phpunit/includes/SummaryFormatterTest.php
3 files changed, 30 insertions(+), 27 deletions(-)

Approvals:
  Jonas Kress (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index 0c47839..576be14 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -758,8 +758,6 @@
         * Handler for the FormatAutocomments hook, implementing localized 
formatting
         * for machine readable autocomments generated by SummaryFormatter.
         *
-        * @param string[] $data Extra data supplied when registering the hook 
function,
-        *        matches list( $contentModel, $messagePrefix ).
         * @param string &$comment reference to the autocomment text
         * @param bool $pre true if there is content before the autocomment
         * @param string $auto the autocomment unformatted
@@ -769,17 +767,27 @@
         *
         * @return bool
         */
-       public static function onFormat( $data, &$comment, $pre, $auto, $post, 
$title, $local ) {
+       public static function onFormat( &$comment, $pre, $auto, $post, $title, 
$local ) {
                global $wgLang, $wgTitle;
-
-               list( $contentModel, $messagePrefix ) = $data;
 
                // If it is possible to avoid loading the whole page then the 
code will be lighter on the server.
                if ( !( $title instanceof Title ) ) {
                        $title = $wgTitle;
                }
 
-               if ( !( $title instanceof Title ) || $title->getContentModel() 
!== $contentModel ) {
+               if ( !( $title instanceof Title ) ) {
+                       return;
+               }
+
+               $namespaceLookup = 
WikibaseRepo::getDefaultInstance()->getEntityNamespaceLookup();
+
+               $entityType = array_search(
+                       $title->getNamespace(),
+                       $namespaceLookup->getEntityNamespaces(),
+                       true
+               );
+
+               if ( $entityType === false ) {
                        return;
                }
 
@@ -794,7 +802,7 @@
                        StubUserLang::unstub( $wgLang );
                }
 
-               $formatter = new AutoCommentFormatter( $wgLang, array( 
$messagePrefix, 'wikibase-entity' ) );
+               $formatter = new AutoCommentFormatter( $wgLang, [ 'wikibase-' . 
$entityType, 'wikibase-entity' ] );
                $formattedComment = $formatter->formatAutoComment( $auto );
 
                if ( is_string( $formattedComment ) ) {
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index 4f132da..edf5d89 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -226,15 +226,7 @@
        $wgHooks['LinkBegin'][] = 
'Wikibase\Repo\Hooks\LinkBeginHookHandler::onLinkBegin';
        $wgHooks['ChangesListInitRows'][] = 
'Wikibase\Repo\Hooks\LabelPrefetchHookHandlers::onChangesListInitRows';
        $wgHooks['OutputPageBodyAttributes'][] = 
'Wikibase\RepoHooks::onOutputPageBodyAttributes';
-       //FIXME: handle other types of entities with autocomments too!
-       $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['FormatAutocomments'][] = 'Wikibase\RepoHooks::onFormat';
        $wgHooks['PageHistoryLineEnding'][] = 
'Wikibase\RepoHooks::onPageHistoryLineEnding';
        $wgHooks['ApiCheckCanExecute'][] = 
'Wikibase\RepoHooks::onApiCheckCanExecute';
        $wgHooks['SetupAfterCache'][] = 'Wikibase\RepoHooks::onSetupAfterCache';
diff --git a/repo/tests/phpunit/includes/SummaryFormatterTest.php 
b/repo/tests/phpunit/includes/SummaryFormatterTest.php
index f00f9fa..2a5c014 100644
--- a/repo/tests/phpunit/includes/SummaryFormatterTest.php
+++ b/repo/tests/phpunit/includes/SummaryFormatterTest.php
@@ -16,6 +16,7 @@
 use Wikibase\DataModel\Snak\Snak;
 use Wikibase\Lib\SnakFormatter;
 use Wikibase\RepoHooks;
+use Wikibase\Repo\WikibaseRepo;
 use Wikibase\Summary;
 use Wikibase\SummaryFormatter;
 
@@ -446,13 +447,15 @@
         *
         * @dataProvider providerOnFormat
         */
-       public function testOnFormat( $model, $root, $pre, $auto, $post, 
$title, $local, $expected ) {
+       public function testOnFormat( $type, $root, $pre, $auto, $post, $title, 
$local, $expected ) {
                $itemTitle = $this->getMock( $title );
-               $itemTitle->expects( $this->once() )->method( 'getContentModel' 
)->will( $this->returnValue( $model ) );
+               $itemTitle->expects( $this->once() )->method( 'getNamespace' 
)->will( $this->returnValue(
+                       
WikibaseRepo::getDefaultInstance()->getEntityNamespaceLookup()->getEntityNamespace(
 $type )
+               ) );
 
                $comment = null;
 
-               RepoHooks::onFormat( array( $model, $root ), $comment, $pre, 
$auto, $post, $itemTitle, $local );
+               RepoHooks::onFormat( $comment, $pre, $auto, $post, $itemTitle, 
$local );
 
                if ( is_null( $expected ) ) {
                        $this->assertEquals( $expected, $comment, "Didn't find 
the expected null" );
@@ -464,7 +467,7 @@
        public function providerOnFormat() {
                return array( //@todo: test other types of entities too!
                        array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
+                               'item',
                                "wikibase-item",
                                false, '', false,
                                'Title',
@@ -472,7 +475,7 @@
                                null
                        ),
                        array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
+                               'item',
                                "wikibase-item",
                                false, '', false,
                                'Title',
@@ -480,7 +483,7 @@
                                null
                        ),
                        array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
+                               'item',
                                "wikibase-item",
                                true, 'wbeditentity', true,
                                'Title',
@@ -488,7 +491,7 @@
                                '!<span dir="auto"><span 
class="autocomment">.*?: </span></span>!'
                        ),
                        array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
+                               'item',
                                "wikibase-item",
                                true, 'wbsetlabel-set:1|en', true,
                                'Title',
@@ -496,7 +499,7 @@
                                '!<span dir="auto"><span 
class="autocomment">.*?\[en\].*?: </span></span>!'
                        ),
                        array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
+                               'item',
                                "wikibase-item",
                                false, 'wbsetlabel-set:1|<>', false,
                                'Title',
@@ -504,7 +507,7 @@
                                '!<span dir="auto"><span 
class="autocomment">.*?\[&lt;&gt;\].*?</span></span>!'
                        ),
                        array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
+                               'item',
                                "wikibase-item",
                                false, 'wbsetlabel-set:1|&lt;&gt;', false,
                                'Title',
@@ -512,7 +515,7 @@
                                '!<span dir="auto"><span 
class="autocomment">.*?\[&lt;&gt;\].*?</span></span>!'
                        ),
                        array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
+                               'item',
                                "wikibase-item",
                                false, 'wbsetlabel-set:1|&', false,
                                'Title',
@@ -520,7 +523,7 @@
                                '!<span dir="auto"><span 
class="autocomment">.*?\[&amp;\].*?</span></span>!'
                        ),
                        array(
-                               CONTENT_MODEL_WIKIBASE_ITEM,
+                               'item',
                                "wikibase-item",
                                false, 'wbsetlabel-set:1|…', false,
                                'Title',

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id90ef676cfd9a11c9ed5ebc99a948495d867da98
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Heine <[email protected]>
Gerrit-Reviewer: Adrian Heine <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to