Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/334343 )

Change subject: Fix minor pattern matching issues in 
WikiTextPropertyOrderProvider
......................................................................

Fix minor pattern matching issues in WikiTextPropertyOrderProvider

This patch changes the regular expression from
@^\*\s*(?:\[\[Property:)?(P\d+)@im
to
@^\* *(?:\[\[(?:d:)?Property:)?(P\d+\b)@im

Changes in detail:
* The \s at the start also matched newlines, but should not. This is now
  covered by a test.
* I added the optional interwiki prefix d:. This is relevant for usages
  on client wikis, when they have a local list for sorting their local
  ArticlePlaceholder pages.
* The word separator \b at the end was missing. Relevant in edge-cases
  like "P2P".

Bug: T150788
Change-Id: If1d9d5f13f15254c381d0a013c23401fc78fe328
---
M lib/includes/Store/WikiTextPropertyOrderProvider.php
M lib/tests/phpunit/Store/HttpUrlPropertyOrderProviderTest.php
M lib/tests/phpunit/Store/WikiPagePropertyOrderProviderTest.php
M lib/tests/phpunit/Store/WikiTextPropertyOrderProviderTestHelper.php
4 files changed, 30 insertions(+), 2 deletions(-)


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

diff --git a/lib/includes/Store/WikiTextPropertyOrderProvider.php 
b/lib/includes/Store/WikiTextPropertyOrderProvider.php
index 6cbb662..746189e 100644
--- a/lib/includes/Store/WikiTextPropertyOrderProvider.php
+++ b/lib/includes/Store/WikiTextPropertyOrderProvider.php
@@ -44,7 +44,7 @@
                $pageContent = preg_replace( '@<!--.*?-->@s', '', $pageContent 
);
 
                preg_match_all(
-                       '@^\*\s*(?:\[\[Property:)?(P\d+)@im',
+                       '@^\* *(?:\[\[(?:d:)?Property:)?(P\d+\b)@im',
                        $pageContent,
                        $orderedPropertiesMatches,
                        PREG_PATTERN_ORDER
diff --git a/lib/tests/phpunit/Store/HttpUrlPropertyOrderProviderTest.php 
b/lib/tests/phpunit/Store/HttpUrlPropertyOrderProviderTest.php
index e652035..35cdab5 100644
--- a/lib/tests/phpunit/Store/HttpUrlPropertyOrderProviderTest.php
+++ b/lib/tests/phpunit/Store/HttpUrlPropertyOrderProviderTest.php
@@ -7,6 +7,7 @@
 
 /**
  * @covers Wikibase\Lib\Store\HttpUrlPropertyOrderProvider
+ * @covers Wikibase\Lib\Store\WikiTextPropertyOrderProvider
  *
  * @group Wikibase
  * @group Database
diff --git a/lib/tests/phpunit/Store/WikiPagePropertyOrderProviderTest.php 
b/lib/tests/phpunit/Store/WikiPagePropertyOrderProviderTest.php
index 4f29a0c..fe3647a 100644
--- a/lib/tests/phpunit/Store/WikiPagePropertyOrderProviderTest.php
+++ b/lib/tests/phpunit/Store/WikiPagePropertyOrderProviderTest.php
@@ -10,6 +10,7 @@
 
 /**
  * @covers Wikibase\Lib\Store\WikiPagePropertyOrderProvider
+ * @covers Wikibase\Lib\Store\WikiTextPropertyOrderProvider
  * @group Wikibase
  * @group Database
  *
diff --git 
a/lib/tests/phpunit/Store/WikiTextPropertyOrderProviderTestHelper.php 
b/lib/tests/phpunit/Store/WikiTextPropertyOrderProviderTestHelper.php
index bf33259..2ed5751 100644
--- a/lib/tests/phpunit/Store/WikiTextPropertyOrderProviderTestHelper.php
+++ b/lib/tests/phpunit/Store/WikiTextPropertyOrderProviderTestHelper.php
@@ -13,6 +13,25 @@
 
        public static function provideGetPropertyOrder() {
                return [
+                       'empty page' => [
+                               '',
+                               []
+                       ],
+                       'syntax that is not accepted' => [
+                               "*\nP1\n"
+                               . "* P2P\n"
+                               . "# P3\n"
+                               . " * P4\n"
+                               . "* Property:P5\n"
+                               . "* [[d:P6]]\n"
+                               . "* d:P7\n"
+                               . "* {{p|8}}\n"
+                               . "* {{P|P9}}\n"
+                               . "* {{Q|P10}}\n"
+                               . "* {{P|Q11}}",
+                               []
+                       ],
+
                        'simple match' => [
                                "* P1 \n"
                                . "*P133 \n"
@@ -35,7 +54,7 @@
                                "* P1 \n"
                                . "* P133 \n"
                                . "* P5 Unicorns are all \n"
-                               . "*  very beautiful!"
+                               . "*  very beautiful!\n"
                                . "** This is a subheading",
                                [ 'P1' => 0, 'P133' => 1, 'P5' => 2 ]
                        ],
@@ -46,6 +65,13 @@
                                . "very beautiful!",
                                [ 'P1' => 0, 'P133' => 1, 'P5' => 2 ]
                        ],
+                       'wiki links' => [
+                               "* [[Property:P9]]\n"
+                               . "* [[Property:P8|P1008]]\n"
+                               . "* [[d:Property:P7]]\n"
+                               . "* [[Q6|P1006]]",
+                               [ 'P9' => 0, 'P8' => 1, 'P7' => 2 ]
+                       ],
                ];
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If1d9d5f13f15254c381d0a013c23401fc78fe328
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

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

Reply via email to