[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Document the interpretation of revision row fields.

2018-01-14 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404173 )

Change subject: Document the interpretation of revision row fields.
..

Document the interpretation of revision row fields.

This adds explicit documentation for all the fields used by
RevisionStore in various methods that take a database row object
or an associative array to describe a revision.

Change-Id: Ic85ee9e82c221c0c215759a7a99801f1a9d53245
---
M includes/Revision.php
M includes/Storage/RevisionStore.php
2 files changed, 86 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/73/404173/1

diff --git a/includes/Revision.php b/includes/Revision.php
index 510c1ee..6078a32 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -474,7 +474,8 @@
}
 
/**
-* @param object|array|RevisionRecord $row Either a database row or an 
array
+* @param object|array|RevisionRecord $row Either a database row or an 
array.
+*   See class level documentation of RevisionStore for supported 
fields and their meaning.
 * @param int $queryFlags
 * @param Title|null $title
 *
diff --git a/includes/Storage/RevisionStore.php 
b/includes/Storage/RevisionStore.php
index f8481fe..4e125d4 100644
--- a/includes/Storage/RevisionStore.php
+++ b/includes/Storage/RevisionStore.php
@@ -54,7 +54,80 @@
 use Wikimedia\Rdbms\LoadBalancer;
 
 /**
- * Service for looking up page revisions.
+ * Service for looking up and storing page revisions.
+ * 
+ * Several methods in this class allow the creation of a RevisionRecord from a 
database row object,
+ * or a programmatically constructed array. The following rules apply when 
constructing a
+ * RevisionRecord from a row object: it is expected to be a database row 
object containing fields
+ * from the revision table, the text table, the page table, and possibly other 
auxiliary tables.
+ * Note that if rev_id is not present but ar_user is, the archive table is 
assumed to be used
+ * instead of the revision table, so the ar_* fields are used instead of the 
rev_* fields.
+ *
+ * The following fields are used when constructing a RevisionStoreRecord resp. 
a
+ * RevisionArchiveRecord from a database row:
+ * - rev_id (or ar_rev_id): the revision ID (required).
+ *   May also be used to load a Title if none is passed explicitly.
+ * - rev_page (or ar_page_id): the ID of the page the revision belongs to.
+ *   May be used to load a Title if none is passed explicitly.
+ * - ar_title and ar_namespace: used to construct a Title object of none is 
provided.
+ *   Note that page_title and page_namespace are not used in this way.
+ * - rev_comment (or ar_comment): handled by CommentStore::getCommentLegacy
+ * - rev_comment_* (or ar_comment_*): handled by CommentStore::getCommentLegacy
+ * - comment_*: handled by CommentStore
+ * - rev_user (or ar_user): the name of the user who created the revision.
+ *   (FUTURE: handled by ActorStore::getActorLegacy)
+ * - rev_user_text (or ar_user_text): the name the user who created the 
revision.
+ *   (FUTURE: handled by ActorStore::getActorLegacy)
+ * - rev_actor: (FUTURE) the actor ID of the user who created the revision, 
andled by ActorStore.
+ * - rev_parent_id (or ar_parent_id): The ID of the parent revision.
+ * - rev_minor (or ar_minor): 1 if the edit was marked as minor by the user.
+ * - rev_deleted (or ar_deleted): bitfield indicating what aspect of the 
revision is suppressed.
+ *
+ * The following fields are used when constructing the main slot content from 
a MW 1.29 style
+ * database row:
+ * - rev_id (or ar_id): the revision ID (required)
+ * - rev_text_id (or ar_text_id): a reference to a row in the text table; 
needed unless
+ *   old_text (or ar_text) is present.
+ * - rev_len (or ar_len): the nominal size of the main slot's content.
+ *   Calculated if missing or null.
+ * - rev_sha1 (or ar_sha1): the Base36 encoded SHA1 hash of the slot's content.
+ *   Calculated if missing or null.
+ * - rev_content_model (or ar_content_model): the main slot's content model.
+ *   Derived from the title of not given.
+ * - rev_content_format (or ar_content_format): the main slot's serialization 
format.
+ *   Derived from the model of not given.
+ * - old_text (or ar_text): the main slots content, with any 
encoding/compression/indirection
+ *   indicated by old_flags.
+ * - old_flags (or ar_flags): flags indicating any 
encoding/compression/indirection to be
+ *   undone when loading the main slot's content. Required if old_text/ar_text 
is present!
+ *   Note that the content will be converted according to any legacy encoding 
configured in
+ *   BlobStore unless the "utf-8" flag is present here!
+ *
+ * Code that constructs a revision programmatically has traditionally done so 
by passing an
+ * associative array to the constructor of Revision. New code is encouraged 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add more tests for legacy encoding in RevisionTest

2018-01-14 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404152 )

Change subject: Add more tests for legacy encoding in RevisionTest
..

Add more tests for legacy encoding in RevisionTest

These are the tests that would have ensured proper handling
of the legacy encoding during refactoring.

Bug: T184749
Change-Id: I5e009de55b72f832e3117c8c0bebb4a0484dc7e1
---
M tests/phpunit/includes/RevisionTest.php
1 file changed, 119 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/52/404152/1

diff --git a/tests/phpunit/includes/RevisionTest.php 
b/tests/phpunit/includes/RevisionTest.php
index 73d69a5..b371947 100644
--- a/tests/phpunit/includes/RevisionTest.php
+++ b/tests/phpunit/includes/RevisionTest.php
@@ -91,6 +91,45 @@
MediaWiki\restoreWarnings();
}
 
+   /**
+* @covers Revision::__construct
+* @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+*/
+   public function testConstructFromArray_LegacyEncoding_ignored() {
+   $blobStore = $this->getBlobStore();
+   $blobStore->setLegacyEncoding( 'iso-8859-1', Language::factory( 
'fr' ) );
+   $this->setService( 'BlobStoreFactory', 
$this->mockBlobStoreFactory( $blobStore ) );
+
+   $title = $this->getMockTitle();
+
+   // if 'flags' is not set, 'text' is assumed to be raw, with no 
conversion needed.
+   $array = [ 'text' => "Wiki est l'\xc3\xa9cole superieur !" ];
+   $rev = new Revision( $array, 0, $title );
+   $this->assertSame( "Wiki est l'\xc3\xa9cole superieur !", 
$rev->getContent()->serialize() );
+
+   // 'utf-8' in flags means "do not apply legacy encoding"
+   $array = [ 'text' => "Wiki est l'\xc3\xa9cole superieur !", 
'flags' => 'utf-8' ];
+   $rev = new Revision( $array, 0, $title );
+   $this->assertSame( "Wiki est l'\xc3\xa9cole superieur !", 
$rev->getContent()->serialize() );
+   }
+
+   /**
+* @covers Revision::__construct
+* @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+*/
+   public function testConstructFromArray_LegacyEncoding_applied() {
+   $blobStore = $this->getBlobStore();
+   $blobStore->setLegacyEncoding( 'iso-8859-1', Language::factory( 
'fr' ) );
+   $this->setService( 'BlobStoreFactory', 
$this->mockBlobStoreFactory( $blobStore ) );
+
+   $title = $this->getMockTitle();
+
+   // empty 'flags' field means "apply legacy encoding"!
+   $array = [ 'text' => "Wiki est l'\xe9cole superieur !", 'flags' 
=> '' ];
+   $rev = new Revision( $array, 0, $title );
+   $this->assertSame( "Wiki est l'\xc3\xa9cole superieur !", 
$rev->getContent()->serialize() );
+   }
+
public function provideConstructFromArray_userSetAsExpected() {
yield 'no user defaults to wgUser' => [
[
@@ -317,18 +356,93 @@
 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
 */
public function testConstructFromRowWithBadPageId() {
+   $row = [ 'rev_page' =>  ];
+
MediaWiki\suppressWarnings();
-   $rev = new Revision( (object)[ 'rev_page' =>  ] );
+   $rev = new Revision( $this->makeRow( $row ) );
$this->assertSame( , $rev->getPage() );
MediaWiki\restoreWarnings();
}
 
+   /**
+* @covers Revision::__construct
+* @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+*/
+   public function testConstructFromRow_LegacyEncoding_ignored() {
+   $blobStore = $this->getBlobStore();
+   $blobStore->setLegacyEncoding( 'iso-8859-1', Language::factory( 
'fr' ) );
+   $this->setService( 'BlobStoreFactory', 
$this->mockBlobStoreFactory( $blobStore ) );
+
+   $title = $this->getMockTitle();
+
+   // 'utf-8' in flags means "do not apply legacy encoding"
+   $row = [ 'old_text' => "Wiki est l'\xc3\xa9cole superieur !", 
'old_flags' => 'utf-8' ];
+   $rev = new Revision( $this->makeRow( $row ), 0, $title );
+   $this->assertSame( "Wiki est l'\xc3\xa9cole superieur !", 
$rev->getContent()->serialize() );
+   }
+
+   /**
+* @covers Revision::__construct
+* @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+*/
+   public function testConstructFromRow_LegacyEncoding_applied() {
+   $blobStore = $this->getBlobStore();
+   $blobStore->setLegacyEncoding( 'iso-8859-1', Language::factory( 
'fr' ) );
+   $this->setService( 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add tests for legacy encoding when constructing RevisionRecords

2018-01-12 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/403926 )

Change subject: Add tests for legacy encoding when constructing RevisionRecords
..

Add tests for legacy encoding when constructing RevisionRecords

Change-Id: I49265a394b0780a48fecbf037477d2bb39195e89
---
M tests/phpunit/includes/Storage/RevisionStoreTest.php
1 file changed, 106 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/26/403926/1

diff --git a/tests/phpunit/includes/Storage/RevisionStoreTest.php 
b/tests/phpunit/includes/Storage/RevisionStoreTest.php
index 2cdd316..0255e3b 100644
--- a/tests/phpunit/includes/Storage/RevisionStoreTest.php
+++ b/tests/phpunit/includes/Storage/RevisionStoreTest.php
@@ -2,10 +2,13 @@
 
 namespace MediaWiki\Tests\Storage;
 
+use HashBagOStuff;
+use Language;
 use MediaWiki\Storage\RevisionAccessException;
 use MediaWiki\Storage\RevisionStore;
 use MediaWiki\Storage\SqlBlobStore;
 use MediaWikiTestCase;
+use Title;
 use WANObjectCache;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\LoadBalancer;
@@ -421,6 +424,108 @@
$store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
}
 
-   // FIXME: test getRevisionSizes
+
+   public function provideNewRevisionFromRow_legacyEncoding_applied() {
+   yield 'windows-1252, old_flags is empty' => [
+   'windows-1252',
+   'en',
+   [
+   'old_flags' => '',
+   'old_text' => "S\xF6me Content",
+   ],
+   'Söme Content'
+   ];
+
+   yield 'windows-1252, old_flags is null' => [
+   'windows-1252',
+   'en',
+   [
+   'old_flags' => null,
+   'old_text' => "S\xF6me Content",
+   ],
+   'Söme Content'
+   ];
+   }
+
+   /**
+* @dataProvider provideNewRevisionFromRow_legacyEncoding_applied
+*
+* @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow
+* @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow_1_29
+*/
+   public function testNewRevisionFromRow_legacyEncoding_applied( 
$encoding, $locale, $row, $text ) {
+   $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] 
);
+
+   $blobStore = new SqlBlobStore( wfGetLB(), $cache );
+   $blobStore->setLegacyEncoding( $encoding, Language::factory( 
$locale ) );
+
+   $store = new RevisionStore( wfGetLB(), $blobStore, $cache );
+
+   $record = $store->newRevisionFromRow(
+   $this->makeRow( $row ),
+   0,
+   Title::newFromText( __METHOD__ . '-UTPage' )
+   );
+
+   $this->assertSame( $text, $record->getContent( 'main' 
)->serialize() );
+   }
+
+   /**
+* @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow
+* @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow_1_29
+*/
+   public function testNewRevisionFromRow_legacyEncoding_ignored() {
+   $row = [
+   'old_flags' => 'utf-8',
+   'old_text' => 'Söme Content',
+   ];
+
+   $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] 
);
+
+   $blobStore = new SqlBlobStore( wfGetLB(), $cache );
+   $blobStore->setLegacyEncoding( 'windows-1252', 
Language::factory( 'en' ) );
+
+   $store = new RevisionStore( wfGetLB(), $blobStore, $cache );
+
+   $record = $store->newRevisionFromRow(
+   $this->makeRow( $row ),
+   0,
+   Title::newFromText( __METHOD__ . '-UTPage' )
+   );
+   $this->assertSame( 'Söme Content', $record->getContent( 'main' 
)->serialize() );
+   }
+
+   private function makeRow( array $array ) {
+   $row = $array + [
+   'rev_id' => 7,
+   'rev_page' => 5,
+   'rev_text_id' => 11,
+   'rev_timestamp' => '2011010100',
+   'rev_user_text' => 'Tester',
+   'rev_user' => 17,
+   'rev_minor_edit' => 0,
+   'rev_deleted' => 0,
+   'rev_len' => 100,
+   'rev_parent_id' => 0,
+   'rev_sha1' => 'deadbeef',
+   'rev_comment_text' => 'Testing',
+   'rev_comment_data' => '{}',

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Document expandBlob behavior when no flags are given.

2018-01-12 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/403922 )

Change subject: Document expandBlob behavior when no flags are given.
..

Document expandBlob behavior when no flags are given.

Bug: T184749
Change-Id: I5f1f029d928a7bc25877b0eae9f3822ec321b24a
---
M includes/Storage/RevisionStore.php
M includes/Storage/SqlBlobStore.php
2 files changed, 11 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/22/403922/1

diff --git a/includes/Storage/RevisionStore.php 
b/includes/Storage/RevisionStore.php
index bca4a4d..246f33a 100644
--- a/includes/Storage/RevisionStore.php
+++ b/includes/Storage/RevisionStore.php
@@ -798,7 +798,8 @@
 * @param SlotRecord $slot The SlotRecord to load content for
 * @param string|null $blobData The content blob, in the form indicated 
by $blobFlags
 * @param string|null $blobFlags Flags indicating how $blobData needs 
to be processed.
-*  null if no processing should happen.
+*Use null if no processing should happen. That is in constrast 
to the empty string,
+*which causes the blob to be decoded according to the 
configured legacy encoding.
 * @param string|null $blobFormat MIME type indicating how $dataBlob is 
encoded
 * @param int $queryFlags
 *
@@ -819,6 +820,7 @@
$cacheKey = $slot->hasAddress() ? $slot->getAddress() : 
null;
 
if ( $blobFlags === null ) {
+   // No blob flags, so use the blob verbatim.
$data = $blobData;
} else {
$data = $this->blobStore->expandBlob( 
$blobData, $blobFlags, $cacheKey );
diff --git a/includes/Storage/SqlBlobStore.php 
b/includes/Storage/SqlBlobStore.php
index 5ddbd34..b270844 100644
--- a/includes/Storage/SqlBlobStore.php
+++ b/includes/Storage/SqlBlobStore.php
@@ -365,6 +365,8 @@
 *May be the blob itself, or the blob compressed, or just the 
address
 *of the actual blob, depending on $flags.
 * @param string|string[] $flags Blob flags, such as 'external' or 
'gzip'.
+*   Note that not including 'utf-8' in $flags will cause the data to 
be decoded
+*   according to the legacy encoding specified via setLegacyEncoding.
 * @param string|null $cacheKey May be used for caching if given
 *
 * @return false|string The expanded blob or false on failure
@@ -427,7 +429,8 @@
$blobFlags = [];
 
// Revisions not marked as UTF-8 will have legacy decoding 
applied by decompressData().
-   // XXX: if $this->legacyEncoding is not set, we could skip 
this. May be risky, though.
+   // XXX: if $this->legacyEncoding is not set, we could skip 
this. That would however be
+   // risky, since $this->legacyEncoding being set in the future 
would lead to data corruption.
$blobFlags[] = 'utf-8';
 
if ( $this->compressBlobs ) {
@@ -456,11 +459,13 @@
 * @todo make this private, there should be no need to use this method 
outside this class.
 *
 * @param mixed $blob Reference to a text
-* @param array $blobFlags Compression flags
+* @param array $blobFlags Compression flags, such as 'gzip'.
+*   Note that not including 'utf-8' in $blobFlags will cause the data 
to be decoded
+*   according to the legacy encoding specified via setLegacyEncoding.
 *
 * @return string|bool Decompressed text, or false on failure
 */
-   public function decompressData( $blob, $blobFlags ) {
+   public function decompressData( $blob, array $blobFlags ) {
if ( $blob === false ) {
// Text failed to be fetched; nothing to do
return false;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5f1f029d928a7bc25877b0eae9f3822ec321b24a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make Revision::__construct work with bad page ID

2018-01-11 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/403682 )

Change subject: Make Revision::__construct work with bad page ID
..

Make Revision::__construct work with bad page ID

For backwards-copatibility, we need to be able to construct a Revision
object even for bad page IDs.

Bug: T184689
Change-Id: I18c823d7b72504447982364d581b34e98924b67f
---
M includes/Revision.php
M includes/Storage/RevisionStore.php
M tests/phpunit/includes/RevisionTest.php
3 files changed, 64 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/82/403682/1

diff --git a/includes/Revision.php b/includes/Revision.php
index 0844e89..c08a50e 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -495,13 +495,13 @@
$this->mRecord = 
self::getRevisionStore()->newMutableRevisionFromArray(
$row,
$queryFlags,
-   $title
+   $this->ensureTitle( $row, $queryFlags, $title )
);
} elseif ( is_object( $row ) ) {
$this->mRecord = 
self::getRevisionStore()->newRevisionFromRow(
$row,
$queryFlags,
-   $title
+   $this->ensureTitle( $row, $queryFlags, $title )
);
} else {
throw new InvalidArgumentException(
@@ -511,6 +511,43 @@
}
 
/**
+* Make sure we have *some* Title object for use by the constructor.
+* For B/C, the constructor shouldn't fail even for a bad page ID or 
bad revision ID.
+*
+* @param array|object $row
+* @param int $queryFlags
+* @param Title|null $title
+*
+* @return Title $title if not null, or a Title constructed from 
information in $row.
+*/
+   private function ensureTitle( $row, $queryFlags, $title = null ) {
+   if ( $title ) {
+   return $title;
+   }
+
+   if ( is_array( $row ) ) {
+   $pageId = isset( $row['page'] ) ? $row['page'] : 0;
+   $revId = isset( $row['id'] ) ? $row['id'] : 0;
+   } else {
+   $pageId = isset( $row->rev_page ) ? $row->rev_page : 0;
+   $revId = isset( $row->rev_id ) ? $row->rev_id : 0;
+   }
+
+   try {
+   $title = self::getRevisionStore()->getTitle( $pageId, 
$revId, $queryFlags );
+   } catch ( RevisionAccessException $ex ) {
+   // construct a dummy title!
+   wfLogWarning( __METHOD__ . ': ' . $ex->getMessage() );
+
+   // NOTE: this Title will only be used inside 
RevisionRecord
+   $title = Title::makeTitleSafe( NS_SPECIAL, 
"Badtitle/ID=$pageId" );
+   $title->resetArticleID( $pageId );
+   }
+
+   return $title;
+   }
+
+   /**
 * @return RevisionRecord
 */
public function getRevisionRecord() {
diff --git a/includes/Storage/RevisionStore.php 
b/includes/Storage/RevisionStore.php
index 78e789e..6c8cac9 100644
--- a/includes/Storage/RevisionStore.php
+++ b/includes/Storage/RevisionStore.php
@@ -164,6 +164,8 @@
 *
 * MCR migration note: this corresponds to Revision::getTitle
 *
+* @note this method should be private, external use should be avoided!
+*
 * @param int|null $pageId
 * @param int|null $revId
 * @param int $queryFlags
@@ -171,7 +173,7 @@
 * @return Title
 * @throws RevisionAccessException
 */
-   private function getTitle( $pageId, $revId, $queryFlags = 0 ) {
+   public function getTitle( $pageId, $revId, $queryFlags = 0 ) {
if ( !$pageId && !$revId ) {
throw new InvalidArgumentException( '$pageId and $revId 
cannot both be 0 or null' );
}
diff --git a/tests/phpunit/includes/RevisionTest.php 
b/tests/phpunit/includes/RevisionTest.php
index 0db76ff..7ce43ed 100644
--- a/tests/phpunit/includes/RevisionTest.php
+++ b/tests/phpunit/includes/RevisionTest.php
@@ -76,6 +76,17 @@
$this->assertNull( $rev->getContent(), 'no content object 
should be available' );
}
 
+   /**
+* @covers Revision::__construct
+* @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+*/
+   public function testConstructFromArrayWithBadPageId() {
+   MediaWiki\suppressWarnings();
+   $rev = new Revision( [ 'page' =>  ] );
+   $this->assertSame( , 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Revision::newNullRevision should return null for bad page ID.

2018-01-11 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/403638 )

Change subject: Revision::newNullRevision should return null for bad page ID.
..

Revision::newNullRevision should return null for bad page ID.

Bug: T184687
Change-Id: I893d71999f034f84bf067dedacb821a74374ea7c
---
M includes/Revision.php
M tests/phpunit/includes/RevisionDbTestBase.php
2 files changed, 16 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/38/403638/1

diff --git a/includes/Revision.php b/includes/Revision.php
index 0844e89..f62e811 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -1066,6 +1066,12 @@
$comment = CommentStoreComment::newUnsavedComment( $summary, 
null );
 
$title = Title::newFromID( $pageId );
+
+   if ( !$title ) {
+   // page not found
+   return null;
+   }
+
$rec = self::getRevisionStore()->newNullRevision( $dbw, $title, 
$comment, $minor, $user );
 
return new Revision( $rec );
diff --git a/tests/phpunit/includes/RevisionDbTestBase.php 
b/tests/phpunit/includes/RevisionDbTestBase.php
index 6139524..427a95e 100644
--- a/tests/phpunit/includes/RevisionDbTestBase.php
+++ b/tests/phpunit/includes/RevisionDbTestBase.php
@@ -620,6 +620,16 @@
}
 
/**
+* @covers Revision::newNullRevision
+*/
+   public function testNewNullRevision_badPage() {
+   $dbw = wfGetDB( DB_MASTER );
+   $rev = Revision::newNullRevision( $dbw, -1, 'a null revision', 
false );
+
+   $this->assertNull( $rev );
+   }
+
+   /**
 * @covers Revision::insertOn
 */
public function testInsertOn() {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I893d71999f034f84bf067dedacb821a74374ea7c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Handle failure to load content in Revision getSize, etc

2018-01-11 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/403634 )

Change subject: Handle failure to load content in Revision getSize, etc
..

Handle failure to load content in Revision getSize, etc

The Revision class used to just return null if size or hsash were unknown
and could nto be determined. This patch restores this behavior by
catching any RevisionAccessExceptions raised by RevisionRecord when
failing to load content.

Bug: T184693
Bug: T184690
Change-Id: I393ea19b9fb48219583fc65ce81ea14d8d0a2357
---
M includes/Revision.php
M includes/Storage/RevisionArchiveRecord.php
M includes/Storage/RevisionRecord.php
M includes/Storage/RevisionStoreRecord.php
M tests/phpunit/includes/RevisionTest.php
5 files changed, 102 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/34/403634/1

diff --git a/includes/Revision.php b/includes/Revision.php
index 0844e89..6db3710 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -608,20 +608,27 @@
/**
 * Returns the length of the text in this revision, or null if unknown.
 *
-* @return int
+* @return int|null
 */
public function getSize() {
-   return $this->mRecord->getSize();
+   try {
+   return $this->mRecord->getSize();
+   } catch ( RevisionAccessException $ex ) {
+   return null;
+   }
}
 
/**
 * Returns the base36 sha1 of the content in this revision, or null if 
unknown.
 *
-* @return string
+* @return string|null
 */
public function getSha1() {
-   // XXX: we may want to drop all the hashing logic, it's not 
worth the overhead.
-   return $this->mRecord->getSha1();
+   try {
+   return $this->mRecord->getSha1();
+   } catch ( RevisionAccessException $ex ) {
+   return null;
+   }
}
 
/**
diff --git a/includes/Storage/RevisionArchiveRecord.php 
b/includes/Storage/RevisionArchiveRecord.php
index 419cb95..3e78b72 100644
--- a/includes/Storage/RevisionArchiveRecord.php
+++ b/includes/Storage/RevisionArchiveRecord.php
@@ -107,6 +107,7 @@
}
 
/**
+* @throw RevisionAccessException if the size was unknown and could not 
be calculated.
 * @return int The nominal revision size, never null. May be computed 
on the fly.
 */
public function getSize() {
@@ -120,6 +121,7 @@
}
 
/**
+* @throw RevisionAccessException if the hash was unknown and could not 
be calculated.
 * @return string The revision hash, never null. May be computed on the 
fly.
 */
public function getSha1() {
diff --git a/includes/Storage/RevisionRecord.php 
b/includes/Storage/RevisionRecord.php
index f490f9b..161075d 100644
--- a/includes/Storage/RevisionRecord.php
+++ b/includes/Storage/RevisionRecord.php
@@ -242,6 +242,7 @@
 *
 * MCR migration note: this replaces Revision::getSize
 *
+* @throw RevisionAccessException if the size was unknown and could not 
be calculated.
 * @return int
 */
abstract public function getSize();
@@ -254,6 +255,7 @@
 *
 * MCR migration note: this replaces Revision::getSha1
 *
+* @throw RevisionAccessException if the hash was unknown and could not 
be calculated.
 * @return string
 */
abstract public function getSha1();
diff --git a/includes/Storage/RevisionStoreRecord.php 
b/includes/Storage/RevisionStoreRecord.php
index 341855d..d605bae 100644
--- a/includes/Storage/RevisionStoreRecord.php
+++ b/includes/Storage/RevisionStoreRecord.php
@@ -150,6 +150,7 @@
}
 
/**
+* @throw RevisionAccessException if the size was unknown and could not 
be calculated.
 * @return string The nominal revision size, never null. May be 
computed on the fly.
 */
public function getSize() {
@@ -163,6 +164,7 @@
}
 
/**
+* @throw RevisionAccessException if the hash was unknown and could not 
be calculated.
 * @return string The revision hash, never null. May be computed on the 
fly.
 */
public function getSha1() {
diff --git a/tests/phpunit/includes/RevisionTest.php 
b/tests/phpunit/includes/RevisionTest.php
index 0db76ff..c8f552a 100644
--- a/tests/phpunit/includes/RevisionTest.php
+++ b/tests/phpunit/includes/RevisionTest.php
@@ -1,7 +1,11 @@
 getMockTitle();
+
+   $rec = new MutableRevisionRecord( $title );
+   $rev = new Revision( $rec, 0, $title );
+
+   $this->assertSame( 0, $rev->getSize(), 'Size of no slots is 0' 
);
+
+   $rec->setSize( 13 );
+   

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Specify encoding expected by DatabaseDomain::newFromId.

2018-01-08 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/402903 )

Change subject: Specify encoding expected by DatabaseDomain::newFromId.
..

Specify encoding expected by DatabaseDomain::newFromId.

Alternative to I45a151a332

Bug: T183914
Change-Id: I647e7bd6dcb3f63c912c8ebb0fd187ff4fd37b45
---
M includes/Storage/RevisionStore.php
M includes/libs/rdbms/database/DatabaseDomain.php
M includes/libs/rdbms/loadbalancer/ILoadBalancer.php
M tests/phpunit/includes/Storage/RevisionStoreDbTest.php
4 files changed, 57 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/03/402903/1

diff --git a/includes/Storage/RevisionStore.php 
b/includes/Storage/RevisionStore.php
index 3101aea..484d1aa 100644
--- a/includes/Storage/RevisionStore.php
+++ b/includes/Storage/RevisionStore.php
@@ -74,6 +74,11 @@
private $wikiId;
 
/**
+* @var null|string
+*/
+   private $dbDomainId;
+
+   /**
 * @var boolean
 */
private $contentHandlerUseDB = true;
@@ -94,7 +99,7 @@
 * @param LoadBalancer $loadBalancer
 * @param SqlBlobStore $blobStore
 * @param WANObjectCache $cache
-* @param bool|string $wikiId
+* @param bool|string $wikiId A wiki database domain, as expected by 
LoadBalancer::getConnection.
 */
public function __construct(
LoadBalancer $loadBalancer,
@@ -268,7 +273,7 @@
 */
public function insertRevisionOn( RevisionRecord $rev, IDatabase $dbw ) 
{
// TODO: pass in a DBTransactionContext instead of a database 
connection.
-   $this->checkDatabaseWikiId( $dbw );
+   $this->checkDatabaseDomain( $dbw );
 
if ( !$rev->getSlotRoles() ) {
throw new InvalidArgumentException( 'At least one slot 
needs to be defined!' );
@@ -507,7 +512,7 @@
$minor,
User $user
) {
-   $this->checkDatabaseWikiId( $dbw );
+   $this->checkDatabaseDomain( $dbw );
 
$fields = [ 'page_latest', 'page_namespace', 'page_title',
'rev_id', 'rev_text_id', 'rev_len', 'rev_sha1' ];
@@ -1462,31 +1467,27 @@
}
 
/**
+* Determines the database domain ID this RevisionStore is bound to.
+*
+* @return string
+*/
+   private function getDomainID() {
+   if ( !$this->dbDomainId ) {
+   $this->dbDomainId = $this->getDBConnectionRef( 
DB_REPLICA )->getDomainID();
+   }
+   return $this->dbDomainId;
+   }
+
+   /**
 * Throws an exception if the given database connection does not belong 
to the wiki this
 * RevisionStore is bound to.
 *
 * @param IDatabase $db
 * @throws MWException
 */
-   private function checkDatabaseWikiId( IDatabase $db ) {
-   $storeWiki = $this->wikiId;
+   private function checkDatabaseDomain( IDatabase $db ) {
+   $storeWiki = $this->getDomainID();
$dbWiki = $db->getDomainID();
-
-   if ( $dbWiki === $storeWiki ) {
-   return;
-   }
-
-   // XXX: we really want the default database ID...
-   $storeWiki = $storeWiki ?: wfWikiID();
-   $dbWiki = $dbWiki ?: wfWikiID();
-
-   if ( $dbWiki === $storeWiki ) {
-   return;
-   }
-
-   // HACK: counteract encoding imposed by DatabaseDomain
-   $storeWiki = str_replace( '?h', '-', $storeWiki );
-   $dbWiki = str_replace( '?h', '-', $dbWiki );
 
if ( $dbWiki === $storeWiki ) {
return;
@@ -1509,7 +1510,7 @@
 * @return object|false data row as a raw object
 */
private function fetchRevisionRowFromConds( IDatabase $db, $conditions, 
$flags = 0 ) {
-   $this->checkDatabaseWikiId( $db );
+   $this->checkDatabaseDomain( $db );
 
$revQuery = self::getQueryInfo( [ 'page', 'user' ] );
$options = [];
@@ -1680,7 +1681,7 @@
 * of the corresponding revision.
 */
public function listRevisionSizes( IDatabase $db, array $revIds ) {
-   $this->checkDatabaseWikiId( $db );
+   $this->checkDatabaseDomain( $db );
 
$revLens = [];
if ( !$revIds ) {
@@ -1749,7 +1750,7 @@
 * @return int
 */
private function getPreviousRevisionId( IDatabase $db, RevisionRecord 
$rev ) {
-   $this->checkDatabaseWikiId( $db );
+   $this->checkDatabaseDomain( $db );
 
if ( $rev->getPageId() === null ) {
return 0;
@@ -1805,7 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Fix dropping of temp tables on SQLite and PG.

2018-01-06 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/402573 )

Change subject: Fix dropping of temp tables on SQLite and PG.
..

Fix dropping of temp tables on SQLite and PG.

Also addresses other compatibility issues with PG mentioned
in comments on I7a4071072.

Bug: T184333
Change-Id: I478aa1aee15fdef99630c65a37b1af5f3f8cce14
---
M tests/phpunit/MediaWikiTestCase.php
M tests/phpunit/tests/MediaWikiTestCaseSchemaTest.sql
2 files changed, 4 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/73/402573/1

diff --git a/tests/phpunit/MediaWikiTestCase.php 
b/tests/phpunit/MediaWikiTestCase.php
index 10f5d41..08e4562 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -1393,9 +1393,8 @@
$this->ensureMockDatabaseConnection( $db );
 
foreach ( $tables as $tbl ) {
-   $tmp = self::$useTemporaryTables ? ' TEMPORARY ' : '';
$tbl = $db->tableName( $tbl );
-   $db->query( "DROP $tmp TABLE IF EXISTS $tbl", 
__METHOD__ );
+   $db->query( "DROP TABLE IF EXISTS $tbl", __METHOD__ );
 
if ( $tbl === 'page' ) {
// Forget about the pages since they don't
diff --git a/tests/phpunit/tests/MediaWikiTestCaseSchemaTest.sql 
b/tests/phpunit/tests/MediaWikiTestCaseSchemaTest.sql
index e5ef5c6..43e8e9b 100644
--- a/tests/phpunit/tests/MediaWikiTestCaseSchemaTest.sql
+++ b/tests/phpunit/tests/MediaWikiTestCaseSchemaTest.sql
@@ -5,9 +5,9 @@
 ) /*$wgDBTableOptions*/;
 
 CREATE TABLE /*_*/imagelinks (
-  il_from int(10) unsigned NOT NULL DEFAULT 0,
-  il_from_namespace int(11) NOT NULL DEFAULT 0,
-  il_to varbinary(255) NOT NULL DEFAULT '',
+  il_from int NOT NULL DEFAULT 0,
+  il_from_namespace int NOT NULL DEFAULT 0,
+  il_to varchar(255) NOT NULL DEFAULT '',
   il_frobniz varchar(255) NOT NULL DEFAULT 'FROB',
   PRIMARY KEY (il_from,il_to)
 ) /*$wgDBTableOptions*/;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I478aa1aee15fdef99630c65a37b1af5f3f8cce14
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Simplify logic for replica selection with groups

2018-01-02 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/401594 )

Change subject: Simplify logic for replica selection with groups
..

Simplify logic for replica selection with groups

Change-Id: I835a25235b88f54eb5e8d4f0afb0df5d55bcc8b9
---
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
1 file changed, 18 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/94/401594/1

diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php 
b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
index daa70a4..716a660 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
@@ -627,6 +627,15 @@
return $ok;
}
 
+   /**
+* @param int $i
+* @param array $groups
+* @param bool $domain
+* @param int $flags
+*
+* @return bool|null|Database|DBNoWriteWrapper|IDatabase
+* @throws DBConnectionError
+*/
public function getConnection( $i, $groups = [], $domain = false, 
$flags = 0 ) {
$requestedIndex = $i;
 
@@ -639,17 +648,18 @@
$domain = false; // local connection requested
}
 
-   $groups = ( $groups === false || $groups === [] )
-   ? [ false ] // check one "group": the generic pool
-   : (array)$groups;
-
$masterOnly = ( $i == self::DB_MASTER || $i == 
$this->getWriterIndex() );
$oldConnsOpened = $this->connsOpened; // connections open now
+
+   $this->mLastError = 'Unknown error'; // reset error string
 
if ( $i == self::DB_MASTER ) {
$i = $this->getWriterIndex();
} elseif ( $i == self::DB_REPLICA ) {
-   # Try to find an available server in any the query 
groups (in order)
+   $groups = (array)$groups;
+   $groups[] = false; // always check the default group.
+
+   // Try to find an available server in any the query 
groups (in order)
foreach ( $groups as $group ) {
$groupIndex = $this->getReaderIndex( $group, 
$domain );
if ( $groupIndex !== false ) {
@@ -657,18 +667,11 @@
break;
}
}
-   }
 
-   # Operation-based index
-   if ( $i == self::DB_REPLICA ) {
-   $this->mLastError = 'Unknown error'; // reset error 
string
-   # Try the general server pool if $groups are 
unavailable.
-   $i = ( $groups === [ false ] )
-   ? false // don't bother with this if that is 
what was tried above
-   : $this->getReaderIndex( false, $domain );
-   # Couldn't find a working server in getReaderIndex()?
-   if ( $i === false ) {
+   // nothing found!
+   if ( $i == self::DB_REPLICA ) {
$this->mLastError = 'No working replica DB 
server: ' . $this->mLastError;
+
// Throw an exception
$this->reportConnectionError();
return null; // not reached

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I835a25235b88f54eb5e8d4f0afb0df5d55bcc8b9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add test for LoadBalancer::getConenction with groups.

2018-01-02 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/401591 )

Change subject: Add test for LoadBalancer::getConenction with groups.
..

Add test for LoadBalancer::getConenction with groups.

Change-Id: I37b0dfb6b356b4a6397b721de9ba88c76d2abbeb
---
M tests/phpunit/includes/db/LoadBalancerTest.php
1 file changed, 83 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/91/401591/1

diff --git a/tests/phpunit/includes/db/LoadBalancerTest.php 
b/tests/phpunit/includes/db/LoadBalancerTest.php
index 9b82c54..9a148ae 100644
--- a/tests/phpunit/includes/db/LoadBalancerTest.php
+++ b/tests/phpunit/includes/db/LoadBalancerTest.php
@@ -133,6 +133,11 @@
$this->assertTrue( $dbr->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on replica" );
$this->assertWriteForbidden( $dbr );
 
+   $db1 = $lb->getConnection( $lb->getReaderIndex() );
+   $this->assertSame( $dbr, $db1, 'getReaderIndex() is equivalent 
to DB_REPLICA' );
+   $this->assertTrue( $db1->getLBInfo( 'replica' ), 'Reader shows 
as replica' );
+   $this->assertWriteForbidden( $db1 );
+
$dbwAuto = $lb->getConnection( DB_MASTER, [], false, 
$lb::CONN_TRX_AUTO );
$this->assertFalse( $dbwAuto->getFlag( $dbw::DBO_TRX ), "No 
DBO_TRX with CONN_TRX_AUTO" );
$this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX 
still set on master" );
@@ -149,6 +154,84 @@
$lb->closeAll();
}
 
+   public function testWithGroups() {
+   global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, 
$wgDBtype, $wgSQLiteDataDir;
+
+   $servers = [
+   [ // master
+   'host'=> $wgDBserver,
+   'dbname'  => $wgDBname,
+   'user'=> $wgDBuser,
+   'password'=> $wgDBpassword,
+   'type'=> $wgDBtype,
+   'dbDirectory' => $wgSQLiteDataDir,
+   'load'=> 0,
+   'flags'   => DBO_TRX, // REPEATABLE-READ 
for consistency
+   'test-name'   => 'master',
+   ],
+   [ // emulated replica for default group
+   'host'=> $wgDBserver,
+   'dbname'  => $wgDBname,
+   'user'=> $wgDBuser,
+   'password'=> $wgDBpassword,
+   'type'=> $wgDBtype,
+   'dbDirectory' => $wgSQLiteDataDir,
+   'load'=> 100,
+   'groupLoads'  => [ 'foo' => 0 ],
+   'test-name'   => 'def-replica',
+   ],
+   [ // emulated replica in foo group
+   'host'=> $wgDBserver,
+   'dbname'  => $wgDBname,
+   'user'=> $wgDBuser,
+   'password'=> $wgDBpassword,
+   'type'=> $wgDBtype,
+   'dbDirectory' => $wgSQLiteDataDir,
+   'load'=> 0,
+   'groupLoads'  => [ 'foo' => 100 ],
+   'test-name'   => 'foo-replica',
+   ]
+   ];
+
+   $lb = new LoadBalancer( [
+   'servers' => $servers,
+   'localDomain' => wfWikiID(),
+   'loadMonitorClass' => 'LoadMonitorNull'
+   ] );
+
+   $db = $lb->getConnection( DB_MASTER );
+   $this->assertSame( 'master', $db->getLBInfo( 'test-name' ), 
'DB_MASTER gets master' );
+
+   $db = $lb->getConnection( $lb->getWriterIndex() );
+   $this->assertSame( 'master', $db->getLBInfo( 'test-name' ), 
'getWriterIndex get master' );
+
+   $db = $lb->getConnection( DB_REPLICA );
+   $this->assertSame( 'def-replica', $db->getLBInfo( 'test-name' 
), 'DB_REPLICA get replica' );
+
+   $db = $lb->getConnection( $lb->getReaderIndex() );
+   $this->assertSame( 'def-replica', $db->getLBInfo( 'test-name' 
), 'getReaderIndex get replica' );
+
+   $db = $lb->getConnection( DB_MASTER, [ 'foo' ] );
+   $this->assertSame( 'master', $db->getLBInfo( 'test-name' ), 
'DB_MASTER ignores group' );
+
+   $db = $lb->getConnection( $lb->getWriterIndex(), [ 'foo' ] );
+   $this->assertSame( 'master', $db->getLBInfo( 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Hint against IDatabase in EntityUsageTableTest

2018-01-02 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/401557 )

Change subject: Hint against IDatabase in EntityUsageTableTest
..

Hint against IDatabase in EntityUsageTableTest

Change-Id: I465fb2a8e82c18a4a684c7a12dec2cab65a54908
---
M client/tests/phpunit/includes/Usage/Sql/EntityUsageTableTest.php
1 file changed, 2 insertions(+), 2 deletions(-)


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

diff --git a/client/tests/phpunit/includes/Usage/Sql/EntityUsageTableTest.php 
b/client/tests/phpunit/includes/Usage/Sql/EntityUsageTableTest.php
index 7c0402a..f27d54d 100644
--- a/client/tests/phpunit/includes/Usage/Sql/EntityUsageTableTest.php
+++ b/client/tests/phpunit/includes/Usage/Sql/EntityUsageTableTest.php
@@ -8,7 +8,7 @@
 use Wikibase\Client\Usage\Sql\EntityUsageTable;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\Entity\ItemIdParser;
-use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\IDatabase;
 
 /**
  * @covers Wikibase\Client\Usage\Sql\EntityUsageTable
@@ -352,7 +352,7 @@
 *
 * @return bool
 */
-   private function rowExists( Database $db, array $conditions ) {
+   private function rowExists( IDatabase $db, array $conditions ) {
$count = $db->selectRowCount( 
EntityUsageTable::DEFAULT_TABLE_NAME, '*', $conditions );
return $count > 0;
}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I465fb2a8e82c18a4a684c7a12dec2cab65a54908
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Fix accidental reference to IDatabase in docs.

2018-01-02 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/401556 )

Change subject: Fix accidental reference to IDatabase in docs.
..

Fix accidental reference to IDatabase in docs.

Change-Id: If8097e711c279e76c9a3763310f3830e846707c0
---
M client/includes/UpdateRepo/UpdateRepoOnMove.php
1 file changed, 1 insertion(+), 1 deletion(-)


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

diff --git a/client/includes/UpdateRepo/UpdateRepoOnMove.php 
b/client/includes/UpdateRepo/UpdateRepoOnMove.php
index 5798e88..992a298 100644
--- a/client/includes/UpdateRepo/UpdateRepoOnMove.php
+++ b/client/includes/UpdateRepo/UpdateRepoOnMove.php
@@ -20,7 +20,7 @@
private $newTitle;
 
/**
-* @param string $repoDB IDatabase name of the repo
+* @param string $repoDB Database name of the repo
 * @param SiteLinkLookup $siteLinkLookup
 * @param User $user
 * @param string $siteId Global id of the client wiki

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If8097e711c279e76c9a3763310f3830e846707c0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Hint against IDatabase instead of the Database base class.

2018-01-02 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/401524 )

Change subject: Hint against IDatabase instead of the Database base class.
..

Hint against IDatabase instead of the Database base class.

Change-Id: Ic05b606c3c9b855bd45a8203f510b9d5991a27d4
---
M client/includes/Specials/SpecialUnconnectedPages.php
M client/includes/UpdateRepo/UpdateRepo.php
M client/includes/UpdateRepo/UpdateRepoOnMove.php
M client/includes/Usage/Sql/EntityUsageTable.php
M client/includes/Usage/Sql/EntityUsageTableBuilder.php
M client/includes/Usage/Sql/SqlSubscriptionManager.php
M client/includes/Usage/Sql/SqlUsageTracker.php
M lib/includes/Store/Sql/SiteLinkTable.php
M lib/includes/Store/Sql/TermSqlIndex.php
M repo/includes/Store/SiteLinkConflictLookup.php
M repo/includes/Store/Sql/ChangesSubscriptionTableBuilder.php
M repo/includes/Store/Sql/DatabaseSchemaUpdater.php
M repo/includes/Store/Sql/LockManagerSqlChangeDispatchCoordinator.php
M repo/includes/Store/Sql/SqlChangeDispatchCoordinator.php
M repo/includes/Store/Sql/SqlIdGenerator.php
M repo/includes/Store/Sql/SqlSiteLinkConflictLookup.php
M repo/includes/Store/Sql/SqlSubscriptionLookup.php
M repo/includes/Store/Sql/TermSearchKeyBuilder.php
18 files changed, 80 insertions(+), 80 deletions(-)


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

diff --git a/client/includes/Specials/SpecialUnconnectedPages.php 
b/client/includes/Specials/SpecialUnconnectedPages.php
index d5766b6..7f8a0a1 100644
--- a/client/includes/Specials/SpecialUnconnectedPages.php
+++ b/client/includes/Specials/SpecialUnconnectedPages.php
@@ -9,7 +9,7 @@
 use Title;
 use Wikibase\Client\WikibaseClient;
 use Wikibase\Client\NamespaceChecker;
-use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\FakeResultWrapper;
 use Wikimedia\Rdbms\ResultWrapper;
 
@@ -83,13 +83,13 @@
/**
 * Build conditionals for namespace
 *
-* @param Database $dbr
+* @param IDatabase $dbr
 * @param Title|null $title
 * @param NamespaceChecker|null $checker
 *
 * @return string[]
 */
-   public function buildConditionals( Database $dbr, Title $title = null, 
NamespaceChecker $checker = null ) {
+   public function buildConditionals( IDatabase $dbr, Title $title = null, 
NamespaceChecker $checker = null ) {
$conds = [];
 
if ( $checker === null ) {
diff --git a/client/includes/UpdateRepo/UpdateRepo.php 
b/client/includes/UpdateRepo/UpdateRepo.php
index edb3968..978259d 100644
--- a/client/includes/UpdateRepo/UpdateRepo.php
+++ b/client/includes/UpdateRepo/UpdateRepo.php
@@ -51,7 +51,7 @@
private $entityId = false;
 
/**
-* @param string $repoDB Database name of the repo
+* @param string $repoDB IDatabase name of the repo
 * @param SiteLinkLookup $siteLinkLookup
 * @param User $user
 * @param string $siteId Global id of the client wiki
diff --git a/client/includes/UpdateRepo/UpdateRepoOnMove.php 
b/client/includes/UpdateRepo/UpdateRepoOnMove.php
index 992a298..5798e88 100644
--- a/client/includes/UpdateRepo/UpdateRepoOnMove.php
+++ b/client/includes/UpdateRepo/UpdateRepoOnMove.php
@@ -20,7 +20,7 @@
private $newTitle;
 
/**
-* @param string $repoDB Database name of the repo
+* @param string $repoDB IDatabase name of the repo
 * @param SiteLinkLookup $siteLinkLookup
 * @param User $user
 * @param string $siteId Global id of the client wiki
diff --git a/client/includes/Usage/Sql/EntityUsageTable.php 
b/client/includes/Usage/Sql/EntityUsageTable.php
index 59a80df..769af95 100644
--- a/client/includes/Usage/Sql/EntityUsageTable.php
+++ b/client/includes/Usage/Sql/EntityUsageTable.php
@@ -11,7 +11,7 @@
 use Wikibase\Client\Usage\PageEntityUsages;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityIdParser;
-use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\DBUnexpectedError;
 use Wikimedia\Rdbms\LBFactory;
 
@@ -41,12 +41,12 @@
private $idParser;
 
/**
-* @var Database
+* @var IDatabase
 */
private $writeConnection;
 
/**
-* @var Database
+* @var IDatabase
 */
private $readConnection;
 
@@ -67,7 +67,7 @@
 
/**
 * @param EntityIdParser $idParser
-* @param Database $writeConnection
+* @param IDatabase $writeConnection
 * @param int $batchSize Batch size for database queries on the entity 
usage table, including
 *  INSERTs, SELECTs, and DELETEs. Defaults to 100.
 * @param string|null $tableName defaults to wbc_entity_usage
@@ -76,7 +76,7 @@
 */
public function __construct(
EntityIdParser $idParser,
-  

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: getConnection( getWriterIndex() ) should return master conne...

2018-01-02 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/401520 )

Change subject: getConnection( getWriterIndex() ) should return master 
connection.
..

getConnection( getWriterIndex() ) should return master connection.

Change-Id: I48ea3cbb5da27b8d2b1908eae8bc0b208b166b45
---
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
M tests/phpunit/includes/db/LoadBalancerTest.php
2 files changed, 6 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/20/401520/1

diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php 
b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
index 1bb627c..daa70a4 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
@@ -648,7 +648,7 @@
 
if ( $i == self::DB_MASTER ) {
$i = $this->getWriterIndex();
-   } else {
+   } elseif ( $i == self::DB_REPLICA ) {
# Try to find an available server in any the query 
groups (in order)
foreach ( $groups as $group ) {
$groupIndex = $this->getReaderIndex( $group, 
$domain );
diff --git a/tests/phpunit/includes/db/LoadBalancerTest.php 
b/tests/phpunit/includes/db/LoadBalancerTest.php
index 17aa994..9b82c54 100644
--- a/tests/phpunit/includes/db/LoadBalancerTest.php
+++ b/tests/phpunit/includes/db/LoadBalancerTest.php
@@ -118,6 +118,11 @@
$this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on master" );
$this->assertWriteAllowed( $dbw );
 
+   $db0 = $lb->getConnection( $lb->getWriterIndex() );
+   $this->assertSame( $dbw, $db0, 'getWriterIndex() is equivalent 
to DB_MASTER' );
+   $this->assertTrue( $db0->getLBInfo( 'master' ), 'Writer shows 
as master' );
+   $this->assertWriteAllowed( $db0 );
+
$dbr = $lb->getConnection( DB_REPLICA );
$this->assertNotSame( $dbw, $dbr, 'Replica connection is not 
master connection' );
$this->assertTrue( $dbr->getLBInfo( 'replica' ), 'replica shows 
as replica' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I48ea3cbb5da27b8d2b1908eae8bc0b208b166b45
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Introduce DBConnectionProxy base class.

2018-01-02 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/401507 )

Change subject: Introduce DBConnectionProxy base class.
..

Introduce DBConnectionProxy base class.

DBConnectionProxy is intended to act as a base class for IDatabase
implementations that delegate to an underlying IDatabase instance.

Change-Id: Ia6a3bfe2fbef2bed94ed87798f4158cb32a9ea35
---
M autoload.php
M includes/libs/rdbms/database/DBConnRef.php
A includes/libs/rdbms/database/DBConnectionProxy.php
3 files changed, 649 insertions(+), 568 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/07/401507/1

diff --git a/autoload.php b/autoload.php
index 4a8e18d..a225ad1 100644
--- a/autoload.php
+++ b/autoload.php
@@ -1657,6 +1657,7 @@
'Wikimedia\\Rdbms\\DBAccessError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBAccessError.php',
'Wikimedia\\Rdbms\\DBConnRef' => __DIR__ . 
'/includes/libs/rdbms/database/DBConnRef.php',
'Wikimedia\\Rdbms\\DBConnectionError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBConnectionError.php',
+   'Wikimedia\\Rdbms\\DBConnectionProxy' => __DIR__ . 
'/includes/libs/rdbms/database/DBConnectionProxy.php',
'Wikimedia\\Rdbms\\DBError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBError.php',
'Wikimedia\\Rdbms\\DBExpectedError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBExpectedError.php',
'Wikimedia\\Rdbms\\DBMasterPos' => __DIR__ . 
'/includes/libs/rdbms/database/position/DBMasterPos.php',
diff --git a/includes/libs/rdbms/database/DBConnRef.php 
b/includes/libs/rdbms/database/DBConnRef.php
index ef2953e..445980f 100644
--- a/includes/libs/rdbms/database/DBConnRef.php
+++ b/includes/libs/rdbms/database/DBConnRef.php
@@ -12,13 +12,12 @@
  * @ingroup Database
  * @since 1.22
  */
-class DBConnRef implements IDatabase {
+class DBConnRef extends DBConnectionProxy {
/** @var ILoadBalancer */
private $lb;
-   /** @var Database|null Live connection handle */
-   private $conn;
+
/** @var array|null N-tuple of (server index, group, 
DatabaseDomain|string) */
-   private $params;
+   private $params = null;
 
const FLD_INDEX = 0;
const FLD_GROUP = 1;
@@ -27,597 +26,58 @@
 
/**
 * @param ILoadBalancer $lb Connection manager for $conn
-* @param Database|array $conn Database handle or (server index, query 
groups, domain, flags)
+* @param IDatabase|array $conn Database handle or (server index, query 
groups, domain, flags)
 */
public function __construct( ILoadBalancer $lb, $conn ) {
$this->lb = $lb;
-   if ( $conn instanceof Database ) {
-   $this->conn = $conn; // live handle
+
+   if ( $conn instanceof IDatabase ) {
+   parent::__construct( $conn );
} elseif ( count( $conn ) >= 4 && $conn[self::FLD_DOMAIN] !== 
false ) {
$this->params = $conn;
+
+   $instantiator = function () {
+   list( $db, $groups, $wiki, $flags ) = 
$this->params;
+   return $this->lb->getConnection( $db, $groups, 
$wiki, $flags );
+   };
+
+   parent::__construct( $instantiator );
} else {
throw new InvalidArgumentException( "Missing lazy 
connection arguments." );
}
}
 
-   function __call( $name, array $arguments ) {
-   if ( $this->conn === null ) {
-   list( $db, $groups, $wiki, $flags ) = $this->params;
-   $this->conn = $this->lb->getConnection( $db, $groups, 
$wiki, $flags );
-   }
-
-   return call_user_func_array( [ $this->conn, $name ], $arguments 
);
-   }
-
-   public function getServerInfo() {
-   return $this->__call( __FUNCTION__, func_get_args() );
-   }
-
-   public function bufferResults( $buffer = null ) {
-   return $this->__call( __FUNCTION__, func_get_args() );
-   }
-
-   public function trxLevel() {
-   return $this->__call( __FUNCTION__, func_get_args() );
-   }
-
-   public function trxTimestamp() {
-   return $this->__call( __FUNCTION__, func_get_args() );
-   }
-
-   public function explicitTrxActive() {
-   return $this->__call( __FUNCTION__, func_get_args() );
-   }
-
-   public function tablePrefix( $prefix = null ) {
-   return $this->__call( __FUNCTION__, func_get_args() );
-   }
-
-   public function dbSchema( $schema = null ) {
-   return $this->__call( __FUNCTION__, func_get_args() );
-   }
-
-   public function getLBInfo( $name = null ) {
-   return $this->__call( __FUNCTION__, 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add test for DBConnRef

2018-01-02 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/401505 )

Change subject: Add test for DBConnRef
..

Add test for DBConnRef

Change-Id: I510b2ed22b3866392592a5df53aa0f3ff6aab750
---
A tests/phpunit/includes/libs/rdbms/database/DBConnRefTest.php
1 file changed, 146 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/05/401505/1

diff --git a/tests/phpunit/includes/libs/rdbms/database/DBConnRefTest.php 
b/tests/phpunit/includes/libs/rdbms/database/DBConnRefTest.php
new file mode 100644
index 000..e660265
--- /dev/null
+++ b/tests/phpunit/includes/libs/rdbms/database/DBConnRefTest.php
@@ -0,0 +1,146 @@
+getMock( ILoadBalancer::class );
+
+   $lb->method( 'getConnection' )->willReturnCallback(
+   function () {
+   return $this->getDatabaseMock();
+   }
+   );
+
+   $lb->method( 'getConnectionRef' )->willReturnCallback(
+   function () use ( $lb ) {
+   return $this->getDBConnRef( $lb );
+   }
+   );
+
+   return $lb;
+   }
+
+   /**
+* @return IDatabase
+*/
+   private function getDatabaseMock() {
+   $db = $this->getMockBuilder( Database::class )
+   ->disableOriginalConstructor()
+   ->getMock();
+
+   $db->method( 'select' )->willReturn( new FakeResultWrapper( [] 
) );
+   $db->method( '__toString' )->willReturn( 'MOCK_DB' );
+
+   return $db;
+   }
+
+   /**
+* @return IDatabase
+*/
+   private function getDBConnRef( ILoadBalancer $lb = null ) {
+   $lb = $lb ?: $this->getLoadBalancerMock();
+   return new DBConnRef( $lb, $this->getDatabaseMock() );
+   }
+
+   public function testConstruct() {
+   $lb = $this->getLoadBalancerMock();
+   $ref = new DBConnRef( $lb, $this->getDatabaseMock() );
+
+   $this->assertInstanceOf( ResultWrapper::class, $ref->select( 
'whatever', '*' ) );
+   }
+
+   public function testConstruct_params() {
+   $lb = $this->getMock( ILoadBalancer::class );
+
+   $lb->expects( $this->once() )
+   ->method( 'getConnection' )
+   ->with( DB_MASTER, [ 'test' ], 'dummy', 
ILoadBalancer::CONN_TRX_AUTO )
+   ->willReturnCallback(
+   function () {
+   return $this->getDatabaseMock();
+   }
+   );
+
+   $ref = new DBConnRef(
+   $lb,
+   [ DB_MASTER, [ 'test' ], 'dummy', 
ILoadBalancer::CONN_TRX_AUTO ]
+   );
+
+   $this->assertInstanceOf( ResultWrapper::class, $ref->select( 
'whatever', '*' ) );
+   }
+
+   public function testDestruct() {
+   $lb = $this->getLoadBalancerMock();
+
+   $lb->expects( $this->once() )
+   ->method( 'reuseConnection' );
+
+   $this->innerMethodForTestDestruct( $lb );
+   }
+
+   private function innerMethodForTestDestruct( ILoadBalancer $lb ) {
+   $ref = $lb->getConnectionRef( DB_REPLICA );
+
+   $this->assertInstanceOf( ResultWrapper::class, $ref->select( 
'whatever', '*' ) );
+   }
+
+   public function testConstruct_failure() {
+   $this->setExpectedException( InvalidArgumentException::class, 
'' );
+
+   $lb = $this->getLoadBalancerMock();
+   new DBConnRef( $lb, 17 ); // bad constructor argument
+   }
+
+   public function testGetWikiID() {
+   $lb = $this->getMock( ILoadBalancer::class );
+
+   // getWikiID is optimized to not create a connection
+   $lb->expects( $this->never() )
+   ->method( 'getConnection' );
+
+   $ref = new DBConnRef( $lb, [ DB_REPLICA, [], 'dummy', 0 ] );
+
+   $this->assertSame( 'dummy', $ref->getWikiID() );
+   }
+
+   public function testGetDomainID() {
+   $lb = $this->getMock( ILoadBalancer::class );
+
+   // getDomainID is optimized to not create a connection
+   $lb->expects( $this->never() )
+   ->method( 'getConnection' );
+
+   $ref = new DBConnRef( $lb, [ DB_REPLICA, [], 'dummy', 0 ] );
+
+   $this->assertSame( 'dummy', $ref->getDomainID() );
+   }
+
+   public function testSelect() {
+   // select should get passed through normally
+   $ref = $this->getDBConnRef();
+   $this->assertInstanceOf( ResultWrapper::class, $ref->select( 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Improve documentation and method naming on Revision and Revi...

2018-01-02 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/400411 )

Change subject: Improve documentation and method naming on Revision and 
RevisionStore.
..

Improve documentation and method naming on Revision and RevisionStore.

Change-Id: I3b049acff9313814a4ac448289d1aef88cb7f9df
---
M includes/Revision.php
M includes/Storage/RevisionStore.php
M tests/phpunit/includes/Storage/RevisionStoreDbTest.php
M tests/phpunit/includes/Storage/RevisionStoreTest.php
4 files changed, 42 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/11/400411/2

diff --git a/includes/Revision.php b/includes/Revision.php
index 8f36e88..d6c4caa 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -214,8 +214,9 @@
 *
 * MCR migration note: replaced by RevisionStore::newRevisionFromRow(). 
Note that
 * newFromRow() also accepts arrays, while newRevisionFromRow() does 
not. Instead,
-* a MutableRevisionRecord should be constructed directly. 
RevisionStore::newRevisionFromArray()
-* can be used as a temporary replacement, but should be avoided.
+* a MutableRevisionRecord should be constructed directly.
+* RevisionStore::newMutableRevisionFromArray() can be used as a 
temporary replacement,
+* but should be avoided.
 *
 * @param object|array $row
 * @return Revision
@@ -285,7 +286,8 @@
 * WARNING: Timestamps may in some circumstances not be unique,
 * so this isn't the best key to use.
 *
-* @deprecated since 1.31, use 
RevisionStore::loadRevisionFromTimestamp() instead.
+* @deprecated since 1.31, use RevisionStore::getRevisionByTimestamp()
+*   or RevisionStore::loadRevisionFromTimestamp() instead.
 *
 * @param IDatabase $db
 * @param Title $title
@@ -293,7 +295,6 @@
 * @return Revision|null
 */
public static function loadFromTimestamp( $db, $title, $timestamp ) {
-   // XXX: replace loadRevisionFromTimestamp by 
getRevisionByTimestamp?
$rec = self::getRevisionStore()->loadRevisionFromTimestamp( 
$db, $title, $timestamp );
return $rec === null ? null : new Revision( $rec );
}
@@ -482,6 +483,9 @@
 
/**
 * Do a batched query to get the parent revision lengths
+*
+* @deprecated use RevisionStore::getRevisionSizes instead.
+*
 * @param IDatabase $db
 * @param array $revIds
 * @return array
@@ -503,6 +507,8 @@
if ( $row instanceof RevisionRecord ) {
$this->mRecord = $row;
} elseif ( is_array( $row ) ) {
+   // If no user is specified, fall back to using the 
global user object, to stay
+   // compatible with pre-1.31 behavior.
if ( !isset( $row['user'] ) && !isset( 
$row['user_text'] ) ) {
$row['user'] = $wgUser;
}
@@ -794,7 +800,7 @@
 * @return int Rcid of the unpatrolled row, zero if there isn't one
 */
public function isUnpatrolled() {
-   return self::getRevisionStore()->isUnpatrolled( $this->mRecord 
);
+   return self::getRevisionStore()->getRcIdIfUnpatrolled( 
$this->mRecord );
}
 
/**
diff --git a/includes/Storage/RevisionStore.php 
b/includes/Storage/RevisionStore.php
index 44dab13..254ca70 100644
--- a/includes/Storage/RevisionStore.php
+++ b/includes/Storage/RevisionStore.php
@@ -562,9 +562,11 @@
/**
 * MCR migration note: this replaces Revision::isUnpatrolled
 *
+* @todo This is overly specific, so move or kill this method.
+*
 * @return int Rcid of the unpatrolled row, zero if there isn't one
 */
-   public function isUnpatrolled( RevisionRecord $rev ) {
+   public function getRcIdIfUnpatrolled( RevisionRecord $rev ) {
$rc = $this->getRecentChange( $rev );
if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == 0 ) {
return $rc->getAttribute( 'rc_id' );
@@ -953,7 +955,7 @@
 * @param string $timestamp
 * @return RevisionRecord|null
 */
-   public function getRevisionFromTimestamp( $title, $timestamp ) {
+   public function getRevisionByTimestamp( $title, $timestamp ) {
return $this->newRevisionFromConds(
[
'rev_timestamp' => $timestamp,
@@ -1651,6 +1653,22 @@
 * @return int[] associative array mapping revision IDs from $revIds to 
the nominal size
 * of the corresponding revision.
 */
+   public function getRevisionSizes( array $revIds ) {
+   return 

[MediaWiki-commits] [Gerrit] mediawiki...Echo[master]: Typehint against IDatabase, nto DatabaseBase

2017-12-21 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399679 )

Change subject: Typehint against IDatabase, nto DatabaseBase
..

Typehint against IDatabase, nto DatabaseBase

Change-Id: Ia94fcae2a1dd28761b4e2f40fa1491f8401ad491
---
M tests/phpunit/EchoDbFactoryTest.php
1 file changed, 6 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/79/399679/1

diff --git a/tests/phpunit/EchoDbFactoryTest.php 
b/tests/phpunit/EchoDbFactoryTest.php
index dc5379c..9180f84 100644
--- a/tests/phpunit/EchoDbFactoryTest.php
+++ b/tests/phpunit/EchoDbFactoryTest.php
@@ -1,5 +1,8 @@
 assertInstanceOf( 'DatabaseBase', $db->getEchoDb( 
DB_MASTER ) );
-   $this->assertInstanceOf( 'DatabaseBase', $db->getEchoDb( 
DB_REPLICA ) );
+   $this->assertInstanceOf( IDatabase::class, $db->getEchoDb( 
DB_MASTER ) );
+   $this->assertInstanceOf( IDatabase::class, $db->getEchoDb( 
DB_REPLICA ) );
}
 
/**
@@ -24,7 +27,7 @@
$reflection = new ReflectionClass( 'MWEchoDbFactory' );
$method = $reflection->getMethod( 'getLB' );
$method->setAccessible( true );
-   $this->assertInstanceOf( 'LoadBalancer', $method->invoke( $db ) 
);
+   $this->assertInstanceOf( ILoadBalancer::class, $method->invoke( 
$db ) );
}
 
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia94fcae2a1dd28761b4e2f40fa1491f8401ad491
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Typehint against IDatabase, not plain Database

2017-12-21 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399678 )

Change subject: Typehint against IDatabase, not plain Database
..

Typehint against IDatabase, not plain Database

Change-Id: Ifcb5aabc880f187fa6ecdc40a19fdbcc5a9b58ac
---
M lib/includes/Store/Sql/WikiPageEntityMetaDataLookup.php
1 file changed, 3 insertions(+), 3 deletions(-)


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

diff --git a/lib/includes/Store/Sql/WikiPageEntityMetaDataLookup.php 
b/lib/includes/Store/Sql/WikiPageEntityMetaDataLookup.php
index 0b3c4b5..d393f90 100644
--- a/lib/includes/Store/Sql/WikiPageEntityMetaDataLookup.php
+++ b/lib/includes/Store/Sql/WikiPageEntityMetaDataLookup.php
@@ -9,7 +9,7 @@
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\Lib\Store\EntityNamespaceLookup;
 use Wikibase\Lib\Store\EntityRevisionLookup;
-use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\DBQueryError;
 use Wikimedia\Rdbms\ResultWrapper;
 
@@ -267,11 +267,11 @@
 
/**
 * @param EntityId[] $entityIds
-* @param Database $db
+* @param IDatabase $db
 *
 * @return string
 */
-   private function getWhere( array $entityIds, Database $db ) {
+   private function getWhere( array $entityIds, IDatabase $db ) {
$where = [];
 
foreach ( $entityIds as $entityId ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifcb5aabc880f187fa6ecdc40a19fdbcc5a9b58ac
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Flow[master]: Use IDatabase instead of DatabaseBase

2017-12-21 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399663 )

Change subject: Use IDatabase instead of DatabaseBase
..

Use IDatabase instead of DatabaseBase

Change-Id: Ibe9aa42a28c308dd04f41e6bd48fd97e20a27f65
---
M includes/BoardMover.php
M includes/Data/Storage/DbStorage.php
M includes/Data/Storage/RevisionStorage.php
M includes/DbFactory.php
M includes/Dump/Exporter.php
M includes/Import/Converter.php
M includes/Import/LiquidThreadsApi/ConversionStrategy.php
M includes/Import/LiquidThreadsApi/Source.php
M includes/Import/Postprocessor/LqtNotifications.php
M includes/Import/SourceStore/FlowRevisionsDb.php
M includes/Search/Iterators/AbstractIterator.php
M includes/Utils/NamespaceIterator.php
M includes/Utils/PagesWithPropertyIterator.php
M includes/WatchedTopicItems.php
M maintenance/FlowExternalStoreMoveCluster.php
M maintenance/FlowFixEditCount.php
M maintenance/FlowFixUserIp.php
M maintenance/FlowSetUserIp.php
M maintenance/FlowUpdateRecentChanges.php
M tests/phpunit/Import/ConverterTest.php
M tests/phpunit/Import/LiquidThreadsApi/ConversionStrategyTest.php
21 files changed, 54 insertions(+), 54 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/63/399663/1

diff --git a/includes/BoardMover.php b/includes/BoardMover.php
index 0f32d2b..e2c7346 100644
--- a/includes/BoardMover.php
+++ b/includes/BoardMover.php
@@ -2,7 +2,7 @@
 
 namespace Flow;
 
-use DatabaseBase;
+use Wikimedia\Rdbms\IDatabase;
 use Flow\Data\ManagerGroup;
 use Flow\Exception\FlowException;
 use Flow\Model\Header;
@@ -27,7 +27,7 @@
protected $nullEditUser;
 
/**
-* @var DatabaseBase|null
+* @var IDatabase|null
 */
protected $dbw;
 
diff --git a/includes/Data/Storage/DbStorage.php 
b/includes/Data/Storage/DbStorage.php
index 53f6c4c..9ea1dbe 100644
--- a/includes/Data/Storage/DbStorage.php
+++ b/includes/Data/Storage/DbStorage.php
@@ -69,7 +69,7 @@
 * 2. Checks for unarmoured raw SQL and errors out if it exists.
 * 3. Finds armoured raw SQL and expands it out.
 *
-* @param array $data Query conditions for DatabaseBase::select
+* @param array $data Query conditions for IDatabase::select
 * @return array query conditions escaped for use
 * @throws DataModelException
 */
diff --git a/includes/Data/Storage/RevisionStorage.php 
b/includes/Data/Storage/RevisionStorage.php
index 7b24592..f1948f8 100644
--- a/includes/Data/Storage/RevisionStorage.php
+++ b/includes/Data/Storage/RevisionStorage.php
@@ -2,7 +2,7 @@
 
 namespace Flow\Data\Storage;
 
-use DatabaseBase;
+use Wikimedia\Rdbms\IDatabase;
 use ExternalStore;
 use Flow\Data\Utils\Merger;
 use Flow\Data\Utils\ResultDuplicator;
@@ -341,7 +341,7 @@
);
}
 
-   protected function buildCompositeInCondition( DatabaseBase $dbr, array 
$queries ) {
+   protected function buildCompositeInCondition( IDatabase $dbr, array 
$queries ) {
$keys = array_keys( reset( $queries ) );
$conditions = [];
if ( count( $keys ) === 1 ) {
diff --git a/includes/DbFactory.php b/includes/DbFactory.php
index 4f1fc6d..b13d7d7 100644
--- a/includes/DbFactory.php
+++ b/includes/DbFactory.php
@@ -71,7 +71,7 @@
 *
 * @param int $db index of the connection to get.  DB_MASTER|DB_REPLICA.
 * @param string|bool $wiki The wiki ID, or false for the current wiki
-* @return \DatabaseBase
+* @return \IDatabase
 */
public function getWikiDB( $db, $wiki = false ) {
return wfGetDB( $this->forceMaster ? DB_MASTER : $db, [], $wiki 
);
diff --git a/includes/Dump/Exporter.php b/includes/Dump/Exporter.php
index 354cdd1..03f0a66 100644
--- a/includes/Dump/Exporter.php
+++ b/includes/Dump/Exporter.php
@@ -3,7 +3,7 @@
 namespace Flow\Dump;
 
 use BatchRowIterator;
-use DatabaseBase;
+use Wikimedia\Rdbms\IDatabase;
 use Exception;
 use Flow\Collection\PostSummaryCollection;
 use Flow\Container;
@@ -127,7 +127,7 @@
 * @return BatchRowIterator
 */
public function getWorkflowIterator( array $pages = null, $startId = 
null, $endId = null ) {
-   /** @var DatabaseBase $dbr */
+   /** @var IDatabase $dbr */
$dbr = Container::get( 'db.factory' )->getDB( DB_REPLICA );
 
$iterator = new BatchRowIterator( $dbr, 'flow_workflow', 
'workflow_id', 300 );
diff --git a/includes/Import/Converter.php b/includes/Import/Converter.php
index 512f975..0885277 100644
--- a/includes/Import/Converter.php
+++ b/includes/Import/Converter.php
@@ -2,7 +2,7 @@
 
 namespace Flow\Import;
 
-use DatabaseBase;
+use Wikimedia\Rdbms\IDatabase;
 use Flow\Exception\FlowException;
 use MovePage;
 use MWExceptionHandler;
@@ -31,7 +31,7 @@
  */
 class Converter {
/**
-* @var 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Test for writes being prevented on replica connections.

2017-12-21 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399604 )

Change subject: Test for writes being prevented on replica connections.
..

Test for writes being prevented on replica connections.

Bug: T183265
Change-Id: I319efa418cf8a46985f6faa60096559efa15d267
---
M tests/phpunit/includes/db/LoadBalancerTest.php
1 file changed, 37 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/04/399604/1

diff --git a/tests/phpunit/includes/db/LoadBalancerTest.php 
b/tests/phpunit/includes/db/LoadBalancerTest.php
index f8ab7f4..a7b0975 100644
--- a/tests/phpunit/includes/db/LoadBalancerTest.php
+++ b/tests/phpunit/includes/db/LoadBalancerTest.php
@@ -1,5 +1,7 @@
 getConnection( DB_MASTER );
$this->assertTrue( $dbw->getLBInfo( 'master' ), 'master shows 
as master' );
$this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on master" );
+   $this->assertWriteAllowed( $dbw );
 
$dbr = $lb->getConnection( DB_REPLICA );
$this->assertTrue( $dbr->getLBInfo( 'master' ), 'DB_REPLICA 
also gets the master' );
-   $this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on replica" );
+   $this->assertTrue( $dbr->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on replica" );
 
$dbwAuto = $lb->getConnection( DB_MASTER, [], false, 
$lb::CONN_TRX_AUTO );
$this->assertFalse( $dbwAuto->getFlag( $dbw::DBO_TRX ), "No 
DBO_TRX with CONN_TRX_AUTO" );
@@ -69,7 +72,7 @@
$lb->closeAll();
}
 
-   public function testLBSimpleServers() {
+   public function testWithReplica() {
global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, 
$wgDBtype, $wgSQLiteDataDir;
 
$servers = [
@@ -83,7 +86,7 @@
'load'=> 0,
'flags'   => DBO_TRX // REPEATABLE-READ for 
consistency
],
-   [ // emulated slave
+   [ // emulated replica
'host'=> $wgDBserver,
'dbname'  => $wgDBname,
'user'=> $wgDBuser,
@@ -108,14 +111,16 @@
$dbw->getLBInfo( 'clusterMasterHost' ),
'cluster master set' );
$this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on master" );
+   $this->assertWriteAllowed( $dbw );
 
$dbr = $lb->getConnection( DB_REPLICA );
-   $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows 
as slave' );
+   $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'replica shows 
as replica' );
$this->assertEquals(
( $wgDBserver != '' ) ? $wgDBserver : 'localhost',
$dbr->getLBInfo( 'clusterMasterHost' ),
'cluster master set' );
-   $this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on replica" );
+   $this->assertTrue( $dbr->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on replica" );
+   $this->assertWriteForbidden( $dbr );
 
$dbwAuto = $lb->getConnection( DB_MASTER, [], false, 
$lb::CONN_TRX_AUTO );
$this->assertFalse( $dbwAuto->getFlag( $dbw::DBO_TRX ), "No 
DBO_TRX with CONN_TRX_AUTO" );
@@ -132,4 +137,30 @@
 
$lb->closeAll();
}
+
+   private function assertWriteForbidden( IDatabase $db ) {
+   try {
+   $db->delete( 'user', [ 'user_id' => 57634126 ], 'TEST' 
);
+   $this->fail( 'Write operation should have failed!' );
+   } catch ( DBError $ex ) {
+   // check that the exception message contains "Write 
operation"
+   $constriant = new 
PHPUnit_Framework_Constraint_StringContains( 'Write operation' );
+
+   if ( !$constriant->evaluate( $ex->getMessage(), '', 
true ) ) {
+   // re-throw original error, to preserve stack 
trace
+   throw $ex;
+   }
+   } finally {
+   $db->rollback( __METHOD__, 'flush' );
+   }
+   }
+
+   private function assertWriteAllowed( IDatabase $db ) {
+   try {
+   $this->assertNotSame( false, $db->delete( 'user', [ 
'user_id' => 57634126 ] ) );
+   } finally {
+   $db->rollback( __METHOD__, 'flush' );
+   }
+   }
+
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Set CONN_NO_WRITE on all relevant code pathes in LoadBalancer.

2017-12-20 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399447 )

Change subject: Set CONN_NO_WRITE on all relevant code pathes in LoadBalancer.
..

Set CONN_NO_WRITE on all relevant code pathes in LoadBalancer.

This also adds a test that verifies that the replica connection
cannot be written to.

Bug: T183265
Change-Id: I32602876905d40197f109fe26adf9cb0d2a1aa30
---
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
M tests/phpunit/includes/db/LoadBalancerTest.php
2 files changed, 39 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/47/399447/1

diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php 
b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
index eb288dd..1f0ee01 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
@@ -434,7 +434,7 @@
$serverName = $this->getServerName( $i );
$this->connLogger->debug( __METHOD__ . ": Using reader 
#$i: $serverName..." );
 
-   $conn = $this->openConnection( $i, $domain );
+   $conn = $this->openConnection( $i, $domain, 
self::CONN_NO_WRITE );
if ( !$conn ) {
$this->connLogger->warning( __METHOD__ . ": 
Failed connecting to $i/$domain" );
unset( $currentLoads[$i] ); // avoid this 
server next iteration
@@ -588,7 +588,7 @@
 
return false;
} else {
-   $conn = $this->openConnection( $index, 
self::DOMAIN_ANY );
+   $conn = $this->openConnection( $index, 
self::DOMAIN_ANY, self::CONN_NO_WRITE );
if ( !$conn ) {
$this->replLogger->warning( __METHOD__ 
. ': failed to connect to {dbserver}',
[ 'dbserver' => $server ] );
diff --git a/tests/phpunit/includes/db/LoadBalancerTest.php 
b/tests/phpunit/includes/db/LoadBalancerTest.php
index f8ab7f4..a7b0975 100644
--- a/tests/phpunit/includes/db/LoadBalancerTest.php
+++ b/tests/phpunit/includes/db/LoadBalancerTest.php
@@ -1,5 +1,7 @@
 getConnection( DB_MASTER );
$this->assertTrue( $dbw->getLBInfo( 'master' ), 'master shows 
as master' );
$this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on master" );
+   $this->assertWriteAllowed( $dbw );
 
$dbr = $lb->getConnection( DB_REPLICA );
$this->assertTrue( $dbr->getLBInfo( 'master' ), 'DB_REPLICA 
also gets the master' );
-   $this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on replica" );
+   $this->assertTrue( $dbr->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on replica" );
 
$dbwAuto = $lb->getConnection( DB_MASTER, [], false, 
$lb::CONN_TRX_AUTO );
$this->assertFalse( $dbwAuto->getFlag( $dbw::DBO_TRX ), "No 
DBO_TRX with CONN_TRX_AUTO" );
@@ -69,7 +72,7 @@
$lb->closeAll();
}
 
-   public function testLBSimpleServers() {
+   public function testWithReplica() {
global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, 
$wgDBtype, $wgSQLiteDataDir;
 
$servers = [
@@ -83,7 +86,7 @@
'load'=> 0,
'flags'   => DBO_TRX // REPEATABLE-READ for 
consistency
],
-   [ // emulated slave
+   [ // emulated replica
'host'=> $wgDBserver,
'dbname'  => $wgDBname,
'user'=> $wgDBuser,
@@ -108,14 +111,16 @@
$dbw->getLBInfo( 'clusterMasterHost' ),
'cluster master set' );
$this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on master" );
+   $this->assertWriteAllowed( $dbw );
 
$dbr = $lb->getConnection( DB_REPLICA );
-   $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows 
as slave' );
+   $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'replica shows 
as replica' );
$this->assertEquals(
( $wgDBserver != '' ) ? $wgDBserver : 'localhost',
$dbr->getLBInfo( 'clusterMasterHost' ),
'cluster master set' );
-   $this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on replica" );
+   $this->assertTrue( $dbr->getFlag( $dbw::DBO_TRX ), "DBO_TRX set 
on replica" );
+   $this->assertWriteForbidden( $dbr );
 
$dbwAuto = 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: [WIP] Prevent writes on connections obtained with DB_REPLICA.

2017-12-20 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399445 )

Change subject: [WIP] Prevent writes on connections obtained with DB_REPLICA.
..

[WIP] Prevent writes on connections obtained with DB_REPLICA.

This introduces DBNoWriteWrapper and refactors DBConnRef for
code sharing.

Bug: T183242
Change-Id: Ida135ec93acf4dc13bef1c5a1d03d2646e984bcb
---
M autoload.php
M includes/libs/rdbms/database/DBConnRef.php
A includes/libs/rdbms/database/DBConnectionProxy.php
A includes/libs/rdbms/database/DBNoWriteWrapper.php
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
M tests/phpunit/includes/db/LoadBalancerTest.php
A tests/phpunit/includes/libs/rdbms/database/DBConnRefTest.php
A tests/phpunit/includes/libs/rdbms/database/DBNoWriteWrapperTest.php
A tests/phpunit/tests/MediaWikiTestCaseDbTest.php
9 files changed, 1,238 insertions(+), 576 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/45/399445/1

diff --git a/autoload.php b/autoload.php
index 6b8387b..99c6581 100644
--- a/autoload.php
+++ b/autoload.php
@@ -1663,9 +1663,11 @@
'Wikimedia\\Rdbms\\DBAccessError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBAccessError.php',
'Wikimedia\\Rdbms\\DBConnRef' => __DIR__ . 
'/includes/libs/rdbms/database/DBConnRef.php',
'Wikimedia\\Rdbms\\DBConnectionError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBConnectionError.php',
+   'Wikimedia\\Rdbms\\DBConnectionProxy' => __DIR__ . 
'/includes/libs/rdbms/database/DBConnectionProxy.php',
'Wikimedia\\Rdbms\\DBError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBError.php',
'Wikimedia\\Rdbms\\DBExpectedError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBExpectedError.php',
'Wikimedia\\Rdbms\\DBMasterPos' => __DIR__ . 
'/includes/libs/rdbms/database/position/DBMasterPos.php',
+   'Wikimedia\\Rdbms\\DBNoWriteWrapper' => __DIR__ . 
'/includes/libs/rdbms/database/DBNoWriteWrapper.php',
'Wikimedia\\Rdbms\\DBQueryError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBQueryError.php',
'Wikimedia\\Rdbms\\DBQueryTimeoutError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBQueryTimeoutError.php',
'Wikimedia\\Rdbms\\DBReadOnlyError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBReadOnlyError.php',
diff --git a/includes/libs/rdbms/database/DBConnRef.php 
b/includes/libs/rdbms/database/DBConnRef.php
index ef2953e..666d246 100644
--- a/includes/libs/rdbms/database/DBConnRef.php
+++ b/includes/libs/rdbms/database/DBConnRef.php
@@ -12,13 +12,12 @@
  * @ingroup Database
  * @since 1.22
  */
-class DBConnRef implements IDatabase {
+class DBConnRef extends DBConnectionProxy {
/** @var ILoadBalancer */
private $lb;
-   /** @var Database|null Live connection handle */
-   private $conn;
+
/** @var array|null N-tuple of (server index, group, 
DatabaseDomain|string) */
-   private $params;
+   private $params = null;
 
const FLD_INDEX = 0;
const FLD_GROUP = 1;
@@ -27,597 +26,50 @@
 
/**
 * @param ILoadBalancer $lb Connection manager for $conn
-* @param Database|array $conn Database handle or (server index, query 
groups, domain, flags)
+* @param IDatabase|array $conn Database handle or (server index, query 
groups, domain, flags)
 */
public function __construct( ILoadBalancer $lb, $conn ) {
$this->lb = $lb;
-   if ( $conn instanceof Database ) {
-   $this->conn = $conn; // live handle
+
+   if ( $conn instanceof IDatabase ) {
+   parent::__construct( $conn );
} elseif ( count( $conn ) >= 4 && $conn[self::FLD_DOMAIN] !== 
false ) {
$this->params = $conn;
+
+   $instantiator = function() {
+   list( $db, $groups, $wiki, $flags ) = 
$this->params;
+   return $this->lb->getConnection( $db, $groups, 
$wiki, $flags );
+   };
+
+   parent::__construct( $instantiator );
} else {
throw new InvalidArgumentException( "Missing lazy 
connection arguments." );
}
}
 
-   function __call( $name, array $arguments ) {
-   if ( $this->conn === null ) {
-   list( $db, $groups, $wiki, $flags ) = $this->params;
-   $this->conn = $this->lb->getConnection( $db, $groups, 
$wiki, $flags );
-   }
-
-   return call_user_func_array( [ $this->conn, $name ], $arguments 
);
-   }
-
-   public function getServerInfo() {
-   return $this->__call( __FUNCTION__, func_get_args() );
-   }
-
-   public function bufferResults( $buffer = null ) {
-   return $this->__call( __FUNCTION__, 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Prevent write operations to database replicas.

2017-12-19 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399208 )

Change subject: Prevent write operations to database replicas.
..

Prevent write operations to database replicas.

Bug: T183265
Change-Id: I8e17644d1b447416adee18e42cf0122b52a80b22
---
M includes/libs/rdbms/database/Database.php
M includes/libs/rdbms/loadbalancer/ILoadBalancer.php
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
3 files changed, 60 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/08/399208/1

diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index 7f0718c..1c9cad5 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -237,6 +237,12 @@
protected $trxProfiler;
 
/**
+* @var bool Whether writing is allowed on this connection.
+*  Should be false for connections to replicas.
+*/
+   protected $allowWrite = true;
+
+   /**
 * Constructor and database handle and attempt to connect to the DB 
server
 *
 * IDatabase classes should not be constructed directly in external
@@ -277,6 +283,7 @@
$this->connLogger = $params['connLogger'];
$this->queryLogger = $params['queryLogger'];
$this->errorLogger = $params['errorLogger'];
+   $this->allowWrite = empty( $params['noWrite'] );
 
// Set initial dummy domain until open() sets the final 
DB/prefix
$this->currentDomain = DatabaseDomain::newUnspecified();
@@ -908,6 +915,13 @@
}
 
if ( $isWrite ) {
+   if ( !$this->allowWrite ) {
+   throw new DBError(
+   $this,
+   'Write operations are not allowed on 
this database connection!'
+   );
+   }
+
# In theory, non-persistent writes are allowed in 
read-only mode, but due to things
# like https://bugs.mysql.com/bug.php?id=33669 that 
might not work anyway...
$reason = $this->getReadOnlyReason();
@@ -2951,6 +2965,13 @@
}
 
final public function begin( $fname = __METHOD__, $mode = 
self::TRANSACTION_EXPLICIT ) {
+   if ( !$this->allowWrite ) {
+   throw new DBError(
+   $this,
+   'Write operations are not allowed on this 
database connection!'
+   );
+   }
+
// Protect against mismatched atomic section, transaction 
nesting, and snapshot loss
if ( $this->mTrxLevel ) {
if ( $this->mTrxAtomicLevels ) {
@@ -3012,6 +3033,14 @@
}
 
final public function commit( $fname = __METHOD__, $flush = '' ) {
+   if ( !$this->allowWrite ) {
+   // we should never get here, since begin() would 
already throw
+   throw new DBError(
+   $this,
+   'Write operations are not allowed on this 
database connection!'
+   );
+   }
+
if ( $this->mTrxLevel && $this->mTrxAtomicLevels ) {
// There are still atomic sections open. This cannot be 
ignored
$levels = implode( ', ', $this->mTrxAtomicLevels );
diff --git a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php 
b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php
index 86c4335..b565b3b 100644
--- a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php
@@ -87,6 +87,9 @@
/** @var int DB handle should have DBO_TRX disabled and the caller will 
leave it as such */
const CONN_TRX_AUTO = 1;
 
+   /** Disable writing for the given connection. Used internally. Do not 
use with DB_MASTER! */
+   const CONN_NO_WRITE = 2;
+
/**
 * Construct a manager of IDatabase connection objects
 *
diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php 
b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
index a9eaa99..eb288dd 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
@@ -645,6 +645,12 @@
$oldConnsOpened = $this->connsOpened; // connections open now
 
if ( $i == self::DB_MASTER ) {
+   if ( $flags & self::CONN_NO_WRITE ) {
+   throw new InvalidArgumentException(
+   'Cannot set CONN_NO_WRITE flag on 
master connection!'
+   );
+   

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Deprecate and gut Revision class [DNM].

2017-12-19 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399174 )

Change subject: Deprecate and gut Revision class [DNM].
..

Deprecate and gut Revision class [DNM].

This is a re-submission of I4f24e7fbb68.

As a first major step towards Multi-Content-Revisions (MCR),
this patch turns the Revision class into a legacy proxy for
the new RevisionRecord and RevisionStore classes.

Backwards compatibility is maintained for all but some
rare edge cases, like constructing a completely empty
Revision object.

For more information on MCR, see
.

DO NOT MERGE before this is confirmed to correctly preserve
chronology during edits in the presence of database replication lag.
This patch has been reverted before due to issues with that,
see Idf3404f3fa8.

Bug: T174025
Change-Id: Ia4c20a91e98df0b9b14b138eb4825c55e5200384
---
M RELEASE-NOTES-1.31
M docs/hooks.txt
M includes/Revision.php
M includes/ServiceWiring.php
M includes/actions/HistoryAction.php
M includes/cache/MessageCache.php
M includes/page/WikiPage.php
M includes/parser/Parser.php
M includes/resourceloader/ResourceLoaderWikiModule.php
M includes/specials/SpecialNewpages.php
M tests/phpunit/includes/MediaWikiServicesTest.php
M tests/phpunit/includes/RevisionDbTestBase.php
M tests/phpunit/includes/RevisionTest.php
13 files changed, 715 insertions(+), 1,420 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/74/399174/1

diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31
index 1a1a9f7..7f67feb 100644
--- a/RELEASE-NOTES-1.31
+++ b/RELEASE-NOTES-1.31
@@ -71,6 +71,10 @@
 * (T180052) Mirandese (mwl) now supports gendered NS_USER/NS_USER_TALK 
namespaces.
 
 === Other changes in 1.31 ===
+* Introducing multi-content-revision capability into the storage layer. For 
details,
+  see 
.
+* The Revision class was deprecated in favor of RevisionStore, BlobStore, and
+  RevisionRecord and its subclasses.
 * MessageBlobStore::insertMessageBlob() (deprecated in 1.27) was removed.
 * The global function wfBCP47 was renamed to LanguageCode::bcp47.
 * The global function wfBCP47 is now deprecated.
@@ -123,6 +127,9 @@
 * The Block class will no longer accept usable-but-missing usernames for
   'byText' or ->setBlocker(). Callers should either ensure the blocker exists
   locally or use a new interwiki-format username like "iw>Example".
+* The RevisionInsertComplete hook is now deprecated, use 
RevisionRecordInserted instead.
+  RevisionInsertComplete is still called, but the second and third parameter 
will always be null.
+  Hard deprecation is scheduled for 1.32.
 * The following methods that get and set ParserOutput state are deprecated.
   Callers should use the new stateless $options parameter to
   ParserOutput::getText() instead.
diff --git a/docs/hooks.txt b/docs/hooks.txt
index ee38ea9..1f4a5f4 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -2810,14 +2810,14 @@
   added to any module.
 &$ResourceLoader: object
 
-'RevisionInsertComplete': Called after a revision is inserted into the 
database.
-&$revision: the Revision
-$data: the data stored in old_text.  The meaning depends on $flags: if external
-  is set, it's the URL of the revision text in external storage; otherwise,
-  it's the revision text itself.  In either case, if gzip is set, the revision
-  text is gzipped.
-$flags: a comma-delimited list of strings representing the options used.  May
-  include: utf8 (this will always be set for new revisions); gzip; external.
+'RevisionRecordInserted': Called after a revision is inserted into the 
database.
+$revisionRecord: the RevisionRecord that has just been inserted.
+
+'RevisionInsertComplete': DEPRECATED! Use RevisionRecordInserted hook instead.
+Called after a revision is inserted into the database.
+$revision: the Revision
+$data: DEPRECATED! Always null!
+$flags: DEPRECATED! Always null!
 
 'SearchableNamespaces': An option to modify which namespaces are searchable.
 &$arr: Array of namespaces ($nsId => $name) which will be used.
diff --git a/includes/Revision.php b/includes/Revision.php
index 25c89c2..ea73a61 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -20,7 +20,14 @@
  * @file
  */
 
-use Wikimedia\Rdbms\Database;
+use MediaWiki\Storage\MutableRevisionRecord;
+use MediaWiki\Storage\RevisionAccessException;
+use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\RevisionStoreRecord;
+use MediaWiki\Storage\SlotRecord;
+use MediaWiki\Storage\SqlBlobStore;
+use MediaWiki\User\UserIdentityValue;
 use Wikimedia\Rdbms\IDatabase;
 use MediaWiki\Linker\LinkTarget;
 use MediaWiki\MediaWikiServices;
@@ -28,78 +35,50 @@
 use Wikimedia\Rdbms\FakeResultWrapper;
 
 /**
- * @todo document
+ * @deprecated since 1.31, 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Revert "[MCR] Turn Revision into a proxy to new code."

2017-12-19 Thread Daniel Kinzler (Code Review)
Hello Bene, Cicalese, Ladsgroup, Brion VIBBER, Legoktm, Addshore, jenkins-bot, 
Anomie,

I'd like you to do a code review.  Please visit

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

to review the following change.


Change subject: Revert "[MCR] Turn Revision into a proxy to new code."
..

Revert "[MCR] Turn Revision into a proxy to new code."

This reverts commit 9dcc56b3c9e7a3212d0900ee23808b9402cad952.

With this patch applied, newly created revisions are sometimes not fund just 
after submitting an edit, until replicas have caught up. Our best theory is 
that it somehow interfere with ChronologyProtector, but we don't have a good 
idea how.

Also, as legoktm mentioned, the commit message is terrible and needs fixing.

Change-Id: Idf3404f3fa8f8d08a7fb2ab8268726e2c1edecfe
---
M RELEASE-NOTES-1.31
M docs/hooks.txt
M includes/Revision.php
M includes/ServiceWiring.php
M includes/actions/HistoryAction.php
M includes/cache/MessageCache.php
M includes/page/WikiPage.php
M includes/parser/Parser.php
M includes/resourceloader/ResourceLoaderWikiModule.php
M includes/specials/SpecialNewpages.php
M tests/phpunit/includes/MediaWikiServicesTest.php
M tests/phpunit/includes/RevisionDbTestBase.php
M tests/phpunit/includes/RevisionTest.php
13 files changed, 1,414 insertions(+), 752 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/56/399156/1

diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31
index 67026f4..1a1a9f7 100644
--- a/RELEASE-NOTES-1.31
+++ b/RELEASE-NOTES-1.31
@@ -123,9 +123,6 @@
 * The Block class will no longer accept usable-but-missing usernames for
   'byText' or ->setBlocker(). Callers should either ensure the blocker exists
   locally or use a new interwiki-format username like "iw>Example".
-* The RevisionInsertComplete hook is now deprecated, use 
RevisionRecordInserted instead.
-  RevisionInsertComplete is still called, but the second and third parameter 
will always be null.
-  Hard deprecation is scheduled for 1.32.
 * The following methods that get and set ParserOutput state are deprecated.
   Callers should use the new stateless $options parameter to
   ParserOutput::getText() instead.
diff --git a/docs/hooks.txt b/docs/hooks.txt
index 1f4a5f4..ee38ea9 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -2810,14 +2810,14 @@
   added to any module.
 &$ResourceLoader: object
 
-'RevisionRecordInserted': Called after a revision is inserted into the 
database.
-$revisionRecord: the RevisionRecord that has just been inserted.
-
-'RevisionInsertComplete': DEPRECATED! Use RevisionRecordInserted hook instead.
-Called after a revision is inserted into the database.
-$revision: the Revision
-$data: DEPRECATED! Always null!
-$flags: DEPRECATED! Always null!
+'RevisionInsertComplete': Called after a revision is inserted into the 
database.
+&$revision: the Revision
+$data: the data stored in old_text.  The meaning depends on $flags: if external
+  is set, it's the URL of the revision text in external storage; otherwise,
+  it's the revision text itself.  In either case, if gzip is set, the revision
+  text is gzipped.
+$flags: a comma-delimited list of strings representing the options used.  May
+  include: utf8 (this will always be set for new revisions); gzip; external.
 
 'SearchableNamespaces': An option to modify which namespaces are searchable.
 &$arr: Array of namespaces ($nsId => $name) which will be used.
diff --git a/includes/Revision.php b/includes/Revision.php
index ea73a61..25c89c2 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -20,14 +20,7 @@
  * @file
  */
 
-use MediaWiki\Storage\MutableRevisionRecord;
-use MediaWiki\Storage\RevisionAccessException;
-use MediaWiki\Storage\RevisionRecord;
-use MediaWiki\Storage\RevisionStore;
-use MediaWiki\Storage\RevisionStoreRecord;
-use MediaWiki\Storage\SlotRecord;
-use MediaWiki\Storage\SqlBlobStore;
-use MediaWiki\User\UserIdentityValue;
+use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
 use MediaWiki\Linker\LinkTarget;
 use MediaWiki\MediaWikiServices;
@@ -35,50 +28,78 @@
 use Wikimedia\Rdbms\FakeResultWrapper;
 
 /**
- * @deprecated since 1.31, use RevisionRecord, RevisionStore, and BlobStore 
instead.
+ * @todo document
  */
 class Revision implements IDBAccessObject {
+   /** @var int|null */
+   protected $mId;
+   /** @var int|null */
+   protected $mPage;
+   /** @var string */
+   protected $mUserText;
+   /** @var string */
+   protected $mOrigUserText;
+   /** @var int */
+   protected $mUser;
+   /** @var bool */
+   protected $mMinorEdit;
+   /** @var string */
+   protected $mTimestamp;
+   /** @var int */
+   protected $mDeleted;
+   /** @var int */
+   protected $mSize;
+   /** @var string */
+   protected $mSha1;
+   /** @var int */
+   protected $mParentId;
+   /** @var string */
+   protected $mComment;

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Fix cache key cleared by populateContentModel.php

2017-12-18 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398885 )

Change subject: Fix cache key cleared by populateContentModel.php
..

Fix cache key cleared by populateContentModel.php

This is a follow-up to I4f24e7fbb6.

Change-Id: I65858cecb5aa779c4893b0d0f575a996f852870e
---
M maintenance/populateContentModel.php
1 file changed, 3 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/85/398885/1

diff --git a/maintenance/populateContentModel.php 
b/maintenance/populateContentModel.php
index a4fac05..70cb91e 100644
--- a/maintenance/populateContentModel.php
+++ b/maintenance/populateContentModel.php
@@ -70,8 +70,10 @@
 
protected function clearCache( $page_id, $rev_id ) {
$contentModelKey = $this->wanCache->makeKey( 
'page-content-model', $rev_id );
+
+   // NOTE: Cache key is defined by 
RevisionStore::getKnownCurrentRevision().
$revisionKey =
-   $this->wanCache->makeGlobalKey( 'revision', 
$this->wikiId, $page_id, $rev_id );
+   $this->wanCache->makeGlobalKey( 'revision-row-1.29', 
$this->wikiId, $page_id, $rev_id );
 
// WikiPage content model cache
$this->wanCache->delete( $contentModelKey );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I65858cecb5aa779c4893b0d0f575a996f852870e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Fetch revisions from master DB if not found on replica.

2017-12-18 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398884 )

Change subject: Fetch revisions from master DB if not found on replica.
..

Fetch revisions from master DB if not found on replica.

This overhauls the logic that determins when we will fall back
to loading a revision from the master databasase.

Change-Id: I316a1c25ecfe9fd9d0e2d0acdef3be6baec6417a
---
M includes/Storage/RevisionStore.php
1 file changed, 97 insertions(+), 45 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/84/398884/1

diff --git a/includes/Storage/RevisionStore.php 
b/includes/Storage/RevisionStore.php
index b8debb8..cb0e11a 100644
--- a/includes/Storage/RevisionStore.php
+++ b/includes/Storage/RevisionStore.php
@@ -842,15 +842,18 @@
 *
 * MCR migration note: this replaces Revision::newFromId
 *
-* $flags include:
-*  IDBAccessObject::READ_LATEST: Select the data from the master
-*  IDBAccessObject::READ_LOCKING : Select & lock the data from the 
master
+* Depending on $flags, this method may try to load the revision from a 
replica
+* before hitting the master database, or try the master database 
immediately.
 *
 * @param int $id
 * @param int $flags (optional)
 * @return RevisionRecord|null
 */
public function getRevisionById( $id, $flags = 0 ) {
+   // Since we know the revision ID, we are pretty sure it exists, 
so we want to fall
+   // back to hitting master if it'S not found on a replica, even 
if no writes were done
+   // in this request. READ_LATEST_IMMUTABLE forces this.
+   $flags |= self::READ_LATEST_IMMUTABLE;
return $this->newRevisionFromConds( [ 'rev_id' => intval( $id ) 
], $flags );
}
 
@@ -861,9 +864,9 @@
 *
 * MCR migration note: this replaces Revision::newFromTitle
 *
-* $flags include:
-*  IDBAccessObject::READ_LATEST: Select the data from the master
-*  IDBAccessObject::READ_LOCKING : Select & lock the data from the 
master
+* Depending on $flags, this method may try to load the revision from a 
replica
+* before hitting the master database, try the master database 
immediately,
+* or give up after trying only the replica.
 *
 * @param LinkTarget $linkTarget
 * @param int $revId (optional)
@@ -881,14 +884,16 @@
// and fall back to master if the page is not found on 
a replica.
// Since the caller supplied a revision ID, we are 
pretty sure the revision is
// supposed to exist, so we should try hard to find it.
+   // The READ_LATEST_IMMUTABLE flag will force a retry 
even if no writes were done
+   // in the present request.
+   $flags |= self::READ_LATEST_IMMUTABLE;
$conds['rev_id'] = $revId;
return $this->newRevisionFromConds( $conds, $flags );
} else {
// Use a join to get the latest revision.
-   // Note that we don't use newRevisionFromConds here 
because we don't want to retry
-   // and fall back to master. The assumption is that we 
only want to force the fallback
-   // if we are quite sure the revision exists because the 
caller supplied a revision ID.
-   // If the page isn't found at all on a replica, it 
probably simply does not exist.
+   // Note that we don't use newRevisionFromConds since we 
do not need to fall back to
+   // master: page_latest is guaranteed to always point to 
an existing revision on the same
+   // database server.
$db = $this->getDBConnection( ( $flags & 
self::READ_LATEST ) ? DB_MASTER : DB_REPLICA );
 
$conds[] = 'rev_id=page_latest';
@@ -906,9 +911,9 @@
 *
 * MCR migration note: this replaces Revision::newFromPageId
 *
-* $flags include:
-*  IDBAccessObject::READ_LATEST: Select the data from the master 
(since 1.20)
-*  IDBAccessObject::READ_LOCKING : Select & lock the data from the 
master
+* Depending on $flags, this method may try to load the revision from a 
replica
+* before hitting the master database, try the master database 
immediately,
+* or give up after trying only the replica.
 *
 * @param int $pageId
 * @param int $revId (optional)
@@ -923,14 +928,16 @@
// and fall back to master if the page is not found on 
a replica.
// Since the caller supplied a revision ID, we are 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Make wbsetclaim and friends check entity permissions.

2017-12-12 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/397899 )

Change subject: Make wbsetclaim and friends check entity permissions.
..

Make wbsetclaim and friends check entity permissions.

wbsetclaim, wbsetclaimvalue, wbsetqualifier, and wbsetreference did not
check user permissions against the actions required by the respective ChangeOp.

Since we currently do not have special permissions defined for modifying 
Statements,
this was not a problem in practice. BUt it's an incosistency that may lead to
nasty surprises down the road.

Change-Id: Ie0d83165508723f89b3a6e9bac6c4704237c7d5a
---
M repo/includes/Api/CreateClaim.php
M repo/includes/Api/SetClaim.php
M repo/includes/Api/SetClaimValue.php
M repo/includes/Api/SetQualifier.php
M repo/includes/Api/SetReference.php
M repo/includes/Api/StatementModificationHelper.php
M repo/tests/phpunit/includes/Api/StatementModificationHelperTest.php
7 files changed, 105 insertions(+), 5 deletions(-)


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

diff --git a/repo/includes/Api/CreateClaim.php 
b/repo/includes/Api/CreateClaim.php
index 1224620..4ced0b3 100644
--- a/repo/includes/Api/CreateClaim.php
+++ b/repo/includes/Api/CreateClaim.php
@@ -95,6 +95,7 @@
/* @var ChangeOpMainSnak $changeOp */
$changeOp = $this->statementChangeOpFactory->newSetMainSnakOp( 
'', $snak );
 
+   $this->modificationHelper->checkPermissions( $entity, 
$this->getUser(), $changeOp );
$this->modificationHelper->applyChangeOp( $changeOp, $entity, 
$summary );
 
$statement = 
$entity->getStatements()->getFirstStatementWithGuid( 
$changeOp->getStatementGuid() );
diff --git a/repo/includes/Api/SetClaim.php b/repo/includes/Api/SetClaim.php
index 7f0a164..37cc663 100644
--- a/repo/includes/Api/SetClaim.php
+++ b/repo/includes/Api/SetClaim.php
@@ -132,6 +132,7 @@
 
$index = isset( $params['index'] ) ? $params['index'] : null;
$changeop = $this->statementChangeOpFactory->newSetStatementOp( 
$statement, $index );
+   $this->modificationHelper->checkPermissions( $entity, 
$this->getUser(), $changeop );
$this->modificationHelper->applyChangeOp( $changeop, $entity, 
$summary );
 
$status = $this->entitySavingHelper->attemptSaveEntity( 
$entity, $summary );
diff --git a/repo/includes/Api/SetClaimValue.php 
b/repo/includes/Api/SetClaimValue.php
index ed76bab..e3d00ed 100644
--- a/repo/includes/Api/SetClaimValue.php
+++ b/repo/includes/Api/SetClaimValue.php
@@ -96,6 +96,7 @@
 
$changeOp = $this->statementChangeOpFactory->newSetMainSnakOp( 
$guid, $snak );
 
+   $this->modificationHelper->checkPermissions( $entity, 
$this->getUser(), $changeOp );
$this->modificationHelper->applyChangeOp( $changeOp, $entity, 
$summary );
 
$status = $this->entitySavingHelper->attemptSaveEntity( 
$entity, $summary );
diff --git a/repo/includes/Api/SetQualifier.php 
b/repo/includes/Api/SetQualifier.php
index 34be6a2..07dc96e 100644
--- a/repo/includes/Api/SetQualifier.php
+++ b/repo/includes/Api/SetQualifier.php
@@ -102,6 +102,7 @@
}
 
$changeOp = $this->getChangeOp();
+   $this->modificationHelper->checkPermissions( $entity, 
$this->getUser(), $changeOp );
$this->modificationHelper->applyChangeOp( $changeOp, $entity, 
$summary );
 
$status = $this->entitySavingHelper->attemptSaveEntity( 
$entity, $summary );
diff --git a/repo/includes/Api/SetReference.php 
b/repo/includes/Api/SetReference.php
index 8f4d060..5626a44 100644
--- a/repo/includes/Api/SetReference.php
+++ b/repo/includes/Api/SetReference.php
@@ -129,6 +129,7 @@
$newReference = new Reference( $snakList );
 
$changeOp = $this->getChangeOp( $newReference );
+   $this->modificationHelper->checkPermissions( $entity, 
$this->getUser(), $changeOp );
$this->modificationHelper->applyChangeOp( $changeOp, $entity, 
$summary );
 
$status = $this->entitySavingHelper->attemptSaveEntity( 
$entity, $summary );
diff --git a/repo/includes/Api/StatementModificationHelper.php 
b/repo/includes/Api/StatementModificationHelper.php
index 78c729c..39bc1ee 100644
--- a/repo/includes/Api/StatementModificationHelper.php
+++ b/repo/includes/Api/StatementModificationHelper.php
@@ -7,6 +7,8 @@
 use LogicException;
 use OutOfBoundsException;
 use ApiUsageException;
+use Status;
+use User;
 use Wikibase\Repo\ChangeOp\ChangeOp;
 use Wikibase\Repo\ChangeOp\ChangeOpException;
 use Wikibase\Repo\ChangeOp\ChangeOpValidationException;
@@ -21,6 +23,7 @@
 use Wikibase\DataModel\Statement\Statement;
 use Wikibase\DataModel\Statement\StatementListProvider;
 use Wikibase\Repo\SnakFactory;
+use 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Document entity storage on wiki pages.

2017-12-06 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/395815 )

Change subject: Document entity storage on wiki pages.
..

Document entity storage on wiki pages.

This clarifies the relationship between entity revisions and page revisions,
among other things.

Change-Id: If6d1b62a1acd39491f377c83f68eb3f7788a46cb
---
A docs/entity-storage.wiki
M lib/includes/Store/EntityRevision.php
M repo/includes/Content/EntityContent.php
M repo/includes/Store/Sql/WikiPageEntityStore.php
M repo/includes/Store/WikiPageEntityStorePermissionChecker.php
5 files changed, 55 insertions(+), 4 deletions(-)


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

diff --git a/docs/entity-storage.wiki b/docs/entity-storage.wiki
new file mode 100644
index 000..6d26ce9
--- /dev/null
+++ b/docs/entity-storage.wiki
@@ -0,0 +1,34 @@
+This page describes how wikibase entities are represented and stored inside 
MediaWiki.
+
+
+== Storage ==
+
+Entities (or more precisely, entity description documents) are stored as 
MediaWiki page content, serialized according to JSON binding of the Wikibase 
data model. The JSON structure encodes an EntityDocument, EntityContent and 
EntityHandler provide the necessary glue to allow MediaWIki to handle 
EntityDocument as page content.
+
+In order to store entities on wiki pages, a mapping between entity IDs and 
page titles is required. In the simplest case, the entity ID is used as the 
page title directly, with the appropriate namespace prefix. For this purpose, 
and entity type is associated with a namespace. Since entity IDs encode the 
entity type, this in principle allows multiple entity types to share the same 
namespace. However, support for multiple entity types sharing the same 
namespace directly is currently not implemented,at least not for top-level 
entities (see below for details).
+
+In some cases, it may be desirable to store multiple entities on the same page 
- conceptually, this may be interpreted as a top-level entity containing 
several sub-entities (or "inner" entities) which are similar to the idea of 
sections in MediaWiki. Just as with sections, the ID of such an inner entity 
has to contain the ID of the parent (top level) entity, so it can be used as an 
address for finding the inner entity in the database.
+
+This implies that the relationship between entity IDs and page titles is 
unique only in one direction: each entity ID is associated with a single page, 
but multiple entity IDs can map to the same page (or sections of the same page, 
depending on interpretation). The same is true for the relationship between 
entity types and mediaWiki namespaces.
+
+
+== Enumeration ==
+
+As a consequence of the above principles, efficient enumeration of all entity 
IDs can be achieved by enumerating all titles in a namespace, but this is only 
possible for top-level entities. In order to enumerate sub-entities contained 
within top-level entities, it may be required to load each top-level entity.
+
+
+== Redirects ==
+
+Some entity types may support redirects. A MediaWiki redirect from one page 
title to another shall be interpreted as the two entity IDs referring to the 
same entity (indeed, the same entity as well as the same entity description). 
The titles of redirect pages correspond to secondary IDs of the entity, while 
the title of the page that actually contains the entity description corresponds 
to the canonical entity ID. The entity description will typically only contain 
the canonical ID.
+
+
+== Versioning ==
+
+Wikibase supports the concepts of versioning through EntityRevisions. These 
roughly correspond to MediaWiki page revisions, with one notable difference: 
the revision ID is considered to be unique only relative to a given entity ID, 
not globally, as in MediaWiki.
+
+In particular, updating a single sub-entity will create a new revision of the 
page that contains that sub-entity. This implies that it also creates a new 
revision for every other entity contained on that page, including the top level 
entity. These "incidental" entity revisions correspond to the concept of "null 
revisions" in MediaWiki: between the new revision and its parent, only the 
(sub-)entities touched by the intentional edit change; all other entities on 
the page remain unchanged between the old and the new revision.
+
+
+== Permissions ==
+
+The permission to perform actions on entities are mapped to MediaWiki page 
permissions by an EntityPermissionChecker. This means that the same permissions 
apply to all entities on a page, and page protection (restrictions) aso apply 
to all entities. However, the same operation (like changing a label) can be 
mapped to different actions for different entity types (e.g. item-term and 
property-term), which in effect allows permissions and restrictions to be 
managed per entity type on a page (but 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Assume PageIdentityValue exists in core.

2017-11-24 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393243 )

Change subject: Assume PageIdentityValue exists in core.
..

Assume PageIdentityValue exists in core.

Change-Id: I0d7fe65f1d28f84ed89978177eb7c2c507f6b14a
Depends-On: Id36fb61986d5804de5cc1a509f38b2fa3daf73e3
---
M repo/tests/phpunit/includes/Content/EntityHandlerTest.php
1 file changed, 3 insertions(+), 6 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php 
b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
index 2e14f32..1491e13 100644
--- a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
@@ -247,12 +247,9 @@
$title->method( 'getLatestRevID' )
->will( $this->returnValue( $id ) );
 
-   // TODO: remove conditional as soon as Title::getPageIdentity() 
is in core.
-   if ( method_exists( Title::class, 'getPageIdentity' ) ) {
-   $page = PageIdentityValue::newFromDBKey( $id, NS_MAIN, 
__CLASS__ );
-   $title->method( 'getPageIdentity' )
-   ->will( $this->returnValue( $page ) );
-   }
+   $page = PageIdentityValue::newFromDBKey( $id, NS_MAIN, 
__CLASS__ );
+   $title->method( 'getPageIdentity' )
+   ->will( $this->returnValue( $page ) );
 
$revision = new Revision( [
'id' => $id,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0d7fe65f1d28f84ed89978177eb7c2c507f6b14a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Make unit tests aware of PageIdentity.

2017-11-24 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393242 )

Change subject: Make unit tests aware of PageIdentity.
..

Make unit tests aware of PageIdentity.

Use of PageIdentity is protected by a method_exists check for now,
until Id36fb61986d is merged into core. We need this change beforehand though,
since without it the affected tests fail on Id36fb61986d.

Change-Id: I6eff5d3a54311b59411216034d28d07d1cc95792
---
M repo/tests/phpunit/includes/Content/EntityHandlerTest.php
1 file changed, 10 insertions(+), 2 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php 
b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
index 26d13c4..2e14f32 100644
--- a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
@@ -11,6 +11,7 @@
 use InvalidArgumentException;
 use Language;
 use LogicException;
+use MediaWiki\Storage\PageIdentityValue;
 use MWException;
 use PHPUnit_Framework_MockObject_MockObject;
 use RequestContext;
@@ -240,12 +241,19 @@
$title->method( 'exists' )
->will( $this->returnValue( true ) );
 
-   $title->method( 'getArticleId' )
+   $title->method( 'getArticleID' )
->will( $this->returnValue( $id ) );
 
-   $title->method( 'getLatestRevId' )
+   $title->method( 'getLatestRevID' )
->will( $this->returnValue( $id ) );
 
+   // TODO: remove conditional as soon as Title::getPageIdentity() 
is in core.
+   if ( method_exists( Title::class, 'getPageIdentity' ) ) {
+   $page = PageIdentityValue::newFromDBKey( $id, NS_MAIN, 
__CLASS__ );
+   $title->method( 'getPageIdentity' )
+   ->will( $this->returnValue( $page ) );
+   }
+
$revision = new Revision( [
'id' => $id,
'title' => $title,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6eff5d3a54311b59411216034d28d07d1cc95792
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Translate[master]: Fix name of test class.

2017-11-23 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393048 )

Change subject: Fix name of test class.
..

Fix name of test class.

Change-Id: Ie38f9ed5f4ec93637e9a45b099ad8fe8ff21c73b
---
M tests/phpunit/PageTranslationTaggingTest.php
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/48/393048/1

diff --git a/tests/phpunit/PageTranslationTaggingTest.php 
b/tests/phpunit/PageTranslationTaggingTest.php
index 4927c75..2e2a6c2 100644
--- a/tests/phpunit/PageTranslationTaggingTest.php
+++ b/tests/phpunit/PageTranslationTaggingTest.php
@@ -4,7 +4,7 @@
  * @group Database
  * @group medium
  */
-class PageTranslationTaggingText extends MediaWikiTestCase {
+class PageTranslationTaggingTest extends MediaWikiTestCase {
protected function setUp() {
parent::setUp();
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie38f9ed5f4ec93637e9a45b099ad8fe8ff21c73b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Remove the need for EntityDocument::isEmpty.

2017-11-21 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/392679 )

Change subject: Remove the need for EntityDocument::isEmpty.
..

Remove the need for EntityDocument::isEmpty.

We'll keep isEmpty in Item and Property for now.

Change-Id: I4086017352e2fee7f1841c5e4ded5a2c8ffae285
---
M repo/includes/Content/EntityContent.php
M repo/includes/Content/ItemContent.php
M repo/includes/Content/PropertyContent.php
M repo/includes/Interactors/ItemMergeInteractor.php
M repo/includes/Interactors/RedirectCreationInteractor.php
5 files changed, 45 insertions(+), 4 deletions(-)


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

diff --git a/repo/includes/Content/EntityContent.php 
b/repo/includes/Content/EntityContent.php
index 230a062..ce57e4f 100644
--- a/repo/includes/Content/EntityContent.php
+++ b/repo/includes/Content/EntityContent.php
@@ -583,7 +583,7 @@
 
$redirAfterPatch = $this->getPatchedRedirect( 
$patch->getRedirectDiff() );
 
-   if ( $redirAfterPatch !== null && !$entityAfterPatch->isEmpty() 
) {
+   if ( $redirAfterPatch !== null && !$this->isEntityEmpty( 
$entityAfterPatch ) ) {
throw new PatcherException( 'EntityContent must not 
contain Entity data as well as'
. ' a redirect after applying the patch!' );
} elseif ( $redirAfterPatch ) {
@@ -636,7 +636,7 @@
}
 
$holder = $this->getEntityHolder();
-   return $holder === null || $holder->getEntity()->isEmpty();
+   return $holder === null || $this->isEntityEmpty( 
$holder->getEntity() );
}
 
/**
@@ -740,4 +740,16 @@
return [];
}
 
+   /**
+* Determines whether the Entity is empty. This implementations always 
returns false.
+* Subclasses should override this with the appropriate logic.
+*
+* @param EntityDocument $entity
+* @return bool
+*/
+   protected function isEntityEmpty( EntityDocument $entity ) {
+   // XXX: this could perhaps live in EntityHandler and subclasses 
instead!
+   return false;
+   }
+
 }
diff --git a/repo/includes/Content/ItemContent.php 
b/repo/includes/Content/ItemContent.php
index baf8af2..d385cd0 100644
--- a/repo/includes/Content/ItemContent.php
+++ b/repo/includes/Content/ItemContent.php
@@ -9,6 +9,7 @@
 use Title;
 use Wikibase\Content\EntityHolder;
 use Wikibase\Content\EntityInstanceHolder;
+use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\EntityRedirect;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\Repo\ItemSearchTextGenerator;
@@ -227,4 +228,9 @@
return $properties;
}
 
+   protected function isEntityEmpty( EntityDocument $entity ) {
+   /** @var Item $entity */
+   return $entity->isEmpty();
+   }
+
 }
diff --git a/repo/includes/Content/PropertyContent.php 
b/repo/includes/Content/PropertyContent.php
index 6732997..da6efda 100644
--- a/repo/includes/Content/PropertyContent.php
+++ b/repo/includes/Content/PropertyContent.php
@@ -6,6 +6,7 @@
 use LogicException;
 use Wikibase\Content\EntityHolder;
 use Wikibase\Content\EntityInstanceHolder;
+use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\Property;
 
 /**
@@ -135,4 +136,9 @@
return !$this->isRedirect() && $this->getProperty()->isEmpty();
}
 
+   protected function isEntityEmpty( EntityDocument $entity ) {
+   /** @var Property $entity */
+   return $entity->isEmpty();
+   }
+
 }
diff --git a/repo/includes/Interactors/ItemMergeInteractor.php 
b/repo/includes/Interactors/ItemMergeInteractor.php
index 686943c..e1187ce 100644
--- a/repo/includes/Interactors/ItemMergeInteractor.php
+++ b/repo/includes/Interactors/ItemMergeInteractor.php
@@ -14,6 +14,7 @@
 use Wikibase\EntityContent;
 use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityStore;
+use Wikibase\Repo\Content\EntityContentFactory;
 use Wikibase\Repo\Store\EntityTitleStoreLookup;
 use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException;
 use Wikibase\Lib\Store\StorageException;
@@ -70,6 +71,11 @@
 */
private $entityTitleLookup;
 
+   /**
+* @var EntityContentFactory
+*/
+   private $entityContentFactory;
+
public function __construct(
MergeChangeOpsFactory $changeOpFactory,
EntityRevisionLookup $entityRevisionLookup,
@@ -88,6 +94,7 @@
$this->user = $user;
$this->interactorRedirect = $interactorRedirect;
$this->entityTitleLookup = $entityTitleLookup;
+   $this->entityContentFactory = ...;
}
 
/**
@@ -181,7 +188,9 @@
 * @return 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Introcude the UserIdentity interface.

2017-11-16 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391888 )

Change subject: Introcude the UserIdentity interface.
..

Introcude the UserIdentity interface.

This provides a narrow view on a user identity, providing access to
ID and name.

This has been extracted from I140f43a6fb443b for re-use with Actors,
on Anomie's request.

Change-Id: Ief00db5ce382537c5bf992159eae6baf096ae4be
---
A includes/user/UserIdentity.php
1 file changed, 45 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/88/391888/1

diff --git a/includes/user/UserIdentity.php b/includes/user/UserIdentity.php
new file mode 100644
index 000..11d0035
--- /dev/null
+++ b/includes/user/UserIdentity.php
@@ -0,0 +1,45 @@
+http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+namespace MediaWiki\User;
+
+/**
+ * Interface for objects representing user identity.
+ *
+ * This represents the identity of a user in the context of page revisions and 
log entries.
+ */
+interface UserIdentity {
+
+   /**
+* @return int The user ID. May be 0 for anonymous users or for users 
with no local account.
+*/
+   public function getId();
+
+   /**
+* @return string The user's logical name. May be an IPv4 or IPv6 
address for anonymous users.
+*/
+   public function getName();
+
+   // TODO: in the future, we should also provide access to the actor ID 
here.
+   // TODO: we may want to (optionally?) provide a global ID, see 
CentralIdLookup.
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ief00db5ce382537c5bf992159eae6baf096ae4be
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Introduce DB schema overrides for unit tests.

2017-11-16 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391866 )

Change subject: Introduce DB schema overrides for unit tests.
..

Introduce DB schema overrides for unit tests.

This introduces MediaWikiTestCase::getSchemaOverrides,  which can be overwritten
to return information about which tables are going to be altered, and which SQL
files should be used to set up the target schema. This allows tests for a class
that interacts with the database can have a subclass for each supported database
schema.

Bug: T180705
Change-Id: I7a4071072d802a82ecf7d16fbf8882ff8c79287f
---
M includes/db/CloneDatabase.php
M includes/libs/rdbms/database/Database.php
M tests/phpunit/MediaWikiTestCase.php
A tests/phpunit/tests/MediaWikiTestCaseSchema1Test.php
A tests/phpunit/tests/MediaWikiTestCaseSchema2Test.php
A tests/phpunit/tests/MediaWikiTestCaseSchemaTest.sql
M tests/phpunit/tests/MediaWikiTestCaseTest.php
7 files changed, 238 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/66/391866/1

diff --git a/includes/db/CloneDatabase.php b/includes/db/CloneDatabase.php
index 3d22c03..98275db 100644
--- a/includes/db/CloneDatabase.php
+++ b/includes/db/CloneDatabase.php
@@ -53,12 +53,12 @@
 * @param bool $dropCurrentTables
 */
public function __construct( IMaintainableDatabase $db, array 
$tablesToClone,
-   $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true
+   $newTablePrefix, $oldTablePrefix = null, $dropCurrentTables = 
true
) {
$this->db = $db;
$this->tablesToClone = $tablesToClone;
$this->newTablePrefix = $newTablePrefix;
-   $this->oldTablePrefix = $oldTablePrefix ? $oldTablePrefix : 
$this->db->tablePrefix();
+   $this->oldTablePrefix = $oldTablePrefix !== null ? 
$oldTablePrefix : $this->db->tablePrefix();
$this->dropCurrentTables = $dropCurrentTables;
}
 
diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index e04566e..6ad5959 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -3390,7 +3390,15 @@
if ( $done || feof( $fp ) ) {
$cmd = $this->replaceVars( $cmd );
 
-   if ( !$inputCallback || call_user_func( 
$inputCallback, $cmd ) ) {
+   if ( $inputCallback ) {
+   $callbackResult = call_user_func( 
$inputCallback, $cmd );
+
+   if ( is_string( $callbackResult ) || 
$callbackResult === false ) {
+   $cmd = $callbackResult;
+   }
+   }
+
+   if ( $cmd ) {
$res = $this->query( $cmd, $fname );
 
if ( $resultCallback ) {
diff --git a/tests/phpunit/MediaWikiTestCase.php 
b/tests/phpunit/MediaWikiTestCase.php
index f04eec7..10b2a38 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -5,8 +5,10 @@
 use MediaWiki\Logger\MonologSpi;
 use MediaWiki\MediaWikiServices;
 use Psr\Log\LoggerInterface;
+use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\IMaintainableDatabase;
 use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\LBFactory;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -406,6 +408,7 @@
// is available in subclass's setUpBeforeClass() and 
setUp() methods.
// This would also remove the need for the HACK that is 
oncePerClass().
if ( $this->oncePerClass() ) {
+   $this->setUpSchema( $this->db );
$this->addDBDataOnce();
}
 
@@ -1152,6 +1155,8 @@
$dbClone = new CloneDatabase( $db, $tablesCloned, $prefix );
$dbClone->useTemporaryTables( self::$useTemporaryTables );
 
+   $db->_originalTablePrefix = $db->tablePrefix();
+
if ( ( $db->getType() == 'oracle' || !self::$useTemporaryTables 
) && self::$reuseDB ) {
CloneDatabase::changePrefix( $prefix );
 
@@ -1296,6 +1301,134 @@
}
 
/**
+* Fail with a LogicException if the given database connection is not a 
set up to use
+* mock tables.
+*/
+   private function ensureMockDatabaseConnection( IDatabase $db ) {
+   if ( $db->tablePrefix() !== self::DB_PREFIX ) {
+   throw new LogicException(
+   'Trying to delete mock tables, but table prefix 
does not indicate a mock database.'
+   

[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Allow action overrides to work with WikiPage for now.

2017-11-15 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391606 )

Change subject: Allow action overrides to work with WikiPage for now.
..

Allow action overrides to work with WikiPage for now.

This is needed until I0335100b2b is merged.

In order to test compliance, this patch changes LexemeHandlerTest to use
the EntityHandlerTest base class.

NOTE: the same should be done for MediaInfo.

Change-Id: I37e5d31f756d7d5d6613ee09e6accb31a99bd3eb
Depends-On: I487a4fcc62aa2ad9a4aeebab4d871583bbe876b8
---
M src/Content/LexemeHandler.php
M tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
2 files changed, 127 insertions(+), 64 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme 
refs/changes/06/391606/1

diff --git a/src/Content/LexemeHandler.php b/src/Content/LexemeHandler.php
index 54b5968..164f290 100644
--- a/src/Content/LexemeHandler.php
+++ b/src/Content/LexemeHandler.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Lexeme\Content;
 
+use Article;
 use IContextSource;
 use Page;
 use Wikibase\Content\EntityHolder;
@@ -79,7 +80,13 @@
 */
public function getActionOverrides() {
return [
-   'history' => function( Page $page, IContextSource 
$context = null ) {
+   'history' => function( Page $page, IContextSource 
$context ) {
+   // NOTE: for now, the callback must work with a 
WikiPage as well as an Article
+   // object. Once I0335100b2 is merged, this is 
no longer needed.
+   if ( !( $page instanceof Article ) ) {
+   $page = Article::newFromWikiPage( 
$page, $context );
+   }
+
return new HistoryEntityAction(
$page,
$context,
diff --git a/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php 
b/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
index a61d942..62da31a 100644
--- a/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
+++ b/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
@@ -8,19 +8,32 @@
 use IContextSource;
 use Language;
 use Page;
-use PHPUnit_Framework_TestCase;
 use RequestContext;
 use Title;
+use Wikibase\Content\EntityInstanceHolder;
+use Wikibase\DataModel\Entity\EntityDocument;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityIdParser;
+use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
+use Wikibase\DataModel\Term\Term;
+use Wikibase\DataModel\Term\TermList;
+use Wikibase\Lexeme\Content\LexemeContent;
+use Wikibase\Lexeme\DataModel\Serialization\ExternalLexemeSerializer;
+use Wikibase\Lexeme\DataModel\Serialization\StorageLexemeSerializer;
 use Wikibase\Lexeme\Search\LexemeFieldDefinitions;
+use Wikibase\Lib\EntityTypeDefinitions;
 use Wikibase\Lib\Store\EntityContentDataCodec;
 use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
 use Wikibase\Lexeme\Content\LexemeHandler;
 use Wikibase\Lexeme\DataModel\Lexeme;
 use Wikibase\Lexeme\DataModel\LexemeId;
+use Wikibase\Repo\Content\EntityHandler;
+use Wikibase\Repo\Tests\Content\EntityHandlerTest;
 use Wikibase\Repo\Validators\EntityConstraintProvider;
 use Wikibase\Repo\Validators\ValidatorErrorLocalizer;
+use Wikibase\Repo\WikibaseRepo;
+use Wikibase\SettingsArray;
 use Wikibase\Store\EntityIdLookup;
 use Wikibase\TermIndex;
 
@@ -32,7 +45,100 @@
  * @license GPL-2.0+
  * @author Bene* < benestar.wikime...@gmail.com >
  */
-class LexemeHandlerTest extends PHPUnit_Framework_TestCase {
+class LexemeHandlerTest extends EntityHandlerTest {
+
+   /**
+* @return string
+*/
+   public function getModelId() {
+   return LexemeContent::CONTENT_MODEL_ID;
+   }
+
+   /**
+* @param SettingsArray|null $settings
+*
+* @return EntityHandler
+*/
+   protected function getHandler( SettingsArray $settings = null ) {
+   return $this->getWikibaseRepo( $settings )
+   ->getEntityContentFactory()
+   ->getContentHandlerForType( Lexeme::ENTITY_TYPE );
+   }
+
+   /**
+* @param EntityId|null $id
+*
+* @return EntityDocument
+*/
+   protected function newEntity( EntityId $id = null ) {
+   if ( !$id ) {
+   $id = new LexemeId( 'L7' );
+   }
+
+   $lexeme = new Lexeme( $id );
+   $lexeme->setLemmas(
+   new TermList(
+   [
+   new Term( 'en', 'goat' ),
+   new Term( 'de', 'Ziege' ),
+   ]
+ 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Allow EntityHandlerTest to be used with Lexemes, etc.

2017-11-15 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391604 )

Change subject: Allow EntityHandlerTest to be used with Lexemes, etc.
..

Allow EntityHandlerTest to be used with Lexemes, etc.

This is needed to allow EntityHandlerTest to be used as a base class
for the respective tests for Lexeme and MediaInfo. Which in turn
is needed to make sure we are consistently asserting the contract
of EntityHandler.

Usinga base class for this isn't great, a trait would be better. That
change is left for later.

Change-Id: I487a4fcc62aa2ad9a4aeebab4d871583bbe876b8
---
M repo/tests/phpunit/includes/Content/EntityHandlerTest.php
M repo/tests/phpunit/includes/Content/ItemHandlerTest.php
M repo/tests/phpunit/includes/Content/PropertyHandlerTest.php
3 files changed, 46 insertions(+), 21 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php 
b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
index 60ccd2f..a3f7115 100644
--- a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
@@ -17,6 +17,7 @@
 use Revision;
 use RuntimeException;
 use SearchEngine;
+use Serializers\Serializer;
 use Title;
 use Wikibase\Content\EntityInstanceHolder;
 use Wikibase\DataModel\Entity\EntityDocument;
@@ -130,7 +131,7 @@
abstract protected function newEntity( EntityId $id = null );
 
/**
-* Returns EntityContents that can be handled by the EntityHandler 
deriving class.
+* Returns EntityContents that can be serialized by the EntityHandler 
deriving class.
 *
 * @return array[]
 */
@@ -388,6 +389,15 @@
$this->assertEquals( $idString, $id->getSerialization() );
}
 
+   /**
+* @return Serializer
+*/
+   protected function getEntitySerializer() {
+   $newSerializerFactory = new SerializerFactory( new 
DataValueSerializer() );
+   $newSerializer = $newSerializerFactory->newEntitySerializer();
+   return $newSerializer;
+   }
+
public function exportTransformProvider() {
$entity = $this->newEntity();
 
@@ -416,8 +426,7 @@
}
 
// make new style blob
-   $newSerializerFactory = new SerializerFactory( new 
DataValueSerializer() );
-   $newSerializer = $newSerializerFactory->newEntitySerializer();
+   $newSerializer = $this->getEntitySerializer();
$newBlob = json_encode( $newSerializer->serialize( $entity ) );
 
return [
@@ -457,7 +466,12 @@
 
public function testGetLegacyExportFormatDetector() {
$detector = 
$this->getHandler()->getLegacyExportFormatDetector();
-   $this->assertInternalType( 'callable', $detector );
+
+   if ( $detector === null ) {
+   $this->assertTrue( true ); // make sure PHPUnit is happy
+   } else {
+   $this->assertInternalType( 'callable', $detector );
+   }
}
 
public function forCreationParamProvider() {
@@ -565,7 +579,7 @@
}
}
 
-   abstract protected function getTestItemContent();
+   abstract protected function getTestContent();
 
/**
 * @param EntityHandler $handler
@@ -578,25 +592,13 @@
->setConstructorArgs( [ Title::newFromText( 'Q1' ) ] )
->getMock();
 
-   $page->method( 'getContent' )->willReturn( 
$this->getTestItemContent() );
+   $page->method( 'getContent' )->willReturn( 
$this->getTestContent() );
$page->method( 'getTitle' )->willReturn( $title );
 
return $page;
}
 
-   public function testDataForSearchIndex() {
-   $handler = $this->getHandler();
-   $engine = $this->getMock( \SearchEngine::class );
-
-   $page = $this->getMockWikiPage( $handler );
-
-   $data = $handler->getDataForSearchIndex( $page, new 
\ParserOutput(), $engine );
-   $this->assertSame( 1, $data['label_count'], 'label_count' );
-   if ( $handler instanceof ItemHandler ) {
-   $this->assertSame( 1, $data['sitelink_count'], 
'sitelink_count' );
-   }
-   $this->assertSame( 1, $data['statement_count'], 
'statement_count' );
-   }
+   public abstract function testDataForSearchIndex();
 
public function testGetActionOverrides() {
$handler = $this->getHandler();
diff --git a/repo/tests/phpunit/includes/Content/ItemHandlerTest.php 
b/repo/tests/phpunit/includes/Content/ItemHandlerTest.php
index 06796f6..174082f 100644
--- 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Action override callbacks must still accept WikiPage for now.

2017-11-15 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391577 )

Change subject: Action override callbacks must still accept WikiPage for now.
..

Action override callbacks must still accept WikiPage for now.

Bug: T180605
Change-Id: I81516b66a0831d0d89ab7b0cbe8d6b01e185e543
---
M repo/includes/Actions/HistoryEntityAction.php
M repo/includes/Content/ItemHandler.php
M repo/includes/Content/PropertyHandler.php
M repo/tests/phpunit/includes/Content/EntityHandlerTest.php
4 files changed, 89 insertions(+), 14 deletions(-)


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

diff --git a/repo/includes/Actions/HistoryEntityAction.php 
b/repo/includes/Actions/HistoryEntityAction.php
index 770582f..ebf012f 100644
--- a/repo/includes/Actions/HistoryEntityAction.php
+++ b/repo/includes/Actions/HistoryEntityAction.php
@@ -28,18 +28,18 @@
private $labelLookup;
 
/**
-* @param Article $page
+* @param Article $article
 * @param IContextSource|null $context
 * @param EntityIdLookup $entityIdLookup
 * @param LabelDescriptionLookup $labelLookup
 */
public function __construct(
-   Article $page,
+   Article $article,
IContextSource $context = null,
EntityIdLookup $entityIdLookup,
LabelDescriptionLookup $labelLookup
) {
-   parent::__construct( $page, $context );
+   parent::__construct( $article, $context );
 
$this->entityIdLookup = $entityIdLookup;
$this->labelLookup = $labelLookup;
diff --git a/repo/includes/Content/ItemHandler.php 
b/repo/includes/Content/ItemHandler.php
index b55eb9b..10a800c 100644
--- a/repo/includes/Content/ItemHandler.php
+++ b/repo/includes/Content/ItemHandler.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Content;
 
+use Article;
 use DataUpdate;
 use IContextSource;
 use Page;
@@ -109,7 +110,13 @@
 */
public function getActionOverrides() {
return [
-   'history' => function( Page $page, IContextSource 
$context = null ) {
+   'history' => function( Page $page, IContextSource 
$context ) {
+   // NOTE: for now, the callback must work with a 
WikiPage as well as an Article
+   // object. Once I0335100b2 is merged, this is 
no longer needed.
+   if ( !( $page instanceof Article ) ) {
+   $page = Article::newFromWikiPage( 
$page, $context );
+   }
+
return new HistoryEntityAction(
$page,
$context,
diff --git a/repo/includes/Content/PropertyHandler.php 
b/repo/includes/Content/PropertyHandler.php
index 2cc9b5a..e201c0e 100644
--- a/repo/includes/Content/PropertyHandler.php
+++ b/repo/includes/Content/PropertyHandler.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Content;
 
+use Article;
 use DataUpdate;
 use IContextSource;
 use Page;
@@ -104,7 +105,13 @@
 */
public function getActionOverrides() {
return [
-   'history' => function( Page $page, IContextSource 
$context = null ) {
+   'history' => function( Page $page, IContextSource 
$context ) {
+   // NOTE: for now, the callback must work with a 
WikiPage as well as an Article
+   // object. Once I0335100b2 is merged, this is 
no longer needed.
+   if ( !( $page instanceof Article ) ) {
+   $page = Article::newFromWikiPage( 
$page, $context );
+   }
+
return new HistoryEntityAction(
$page,
$context,
diff --git a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php 
b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
index 0d2c12e..852a47f 100644
--- a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
@@ -2,6 +2,8 @@
 
 namespace Wikibase\Repo\Tests\Content;
 
+use Action;
+use Article;
 use ContentHandler;
 use DataValues\Serializers\DataValueSerializer;
 use DummySearchIndexFieldDefinition;
@@ -10,6 +12,7 @@
 use Language;
 use LogicException;
 use MWException;
+use PHPUnit_Framework_MockObject_MockObject;
 use RequestContext;
 use Revision;
 use RuntimeException;
@@ -493,15 +496,25 @@
$this->assertRegExp( '/wb\d+/', $hash, 'contains Wikibase 
version' );
}
 
+   /**
+* @param Title $title
+* @return RequestContext
+  

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Always supplay an Article when constructing an Action.

2017-11-01 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387788 )

Change subject: Always supplay an Article when constructing an Action.
..

Always supplay an Article when constructing an Action.

This is required for compatibility with I0335100b2bb.

Change-Id: Icf6055feb2a12f60017cbfdb45c9835ddc9b50b3
---
M 
client/tests/phpunit/includes/Hooks/SkinTemplateOutputPageBeforeExecHandlerTest.php
M repo/includes/Actions/HistoryEntityAction.php
2 files changed, 21 insertions(+), 8 deletions(-)


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

diff --git 
a/client/tests/phpunit/includes/Hooks/SkinTemplateOutputPageBeforeExecHandlerTest.php
 
b/client/tests/phpunit/includes/Hooks/SkinTemplateOutputPageBeforeExecHandlerTest.php
index e4099ee..cb53f84 100644
--- 
a/client/tests/phpunit/includes/Hooks/SkinTemplateOutputPageBeforeExecHandlerTest.php
+++ 
b/client/tests/phpunit/includes/Hooks/SkinTemplateOutputPageBeforeExecHandlerTest.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Client\Tests\Hooks;
 
 use ConfigFactory;
+use ContentHandler;
 use FauxRequest;
 use IContextSource;
 use OutputPage;
@@ -139,11 +140,7 @@
$output = new OutputPage( $this->getContext() );
$output->setProperty( 'noexternallanglinks', 
$noexternallanglinks );
$output->setProperty( 'wikibase_item', 'Q2013' );
-
-   $title = $this->getMock( Title::class );
-   $title->expects( $this->any() )
-   ->method( 'exists' )
-   ->will( $this->returnValue( true ) );
+   $title = $output->getTitle();
 
$skin->expects( $this->any() )
->method( 'getOutput' )
@@ -164,12 +161,25 @@
private function getContext() {
$request = new FauxRequest( [ 'action' => 'view' ] );
 
+   $title = $this->getMock( Title::class );
+   $title->expects( $this->any() )
+   ->method( 'exists' )
+   ->will( $this->returnValue( true ) );
+
+   $contentHandler = ContentHandler::getForModelID( 
CONTENT_MODEL_WIKITEXT );
+
$wikiPage = $this->getMockBuilder( WikiPage::class )
->disableOriginalConstructor()
->getMock();
$wikiPage->expects( $this->any() )
->method( 'getActionOverrides' )
->will( $this->returnValue( [] ) );
+   $wikiPage->expects( $this->any() )
+   ->method( 'getContentHandler' )
+   ->will( $this->returnValue( $contentHandler ) );
+   $wikiPage->expects( $this->any() )
+   ->method( 'getTitle' )
+   ->will( $this->returnValue( $title ) );
 
$context = $this->getMock( IContextSource::class );
$context->expects( $this->any() )
@@ -182,6 +192,9 @@
->method( 'getRequest' )
->will( $this->returnValue( $request ) );
$context->expects( $this->any() )
+   ->method( 'getTitle' )
+   ->will( $this->returnValue( $title ) );
+   $context->expects( $this->any() )
->method( 'getConfig' )
->will( $this->returnValue(

ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
diff --git a/repo/includes/Actions/HistoryEntityAction.php 
b/repo/includes/Actions/HistoryEntityAction.php
index b572bfd..770582f 100644
--- a/repo/includes/Actions/HistoryEntityAction.php
+++ b/repo/includes/Actions/HistoryEntityAction.php
@@ -2,9 +2,9 @@
 
 namespace Wikibase;
 
+use Article;
 use HistoryAction;
 use IContextSource;
-use Page;
 use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
 use Wikibase\Store\EntityIdLookup;
 
@@ -28,13 +28,13 @@
private $labelLookup;
 
/**
-* @param Page $page
+* @param Article $page
 * @param IContextSource|null $context
 * @param EntityIdLookup $entityIdLookup
 * @param LabelDescriptionLookup $labelLookup
 */
public function __construct(
-   Page $page,
+   Article $page,
IContextSource $context = null,
EntityIdLookup $entityIdLookup,
LabelDescriptionLookup $labelLookup

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf6055feb2a12f60017cbfdb45c9835ddc9b50b3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 


[MediaWiki-commits] [Gerrit] mediawiki...WikibaseMediaInfo[master]: Always supplay an Article when constructing an Action.

2017-11-01 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387787 )

Change subject: Always supplay an Article when constructing an Action.
..

Always supplay an Article when constructing an Action.

This is required for compatibility with I0335100b2bb.

Change-Id: I55edb348f7bcbf298814bae335936cf6485d0443
---
M src/Content/MediaInfoHandler.php
M tests/phpunit/mediawiki/Content/MediaInfoHandlerTest.php
2 files changed, 8 insertions(+), 4 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseMediaInfo 
refs/changes/87/387787/1

diff --git a/src/Content/MediaInfoHandler.php b/src/Content/MediaInfoHandler.php
index b149ba3..c46a0b2 100644
--- a/src/Content/MediaInfoHandler.php
+++ b/src/Content/MediaInfoHandler.php
@@ -2,8 +2,8 @@
 
 namespace Wikibase\MediaInfo\Content;
 
+use Article;
 use IContextSource;
-use Page;
 use Title;
 use Wikibase\Content\EntityHolder;
 use Wikibase\DataModel\Entity\EntityId;
@@ -99,7 +99,7 @@
 */
public function getActionOverrides() {
return [
-   'history' => function( Page $page, IContextSource 
$context = null ) {
+   'history' => function( Article $page, IContextSource 
$context = null ) {
return new HistoryEntityAction(
$page,
$context,
diff --git a/tests/phpunit/mediawiki/Content/MediaInfoHandlerTest.php 
b/tests/phpunit/mediawiki/Content/MediaInfoHandlerTest.php
index c25550a..02206a4 100644
--- a/tests/phpunit/mediawiki/Content/MediaInfoHandlerTest.php
+++ b/tests/phpunit/mediawiki/Content/MediaInfoHandlerTest.php
@@ -3,11 +3,11 @@
 namespace Wikibase\MediaInfo\Tests\MediaWiki\Content;
 
 use Action;
+use Article;
 use Closure;
 use FauxRequest;
 use IContextSource;
 use Language;
-use Page;
 use PHPUnit_Framework_TestCase;
 use RequestContext;
 use Title;
@@ -116,7 +116,11 @@
->method( 'getLanguage' )
->will( $this->returnValue( 
$this->getMockWithoutConstructor( Language::class ) ) );
 
-   $action = $override( $this->getMock( Page::class ), 
$context );
+   $article = $this->getMockBuilder( Article::class )
+   ->disableOriginalConstructor()
+   ->getMock();
+
+   $action = $override( $article, $context );
$this->assertInstanceOf( Action::class, $action );
} else {
$this->assertTrue( is_subclass_of( $override, 
Action::class ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I55edb348f7bcbf298814bae335936cf6485d0443
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseMediaInfo
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Deprecate methods in Article that delegate to WikiPage

2017-10-31 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387685 )

Change subject: Deprecate methods in Article that delegate to WikiPage
..

Deprecate methods in Article that delegate to WikiPage

The intent of this patch is to free us of the need to mirror
WikiPage's interface in the old Article class. This is a precondition
to splitting WikiPage into PageRecord, PageStore, and PageUpdater
for MCR.

Change-Id: I0335100b2bb41b783b73487b083b7fdef76e7ad9
---
M autoload.php
M includes/MediaWiki.php
M includes/actions/Action.php
M includes/actions/CachedAction.php
M includes/actions/CreditsAction.php
M includes/actions/DeleteAction.php
M includes/actions/EditAction.php
M includes/actions/FormAction.php
M includes/actions/HistoryAction.php
M includes/actions/InfoAction.php
M includes/actions/ProtectAction.php
M includes/actions/PurgeAction.php
M includes/actions/RawAction.php
M includes/actions/RenderAction.php
M includes/actions/RevertAction.php
M includes/actions/RollbackAction.php
M includes/actions/ViewAction.php
M includes/page/Article.php
M includes/page/Page.php
A includes/page/PageDisplayController.php
M includes/page/WikiPage.php
M tests/phpunit/includes/actions/ActionTest.php
22 files changed, 280 insertions(+), 73 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/85/387685/1

diff --git a/autoload.php b/autoload.php
index 3bee411..2d2111b 100644
--- a/autoload.php
+++ b/autoload.php
@@ -1084,6 +1084,7 @@
'Page' => __DIR__ . '/includes/page/Page.php',
'PageArchive' => __DIR__ . '/includes/page/PageArchive.php',
'PageDataRequestHandler' => __DIR__ . 
'/includes/linkeddata/PageDataRequestHandler.php',
+   'PageDisplayController' => __DIR__ . 
'/includes/page/PageDisplayController.php',
'PageExists' => __DIR__ . '/maintenance/pageExists.php',
'PageLangLogFormatter' => __DIR__ . 
'/includes/logging/PageLangLogFormatter.php',
'PageProps' => __DIR__ . '/includes/PageProps.php',
diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index 43de4ba..9f06a7e 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -458,23 +458,23 @@
/**
 * Perform one of the "standard" actions
 *
-* @param Page $page
+* @param Article $article
 * @param Title $requestTitle The original title, before any redirects 
were applied
 */
-   private function performAction( Page $page, Title $requestTitle ) {
+   private function performAction( Article $article, Title $requestTitle ) 
{
$request = $this->context->getRequest();
$output = $this->context->getOutput();
$title = $this->context->getTitle();
$user = $this->context->getUser();
 
if ( !Hooks::run( 'MediaWikiPerformAction',
-   [ $output, $page, $title, $user, $request, 
$this ] )
+   [ $output, $article, $title, $user, $request, 
$this ] )
) {
return;
}
 
$act = $this->getAction();
-   $action = Action::factory( $act, $page, $this->context );
+   $action = Action::factory( $act, $article, $this->context );
 
if ( $action instanceof Action ) {
// Narrow DB query expectations for this HTTP request
@@ -504,7 +504,7 @@
'UnknownAction',
[
$request->getVal( 'action', 'view' ),
-   $page
+   $article
],
'1.19'
) ) {
diff --git a/includes/actions/Action.php b/includes/actions/Action.php
index e8d9a3e..c8a72fa 100644
--- a/includes/actions/Action.php
+++ b/includes/actions/Action.php
@@ -39,7 +39,7 @@
/**
 * Page on which we're performing the action
 * @since 1.17
-* @var WikiPage|Article|ImagePage|CategoryPage|Page $page
+* @var Article
 */
protected $page;
 
@@ -84,27 +84,47 @@
}
 
/**
+* @param WikiPage $page
+*
+* @return array
+*/
+   private static function getActionOverrides( WikiPage $page ) {
+   // TODO: action overrides need to take into account the target 
slot and the namespace.
+   return $page->getContentHandler()->getActionOverrides();
+   }
+
+   /**
 * Get an appropriate Action subclass for the given action
 * @since 1.17
 * @param string $action
-* @param Page $page
+* @param WikiPage|Article $article
 * @param IContextSource|null $context
 * @return Action|bool|null False if the action is disabled, null
 * if it is not recognised
 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: [MCR] Make WikiPage use Revisionrecord instead of Revision

2017-10-31 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387640 )

Change subject: [MCR] Make WikiPage use Revisionrecord instead of Revision
..

[MCR] Make WikiPage use Revisionrecord instead of Revision

This is preparatory work for splittinng WikiPage into
PageRecord, PageStore, and PageUpdater.

Change-Id: I29d817b682ed556875e1f520d410f0623a4cc15b
---
M includes/Storage/RevisionStore.php
M includes/Title.php
M includes/page/WikiPage.php
M includes/resourceloader/ResourceLoaderWikiModule.php
4 files changed, 271 insertions(+), 108 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/40/387640/1

diff --git a/includes/Storage/RevisionStore.php 
b/includes/Storage/RevisionStore.php
index fa566d3..9b34d1e 100644
--- a/includes/Storage/RevisionStore.php
+++ b/includes/Storage/RevisionStore.php
@@ -1727,6 +1727,41 @@
}
}
 
+   /**
+* Get the first revision of the page, or null if the page does not 
exist.
+*
+* @param Title $title
+* @param int $flags See IDBAccessObject::READ_XXX, default is 0.
+*
+* @return RevisionRecord|null
+*/
+   public function getFirstRevision( Title $title, $flags = 0 ) {
+   if ( !$title->exists( $flags ) ) {
+   return null;
+   }
+
+   $pageId = $title->getArticleID( $flags );
+
+   $db = ( $flags & self::READ_LATEST )
+   ? $this->getDBConnection( DB_MASTER )
+   : $this->getDBConnection( DB_REPLICA );
+
+   $row = $db->selectRow( 'revision', self::selectRevisionFields(),
+   [ 'rev_page' => $pageId ],
+   __METHOD__,
+   [
+   'ORDER BY' => 'rev_timestamp ASC, rev_id ASC',
+   'IGNORE INDEX' => 'rev_timestamp', // See 
T159319
+   ]
+   );
+
+   if ( $row ) {
+   return $this->newRevisionFromRow( $row );
+   }
+
+   return null;
+   }
+
// TODO: move relevant methods from Title here, e.g. getFirstRevision, 
isBigDeletion, etc.
 
 }
diff --git a/includes/Title.php b/includes/Title.php
index 718239d..492b747 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -22,6 +22,7 @@
  * @file
  */
 
+use MediaWiki\Storage\RevisionStore;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
 use MediaWiki\Linker\LinkTarget;
@@ -51,7 +52,7 @@
 * Used to be GAID_FOR_UPDATE define. Used with getArticleID() and 
friends
 * to use the master DB
 */
-   const GAID_FOR_UPDATE = 1;
+   const GAID_FOR_UPDATE = IDBAccessObject::READ_LATEST;
 
/**
 * @name Private member variables
@@ -4184,28 +4185,19 @@
}
 
/**
-* Get the first revision of the page
+* Get the first revision of the page, or null if the page does not 
exist.
 *
 * @param int $flags Title::GAID_FOR_UPDATE
 * @return Revision|null If page doesn't exist
 */
public function getFirstRevision( $flags = 0 ) {
-   $pageId = $this->getArticleID( $flags );
-   if ( $pageId ) {
-   $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( 
DB_MASTER ) : wfGetDB( DB_REPLICA );
-   $row = $db->selectRow( 'revision', 
Revision::selectFields(),
-   [ 'rev_page' => $pageId ],
-   __METHOD__,
-   [
-   'ORDER BY' => 'rev_timestamp ASC, 
rev_id ASC',
-   'IGNORE INDEX' => 'rev_timestamp', // 
See T159319
-   ]
-   );
-   if ( $row ) {
-   return new Revision( $row );
-   }
-   }
-   return null;
+   // not needed if we rely on self::GAID_FOR_UPDATE === 
RevisionStore::READ_LATEST.
+   $revStoreFlags = ( $flags & self::GAID_FOR_UPDATE ) ? 
RevisionStore::READ_LATEST : 0;
+
+   $revStore = 
MediaWikiServices::getInstance()->getRevisionStore(); // inject?
+   $revRec = $revStore->getFirstRevision( $this, $revStoreFlags );
+
+   return $revRec ? new Revision( $revRec, $revStoreFlags, $this ) 
: null;
}
 
/**
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index e015230..a9b9ba4 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -23,6 +23,8 @@
 use MediaWiki\Edit\PreparedEdit;
 use \MediaWiki\Logger\LoggerFactory;
 use \MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\RevisionRecord;
+use 

[MediaWiki-commits] [Gerrit] mediawiki...MobileFrontend[master]: Make MFMockRevision more robust against changes to Revision.

2017-10-30 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387353 )

Change subject: Make MFMockRevision more robust against changes to Revision.
..

Make MFMockRevision more robust against changes to Revision.

This allows MFMockRevision to work with I4f24e7fbb

Change-Id: I9593276eba701e34ad93ea568441196cedcaa2fb
---
M tests/phpunit/specials/SpecialMobileDiffTest.php
1 file changed, 21 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/53/387353/1

diff --git a/tests/phpunit/specials/SpecialMobileDiffTest.php 
b/tests/phpunit/specials/SpecialMobileDiffTest.php
index cb9f39c..674cac2 100644
--- a/tests/phpunit/specials/SpecialMobileDiffTest.php
+++ b/tests/phpunit/specials/SpecialMobileDiffTest.php
@@ -3,7 +3,7 @@
 /**
  * @group MobileFrontend
  */
-class SpecialMobileDiffTest extends MediaWikiTestCase {
+class SpecialMobileDiffTest extends MediaWikiLangTestCase {
/** Keeps track of request variables that should be unset on teardown 
**/
private $unsetReqVals = [];
 
@@ -101,31 +101,37 @@
 }
 
 class MFMockRevision extends Revision {
-   private $id;
 
-   public function getId() {
-   return $this->id;
-   }
-
+   /**
+* @param int $revisionId
+*/
public function __construct( $revisionId ) {
-   if ( $revisionId > 200 ) {
-   throw new Exception( 'Unknown revision ID' );
-   }
-   $this->id = $revisionId;
+   $title = Title::newFromText( "Page_$revisionId" );
+
+   parent::__construct( [
+   'id' => $revisionId,
+   'title' => $title,
+   ] );
}
 
public static function newFromId( $revisionId, $flags = 0 ) {
if ( $revisionId <= 200 ) {
return new MFMockRevision( $revisionId );
+   } else {
+   return null;
}
}
 
-   public function getTitle() {
-   return Title::newFromText( "Page_$this->id" );
+   public function getPrevious() {
+   return new MFMockRevision( $this->getId() - 1 );
}
 
-   public function getPrevious() {
-   return new MFMockRevision( $this->id - 1 );
+   public function getSize() {
+   return 100;
+   }
+
+   public function getSha1() {
+   return 'mock-hash-' . $this->getId();
}
 
/**
@@ -134,7 +140,7 @@
 * @return Revision or null
 */
public function getNext() {
-   return new MFMockRevision( $this->id + 1 );
+   return new MFMockRevision( $this->getId() + 1 );
}
 }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9593276eba701e34ad93ea568441196cedcaa2fb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Use mock titles instead of bogus page IDs in tests.

2017-10-30 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387302 )

Change subject: Use mock titles instead of bogus page IDs in tests.
..

Use mock titles instead of bogus page IDs in tests.

With MCR, Revision objects can no longer be constructed with a bad
page ID, unless a Title object is provided.

Change-Id: I3e069144c1958457e6fa9e44cbda8a6236b34993
---
M repo/tests/phpunit/includes/Content/EntityHandlerTest.php
M repo/tests/phpunit/includes/Notifications/ChangeNotifierTest.php
2 files changed, 34 insertions(+), 2 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php 
b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
index 024c989..8cda580 100644
--- a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
@@ -230,9 +230,25 @@
}
 
protected function fakeRevision( EntityContent $content, $id = 0 ) {
+   $title = $this->getMockBuilder( Title::class )
+   ->disableOriginalConstructor()
+   ->getMock();
+
+   $title->expects( $this->any() )
+   ->method( 'exists()' )
+   ->will( $this->returnValue( true ) );
+
+   $title->expects( $this->any() )
+   ->method( 'getArticleId()' )
+   ->will( $this->returnValue( $id ) );
+
+   $title->expects( $this->any() )
+   ->method( 'getLatestRevId()' )
+   ->will( $this->returnValue( $id ) );
+
$revision = new Revision( [
'id' => $id,
-   'page' => $id,
+   'title' => $title,
'content' => $content,
] );
 
diff --git a/repo/tests/phpunit/includes/Notifications/ChangeNotifierTest.php 
b/repo/tests/phpunit/includes/Notifications/ChangeNotifierTest.php
index 81d98db..2a06d15 100644
--- a/repo/tests/phpunit/includes/Notifications/ChangeNotifierTest.php
+++ b/repo/tests/phpunit/includes/Notifications/ChangeNotifierTest.php
@@ -75,9 +75,25 @@
 * @return Revision
 */
private function makeRevision( Content $content, User $user, 
$revisionId, $timestamp, $parent_id = 0 ) {
+   $title = $this->getMockBuilder( Title::class )
+   ->disableOriginalConstructor()
+   ->getMock();
+
+   $title->expects( $this->any() )
+   ->method( 'exists()' )
+   ->will( $this->returnValue( true ) );
+
+   $title->expects( $this->any() )
+   ->method( 'getArticleId()' )
+   ->will( $this->returnValue( 7 ) );
+
+   $title->expects( $this->any() )
+   ->method( 'getLatestRevId()' )
+   ->will( $this->returnValue( $revisionId ) );
+
return new Revision( [
'id' => $revisionId,
-   'page' => 7,
+   'title' => $title,
'content' => $content,
'user' => $user->getId(),
'user_text' => $user->getName(),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e069144c1958457e6fa9e44cbda8a6236b34993
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Warn when page_latest is 0 unexpectedly.

2017-10-28 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387063 )

Change subject: Warn when page_latest is 0 unexpectedly.
..

Warn when page_latest is 0 unexpectedly.

Change-Id: I5aec379f2df0d39aad7c90a7ae2ea69abb7b4210
---
M includes/Title.php
M includes/cache/LinkCache.php
2 files changed, 11 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/63/387063/1

diff --git a/includes/Title.php b/includes/Title.php
index 718239d..22b98b3 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -481,6 +481,10 @@
}
if ( isset( $row->page_latest ) ) {
$this->mLatestID = (int)$row->page_latest;
+   if ( !$this->mLatestID ) {
+   wfWarn( 'Initializing Title from page 
row with page_latest = 0!' );
+   $this->mLatestID = false;
+   }
}
if ( !$this->mForcedContentModel && isset( 
$row->page_content_model ) ) {
$this->mContentModel = strval( 
$row->page_content_model );
@@ -3431,6 +3435,7 @@
$cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
if ( $cached === null ) {
# Trust LinkCache's state over our own, as for 
isRedirect()
+   // XXX: Shouldn't we set $this->mArticleID = 0 here? Or 
call resetArticleID()?
$this->mLatestID = 0;
return $this->mLatestID;
}
diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php
index 2d08895..1a87c01 100644
--- a/includes/cache/LinkCache.php
+++ b/includes/cache/LinkCache.php
@@ -271,8 +271,12 @@
}
 
if ( $row ) {
-   $this->addGoodLinkObjFromRow( $nt, $row );
-   $id = intval( $row->page_id );
+   if ( intval( $row->page_latest ) ) {
+   $this->addGoodLinkObjFromRow( $nt, $row );
+   $id = intval( $row->page_id );
+   } else {
+   wfWarn( 'Attempt to cache incomplete page row 
for page ID ' . $row->page_id . '!' );
+   }
} else {
$this->addBadLinkObj( $nt );
$id = 0;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5aec379f2df0d39aad7c90a7ae2ea69abb7b4210
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Introduce EntityByTitleLookup for use by EntityByTitleHelper...

2017-10-25 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/386422 )

Change subject: Introduce EntityByTitleLookup for use by EntityByTitleHelper 
and EntityLoadingHelper.
..

Introduce EntityByTitleLookup for use by EntityByTitleHelper and 
EntityLoadingHelper.

EntityByTitleLookup replaces SiteLinkLookup in this context, to provide a more 
narrow interface
that can more easily be used with alternative implementations.

Background: We want to be able to address MediaInfo entities via the name of 
the file page.

Bug: T177022
Change-Id: Ia43ebfa2449c10dc5c391a5d122e4ed989d7fc1d
---
A lib/includes/Store/EntityByTitleLookup.php
M lib/includes/Store/HashSiteLinkStore.php
M lib/includes/Store/SiteLinkStore.php
M lib/includes/Store/Sql/SiteLinkTable.php
M lib/tests/phpunit/Store/HashSiteLinkStoreTest.php
M lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php
M repo/includes/Api/ApiHelperFactory.php
R repo/includes/Api/EntityByTitleHelper.php
M repo/includes/Api/EntityLoadingHelper.php
M repo/includes/Api/GetEntities.php
M repo/includes/Store/Sql/SqlStore.php
M repo/includes/Store/Store.php
M repo/includes/WikibaseRepo.php
R repo/tests/phpunit/includes/Api/EntityByTitleHelperTest.php
M repo/tests/phpunit/includes/Api/EntityLoadingHelperTest.php
15 files changed, 178 insertions(+), 79 deletions(-)


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

diff --git a/lib/includes/Store/EntityByTitleLookup.php 
b/lib/includes/Store/EntityByTitleLookup.php
new file mode 100644
index 000..3a31fe4
--- /dev/null
+++ b/lib/includes/Store/EntityByTitleLookup.php
@@ -0,0 +1,27 @@
+getSiteId() . ':' . $siteLink->getPageName();
}
 
+   /**
+* @param string $globalSiteId
+* @param string $pageTitle
+*
+* @return EntityId|null
+*/
+   public function getEntityIdForLink( $globalSiteId, $pageTitle ) {
+   return $this->getItemIdForLink( $globalSiteId, $pageTitle );
+   }
+
 }
diff --git a/lib/includes/Store/SiteLinkStore.php 
b/lib/includes/Store/SiteLinkStore.php
index a002365..1512cfa 100644
--- a/lib/includes/Store/SiteLinkStore.php
+++ b/lib/includes/Store/SiteLinkStore.php
@@ -11,7 +11,7 @@
  * @license GPL-2.0+
  * @author Jeroen De Dauw < jeroended...@gmail.com >
  */
-interface SiteLinkStore extends SiteLinkLookup {
+interface SiteLinkStore extends SiteLinkLookup, EntityByTitleLookup {
 
/**
 * Saves the links for the provided item.
diff --git a/lib/includes/Store/Sql/SiteLinkTable.php 
b/lib/includes/Store/Sql/SiteLinkTable.php
index c5304d5..28f0830 100644
--- a/lib/includes/Store/Sql/SiteLinkTable.php
+++ b/lib/includes/Store/Sql/SiteLinkTable.php
@@ -4,6 +4,7 @@
 
 use DBAccessBase;
 use MWException;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\SiteLink;
@@ -343,4 +344,14 @@
return $siteLinks;
}
 
+   /**
+* @param string $globalSiteId
+* @param string $pageTitle
+*
+* @return EntityId|null
+*/
+   public function getEntityIdForLink( $globalSiteId, $pageTitle ) {
+   return $this->getItemIdForLink( $globalSiteId, $pageTitle );
+   }
+
 }
diff --git a/lib/tests/phpunit/Store/HashSiteLinkStoreTest.php 
b/lib/tests/phpunit/Store/HashSiteLinkStoreTest.php
index 34ba82f..d3e651f 100644
--- a/lib/tests/phpunit/Store/HashSiteLinkStoreTest.php
+++ b/lib/tests/phpunit/Store/HashSiteLinkStoreTest.php
@@ -32,6 +32,19 @@
$this->assertNull( $siteLinkStore->getItemIdForLink( 'xywiki', 
'Foo' ) );
}
 
+   public function testGetEntityIdForLink() {
+   $itemId = new ItemId( 'Q900' );
+
+   $item = new Item( $itemId );
+   $item->getSiteLinkList()->addNewSiteLink( 'enwiki', 'Foo' );
+
+   $siteLinkStore = new HashSiteLinkStore();
+   $siteLinkStore->saveLinksOfItem( $item );
+
+   $this->assertEquals( $itemId, 
$siteLinkStore->getEntityIdForLink( 'enwiki', 'Foo' ) );
+   $this->assertNull( $siteLinkStore->getEntityIdForLink( 
'xywiki', 'Foo' ) );
+   }
+
public function provideGetLinks() {
$cases = [];
 
diff --git a/lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php 
b/lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php
index ecc8a9d..35e4422a 100644
--- a/lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php
+++ b/lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php
@@ -142,6 +142,19 @@
/**
 * @dataProvider itemProvider
 */
+   public function testGetEntityIdForLink( Item $item ) {
+   $this->siteLinkTable->saveLinksOfItem( $item );
+   foreach ( $item->getSiteLinkList()->toArray() as $siteLink ) {
+   $this->assertEquals(
+ 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Treat NULL and 0 as equivalent for rev_parent_id

2017-10-23 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/386048 )

Change subject: Treat NULL and 0 as equivalent for rev_parent_id
..

Treat NULL and 0 as equivalent for rev_parent_id

The return value of Revision::getParentId is under-specified.
Calling code should treat null and 0 as equivalent.

Change-Id: Ia4e281c6b499441803b581ba81d3211e1a09789a
---
M client/includes/RecentChanges/RevisionData.php
M repo/Wikibase.hooks.php
2 files changed, 13 insertions(+), 4 deletions(-)


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

diff --git a/client/includes/RecentChanges/RevisionData.php 
b/client/includes/RecentChanges/RevisionData.php
index 48ab89d..7ab6d63 100644
--- a/client/includes/RecentChanges/RevisionData.php
+++ b/client/includes/RecentChanges/RevisionData.php
@@ -98,7 +98,7 @@
 * @return int
 */
public function getParentId() {
-   return $this->changeParams['parent_id'];
+   return intval( $this->changeParams['parent_id'] );
}
 
/**
diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index aea60e9..253486e 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -192,12 +192,21 @@
self::notifyEntityStoreWatcherOnUpdate( $revision );
 
$notifier = 
WikibaseRepo::getDefaultInstance()->getChangeNotifier();
+   $parentId = $revision->getParentId();
 
-   if ( $revision->getParentId() === null ) {
+   if ( !$parentId ) {
$notifier->notifyOnPageCreated( $revision );
} else {
-   $parent = Revision::newFromId( 
$revision->getParentId() );
-   $notifier->notifyOnPageModified( $revision, 
$parent );
+   $parent = Revision::newFromId( $parentId );
+
+   if ( !$parent ) {
+   wfLogWarning(
+   __METHOD__ . ': Cannot notify 
on page modification: '
+   . 'failed to load parent 
revision with ID ' . $parentId
+   );
+   } else {
+   $notifier->notifyOnPageModified( 
$revision, $parent );
+   }
}
}
}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia4e281c6b499441803b581ba81d3211e1a09789a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Add tracking for fallout from fix for T177707

2017-10-11 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/383551 )

Change subject: Add tracking for fallout from fix for T177707
..

Add tracking for fallout from fix for T177707

Bug: T177707
Change-Id: I1c7766f795c15bef31e3824213c70f7b33113463
---
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
2 files changed, 4 insertions(+), 0 deletions(-)


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

diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index 70b9659..a5c6eee 100644
--- a/client/includes/Changes/WikiPageUpdater.php
+++ b/client/includes/Changes/WikiPageUpdater.php
@@ -241,6 +241,9 @@
 
$this->incrementStats( 'InjectRCRecords.jobs', count( $jobs ) );
$this->incrementStats( 'InjectRCRecords.titles', $titleCount );
+
+   // tracking fallout of the hacky fix for T177707
+   $this->incrementStats( 'InjectRCRecords.discardedTitles', 
count( $titles ) - $titleCount );
}
 
 }
diff --git a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php 
b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
index 97b9df1..8614998 100644
--- a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
+++ b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
@@ -279,6 +279,7 @@
// FIXME: Because of the hot fix for T177707 we 
expect only the first batch.
'InjectRCRecords.jobs' => 1,
'InjectRCRecords.titles' => 2,
+   'InjectRCRecords.discardedTitles' => 1,
] )
);
$updater->setRecentChangesBatchSize( 2 );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c7766f795c15bef31e3824213c70f7b33113463
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Quick fix for flooding of the RC table.

2017-10-10 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/383384 )

Change subject: Quick fix for flooding of the RC table.
..

Quick fix for flooding of the RC table.

Under some conditions, Wikibase can trigger a very large number (millions)
of recentchanges rows to be inserted as the result of a single edit. These
inserts are batched according to the recentChangesBatchSize setting.

This patch aborts the injection after the first batch, to mittigate
the problem if flooding the rc table. This is not a permanent solution,
please refer to T177707 for discussion. ONe possible refinement would be
to inject rc records only for the pages with the most watchers.

Bug: T177707
Change-Id: I0162cbfd6db3ef147745d281a7568313e998f0c3
---
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
2 files changed, 6 insertions(+), 3 deletions(-)


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

diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index f637c25..3bdbe69 100644
--- a/client/includes/Changes/WikiPageUpdater.php
+++ b/client/includes/Changes/WikiPageUpdater.php
@@ -230,6 +230,7 @@
. count( $batch ) . " titles" );
 
$jobs[] = InjectRCRecordsJob::makeJobSpecification( 
$batch, $change, $rootJobParams );
+   break; // Quick fix for T177707.
}
 
$this->jobQueueGroup->lazyPush( $jobs );
diff --git a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php 
b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
index 6137192..e07d54c 100644
--- a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
+++ b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
@@ -276,7 +276,7 @@
$this->getLBFactoryMock(),
$this->getRCDupeDetectorMock(),
$this->getStatsdDataFactoryMock( [
-   'InjectRCRecords.jobs' => 2, // 2 batches 
(batch size 2, 3 titles)
+   'InjectRCRecords.jobs' => 1, // Quick fix for 
T177707: only push first batch!
'InjectRCRecords.titles' => 3,
] )
);
@@ -288,10 +288,12 @@
[ 'rootJobTimestamp' => '20202211060708', 
'rootJobSignature' => 'Kittens!', ]
);
 
-   $this->assertEquals( [ 21, 22, 23 ], array_keys( $pages ) );
+   // Quick fix for T177707: only push first batch!
+   // $this->assertEquals( [ 21, 22, 23 ], array_keys( $pages ) );
+   $this->assertEquals( [ 21, 22 ], array_keys( $pages ) );
$this->assertEquals( [ 0, 'Foo' ], $pages[21], '$pages[21]' );
$this->assertEquals( [ 0, 'Bar' ], $pages[22], '$pages[22]' );
-   $this->assertEquals( [ 0, 'Cuzz' ], $pages[23], '$pages[23]' );
+   // $this->assertEquals( [ 0, 'Cuzz' ], $pages[23], '$pages[23]' 
);
 
$this->assertEquals(
[

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0162cbfd6db3ef147745d281a7568313e998f0c3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: EXPERIMENT: treat Forms as Sub-Entities

2017-09-19 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/378946 )

Change subject: EXPERIMENT: treat Forms as Sub-Entities
..

EXPERIMENT: treat Forms as Sub-Entities

Change-Id: I13f232b24b91afa6a3696dd62bbaa6c854706c9a
---
M WikibaseLexeme.entitytypes.php
M src/DataModel/Form.php
M src/DataModel/FormId.php
M src/DataModel/Lexeme.php
4 files changed, 221 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme 
refs/changes/46/378946/1

diff --git a/WikibaseLexeme.entitytypes.php b/WikibaseLexeme.entitytypes.php
index 06a5230..33beed0 100644
--- a/WikibaseLexeme.entitytypes.php
+++ b/WikibaseLexeme.entitytypes.php
@@ -23,10 +23,14 @@
 use 
Wikibase\Lexeme\ChangeOp\Deserialization\LexicalCategoryChangeOpDeserializer;
 use Wikibase\Lexeme\Content\LexemeContent;
 use Wikibase\Lexeme\Content\LexemeHandler;
+use Wikibase\Lexeme\DataModel\Form;
+use Wikibase\Lexeme\DataModel\FormId;
 use Wikibase\Lexeme\DataModel\Lexeme;
 use Wikibase\Lexeme\DataModel\LexemeId;
 use Wikibase\Lexeme\DataModel\Serialization\LexemeDeserializer;
 use Wikibase\Lexeme\DataModel\Serialization\LexemeSerializer;
+use Wikibase\Lexeme\DataModel\Services\Diff\FormDiffer;
+use Wikibase\Lexeme\DataModel\Services\Diff\FormPatcher;
 use Wikibase\Lexeme\DataModel\Services\Diff\LexemeDiffer;
 use Wikibase\Lexeme\DataModel\Services\Diff\LexemePatcher;
 use Wikibase\Lexeme\Rdf\LexemeRdfBuilder;
@@ -154,5 +158,44 @@
$writer
);
}
+   ],
+   'form' => [
+   'serializer-factory-callback' => function( SerializerFactory 
$serializerFactory ) {
+   return new FormSerializer(
+   $serializerFactory->newTermListSerializer(),
+   $serializerFactory->newStatementListSerializer()
+   );
+   },
+   'deserializer-factory-callback' => function( 
DeserializerFactory $deserializerFactory ) {
+   return new FormDeserializer(
+   $deserializerFactory->newEntityIdDeserializer(),
+   
$deserializerFactory->newStatementListDeserializer()
+   );
+   },
+   'entity-id-pattern' => FormId::PATTERN,
+   'entity-id-builder' => function( $serialization ) {
+   return new FormId( $serialization );
+   },
+   'entity-differ-strategy-builder' => function() {
+   return new FormDiffer();
+   },
+   'entity-patcher-strategy-builder' => function() {
+   return new FormPatcher();
+   },
+   'entity-factory-callback' => function() {
+   return new Form();
+   },
+   'rdf-builder-factory-callback' => function(
+   $flavorFlags,
+   RdfVocabulary $vocabulary,
+   RdfWriter $writer,
+   $mentionedEntityTracker,
+   $dedupe
+   ) {
+   return new FormRdfBuilder(
+   $vocabulary,
+   $writer
+   );
+   }
]
 ];
diff --git a/src/DataModel/Form.php b/src/DataModel/Form.php
index 2ba1464..fb4e324 100644
--- a/src/DataModel/Form.php
+++ b/src/DataModel/Form.php
@@ -3,6 +3,8 @@
 namespace Wikibase\Lexeme\DataModel;
 
 use InvalidArgumentException;
+use Wikibase\DataModel\Entity\EntityDocument;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Statement\StatementList;
 use Wikibase\DataModel\Statement\StatementListProvider;
 use Wikibase\DataModel\Entity\ItemId;
@@ -12,7 +14,7 @@
 /**
  * @license GPL-2.0+
  */
-class Form implements StatementListProvider {
+class Form implements StatementListProvider, EntityDocument {
 
/**
 * @var FormId
@@ -35,7 +37,7 @@
private $statementList;
 
/**
-* @param FormId $id
+* @param FormId|null $id
 * @param TermList $representations
 * @param ItemId[] $grammaticalFeatures
 * @param StatementList|null $statementList
@@ -43,7 +45,7 @@
 * @throws InvalidArgumentException
 */
public function __construct(
-   FormId $id,
+   FormId $id = null,
TermList $representations,
array $grammaticalFeatures,
StatementList $statementList = null
@@ -105,4 +107,91 @@
return $this->statementList;
}
 
+   /**
+* Returns a type identifier for the entity, e.g. "item" or "property".
+*
+* @since 0.8.2
+*
+* @return string
+*/
+   public 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: EXPERIMENT: infrastructure for hierarchicaly adressable enti...

2017-09-18 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/378786 )

Change subject: EXPERIMENT: infrastructure for hierarchicaly adressable entities
..

EXPERIMENT: infrastructure for hierarchicaly adressable entities

Needs https://github.com/wmde/WikibaseDataModel/pull/760

Bug: T165328
Change-Id: I581a2be249c105a971da2c719d605a812fd48013
---
A lib/includes/Store/HierarchicalEntityRevisionLookup.php
A lib/includes/Store/HierarchicalEntityStore.php
2 files changed, 329 insertions(+), 0 deletions(-)


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

diff --git a/lib/includes/Store/HierarchicalEntityRevisionLookup.php 
b/lib/includes/Store/HierarchicalEntityRevisionLookup.php
new file mode 100644
index 000..9086ada
--- /dev/null
+++ b/lib/includes/Store/HierarchicalEntityRevisionLookup.php
@@ -0,0 +1,94 @@
+lookup = $lookup;
+   }
+
+   /**
+* @see EntityRevisionLookup::getEntityRevision.
+*
+* This implementation recursively resolves HierarchicalEntityIds.
+*
+* @param EntityId $entityId
+* @param int $revisionId
+* @param string $mode
+*
+* @throws RevisionedUnresolvedRedirectException
+* @throws StorageException
+* @return EntityRevision|null
+*/
+   public function getEntityRevision(
+   EntityId $entityId,
+   $revisionId = 0,
+   $mode = self::LATEST_FROM_REPLICA
+   ) {
+   if ( !( $entityId instanceof HierarchicalEntityId ) ) {
+   return $this->lookup->getEntityRevision( $entityId, 
$revisionId, $mode );
+   }
+
+   $baseId = $entityId->getBaseId();
+   $containerRevision = $this->getEntityRevision( $baseId, 
$revisionId, $mode );
+
+   if ( $containerRevision === null ) {
+   return null;
+   }
+
+   $container = $containerRevision->getEntity();
+
+   if ( !( $container instanceof  EntityContainer) ) {
+   throw new StorageException( 'Cannot resolve ID ' . 
$entityId );
+   }
+
+   $entity = $container->getEntity( $entityId );
+
+   return new EntityRevision(
+   $entity,
+   $containerRevision->getRevisionId(),
+   $containerRevision->getTimestamp()
+   );
+   }
+
+   /**
+* @see EntityRevisionLookup::getLatestRevisionId.
+*
+* This implementation finds the root of any hierarchical EntityId 
before looking up the
+* latest revision.
+*
+* @param EntityId $entityId
+* @param string $mode LATEST_FROM_REPLICA, 
LATEST_FROM_REPLICA_WITH_FALLBACK or LATEST_FROM_MASTER.
+*LATEST_FROM_MASTER would force the revision to be determined 
from the canonical master database.
+*
+* @return int|false Returns false in case the entity doesn't exist 
(this includes redirects).
+*/
+   public function getLatestRevisionId( EntityId $entityId, $mode = 
self::LATEST_FROM_REPLICA ) {
+   if ( $entityId instanceof HierarchicalEntityId ) {
+   $entityId = $entityId->getRootId();
+   }
+
+   return $this->lookup->getLatestRevisionId( $entityId, $mode );
+   }
+
+}
diff --git a/lib/includes/Store/HierarchicalEntityStore.php 
b/lib/includes/Store/HierarchicalEntityStore.php
new file mode 100644
index 000..703ab10
--- /dev/null
+++ b/lib/includes/Store/HierarchicalEntityStore.php
@@ -0,0 +1,235 @@
+store = $store;
+   $this->lookup = $lookup;
+   }
+
+   /**
+* @param HierarchicalEntityId $id
+*
+* @throws StorageException
+* @return EntityRevision
+*/
+   private function getContainerRevision(
+   HierarchicalEntityId $id,
+   $revisionId = 0,
+   $mode = EntityRevisionLookup::LATEST_FROM_MASTER
+   ) {
+   $baseId = $id->getBaseId();
+   $rev = $this->lookup->getEntityRevision( $baseId, $revisionId, 
$mode );
+
+   if ( !$rev ) {
+   throw new StorageException( 'Cannot resolve base entity 
ID ' . $baseId->getSerialization() );
+   }
+
+   if ( !( $rev->getEntity() instanceof  EntityContainer) ) {
+   throw new StorageException( 'Cannot resolve ID ' . $id 
);
+   }
+
+   return $rev;
+   }
+
+   /**
+* @param HierarchicalEntityId $id
+*
+* @throws StorageException
+* @return EntityContainer|EntityDocument
+*/
+   private function getContainer( HierarchicalEntityId $id ) {
+   return $this->getContainerRevision( 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: [DNM] Remove redundant fields from old DB tables.

2017-09-18 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/378729 )

Change subject: [DNM] Remove redundant fields from old DB tables.
..

[DNM] Remove redundant fields from old DB tables.

This patch is intended as a showcase only!

Bug: T174028
Change-Id: I5e37c929713efad34218e616829235f417f1861c
---
M maintenance/tables.sql
1 file changed, 0 insertions(+), 42 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/29/378729/1

diff --git a/maintenance/tables.sql b/maintenance/tables.sql
index 37c4dc5..c7a24e1 100644
--- a/maintenance/tables.sql
+++ b/maintenance/tables.sql
@@ -303,9 +303,6 @@
   -- Uncompressed length in bytes of the page's current source text.
   page_len int unsigned NOT NULL,
 
-  -- content model, see CONTENT_MODEL_XXX constants
-  page_content_model varbinary(32) DEFAULT NULL,
-
   -- Page content language
   page_lang varbinary(35) DEFAULT NULL
 ) /*$wgDBTableOptions*/;
@@ -339,12 +336,6 @@
   -- Key to page_id. This should _never_ be invalid.
   rev_page int unsigned NOT NULL,
 
-  -- Key to text.old_id, where the actual bulk text is stored.
-  -- It's possible for multiple revisions to use the same text,
-  -- for instance revisions where only metadata is altered
-  -- or a rollback to a previous version.
-  rev_text_id int unsigned NOT NULL,
-
   -- Text comment summarizing the change. Deprecated in favor of
   -- revision_comment_temp.revcomment_comment_id.
   rev_comment varbinary(767) NOT NULL default '',
@@ -375,12 +366,6 @@
 
   -- SHA-1 text content hash in base-36
   rev_sha1 varbinary(32) NOT NULL default '',
-
-  -- content model, see CONTENT_MODEL_XXX constants
-  rev_content_model varbinary(32) DEFAULT NULL,
-
-  -- content format, see CONTENT_FORMAT_XXX constants
-  rev_content_format varbinary(64) DEFAULT NULL
 
 ) /*$wgDBTableOptions*/ MAX_ROWS=1000 AVG_ROW_LENGTH=1024;
 -- In case tables are created as MyISAM, use row hints for MySQL <5.0 to avoid 
4GB limit
@@ -536,14 +521,6 @@
   ar_namespace int NOT NULL default 0,
   ar_title varchar(255) binary NOT NULL default '',
 
-  -- Newly deleted pages will not store text in this table,
-  -- but will reference the separately existing text rows.
-  -- This field is retained for backwards compatibility,
-  -- so old archived pages will remain accessible after
-  -- upgrading from 1.4 to 1.5.
-  -- Text may be gzipped or otherwise funky.
-  ar_text mediumblob NOT NULL,
-
   -- Basic revision stuff...
   ar_comment varbinary(767) NOT NULL default '', -- Deprecated in favor of 
ar_comment_id
   ar_comment_id bigint unsigned NOT NULL DEFAULT 0, -- ("DEFAULT 0" is 
temporary, signaling that ar_comment should be used)
@@ -551,9 +528,6 @@
   ar_user_text varchar(255) binary NOT NULL,
   ar_timestamp binary(14) NOT NULL default '',
   ar_minor_edit tinyint NOT NULL default 0,
-
-  -- See ar_text note.
-  ar_flags tinyblob NOT NULL,
 
   -- When revisions are deleted, their unique rev_id is stored
   -- here so it can be retained after undeletion. This is necessary
@@ -563,17 +537,6 @@
   -- Old entries from 1.4 will be NULL here, and a new rev_id will
   -- be created on undeletion for those revisions.
   ar_rev_id int unsigned,
-
-  -- For newly deleted revisions, this is the text.old_id key to the
-  -- actual stored text. To avoid breaking the block-compression scheme
-  -- and otherwise making storage changes harder, the actual text is
-  -- *not* deleted from the text table, merely hidden by removal of the
-  -- page and revision entries.
-  --
-  -- Old entries deleted under 1.2-1.4 will have NULL here, and their
-  -- ar_text and ar_flags fields will be used to create a new text
-  -- row upon undeletion.
-  ar_text_id int unsigned,
 
   -- rev_deleted for archives
   ar_deleted tinyint unsigned NOT NULL default 0,
@@ -594,11 +557,6 @@
   -- SHA-1 text content hash in base-36
   ar_sha1 varbinary(32) NOT NULL default '',
 
-  -- content model, see CONTENT_MODEL_XXX constants
-  ar_content_model varbinary(32) DEFAULT NULL,
-
-  -- content format, see CONTENT_FORMAT_XXX constants
-  ar_content_format varbinary(64) DEFAULT NULL
 ) /*$wgDBTableOptions*/;
 
 -- Index for Special:Undelete to page through deleted revisions

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e37c929713efad34218e616829235f417f1861c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: [WIP] first shot at MCR database schema

2017-09-18 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/378724 )

Change subject: [WIP] first shot at MCR database schema
..

[WIP] first shot at MCR database schema

Bug: T174028
Change-Id: I30a3a9834d54d0e6957553d91908b2b73b2c802f
---
M maintenance/tables.sql
1 file changed, 86 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/24/378724/1

diff --git a/maintenance/tables.sql b/maintenance/tables.sql
index 1813f6c..37c4dc5 100644
--- a/maintenance/tables.sql
+++ b/maintenance/tables.sql
@@ -611,6 +611,92 @@
 -- rows, such as change_tag.
 CREATE INDEX /*i*/ar_revid ON /*_*/archive (ar_rev_id);
 
+--
+-- Slots represent an n:m relation between revisions and content objects.
+-- A content object can have a specific "role" in one or more revisions.
+-- Each revision can have multiple content objects, each having a different 
role.
+--
+CREATE TABLE /*_*/slots (
+  -- The page this slot belongs to; reference to page_id
+  -- TODO: decide if we need this (for sharding, analysis, and recovery)
+  -- TODO: bigint?
+  slot_page int unsigned NOT NULL,
+
+  -- reference to rev_id
+  slot_revision bigint unsigned NOT NULL,
+
+  -- reference to role_id
+  slot_role smallint unsigned NOT NULL,
+
+  -- reference to content_id
+  slot_content bigint unsigned NOT NULL,
+
+  -- whether the content is inherited (1) or new in this revision (0)
+  slot_inherited tinyint unsigned NOT NULL DEFAULT 0,
+
+  PRIMARY KEY ( slot_page, slot_revision, slot_role )
+) /*$wgDBTableOptions*/;
+
+-- Index for finding revisions that modified a specific slot
+CREATE INDEX /*i*/slot_page_role_inherited ON /*_*/slots (slot_page, 
slot_role, slot_inherited);
+
+-- Index for finding content usage (and thus detecting orphan content rows)
+CREATE INDEX /*i*/slot_content ON /*_*/slots (slot_page, slot_content);
+
+--
+-- The content table represents content objects. It's primary purpose is to 
provide the necessary
+-- meta-data for loading and interpreting a serialized data blob to create a 
content object.
+--
+CREATE TABLE /*_*/content (
+  -- The page this slot belongs to; reference to page_id
+  -- TODO: decide if we need this (for sharding, analysis, and recovery)
+  -- TODO: bigint?
+  content_page int unsigned NOT NULL,
+
+  -- ID of the content object
+  content_id bigint unsigned NOT NULL AUTO_INCREMENT,
+
+  -- Nominal size of the content object (not necessarily of the serialized 
blob)
+  content_size int unsigned NOT NULL,
+
+  -- Nominal hash of the content object (not necessarily of the serialized 
blob)
+  -- TODO: only needed if we want to maintain a pre-computed rev_sha1
+  content_sha1 varbinary(32) NOT NULL,
+
+  -- reference to model_id
+  -- TODO: we may want an index for this for statistics
+  content_model smallint unsigned NOT NULL,
+
+  -- URL-like address of the content blob
+  -- TODO: we may want an index on this so we can find orphan blobs
+  content_address varbinary(255) NOT NULL,
+
+  PRIMARY KEY ( content_page, content_id )
+) /*$wgDBTableOptions*/;
+
+--
+-- Normalization table for role names
+--
+CREATE TABLE /*_*/roles (
+  role_id smallint PRIMARY KEY AUTO_INCREMENT,
+  role_name varbinary(64) NOT NULL
+);
+
+-- Index for looking of the internal ID of for a name
+-- TODO should this be (role_name, role_id) so the index covers the requested 
fields?
+CREATE UNIQUE INDEX /*i*/role_name ON /*_*/roles (role_name);
+
+--
+-- Normalization table for content model names
+--
+CREATE TABLE /*_*/models (
+  model_id smallint PRIMARY KEY AUTO_INCREMENT,
+  model_name varbinary(64) NOT NULL
+);
+
+-- Index for looking of the internal ID of for a name
+-- TODO should this be (role_name, role_id) so the index covers the requested 
fields?
+CREATE UNIQUE INDEX /*i*/model_name ON /*_*/models (model_name);
 
 --
 -- Track page-to-page hyperlinks within the wiki.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I30a3a9834d54d0e6957553d91908b2b73b2c802f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Document change dispatching and change handling in change-pr...

2017-09-18 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/378707 )

Change subject: Document change dispatching and change handling in 
change-propagation.wiki
..

Document change dispatching and change handling in change-propagation.wiki

Change-Id: Ic10f3067dca522197db639e2cfdf18591a40a9d7
---
M docs/change-propagation.wiki
1 file changed, 24 insertions(+), 2 deletions(-)


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

diff --git a/docs/change-propagation.wiki b/docs/change-propagation.wiki
index b7b45dd..0d46693 100644
--- a/docs/change-propagation.wiki
+++ b/docs/change-propagation.wiki
@@ -8,11 +8,14 @@
 * Subscription management, so the repository knows which client wiki is 
interested in changes to which entities.
 * Dispatch state, so the repository knows which changes have already been 
dispatched to which client.
 * A buffer of the changes themselves.
-* Access to each client's job queue.
+* Access to each client's job queue, to push ChangeNotificationJobs to.
 
 On each client, there needs to be:
 * Usage tracking.
 * Access to sitelinks stored in the repository.
+* ChangeHandler for processing changes on the repo, triggered by 
ChangeNotificationJobs being executed.
+* AffectedPagesFinder, a mechanism to determine which pages are affected by 
which change, based on usage tracking information (see usagetracking.wiki).
+* WikiPageUpdater, for updating the client wiki's state.
 
 The basic operation of change dispatching involves running two scripts 
regularly, typically as cron jobs: dispatchChanges.php and pruneChanges.php, 
both located in the repo/maintenance/ directory. A typical cron setup could 
look like this:
 * Every minute, run dispatchChanges.php --max-time 120
@@ -62,5 +65,24 @@
 
 Per default, global MySQL locks are used to ensure that only one process can 
dispatch to any given client wiki at a time.
 
+== dispatchChanges.php script ==
+The dispatchChanges script notifies client wikis of changes on the repository. 
It reads information from the wb_changes and wb_changes_dispatch tables, and 
posts ChangeNotificationJobs to the clients' job queues.
+
+The basic scheduling algorithm is as follows: for each client wiki, define how 
many changes they have not yet seen according to wb_changes_dispatch (we refer 
to that number as "dispatch lag"). Find the n client wikis that have the most 
lag (and have not been touched for some minimal delay). Pick one of these wikis 
at random. For the selected target wiki, find changes it has not yet seen to 
entities it is subscribed to, up to some maximum number of m changes. Construct 
a ChangeNotificationJob event containing the IDs of these changes, and push it 
to the target wiki's JobQueue. In wb_changes_dispatch, record all changes 
touched in this process as seen by the target wiki.
+
+The dispatchChanges is designed to be safe against concurrent execution. It 
can be scaled easily be simply running more instances in parallel. The locking 
mechanism used to prevent race conditions can be configured using the 
dispatchingLockManager setting. Per default, named locks on the repo database 
are used. Redis based locks are supported as an alternative.
+
 == SiteLinkLookup ==
-Each client wiki can access the repo's sitelink information via a 
SiteLinkLookup service returned by ClientStore::getSiteLinkLookup. This 
information is stored in the wb_items_per_site table in the repo's database.
+A SiteLinkLookup allows the client wiki to determine which local pages are 
"connected" to a given Item on the repository. Each client wiki can access the 
repo's sitelink information via a SiteLinkLookup service returned by 
ClientStore::getSiteLinkLookup. This information is stored in the 
wb_items_per_site table in the repo's database.
+
+== ChangeHandler ==
+The handleChanges() method of the ChangeHandler class gets called with a list 
of changes loaded by a ChangeNotificationJob. A ChangeRunCoalesker is then used 
to merge consecutive changes by the same user to the same entity, reducing the 
number of logical events to be processed on the client, and to be presented to 
the user.
+
+ChangeHandler will then use a (Wiki)PageUpdater to update the client wiki's 
state based according to each change being processed. In particular, rows are 
injected into the recentchanges table, and pages using the affected entity's 
data are re-parsed, and the web cache for these pages is purged.
+
+== WikiPageUpdater ==
+The WikiPageUpdater class defines three methods for updating the client wikis 
state according to a given change on the repository:
+* scheduleRefreshLinks() will re-parse each affected page, allowing the link 
tables to be updated appropriately. This is done asynchronously using 
RefreshLinksJobs. No batching is applied, since RefreshLinksJobs are slow and 
this benefit more from deduplication than from 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Do not ignore edit conflicts with oneself.

2017-09-13 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/377813 )

Change subject: Do not ignore edit conflicts with oneself.
..

Do not ignore edit conflicts with oneself.

Please refer to the ticket to see whether this change of behavior
has found consensus. For now, it is here just to show what the proposed
change actually entails.

Bug: T175745
Change-Id: I661abd0528432e1635be9f6da72d1868b02c9ca1
---
M includes/EditPage.php
M includes/Revision.php
M tests/phpunit/includes/RevisionStorageTest.php
3 files changed, 0 insertions(+), 144 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/13/377813/1

diff --git a/includes/EditPage.php b/includes/EditPage.php
index 9f3f586..8d141c8 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -1994,15 +1994,6 @@
$this->isConflict = false;
wfDebug( __METHOD__ . ": 
conflict suppressed; new section\n" );
}
-   } elseif ( $this->section == ''
-   && Revision::userWasLastToEdit(
-   DB_MASTER, 
$this->mTitle->getArticleID(),
-   $wgUser->getId(), 
$this->edittime
-   )
-   ) {
-   # Suppress edit conflict with self, 
except for section edits where merging is required.
-   wfDebug( __METHOD__ . ": Suppressing 
edit conflict, same user.\n" );
-   $this->isConflict = false;
}
}
 
diff --git a/includes/Revision.php b/includes/Revision.php
index 006e700..50f166e 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -1884,47 +1884,6 @@
}
 
/**
-* Check if no edits were made by other users since
-* the time a user started editing the page. Limit to
-* 50 revisions for the sake of performance.
-*
-* @since 1.20
-* @deprecated since 1.24
-*
-* @param IDatabase|int $db The Database to perform the check on. May 
be given as a
-*Database object or a database identifier usable with wfGetDB.
-* @param int $pageId The ID of the page in question
-* @param int $userId The ID of the user in question
-* @param string $since Look at edits since this time
-*
-* @return bool True if the given user was the only one to edit since 
the given timestamp
-*/
-   public static function userWasLastToEdit( $db, $pageId, $userId, $since 
) {
-   if ( !$userId ) {
-   return false;
-   }
-
-   if ( is_int( $db ) ) {
-   $db = wfGetDB( $db );
-   }
-
-   $res = $db->select( 'revision',
-   'rev_user',
-   [
-   'rev_page' => $pageId,
-   'rev_timestamp > ' . $db->addQuotes( 
$db->timestamp( $since ) )
-   ],
-   __METHOD__,
-   [ 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ] );
-   foreach ( $res as $row ) {
-   if ( $row->rev_user != $userId ) {
-   return false;
-   }
-   }
-   return true;
-   }
-
-   /**
 * Load a revision based on a known page ID and current revision ID 
from the DB
 *
 * This method allows for the use of caching, though accessing anything 
that normally
diff --git a/tests/phpunit/includes/RevisionStorageTest.php 
b/tests/phpunit/includes/RevisionStorageTest.php
index e9f16db..4962ad9 100644
--- a/tests/phpunit/includes/RevisionStorageTest.php
+++ b/tests/phpunit/includes/RevisionStorageTest.php
@@ -477,98 +477,4 @@
];
}
 
-   /**
-* @dataProvider provideUserWasLastToEdit
-*/
-   public function testUserWasLastToEdit( $sinceIdx, $expectedLast ) {
-   $userA = User::newFromName( "RevisionStorageTest_userA" );
-   $userB = User::newFromName( "RevisionStorageTest_userB" );
-
-   if ( $userA->getId() === 0 ) {
-   $userA = User::createNew( $userA->getName() );
-   }
-
-   if ( $userB->getId() === 0 ) {
-   $userB = User::createNew( $userB->getName() );
-   }
-
-   $ns = $this->getDefaultWikitextNS();
-
-   $dbw = wfGetDB( DB_MASTER );
-   $revisions = [];
-
-   // create revisions 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[wmf/1.30.0-wmf.18]: Split page set before constructing InjectRCRecordsJob

2017-09-13 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/377812 )

Change subject: Split page set before constructing InjectRCRecordsJob
..

Split page set before constructing InjectRCRecordsJob

Bug: T175316
Change-Id: If11f0cec4659dd65e3e5b05a64311037b14d7fab
---
M client/includes/Changes/InjectRCRecordsJob.php
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
4 files changed, 21 insertions(+), 78 deletions(-)


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

diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
index d47acb6..72927a8 100644
--- a/client/includes/Changes/InjectRCRecordsJob.php
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -68,11 +68,6 @@
private $stats = null;
 
/**
-* @var int Batch size for database operations
-*/
-   private $dbBatchSize = 100;
-
-   /**
 * @param Title[] $titles
 * @param EntityChange $change
 *
@@ -184,14 +179,6 @@
}
 
/**
-* @param int $dbBatchSize
-*/
-   public function setDbBatchSize( $dbBatchSize ) {
-   Assert::parameterType( 'integer', $dbBatchSize, '$dbBatchSize' 
);
-   $this->dbBatchSize = $dbBatchSize;
-   }
-
-   /**
 * Returns the change that should be processed.
 *
 * EntityChange objects are loaded using a EntityChangeLookup.
@@ -261,7 +248,6 @@
 
$rcAttribs = $this->rcFactory->prepareChangeAttributes( $change 
);
 
-   $c = 0;
$trxToken = $this->lbFactory->getEmptyTransactionTicket( 
__METHOD__ );
 
foreach ( $titles as $title ) {
@@ -279,17 +265,9 @@
$this->logger->debug( __FUNCTION__ . ": saving 
RC entry for " . $title->getFullText() );
$rc->save();
}
-
-   if ( ++$c >= $this->dbBatchSize ) {
-   $this->lbFactory->commitAndWaitForReplication( 
__METHOD__, $trxToken );
-   $trxToken = 
$this->lbFactory->getEmptyTransactionTicket( __METHOD__ );
-   $c = 0;
-   }
}
 
-   if ( $c > 0 ) {
-   $this->lbFactory->commitAndWaitForReplication( 
__METHOD__, $trxToken );
-   }
+   $this->lbFactory->commitAndWaitForReplication( __METHOD__, 
$trxToken );
 
$this->incrementStats( 'InjectRCRecords.run.titles', count( 
$titles ) );
 
diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index 027e957..f7da3fe 100644
--- a/client/includes/Changes/WikiPageUpdater.php
+++ b/client/includes/Changes/WikiPageUpdater.php
@@ -113,7 +113,7 @@
/* @var Title[] $batch */
foreach ( $titleBatches as $batch ) {
wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
HTMLCacheUpdateJob for "
-. count( $batch ) . " titles" );
+   . count( $batch ) . " titles" );
 
$dummyTitle = Title::makeTitle( NS_SPECIAL, 'Badtitle/' 
. __CLASS__ );
 
@@ -195,11 +195,19 @@
return;
}
 
-   $jobSpec = InjectRCRecordsJob::makeJobSpecification( $titles, 
$change );
+   $jobs = [];
+   $titleBatches = array_chunk( $titles, $this->dbBatchSize );
 
-   $this->jobQueueGroup->lazyPush( $jobSpec );
+   /* @var Title[] $batch */
+   foreach ( $titleBatches as $batch ) {
+   wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
InjectRCRecords for "
+   . count( $batch ) . " titles" );
 
-   $this->incrementStats( 'InjectRCRecords.jobs', 1 );
+   $jobs[] = InjectRCRecordsJob::makeJobSpecification( 
$batch, $change );
+   }
+
+   $this->jobQueueGroup->lazyPush( $jobs );
+   $this->incrementStats( 'InjectRCRecords.jobs', count( $jobs ) );
$this->incrementStats( 'InjectRCRecords.titles', count( $titles 
) );
}
 
diff --git a/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php 
b/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
index 41c54bf..578b5f3 100644
--- a/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
+++ b/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
@@ -9,7 +9,6 @@
 use Wikibase\Client\RecentChanges\RecentChangeFactory;
 use 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Split page set before constructing InjectRCRecordsJob

2017-09-13 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/377811 )

Change subject: Split page set before constructing InjectRCRecordsJob
..

Split page set before constructing InjectRCRecordsJob

Bug: T173710
Change-Id: If11f0cec4659dd65e3e5b05a64311037b14d7fab
---
M client/includes/Changes/InjectRCRecordsJob.php
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
4 files changed, 21 insertions(+), 78 deletions(-)


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

diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
index d47acb6..72927a8 100644
--- a/client/includes/Changes/InjectRCRecordsJob.php
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -68,11 +68,6 @@
private $stats = null;
 
/**
-* @var int Batch size for database operations
-*/
-   private $dbBatchSize = 100;
-
-   /**
 * @param Title[] $titles
 * @param EntityChange $change
 *
@@ -184,14 +179,6 @@
}
 
/**
-* @param int $dbBatchSize
-*/
-   public function setDbBatchSize( $dbBatchSize ) {
-   Assert::parameterType( 'integer', $dbBatchSize, '$dbBatchSize' 
);
-   $this->dbBatchSize = $dbBatchSize;
-   }
-
-   /**
 * Returns the change that should be processed.
 *
 * EntityChange objects are loaded using a EntityChangeLookup.
@@ -261,7 +248,6 @@
 
$rcAttribs = $this->rcFactory->prepareChangeAttributes( $change 
);
 
-   $c = 0;
$trxToken = $this->lbFactory->getEmptyTransactionTicket( 
__METHOD__ );
 
foreach ( $titles as $title ) {
@@ -279,17 +265,9 @@
$this->logger->debug( __FUNCTION__ . ": saving 
RC entry for " . $title->getFullText() );
$rc->save();
}
-
-   if ( ++$c >= $this->dbBatchSize ) {
-   $this->lbFactory->commitAndWaitForReplication( 
__METHOD__, $trxToken );
-   $trxToken = 
$this->lbFactory->getEmptyTransactionTicket( __METHOD__ );
-   $c = 0;
-   }
}
 
-   if ( $c > 0 ) {
-   $this->lbFactory->commitAndWaitForReplication( 
__METHOD__, $trxToken );
-   }
+   $this->lbFactory->commitAndWaitForReplication( __METHOD__, 
$trxToken );
 
$this->incrementStats( 'InjectRCRecords.run.titles', count( 
$titles ) );
 
diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index 027e957..f7da3fe 100644
--- a/client/includes/Changes/WikiPageUpdater.php
+++ b/client/includes/Changes/WikiPageUpdater.php
@@ -113,7 +113,7 @@
/* @var Title[] $batch */
foreach ( $titleBatches as $batch ) {
wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
HTMLCacheUpdateJob for "
-. count( $batch ) . " titles" );
+   . count( $batch ) . " titles" );
 
$dummyTitle = Title::makeTitle( NS_SPECIAL, 'Badtitle/' 
. __CLASS__ );
 
@@ -195,11 +195,19 @@
return;
}
 
-   $jobSpec = InjectRCRecordsJob::makeJobSpecification( $titles, 
$change );
+   $jobs = [];
+   $titleBatches = array_chunk( $titles, $this->dbBatchSize );
 
-   $this->jobQueueGroup->lazyPush( $jobSpec );
+   /* @var Title[] $batch */
+   foreach ( $titleBatches as $batch ) {
+   wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
InjectRCRecords for "
+   . count( $batch ) . " titles" );
 
-   $this->incrementStats( 'InjectRCRecords.jobs', 1 );
+   $jobs[] = InjectRCRecordsJob::makeJobSpecification( 
$batch, $change );
+   }
+
+   $this->jobQueueGroup->lazyPush( $jobs );
+   $this->incrementStats( 'InjectRCRecords.jobs', count( $jobs ) );
$this->incrementStats( 'InjectRCRecords.titles', count( $titles 
) );
}
 
diff --git a/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php 
b/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
index 41c54bf..578b5f3 100644
--- a/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
+++ b/client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
@@ -9,7 +9,6 @@
 use Wikibase\Client\RecentChanges\RecentChangeFactory;
 use 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: First spike exploring usage of new RevisionStore class

2017-09-12 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/377654 )

Change subject: First spike exploring usage of new RevisionStore class
..

First spike exploring usage of new RevisionStore class

Change-Id: Id34772d13b44d3c5be3d9abc891571075bdd7ce6
---
M includes/Revision.php
M includes/Title.php
M includes/api/ApiQueryAllDeletedRevisions.php
M includes/api/ApiQueryAllRevisions.php
M includes/api/ApiQueryDeletedRevisions.php
M includes/api/ApiQueryRevisions.php
M includes/api/ApiQueryRevisionsBase.php
M includes/api/ApiQueryUserContributions.php
M maintenance/Maintenance.php
M maintenance/rebuildtextindex.php
10 files changed, 52 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/54/377654/1

diff --git a/includes/Revision.php b/includes/Revision.php
index c282b2f..efc52e0 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -158,6 +158,7 @@
 * Returns null if no such revision can be found.
 *
 * @deprecated since 1.30, use RevisionStore::getRevisionById() instead.
+* @note No callers in core.
 *
 * @param IDatabase $db
 * @param int $id
@@ -175,6 +176,7 @@
 * to that page, will return null.
 *
 * @deprecated since 1.30, use RevisionStore::getRevisionByPageId() 
instead.
+* @note No callers in core.
 *
 * @param IDatabase $db
 * @param int $pageid
@@ -434,7 +436,7 @@
 * @param Title $title
 */
public function setTitle( $title ) {
-   // FIXME!
+   // FIXME! Quite a few callers!
throw new LogicException( 'Not implemented: ' . __METHOD__ );
}
 
diff --git a/includes/Title.php b/includes/Title.php
index 0687a15..062545c 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -4144,7 +4144,8 @@
]
);
if ( $row ) {
-   return new Revision( $row );
+   $revStore = 
MediaWikiServices::getInstance()->getRevisionStore();
+   return $revStore->newRevisionFromRow( $row );
}
}
return null;
diff --git a/includes/api/ApiQueryAllDeletedRevisions.php 
b/includes/api/ApiQueryAllDeletedRevisions.php
index b22bb1f..725cd95 100644
--- a/includes/api/ApiQueryAllDeletedRevisions.php
+++ b/includes/api/ApiQueryAllDeletedRevisions.php
@@ -24,6 +24,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Query module to enumerate all deleted revisions.
@@ -342,7 +343,8 @@
$generated[] = $row->ar_rev_id;
}
} else {
-   $revision = Revision::newFromArchiveRow( $row );
+   $revisionStore = 
MediaWikiServices::getInstance()->getRevisionStore();
+   $revision = 
$revisionStore->newRevisionFromArchiveRow( $row );
$rev = $this->extractRevisionInfo( $revision, 
$row );
 
if ( !isset( 
$pageMap[$row->ar_namespace][$row->ar_title] ) ) {
diff --git a/includes/api/ApiQueryAllRevisions.php 
b/includes/api/ApiQueryAllRevisions.php
index 8f7d6eb..d8d4a3b 100644
--- a/includes/api/ApiQueryAllRevisions.php
+++ b/includes/api/ApiQueryAllRevisions.php
@@ -21,6 +21,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Query module to enumerate all revisions.
@@ -198,7 +199,8 @@
$generated[] = $row->rev_id;
}
} else {
-   $revision = Revision::newFromRow( $row );
+   $revisionStore = 
MediaWikiServices::getInstance()->getRevisionStore();
+   $revision = $revisionStore->newRevisionFromRow( 
$row );
$rev = $this->extractRevisionInfo( $revision, 
$row );
 
if ( !isset( $pageMap[$row->rev_page] ) ) {
diff --git a/includes/api/ApiQueryDeletedRevisions.php 
b/includes/api/ApiQueryDeletedRevisions.php
index 8e4752e..d4f6cb6 100644
--- a/includes/api/ApiQueryDeletedRevisions.php
+++ b/includes/api/ApiQueryDeletedRevisions.php
@@ -24,6 +24,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Query module to enumerate deleted revisions for pages.
@@ -227,9 +228,11 @@
);
}
 
+   $revisionStore = 
MediaWikiServices::getInstance()->getRevisionStore();
+   $revision = 
$revisionStore->newRevisionFromArchiveRow( $row );

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Allow batch sizes for different jobs to be defined separately.

2017-09-10 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/377046 )

Change subject: Allow batch sizes for different jobs to be defined separately.
..

Allow batch sizes for different jobs to be defined separately.

In particular, the batch size for UpdateHtmlCacheJob can be quite large,
while the batch size for the slow running RefreshLinksJob should be
rather small.

Bug: T173710
Change-Id: Ic095e2eba985ea3a6e51645d0be58589b326f218
---
M client/config/WikibaseClient.default.php
M client/includes/Changes/InjectRCRecordsJob.php
M client/includes/Changes/WikiPageUpdater.php
M client/includes/WikibaseClient.php
M client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
M docs/options.wiki
6 files changed, 88 insertions(+), 30 deletions(-)


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

diff --git a/client/config/WikibaseClient.default.php 
b/client/config/WikibaseClient.default.php
index f75c05c..ca7f007 100644
--- a/client/config/WikibaseClient.default.php
+++ b/client/config/WikibaseClient.default.php
@@ -96,8 +96,23 @@
$settings->getSetting( 'hasFullEntityIdColumn' 
) : true;
},
 
-   // Database batch size in WikiPageUpdater which ChangeHandler 
uses
-   'wikiPageUpdaterDbBatchSize' => 50,
+   // Batch size for UpdateHtmlCacheJob
+   'purgeCacheBatchSize' => function ( SettingsArray $settings ) {
+   return $settings->hasSetting( 
'wikiPageUpdaterDbBatchSize' ) ?
+   $settings->getSetting( 
'wikiPageUpdaterDbBatchSize' ) : 100;
+   },
+
+   // Batch size for InjectRCRecordsJob
+   'recentChangesBatchSize' => function ( SettingsArray $settings 
) {
+   return $settings->hasSetting( 
'wikiPageUpdaterDbBatchSize' ) ?
+   $settings->getSetting( 
'wikiPageUpdaterDbBatchSize' ) : 100;
+   },
+
+   // Batch size for RefreshLinksJobs
+   'refreshLinksBatchSize' => function ( SettingsArray $settings ) 
{
+   return $settings->hasSetting( 
'wikiPageUpdaterDbBatchSize' ) ?
+   $settings->getSetting( 
'wikiPageUpdaterDbBatchSize' ) : 5;
+   },
];
 
// Some defaults depend on information not available at this time.
diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
index dd220ed..ded5067 100644
--- a/client/includes/Changes/InjectRCRecordsJob.php
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -68,21 +68,18 @@
private $stats = null;
 
/**
-* @var int Batch size for database operations
-*/
-   private $dbBatchSize = 100;
-
-   /**
 * @param Title[] $titles
 * @param EntityChange $change
 * @param array $rootJobParams
+* @param int $batchSize
 *
 * @return JobSpecification
 */
public static function makeJobSpecification(
array $titles,
EntityChange $change,
-   array $rootJobParams = []
+   array $rootJobParams = [],
+   $batchSize = 100
) {
$pages = [];
 
@@ -99,7 +96,8 @@
// See JobQueueChangeNotificationSender::getJobSpecification 
for relevant root job parameters.
$params = array_merge( $rootJobParams, [
'change' => $changeData,
-   'pages' => $pages
+   'pages' => $pages,
+   'batchSize' => $batchSize,
] );
 
return new JobSpecification(
@@ -190,11 +188,11 @@
}
 
/**
-* @param int $dbBatchSize
+* @return int
 */
-   public function setDbBatchSize( $dbBatchSize ) {
-   Assert::parameterType( 'integer', $dbBatchSize, '$dbBatchSize' 
);
-   $this->dbBatchSize = $dbBatchSize;
+   private function getBatchSize() {
+   $params = $this->getParams();
+   return isset( $params['batchSize'] ) ? intval( 
$params['batchSize'] ) : 100;
}
 
/**
@@ -286,7 +284,7 @@
$rc->save();
}
 
-   if ( ++$c >= $this->dbBatchSize ) {
+   if ( ++$c >= $this->getBatchSize() ) {
$this->lbFactory->commitAndWaitForReplication( 
__METHOD__, $trxToken );
$trxToken = 
$this->lbFactory->getEmptyTransactionTicket( __METHOD__ );
$c = 0;
diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index 6e66fcb..363cd73 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Turn Revision into a proxy to the new code.

2017-09-05 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/375050 )

Change subject: Turn Revision into a proxy to the new code.
..

Turn Revision into a proxy to the new code.

Change-Id: I4f24e7fbb683cb51f3fd8b250732bae9c7541ba2
---
M includes/Revision.php
M includes/Storage/DefaultRevisionRecord.php
M includes/Storage/RevisionLookup.php
M includes/Storage/RevisionStore.php
4 files changed, 190 insertions(+), 1,262 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/50/375050/1

diff --git a/includes/Revision.php b/includes/Revision.php
index e457beb..61b8b24 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -20,6 +20,11 @@
  * @file
  */
 
+use MediaWiki\Storage\ContentStore;
+use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\RevisionSlots;
+use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
 use MediaWiki\Linker\LinkTarget;
@@ -28,78 +33,46 @@
 use Wikimedia\Rdbms\FakeResultWrapper;
 
 /**
- * @todo document
+ * @deprecated since 1.30, use RevisionRecord, RevisionStore, and ContentStore 
instead.
  */
 class Revision implements IDBAccessObject {
-   /** @var int|null */
+   /** @var int|null Needed on top of $mRecord, bnecause it may be 
updated! */
protected $mId;
-   /** @var int|null */
-   protected $mPage;
-   /** @var string */
-   protected $mUserText;
-   /** @var string */
-   protected $mOrigUserText;
-   /** @var int */
-   protected $mUser;
-   /** @var bool */
-   protected $mMinorEdit;
-   /** @var string */
-   protected $mTimestamp;
-   /** @var int */
-   protected $mDeleted;
-   /** @var int */
-   protected $mSize;
-   /** @var string */
-   protected $mSha1;
-   /** @var int */
-   protected $mParentId;
-   /** @var string */
-   protected $mComment;
-   /** @var string */
-   protected $mText;
-   /** @var int */
-   protected $mTextId;
-   /** @var int */
-   protected $mUnpatrolled;
 
-   /** @var stdClass|null */
-   protected $mTextRow;
-
-   /**  @var null|Title */
-   protected $mTitle;
-   /** @var bool */
-   protected $mCurrent;
-   /** @var string */
-   protected $mContentModel;
-   /** @var string */
-   protected $mContentFormat;
-
-   /** @var Content|null|bool */
-   protected $mContent;
-   /** @var null|ContentHandler */
-   protected $mContentHandler;
+   /** @var RevisionRecord */
+   protected $mRecord;
 
/** @var int */
protected $mQueryFlags = 0;
-   /** @var bool Used for cached values to reload user text and 
rev_deleted */
-   protected $mRefreshMutableFields = false;
-   /** @var string Wiki ID; false means the current wiki */
-   protected $mWiki = false;
 
// Revision deletion constants
-   const DELETED_TEXT = 1;
-   const DELETED_COMMENT = 2;
-   const DELETED_USER = 4;
-   const DELETED_RESTRICTED = 8;
-   const SUPPRESSED_USER = 12; // convenience
-   const SUPPRESSED_ALL = 15; // convenience
+   const DELETED_TEXT = RevisionRecord::DELETED_TEXT;
+   const DELETED_COMMENT = RevisionRecord::DELETED_COMMENT;
+   const DELETED_USER = RevisionRecord::DELETED_USER;
+   const DELETED_RESTRICTED = RevisionRecord::DELETED_RESTRICTED;
+   const SUPPRESSED_USER = RevisionRecord::SUPPRESSED_USER;
+   const SUPPRESSED_ALL = RevisionRecord::SUPPRESSED_ALL;
 
// Audience options for accessors
-   const FOR_PUBLIC = 1;
-   const FOR_THIS_USER = 2;
-   const RAW = 3;
+   const FOR_PUBLIC = RevisionRecord::FOR_PUBLIC;
+   const FOR_THIS_USER = RevisionRecord::FOR_THIS_USER;
+   const RAW = RevisionRecord::RAW;
 
-   const TEXT_CACHE_GROUP = 'revisiontext:10'; // process cache name and 
max key count
+   const TEXT_CACHE_GROUP = ContentStore::TEXT_CACHE_GROUP;
+
+   /**
+* @return RevisionStore
+*/
+   protected static function getRevisionStore() {
+   MediaWikiServices::getInstance()->getRevisionStore();
+   }
+
+   /**
+* @return ContentStore
+*/
+   protected static function getContentStore() {
+   MediaWikiServices::getInstance()->getContentStore();
+   }
 
/**
 * Load a page revision from a given revision ID number.
@@ -114,7 +87,8 @@
 * @return Revision|null
 */
public static function newFromId( $id, $flags = 0 ) {
-   return self::newFromConds( [ 'rev_id' => intval( $id ) ], 
$flags );
+   $rec = self::getRevisionStore()->getRevisionById( $id, $flags );
+   return $rec === null ? null : new Revision( $rec, $flags );
}
 
/**
@@ -132,20 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Pass root job params through WikiPageUpdater

2017-09-04 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/375819 )

Change subject: Pass root job params through WikiPageUpdater
..

Pass root job params through WikiPageUpdater

Root job timestamps help with deduplication.

Change-Id: I566d2253080a0e8fb74526f33763d23f7ecdadcf
---
M client/includes/ChangeNotificationJob.php
M client/includes/Changes/ChangeHandler.php
M client/includes/Changes/InjectRCRecordsJob.php
M client/includes/Changes/PageUpdater.php
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/MockPageUpdater.php
M docs/hooks.txt
7 files changed, 61 insertions(+), 32 deletions(-)


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

diff --git a/client/includes/ChangeNotificationJob.php 
b/client/includes/ChangeNotificationJob.php
index 3822471..2a4fe72 100644
--- a/client/includes/ChangeNotificationJob.php
+++ b/client/includes/ChangeNotificationJob.php
@@ -96,7 +96,7 @@
$changes = $this->getChanges();
 
$changeHandler = $this->getChangeHandler();
-   $changeHandler->handleChanges( $changes );
+   $changeHandler->handleChanges( $changes, 
$this->getRootJobParams() );
 
if ( $changes ) {
/* @var EntityChange $last */
diff --git a/client/includes/Changes/ChangeHandler.php 
b/client/includes/Changes/ChangeHandler.php
index 8d8046d..ad39923 100644
--- a/client/includes/Changes/ChangeHandler.php
+++ b/client/includes/Changes/ChangeHandler.php
@@ -75,20 +75,21 @@
 
/**
 * @param EntityChange[] $changes
+* @param array $rootJobParams any relevant root job parameters to be 
inherited by new jobs.
 */
-   public function handleChanges( array $changes ) {
+   public function handleChanges( array $changes, array $rootJobParams = 
[] ) {
$changes = $this->changeRunCoalescer->transformChangeList( 
$changes );
 
-   if ( !Hooks::run( 'WikibaseHandleChanges', [ $changes ] ) ) {
+   if ( !Hooks::run( 'WikibaseHandleChanges', [ $changes, 
$rootJobParams ] ) ) {
return;
}
 
foreach ( $changes as $change ) {
-   if ( !Hooks::run( 'WikibaseHandleChange', [ $change ] ) 
) {
+   if ( !Hooks::run( 'WikibaseHandleChange', [ $change, 
$rootJobParams ] ) ) {
continue;
}
 
-   $this->handleChange( $change );
+   $this->handleChange( $change, $rootJobParams );
}
}
 
@@ -98,10 +99,9 @@
 * @todo: process multiple changes at once!
 *
 * @param EntityChange $change
-*
-* @throws MWException
+* @param array $rootJobParams any relevant root job parameters to be 
inherited by new jobs.
 */
-   public function handleChange( EntityChange $change ) {
+   public function handleChange( EntityChange $change, array 
$rootJobParams = [] ) {
$changeId = $this->getChangeIdForLog( $change );
wfDebugLog( __CLASS__, __FUNCTION__ . ": handling change 
#$changeId"
. ' (' . $change->getType() . ')' );
@@ -116,9 +116,9 @@
 
( new LinkBatch( $titlesToUpdate ) )->execute();
 
-   $this->updater->purgeWebCache( $titlesToUpdate );
-   $this->updater->scheduleRefreshLinks( $titlesToUpdate );
-   $this->updater->injectRCRecords( $titlesToUpdate, $change );
+   $this->updater->purgeWebCache( $titlesToUpdate, $rootJobParams 
);
+   $this->updater->scheduleRefreshLinks( $titlesToUpdate, 
$rootJobParams );
+   $this->updater->injectRCRecords( $titlesToUpdate, $change, 
$rootJobParams );
// TODO: inject dummy revisions
}
 
diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
index d47acb6..2f0a712 100644
--- a/client/includes/Changes/InjectRCRecordsJob.php
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -75,10 +75,15 @@
/**
 * @param Title[] $titles
 * @param EntityChange $change
+* @param array $rootJobParams
 *
 * @return JobSpecification
 */
-   public static function makeJobSpecification( array $titles, 
EntityChange $change ) {
+   public static function makeJobSpecification(
+   array $titles,
+   EntityChange $change,
+   array $rootJobParams = []
+   ) {
$pages = [];
 
foreach ( $titles as $t ) {
@@ -91,10 +96,10 @@
$changeData = $change->getFields();
$changeData['info'] = $change->getSerializedInfo( [ 'changes' ] 
);
 
-   

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Pre-fetch titles in ChangeHandler

2017-08-29 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/374570 )

Change subject: Pre-fetch titles in ChangeHandler
..

Pre-fetch titles in ChangeHandler

This is for parity with I71af6f13c84.

Change-Id: Ibd9cbd44ead325d1ffe4f06924647a247b6d42a5
---
M client/includes/Changes/ChangeHandler.php
1 file changed, 3 insertions(+), 0 deletions(-)


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

diff --git a/client/includes/Changes/ChangeHandler.php 
b/client/includes/Changes/ChangeHandler.php
index 58dc2ec..81c45de 100644
--- a/client/includes/Changes/ChangeHandler.php
+++ b/client/includes/Changes/ChangeHandler.php
@@ -5,6 +5,7 @@
 use Exception;
 use Hooks;
 use InvalidArgumentException;
+use LinkBatch;
 use MWException;
 use SiteLookup;
 use Title;
@@ -133,6 +134,8 @@
// Run all updates on all affected pages
$titlesToUpdate = $this->getTitlesForUsages( $usagesPerPage );
 
+   ( new LinkBatch( $titlesToUpdate ) )->execute();
+
$this->updater->purgeWebCache( $titlesToUpdate );
$this->updater->scheduleRefreshLinks( $titlesToUpdate );
$this->updater->injectRCRecords( $titlesToUpdate, $change );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd9cbd44ead325d1ffe4f06924647a247b6d42a5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Remove pointless showExternalRecentChanges option.

2017-08-09 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370974 )

Change subject: Remove pointless showExternalRecentChanges option.
..

Remove pointless showExternalRecentChanges option.

Change-Id: I67de8daf7fcdc3c27a2e6470ac25cc6b600c3802
---
M client/WikibaseClient.hooks.php
M client/config/WikibaseClient.default.php
M client/config/WikibaseClient.example.php
M client/includes/Hooks/ChangesListSpecialPageHookHandlers.php
M docs/options.wiki
5 files changed, 3 insertions(+), 58 deletions(-)


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

diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 4853c6d..f0d6458 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -252,10 +252,6 @@
public static function onGetPreferences( User $user, array &$prefs ) {
$settings = WikibaseClient::getDefaultInstance()->getSettings();
 
-   if ( !$settings->getSetting( 'showExternalRecentChanges' ) ) {
-   return true;
-   }
-
$prefs['rcshowwikidata'] = [
'type' => 'toggle',
'label-message' => 'wikibase-rc-show-wikidata-pref',
diff --git a/client/config/WikibaseClient.default.php 
b/client/config/WikibaseClient.default.php
index 29b8098..023acfe 100644
--- a/client/config/WikibaseClient.default.php
+++ b/client/config/WikibaseClient.default.php
@@ -24,7 +24,6 @@
// but we will need to make sure the caching works good enough
'siteLocalID' => $wgLanguageCode,
'languageLinkSiteGroup' => null,
-   'showExternalRecentChanges' => true,
'sendEchoNotification' => false,
'echoIcon' => false,
'allowDataTransclusion' => true,
diff --git a/client/config/WikibaseClient.example.php 
b/client/config/WikibaseClient.example.php
index 07d4489..03f2cfe 100644
--- a/client/config/WikibaseClient.example.php
+++ b/client/config/WikibaseClient.example.php
@@ -20,8 +20,6 @@
 // Defaults to $wgDBname.
 // $wgWBClientSettings['siteGlobalID'] = "mywiki";
 
-$wgWBClientSettings['showExternalRecentChanges'] = true;
-
 // If this wiki also runs the Wikibase repo extension,
 // use the automatic defaults for repo-related settings.
 // If this wiki isn't running the repo extension,
diff --git a/client/includes/Hooks/ChangesListSpecialPageHookHandlers.php 
b/client/includes/Hooks/ChangesListSpecialPageHookHandlers.php
index 26ea3b9..ecfb0c4 100644
--- a/client/includes/Hooks/ChangesListSpecialPageHookHandlers.php
+++ b/client/includes/Hooks/ChangesListSpecialPageHookHandlers.php
@@ -44,11 +44,6 @@
private $pageName;
 
/**
-* @var bool
-*/
-   private $showExternalChanges;
-
-   /**
 * @var self
 */
private static $instance = null;
@@ -58,20 +53,17 @@
 * @param User $user
 * @param LoadBalancer $loadBalancer
 * @param string $pageName
-* @param bool $showExternalChanges
 */
public function __construct(
WebRequest $request,
User $user,
LoadBalancer $loadBalancer,
-   $pageName,
-   $showExternalChanges
+   $pageName
) {
$this->request = $request;
$this->user = $user;
$this->loadBalancer = $loadBalancer;
$this->pageName = $pageName;
-   $this->showExternalChanges = $showExternalChanges;
}
 
/**
@@ -92,8 +84,7 @@
$context->getRequest(),
$context->getUser(),
MediaWikiServices::getInstance()->getDBLoadBalancer(),
-   $specialPageName,
-   $settings->getSetting( 'showExternalRecentChanges' )
+   $specialPageName
);
}
 
@@ -162,40 +153,9 @@
$specialPageName
);
 
-   $hookHandler->addWikibaseConditionsIfFilterUnavailable( $conds 
);
+   // FIXME: now the hook hander is unused - can this entire 
method go away?
 
return true;
-   }
-
-   // This is separate so hasWikibaseChangesEnabled can be mocked
-
-   /**
-* This is used to force-hide Wikibase changes if 
hasWikibaseChangesEnabled returns
-* false.  The user will not even see the option in that case.
-*
-* @param array &$conds
-*/
-   protected function addWikibaseConditionsIfFilterUnavailable( array 
&$conds ) {
-   if ( !$this->hasWikibaseChangesEnabled() ) {
-   // Force-hide if hasWikibaseChangesEnabled is false
-   // The user-facing 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: remove unused injectrecentChanges option

2017-08-09 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370972 )

Change subject: remove unused injectrecentChanges option
..

remove unused injectrecentChanges option

This setting has been ineffective since I19f29d7784fae

Change-Id: I3d38a459460f19744fbfdb8ff31c0a9ededb8499
---
M client/config/WikibaseClient.default.php
M client/config/WikibaseClient.example.php
M client/includes/Changes/ChangeHandler.php
M client/includes/WikibaseClient.php
M client/tests/phpunit/includes/Changes/ChangeHandlerTest.php
M docs/options.wiki
6 files changed, 4 insertions(+), 30 deletions(-)


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

diff --git a/client/config/WikibaseClient.default.php 
b/client/config/WikibaseClient.default.php
index 0f233c3..29b8098 100644
--- a/client/config/WikibaseClient.default.php
+++ b/client/config/WikibaseClient.default.php
@@ -24,7 +24,6 @@
// but we will need to make sure the caching works good enough
'siteLocalID' => $wgLanguageCode,
'languageLinkSiteGroup' => null,
-   'injectRecentChanges' => true,
'showExternalRecentChanges' => true,
'sendEchoNotification' => false,
'echoIcon' => false,
diff --git a/client/config/WikibaseClient.example.php 
b/client/config/WikibaseClient.example.php
index 27469f0..07d4489 100644
--- a/client/config/WikibaseClient.example.php
+++ b/client/config/WikibaseClient.example.php
@@ -20,7 +20,6 @@
 // Defaults to $wgDBname.
 // $wgWBClientSettings['siteGlobalID'] = "mywiki";
 
-$wgWBClientSettings['injectRecentChanges'] = true;
 $wgWBClientSettings['showExternalRecentChanges'] = true;
 
 // If this wiki also runs the Wikibase repo extension,
diff --git a/client/includes/Changes/ChangeHandler.php 
b/client/includes/Changes/ChangeHandler.php
index 58dc2ec..3c65800 100644
--- a/client/includes/Changes/ChangeHandler.php
+++ b/client/includes/Changes/ChangeHandler.php
@@ -50,23 +50,11 @@
private $siteLookup;
 
/**
-* @var string
-*/
-   private $repoId;
-
-   /**
-* @var bool
-*/
-   private $injectRecentChanges;
-
-   /**
 * @param AffectedPagesFinder $affectedPagesFinder
 * @param TitleFactory $titleFactory
 * @param PageUpdater $updater
 * @param ChangeRunCoalescer $changeRunCoalescer
 * @param SiteLookup $siteLookup
-* @param string $repoId
-* @param bool $injectRecentChanges
 *
 * @throws InvalidArgumentException
 */
@@ -75,21 +63,13 @@
TitleFactory $titleFactory,
PageUpdater $updater,
ChangeRunCoalescer $changeRunCoalescer,
-   SiteLookup $siteLookup,
-   $repoId,
-   $injectRecentChanges = true
+   SiteLookup $siteLookup
) {
-   if ( !is_bool( $injectRecentChanges ) ) {
-   throw new InvalidArgumentException( 
'$injectRecentChanges must be a bool' );
-   }
-
$this->affectedPagesFinder = $affectedPagesFinder;
$this->titleFactory = $titleFactory;
$this->updater = $updater;
$this->changeRunCoalescer = $changeRunCoalescer;
$this->siteLookup = $siteLookup;
-   $this->repoId = $repoId;
-   $this->injectRecentChanges = $injectRecentChanges;
}
 
/**
diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index 164f09f..8a250dc 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -1199,8 +1199,7 @@
new TitleFactory(),
$pageUpdater,
$changeListTransformer,
-   $this->siteLookup,
-   $this->settings->getSetting( 'injectRecentChanges' )
+   $this->siteLookup
);
}
 
diff --git a/client/tests/phpunit/includes/Changes/ChangeHandlerTest.php 
b/client/tests/phpunit/includes/Changes/ChangeHandlerTest.php
index a3dc146..5857711 100644
--- a/client/tests/phpunit/includes/Changes/ChangeHandlerTest.php
+++ b/client/tests/phpunit/includes/Changes/ChangeHandlerTest.php
@@ -78,9 +78,7 @@
$titleFactory,
$updater ?: new MockPageUpdater(),
$this->getChangeRunCoalescer(),
-   $this->getMock( SiteLookup::class ),
-   'repowiki',
-   true
+   $this->getMock( SiteLookup::class )
);
 
return $handler;
diff --git a/docs/options.wiki b/docs/options.wiki
index f1905ca..3e8a570 100644
--- a/docs/options.wiki
+++ b/docs/options.wiki

[MediaWiki-commits] [Gerrit] operations/mediawiki-config[master]: Enable injection of RC records on wikidata org.

2017-08-09 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370966 )

Change subject: Enable injection of RC records on wikidata org.
..

Enable injection of RC records on wikidata org.

This will cause RecentChanges to show changes to Items
as changes on pages that use the item.

This functionality is enabled on all client wikis.
On Wikidata itself, very few pages use items, so the impact
should be minimal. There is no reason to make wikidata a special
case.

Change-Id: I605f83faa54def1bbfd1b20216fe8ae8f3cd8a0b
---
M wmf-config/Wikibase.php
1 file changed, 0 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/mediawiki-config 
refs/changes/66/370966/1

diff --git a/wmf-config/Wikibase.php b/wmf-config/Wikibase.php
index 7ef0e97..a13e3f6 100644
--- a/wmf-config/Wikibase.php
+++ b/wmf-config/Wikibase.php
@@ -216,8 +216,6 @@
];
 
$wgWBClientSettings['languageLinkSiteGroup'] = 'wikipedia';
-   $wgWBClientSettings['injectRecentChanges'] = false;
-   $wgWBClientSettings['showExternalRecentChanges'] = false;
}
 
foreach ( $wmgWikibaseClientSettings as $setting => $value ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I605f83faa54def1bbfd1b20216fe8ae8f3cd8a0b
Gerrit-PatchSet: 1
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...News[master]: Check Title::canHaveTalkPage before calling getTalkPage()

2017-08-05 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370326 )

Change subject: Check Title::canHaveTalkPage before calling getTalkPage()
..

Check Title::canHaveTalkPage before calling getTalkPage()

Bug: T172146
Change-Id: Iba8616448b8219109277e24d1af10345c49b5ee9
---
M NewsRenderer.php
1 file changed, 8 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/News 
refs/changes/26/370326/1

diff --git a/NewsRenderer.php b/NewsRenderer.php
index 50057bc..8db7151 100644
--- a/NewsRenderer.php
+++ b/NewsRenderer.php
@@ -380,6 +380,11 @@
return $html;
}
 
+   /**
+* @param FeedItem $item
+*
+* @return string
+*/
function renderFeedItem( $item ) {
global $wgContLang;
 
@@ -401,9 +406,9 @@
$html .= $item->raw_text;
$html .= '';
$html .= '';
-   if ( $item->getComments() ) {
+   if ( $item->getComments() && $item->comment_object ) {
$html .= '(';
-   $html .= ''.htmlspecialchars($item->title_object->getTalkPage()->getPrefixedText()).'';
+   $html .= ''.htmlspecialchars( 
$item->comment_object->getPrefixedText() ).'';
$html .= ')';
}
$html .= '';
@@ -458,8 +463,7 @@
 
//XXX: ugly hack - things used by preview
$item->raw_text = $text; //needed because FeedItem holds text 
html-encoded internally. wtf
-   $item->raw_comment = $title->getTalkPage()->getFullURL(); 
//needed because FeedItem holds text html-encoded internally. wtf
-   $item->raw_title = $name; //needed because FeedItem holds text 
html-encoded internally. wtf
+   $item->comment_object = $title->canHaveTalkPage() ? 
$title->getTalkPage() : null; //needed because FeedItem holds text html-encoded 
internally. wtf
$item->title_object = $title; //title object
return $item;
}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba8616448b8219109277e24d1af10345c49b5ee9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/News
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[wmf/1.30.0-wmf.12]: Hot fix for InjectRCRecordsJob: disable coalescing

2017-08-03 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/369847 )

Change subject: Hot fix for InjectRCRecordsJob: disable coalescing
..

Hot fix for InjectRCRecordsJob: disable coalescing

Bug: T172320
Change-Id: I039b815395c56bc522ec34fd60230a0997f6c27d
---
M client/includes/Changes/ChangeHandler.php
M client/includes/Changes/InjectRCRecordsJob.php
2 files changed, 7 insertions(+), 2 deletions(-)


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

diff --git a/client/includes/Changes/ChangeHandler.php 
b/client/includes/Changes/ChangeHandler.php
index 884c30e..a5a5f1f 100644
--- a/client/includes/Changes/ChangeHandler.php
+++ b/client/includes/Changes/ChangeHandler.php
@@ -123,7 +123,8 @@
 * @param EntityChange[] $changes
 */
public function handleChanges( array $changes ) {
-   $changes = $this->changeRunCoalescer->transformChangeList( 
$changes );
+   // FIXME: Commented out as a HOT FIX for T172320
+   // $changes = $this->changeRunCoalescer->transformChangeList( 
$changes );
 
if ( !Hooks::run( 'WikibaseHandleChanges', [ $changes ] ) ) {
return;
diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
index 54c4781..20c361e 100644
--- a/client/includes/Changes/InjectRCRecordsJob.php
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Client\Changes;
 
+use InvalidArgumentException;
 use Job;
 use JobSpecification;
 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
@@ -75,6 +76,10 @@
 * @return JobSpecification
 */
public static function makeJobSpecification( array $titles, 
EntityChange $change ) {
+   if ( $change->getId() === null ) {
+   throw new InvalidArgumentException( 'The given Change 
does not have an ID defined' );
+   }
+
$pages = [];
 
foreach ( $titles as $t ) {
@@ -91,7 +96,6 @@
'wikibase-InjectRCRecords',
$params
);
-
}
 
/**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I039b815395c56bc522ec34fd60230a0997f6c27d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.30.0-wmf.12
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Hot fix for InjectRCRecordsJob: disable coalescing

2017-08-03 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/369846 )

Change subject: Hot fix for InjectRCRecordsJob: disable coalescing
..

Hot fix for InjectRCRecordsJob: disable coalescing

Bug: T172320
Change-Id: I039b815395c56bc522ec34fd60230a0997f6c27d
---
M client/includes/Changes/ChangeHandler.php
M client/includes/Changes/InjectRCRecordsJob.php
2 files changed, 7 insertions(+), 2 deletions(-)


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

diff --git a/client/includes/Changes/ChangeHandler.php 
b/client/includes/Changes/ChangeHandler.php
index 884c30e..a5a5f1f 100644
--- a/client/includes/Changes/ChangeHandler.php
+++ b/client/includes/Changes/ChangeHandler.php
@@ -123,7 +123,8 @@
 * @param EntityChange[] $changes
 */
public function handleChanges( array $changes ) {
-   $changes = $this->changeRunCoalescer->transformChangeList( 
$changes );
+   // FIXME: Commented out as a HOT FIX for T172320
+   // $changes = $this->changeRunCoalescer->transformChangeList( 
$changes );
 
if ( !Hooks::run( 'WikibaseHandleChanges', [ $changes ] ) ) {
return;
diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
index 54c4781..20c361e 100644
--- a/client/includes/Changes/InjectRCRecordsJob.php
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Client\Changes;
 
+use InvalidArgumentException;
 use Job;
 use JobSpecification;
 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
@@ -75,6 +76,10 @@
 * @return JobSpecification
 */
public static function makeJobSpecification( array $titles, 
EntityChange $change ) {
+   if ( $change->getId() === null ) {
+   throw new InvalidArgumentException( 'The given Change 
does not have an ID defined' );
+   }
+
$pages = [];
 
foreach ( $titles as $t ) {
@@ -91,7 +96,6 @@
'wikibase-InjectRCRecords',
$params
);
-
}
 
/**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I039b815395c56bc522ec34fd60230a0997f6c27d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Introduce Title::getTalkPageIfDefined.

2017-08-01 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/369424 )

Change subject: Introduce Title::getTalkPageIfDefined.
..

Introduce Title::getTalkPageIfDefined.

This is part of the effort to remove the assumption that every page
can have a talk page. Before we can merge Icee208dc4 which makes
Title::getTalkPage() throw an exception of no corresponding talk
namespace is defined, all extensions that call getTalkPage() must
be changed to either check canHaveTalkPage() first, or to use
the conveniance function getTalkPageIfDefined() instead.

Bug: T165149
Bug: T172146
Change-Id: I6d2613d8f7105048022f8093186dc57f1f8173ab
---
M includes/Title.php
M tests/phpunit/includes/TitleTest.php
2 files changed, 67 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/24/369424/1

diff --git a/includes/Title.php b/includes/Title.php
index edfdaca..0a2f868 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -1317,6 +1317,21 @@
}
 
/**
+* Get a Title object associated with the talk page of this article,
+* if such a talk page can exist.
+*
+* @return Title The object for the talk page,
+* or null if no associated talk page can exist, according to 
canHaveTalkPage().
+*/
+   public function getTalkPageIfDefined() {
+   if ( !$this->canHaveTalkPage() ) {
+   return null;
+   }
+
+   return $this->getTalkPage();
+   }
+
+   /**
 * Get a title object associated with the subject page of this
 * talk page
 *
diff --git a/tests/phpunit/includes/TitleTest.php 
b/tests/phpunit/includes/TitleTest.php
index c06a2e4..7770cbc 100644
--- a/tests/phpunit/includes/TitleTest.php
+++ b/tests/phpunit/includes/TitleTest.php
@@ -716,6 +716,58 @@
$this->assertSame( $expected, $actual, 
$title->getPrefixedDBkey() );
}
 
+   public static function provideGetTalkPage_good() {
+   return [
+   [ Title::makeTitle( NS_MAIN, 'Test' ), 
Title::makeTitle( NS_TALK, 'Test' ) ],
+   [ Title::makeTitle( NS_TALK, 'Test' ), 
Title::makeTitle( NS_TALK, 'Test' ) ],
+   ];
+   }
+
+   /**
+* @dataProvider provideGetTalkPage_good
+* @covers Title::getTalkPage
+*/
+   public function testGetTalkPage_good( Title $title, Title $expected ) {
+   $talk = $title->getTalkPage();
+   $this->assertSame(
+   $expected->getPrefixedDBKey(),
+   $talk->getPrefixedDBKey(),
+   $title->getPrefixedDBKey()
+   );
+   }
+
+   /**
+* @dataProvider provideGetTalkPage_good
+* @covers Title::getTalkPageIfDefined
+*/
+   public function testGetTalkPageIfDefined_good( Title $title ) {
+   $talk = $title->getTalkPageIfDefined();
+   $this->assertInstanceOf(
+   Title::class,
+   $talk,
+   $title->getPrefixedDBKey()
+   );
+   }
+
+   public static function provideGetTalkPage_bad() {
+   return [
+   [ Title::makeTitle( NS_SPECIAL, 'Test' ) ],
+   [ Title::makeTitle( NS_MEDIA, 'Test' ) ],
+   ];
+   }
+
+   /**
+* @dataProvider provideGetTalkPage_bad
+* @covers Title::getTalkPageIfDefined
+*/
+   public function testGetTalkPageIfDefined_bad( Title $title ) {
+   $talk = $title->getTalkPageIfDefined();
+   $this->assertNull(
+   $talk,
+   $title->getPrefixedDBKey()
+   );
+   }
+
public function provideCreateFragmentTitle() {
return [
[ Title::makeTitle( NS_MAIN, 'Test' ), 'foo' ],

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6d2613d8f7105048022f8093186dc57f1f8173ab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Track per-client statistics for dispatchCHanges.

2017-08-01 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/369422 )

Change subject: Track per-client statistics for dispatchCHanges.
..

Track per-client statistics for dispatchCHanges.

Change-Id: Ifa7e56c202dcd88b06c520140cafa6c63c9f1235
---
M repo/maintenance/dispatchChanges.php
1 file changed, 2 insertions(+), 0 deletions(-)


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

diff --git a/repo/maintenance/dispatchChanges.php 
b/repo/maintenance/dispatchChanges.php
index 7189bda..1ca5612 100644
--- a/repo/maintenance/dispatchChanges.php
+++ b/repo/maintenance/dispatchChanges.php
@@ -232,6 +232,8 @@
if ( $wikiState ) {
$dispatchedChanges = 
$dispatcher->dispatchTo( $wikiState );
$stats->updateCount( 
'wikibase.repo.dispatchChanges.changes', $dispatchedChanges );
+   $stats->updateCount( 
'wikibase.repo.dispatchChanges.changes-per-client.'
+   
. $wikiState['chd_site'], $dispatchedChanges );
} else {
$stats->increment( 
'wikibase.repo.dispatchChanges.noclient' );
// Try again later, unless we have 
already reached the limit.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifa7e56c202dcd88b06c520140cafa6c63c9f1235
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Fix bad value type in demo data for Leiter

2017-08-01 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/369394 )

Change subject: Fix bad value type in demo data for Leiter
..

Fix bad value type in demo data for Leiter

Change-Id: I604a6b4f5f81fb68af1e89bcca42a6bedd5f3751
---
M src/DemoData/LeiterLexemePopulator.php
1 file changed, 3 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme 
refs/changes/94/369394/1

diff --git a/src/DemoData/LeiterLexemePopulator.php 
b/src/DemoData/LeiterLexemePopulator.php
index af505ea..cb3c844 100644
--- a/src/DemoData/LeiterLexemePopulator.php
+++ b/src/DemoData/LeiterLexemePopulator.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Lexeme\DemoData;
 
+use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\Lexeme\DataModel\Lexeme;
 use Wikibase\Lexeme\Tests\DataModel\NewForm;
 use Wikibase\Lexeme\Tests\DataModel\NewSense;
@@ -74,7 +75,7 @@
->withGloss( 'en', 'leader' )
->withStatement(
NewStatement::forProperty( Id::P_DENOTES )
-   ->withValue( Id::Q_LEADER )
+   ->withValue( new ItemId( Id::Q_LEADER ) 
)
->withSomeGuid()
)
->build();
@@ -89,7 +90,7 @@
->withGloss( 'en', 'electrical conductor' )
->withStatement(
NewStatement::forProperty( Id::P_DENOTES )
-   ->withValue( Id::Q_CONDUCTOR )
+   ->withValue( new ItemId( 
Id::Q_CONDUCTOR ) )
->withSomeGuid()
)
->build();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I604a6b4f5f81fb68af1e89bcca42a6bedd5f3751
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Remove unused EditEntity::showErrorPage.

2017-07-31 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/368821 )

Change subject: Remove unused EditEntity::showErrorPage.
..

Remove unused EditEntity::showErrorPage.

This also removes the need to supply an IContextSource to EditEntity
and EditEntityFactory.

Change-Id: I8903b161efb728e81c07e47b2a1f98684749cbec
---
M repo/includes/EditEntity.php
M repo/includes/EditEntityFactory.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/EditEntityTest.php
4 files changed, 5 insertions(+), 120 deletions(-)


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

diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index 6fe10e3..30250e8 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -106,11 +106,6 @@
private $title = null;
 
/**
-* @var IContextSource
-*/
-   private $context;
-
-   /**
 * @var EditFilterHookRunner
 */
private $editFilterHookRunner;
@@ -178,10 +173,6 @@
 *This will detect "late" edit conflicts, i.e. someone 
squeezing in an edit
 *just before the actual database transaction for saving beings.
 *The empty string and 0 are both treated as `false`, disabling 
conflict checks.
-* @param IContextSource|null $context the context to use while 
processing
-*the edit; defaults to RequestContext::getMain().
-*
-* @throws InvalidArgumentException
 */
public function __construct(
EntityTitleStoreLookup $titleLookup,
@@ -193,8 +184,7 @@
EntityDocument $newEntity,
User $user,
EditFilterHookRunner $editFilterHookRunner,
-   $baseRevId = false,
-   IContextSource $context = null
+   $baseRevId = false
) {
$this->newEntity = $newEntity;
 
@@ -211,12 +201,6 @@
 
$this->errorType = 0;
$this->status = Status::newGood();
-
-   if ( $context === null ) {
-   $context = RequestContext::getMain();
-   }
-
-   $this->context = $context;
 
$this->titleLookup = $titleLookup;
$this->entityRevisionLookup = $entityLookup;
@@ -678,56 +662,6 @@
 */
public function doesCheckForEditConflicts() {
return $this->getBaseRevisionId() !== false;
-   }
-
-   /**
-* Shows an error page showing the errors that occurred during 
attemptSave(), if any.
-*
-* If $titleMessage is set it is made an assumption that the page is 
still the original
-* one, and there should be no link back from a special error page.
-*
-* @param string|null $titleMessage Message key for the page title.
-*
-* @return bool true if an error page was shown, false if there were no 
errors to show.
-*/
-   public function showErrorPage( $titleMessage = null ) {
-   $out = $this->context->getOutput();
-
-   if ( $this->status === null || $this->status->isOK() ) {
-   return false;
-   }
-
-   if ( $titleMessage === null ) {
-   $out->prepareErrorPage( wfMessage( 'errorpagetitle' ) );
-   } else {
-   $out->prepareErrorPage( wfMessage( $titleMessage ), 
wfMessage( 'errorpagetitle' ) );
-   }
-
-   $this->showStatus();
-
-   if ( !isset( $titleMessage ) ) {
-   $out->returnToMain( '', $this->getTitle() );
-   }
-
-   return true;
-   }
-
-   /**
-* Shows any errors or warnings from attemptSave().
-*
-* @return bool true if any message was shown, false if there were no 
errors to show.
-*/
-   private function showStatus() {
-   if ( $this->status === null || $this->status->isGood() ) {
-   return false;
-   }
-
-   $out = $this->context->getOutput();
-   $text = $this->status->getHTML();
-
-   $out->addHTML( Html::rawElement( 'div', [ 'class' => 'error' ], 
$text ) );
-
-   return true;
}
 
/**
diff --git a/repo/includes/EditEntityFactory.php 
b/repo/includes/EditEntityFactory.php
index d88a6c5..b81e94b 100644
--- a/repo/includes/EditEntityFactory.php
+++ b/repo/includes/EditEntityFactory.php
@@ -55,11 +55,6 @@
private $editFilterHookRunner;
 
/**
-* @var IContextSource|null
-*/
-   private $context;
-
-   /**
 * @param EntityTitleStoreLookup $titleLookup
 * @param EntityRevisionLookup $entityLookup
 * @param EntityStore $entityStore
@@ 

[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Tweak demo data:

2017-07-31 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/368797 )

Change subject: Tweak demo data:
..

Tweak demo data:

* fix a type
* rename "related concept" to "evokes"
* introduce "denotes" relation

Change-Id: If19ca109b5fc210937750588aaf165981d2249b6
---
M src/DemoData/AskOut1Populator.php
M src/DemoData/HardLexemePopulator.php
M src/DemoData/Id.php
M src/DemoData/LeiterLexemePopulator.php
4 files changed, 18 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme 
refs/changes/97/368797/1

diff --git a/src/DemoData/AskOut1Populator.php 
b/src/DemoData/AskOut1Populator.php
index 930851a..e0944c1 100644
--- a/src/DemoData/AskOut1Populator.php
+++ b/src/DemoData/AskOut1Populator.php
@@ -19,7 +19,7 @@
 */
private function buildDefaultSense() {
return NewSense::havingId( 'S5' )
-   ->withGloss( 'en', 'To ask somebody out’: To request a 
romantic date' )
+   ->withGloss( 'en', '’To ask somebody out’: To request a 
romantic date' )
->build();
}
 
diff --git a/src/DemoData/HardLexemePopulator.php 
b/src/DemoData/HardLexemePopulator.php
index 2f49593..5581663 100644
--- a/src/DemoData/HardLexemePopulator.php
+++ b/src/DemoData/HardLexemePopulator.php
@@ -116,17 +116,17 @@
->withGloss( 'en', 'resisting deformation' )
->withGloss( 'de', 'schwer verformbar' )
->withStatement(
-   NewStatement::forProperty( 
Id::P_RELATED_CONCEPT )
+   NewStatement::forProperty( Id::P_EVOKES )
->withValue( new ItemId( 
Id::Q_ELASTICITY ) )
->withSomeGuid()
)
->withStatement(
-   NewStatement::forProperty( 
Id::P_RELATED_CONCEPT )
+   NewStatement::forProperty( Id::P_EVOKES )
->withValue( new ItemId( 
Id::Q_DUCTILITY ) )
->withSomeGuid()
)
->withStatement(
-   NewStatement::forProperty( 
Id::P_RELATED_CONCEPT )
+   NewStatement::forProperty( Id::P_EVOKES )
->withValue( new ItemId( Id::Q_HARDNESS 
) )
->withSomeGuid()
)
diff --git a/src/DemoData/Id.php b/src/DemoData/Id.php
index 6631dea..ea0e5d7 100644
--- a/src/DemoData/Id.php
+++ b/src/DemoData/Id.php
@@ -33,7 +33,7 @@
const P_REGION = 'P11';
const P_PRONUNCIATION_AUDIO = 'P12';
const P_REGISTER = 'P13';
-   const P_RELATED_CONCEPT = 'P14';
+   const P_EVOKES = 'P14';
const P_MORPHOLOGY = 'P15';
const P_GRAMMATICAL_GENDER = 'P16';
const P_GENDERED_FORM = 'P17';
@@ -46,7 +46,10 @@
const P_TRANSLATION = 'P22';
const P_ANTONYM = 'P24';
const P_REFERS_TO_SENSE = 'P25';
+   const P_DENOTES = 'P26';
 
+   const Q_CONDUCTOR = 'Q33';
+   const Q_LEADER = 'Q32';
const Q_VERBAL_PHRASE = 'Q31';
const Q_FEMALE = 'Q30';
const Q_GENITIVE = 'Q29';
diff --git a/src/DemoData/LeiterLexemePopulator.php 
b/src/DemoData/LeiterLexemePopulator.php
index f3093a6..af505ea 100644
--- a/src/DemoData/LeiterLexemePopulator.php
+++ b/src/DemoData/LeiterLexemePopulator.php
@@ -72,6 +72,11 @@
return NewSense::havingId( 'S1' )
->withGloss( 'de', 'Führungsperson' )
->withGloss( 'en', 'leader' )
+   ->withStatement(
+   NewStatement::forProperty( Id::P_DENOTES )
+   ->withValue( Id::Q_LEADER )
+   ->withSomeGuid()
+   )
->build();
}
 
@@ -82,6 +87,11 @@
return NewSense::havingId( 'S2' )
->withGloss( 'de', 'elektrischer Leiter' )
->withGloss( 'en', 'electrical conductor' )
+   ->withStatement(
+   NewStatement::forProperty( Id::P_DENOTES )
+   ->withValue( Id::Q_CONDUCTOR )
+   ->withSomeGuid()
+   )
->build();
}
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If19ca109b5fc210937750588aaf165981d2249b6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[wmf/1.30.0-wmf.10]: Move injection of RC records to a separate job.

2017-07-27 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/368224 )

Change subject: Move injection of RC records to a separate job.
..

Move injection of RC records to a separate job.

This should also fix the nested transaction issue introduced by If195a35e9c.

Bug: T107722
Bug: T171370
Change-Id: I9100c174537c56527c2dcec38a69234b7ebe80c9
(cherry picked from commit 2987fe5bcf6223d03835670f7a6832e6a41a51ef)
---
M client/WikibaseClient.php
A client/includes/Changes/InjectRCRecordsJob.php
M client/includes/Changes/WikiPageUpdater.php
M client/includes/WikibaseClient.php
A client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
6 files changed, 590 insertions(+), 100 deletions(-)


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

diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index fd0fe88..012905d 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -182,6 +182,24 @@
// job classes
$wgJobClasses['wikibase-addUsagesForPage'] = 
Wikibase\Client\Store\AddUsagesForPageJob::class;
$wgJobClasses['ChangeNotification'] = 
Wikibase\Client\ChangeNotificationJob::class;
+   $wgJobClasses['wikibase-InjectRCRecords'] = function ( Title $unused, 
array $params ) {
+   $mwServices = MediaWiki\MediaWikiServices::getInstance();
+   $wbServices = 
Wikibase\Client\WikibaseClient::getDefaultInstance();
+
+   $job = new Wikibase\Client\Changes\InjectRCRecordsJob(
+   $mwServices->getDBLoadBalancerFactory(),
+   $wbServices->getStore()->getEntityChangeLookup(),
+   $wbServices->getRecentChangeFactory(),
+   $params
+   );
+
+   $job->setRecentChangesDuplicateDetector( 
$wbServices->getStore()->getRecentChangesDuplicateDetector() );
+
+   $job->setLogger( MediaWiki\Logger\LoggerFactory::getInstance( 
'wikibase.client.pageupdates' ) );
+   $job->setStats( $mwServices->getStatsdDataFactory() );
+
+   return $job;
+   };
 
// api modules
$wgAPIMetaModules['wikibase'] = array(
@@ -226,8 +244,8 @@
$wgAPIPropModules['wbentityusage'] = [
'class' => Wikibase\Client\Api\ApiPropsEntityUsage::class,
'factory' => function ( ApiQuery $query, $moduleName ) {
-   $repoLinker = 
\Wikibase\Client\WikibaseClient::getDefaultInstance()->newRepoLinker();
-   return new \Wikibase\Client\Api\ApiPropsEntityUsage(
+   $repoLinker = 
Wikibase\Client\WikibaseClient::getDefaultInstance()->newRepoLinker();
+   return new Wikibase\Client\Api\ApiPropsEntityUsage(
$query,
$moduleName,
$repoLinker
diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
new file mode 100644
index 000..54c4781
--- /dev/null
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -0,0 +1,272 @@
+getArticleId();
+   $pages[$id] = [ $t->getNamespace(), $t->getDBkey() ];
+   }
+
+   $params = [
+   'change' => $change->getId(),
+   'pages' => $pages
+   ];
+
+   return new JobSpecification(
+   'wikibase-InjectRCRecords',
+   $params
+   );
+
+   }
+
+   /**
+* Constructs an InjectRCRecordsJob for injecting a change into the 
recentchanges feed
+* for the given pages.
+*
+* @param LBFactory $lbFactory
+* @param EntityChangeLookup $changeLookup
+* @param RecentChangeFactory $rcFactory
+* @param array $params Needs to have two keys: "change": the id of the 
change,
+* "pages": array of pages, represented as $pageId => [ $namespace, 
$dbKey ].
+*/
+   public function __construct(
+   LBFactory $lbFactory,
+   EntityChangeLookup $changeLookup,
+   RecentChangeFactory $rcFactory,
+   array $params
+   ) {
+   $title = Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __CLASS__ 
);
+   parent::__construct( 'wikibase-InjectRCRecords', $title, 
$params );
+
+   Assert::parameter(
+   isset( $params['change'] ),
+   '$params',
+   '$params[\'change\'] not set.'
+   );
+   Assert::parameter(
+   isset( $params['pages'] ),
+   '$params',
+   '$params[\'pages\'] not set.'
+ 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Track calls to wbeditentity and usage of the clear switch

2017-07-25 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/367703 )

Change subject: Track calls to wbeditentity and usage of the clear switch
..

Track calls to wbeditentity and usage of the clear switch

Bug: T171609
Change-Id: If316331e1bfa4a35fef50b6b46a2ab913d08b3d4
---
M repo/includes/Api/EditEntity.php
1 file changed, 11 insertions(+), 3 deletions(-)


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

diff --git a/repo/includes/Api/EditEntity.php b/repo/includes/Api/EditEntity.php
index c6768e4..6d7a1c5 100644
--- a/repo/includes/Api/EditEntity.php
+++ b/repo/includes/Api/EditEntity.php
@@ -252,11 +252,19 @@
 
if ( $preparedParameters['clear'] ) {
$entity = $this->clearEntity( $entity );
+
+   $this->getStats()->increment( 
'wikibase.api.EditEntity.modifyEntity.clear' );
+   } else {
+   $this->getStats()->increment( 
'wikibase.api.EditEntity.modifyEntity.no-clear' );
}
 
-   // if we create a new property, make sure we set the datatype
-   if ( !$exists && $entity instanceof Property ) {
-   $entity->setDataTypeId( $data['datatype'] );
+   if ( !$exists ) {
+   // if we create a new property, make sure we set the 
datatype
+   if ( $entity instanceof Property ) {
+   $entity->setDataTypeId( $data['datatype'] );
+   }
+
+   $this->getStats()->increment( 
'wikibase.api.EditEntity.modifyEntity.create' );
}
 
$changeOps = $this->getChangeOp( $data, $entity );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If316331e1bfa4a35fef50b6b46a2ab913d08b3d4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Move injection of RC records to a separate job.

2017-07-23 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/367328 )

Change subject: Move injection of RC records to a separate job.
..

Move injection of RC records to a separate job.

This should also fix the nested transaction issue introduced by If195a35e9c.

Bug: T107722
Bug: T171370
Change-Id: I9100c174537c56527c2dcec38a69234b7ebe80c9
---
M client/WikibaseClient.php
A client/includes/Changes/InjectRCRecordsJob.php
M client/includes/Changes/WikiPageUpdater.php
M client/includes/WikibaseClient.php
A client/tests/phpunit/includes/Changes/InjectRCRecordsJobTest.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
6 files changed, 589 insertions(+), 98 deletions(-)


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

diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index fd0fe88..1d4a527 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -182,6 +182,24 @@
// job classes
$wgJobClasses['wikibase-addUsagesForPage'] = 
Wikibase\Client\Store\AddUsagesForPageJob::class;
$wgJobClasses['ChangeNotification'] = 
Wikibase\Client\ChangeNotificationJob::class;
+   $wgJobClasses['wikibase-InjectRCRecords'] = function ( Title $unused, 
array $params ) {
+   $mwServices = \MediaWiki\MediaWikiServices::getInstance();
+   $wbServices = 
Wikibase\Client\WikibaseClient::getDefaultInstance();
+
+   $job = new \Wikibase\Client\Changes\InjectRCRecordsJob(
+   $mwServices->getDBLoadBalancerFactory(),
+   $wbServices->getStore()->getEntityChangeLookup(),
+   $wbServices->getRecentChangeFactory(),
+   $params
+   );
+
+   $job->setRecentChangesDuplicateDetector( 
$wbServices->getStore()->getRecentChangesDuplicateDetector() );
+
+   $job->setLogger( \MediaWiki\Logger\LoggerFactory::getInstance( 
'wikibase.client.pageupdates' ) );
+   $job->setStats( $mwServices->getStatsdDataFactory() );
+
+   return $job;
+   };
 
// api modules
$wgAPIMetaModules['wikibase'] = array(
diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
new file mode 100644
index 000..a00f8dd
--- /dev/null
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -0,0 +1,273 @@
+getArticleId();
+   $pages[$id] = [ $t->getNamespace(), $t->getDBkey() ];
+   }
+
+   $params = [
+   'change' => $change->getId(),
+   'pages' => $pages
+   ];
+
+   return new JobSpecification(
+   'wikibase-InjectRCRecords',
+   $params
+   );
+
+   }
+
+   /**
+* Constructs an InjectRCRecordsJob for injecting a change into the 
recentchanges feed
+* for the given pages.
+*
+* @param LBFactory $lbFactory
+* @param EntityChangeLookup $changeLookup
+* @param RecentChangeFactory $rcFactory
+* @param array $params Needs to have two keys: "change": the id of the 
change,
+* "pages": array of pages, represented as $pageId => [ $namespace, 
$dbKey ].
+*/
+   public function __construct(
+   LBFactory $lbFactory,
+   EntityChangeLookup $changeLookup,
+   RecentChangeFactory $rcFactory,
+   array $params
+   ) {
+   $title = Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __CLASS__ 
);
+   parent::__construct( 'wikibase-InjectRCRecords', $title, 
$params );
+
+   Assert::parameterType( 'array', $params, '$params' );
+   Assert::parameter(
+   isset( $params['change'] ),
+   '$params',
+   '$params[\'change\'] not set.'
+   );
+   Assert::parameter(
+   isset( $params['pages'] ) && is_array( $params['pages'] 
),
+   '$params',
+   '$params[\'pages\'] not set or not an array.'
+   );
+   Assert::parameterElementType(
+   'array',
+   $params['pages'],
+   '$params[\'pages\']'
+   );
+
+   $this->lbFactory = $lbFactory;
+   $this->changeLookup = $changeLookup;
+   $this->rcFactory = $rcFactory;
+
+   $this->titleFactory = new TitleFactory();
+   $this->logger = new NullLogger();
+   }
+
+   /**
+* @param RecentChangesDuplicateDetector $rcDuplicateDetector
+*/
+   public function setRecentChangesDuplicateDetector( 
RecentChangesDuplicateDetector 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Use proper DB name for local wiki in wb_changes_dispatch table.

2017-07-23 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/367325 )

Change subject: Use proper DB name for local wiki in wb_changes_dispatch table.
..

Use proper DB name for local wiki in wb_changes_dispatch table.

The database name was previously recorded as "0" for the local database
if the list of client databases represented the local db name as `false`,
as is common in MediaWiki.

Note that this change should not have any effect on the live site:

Firstly, the changed code will only affect what value will be used
when inserting new rows into changedispatch. This only happens when
new wikis are added to the client list. For wikidata.org, the local
(repo) wiki is already present in the table.

Secondly, this is only relevant if the local wiki is represented as
`false` in the list of clients. This is not the case for the live
site.

Thirdly, the value of the chd_db field is only used for logging and
reporting. It has no impact on behavior.

Change-Id: I4195e08b2345880f8380f76c329544d603c804d1
---
M repo/maintenance/dispatchChanges.php
1 file changed, 16 insertions(+), 7 deletions(-)


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

diff --git a/repo/maintenance/dispatchChanges.php 
b/repo/maintenance/dispatchChanges.php
index c507954..92ba701 100644
--- a/repo/maintenance/dispatchChanges.php
+++ b/repo/maintenance/dispatchChanges.php
@@ -64,19 +64,23 @@
}
 
/**
-* @param SettingsArray $settings
+* @param array $clientWikis
+* @param string $localDBname
 *
 * @return string[] A mapping of client wiki site IDs to logical 
database names.
 */
-   private function getClientWikis( SettingsArray $settings ) {
-   $clientWikis = $settings->getSetting( 'localClientDatabases' );
-
+   private function getClientWikis( array $clientWikis, $localDBname ) {
// make sure we have a mapping from siteId to database name in 
clientWikis:
foreach ( $clientWikis as $siteID => $dbName ) {
+   if ( $dbName === false ) {
+   // resolve local DB name
+   $dbName = $localDBname;
+   }
if ( is_int( $siteID ) ) {
unset( $clientWikis[$siteID] );
-   $clientWikis[$dbName] = $dbName;
+   $siteID = $dbName;
}
+   $clientWikis[$siteID] = $dbName;
}
 
return $clientWikis;
@@ -165,7 +169,12 @@
$delay = (int)$this->getOption( 'idle-delay', 10 );
 
$wikibaseRepo = WikibaseRepo::getDefaultInstance();
-   $clientWikis = $this->getClientWikis( 
$wikibaseRepo->getSettings() );
+   $mediaWikiServices = MediaWikiServices::getInstance();
+
+   $clientWikis = $this->getClientWikis(
+   $wikibaseRepo->getSettings()->getSetting( 
'localClientDatabases' ),
+   $mediaWikiServices->getMainConfig()->get( 'DBname' )
+   );
 
if ( empty( $clientWikis ) ) {
throw new MWException( "No client wikis configured! 
Please set \$wgWBRepoSettings['localClientDatabases']." );
@@ -179,7 +188,7 @@
 
$dispatcher->getDispatchCoordinator()->initState( $clientWikis 
);
 
-   $stats = 
MediaWikiServices::getInstance()->getStatsdDataFactory();
+   $stats = $mediaWikiServices->getStatsdDataFactory();
$stats->increment( 'wikibase.repo.dispatchChanges.start' );
 
$passes = $maxPasses === PHP_INT_MAX ? "unlimited" : $maxPasses;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4195e08b2345880f8380f76c329544d603c804d1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Streamline input validation for Special pages.

2017-07-22 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/367045 )

Change subject: Streamline input validation for Special pages.
..

Streamline input validation for Special pages.

Change-Id: I0886cfe8ad5b490e2362175452459a1635160e70
---
M repo/includes/Specials/SpecialModifyEntity.php
M repo/includes/Specials/SpecialModifyTerm.php
M repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
M repo/includes/Specials/SpecialSetSiteLink.php
4 files changed, 97 insertions(+), 53 deletions(-)


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

diff --git a/repo/includes/Specials/SpecialModifyEntity.php 
b/repo/includes/Specials/SpecialModifyEntity.php
index 3c850ca..4905c54 100644
--- a/repo/includes/Specials/SpecialModifyEntity.php
+++ b/repo/includes/Specials/SpecialModifyEntity.php
@@ -32,7 +32,7 @@
/**
 * @var EntityDocument|null
 */
-   private $entity = null;
+   private $entityForModification = null;
 
/**
 * @var EntityId|null
@@ -173,12 +173,30 @@
 * @return EntityDocument
 */
protected function getEntityForModification() {
-   if ( !$this->entity ) {
+   if ( !$this->entityForModification ) {
$revision = $this->getBaseRevision();
-   $this->entity = $revision->getEntity()->copy();
+   $this->entityForModification = 
$revision->getEntity()->copy();
}
 
-   return $this->entity;
+   return $this->entityForModification;
+   }
+
+   /**
+* Returns the EntityDocument that is to be shown by code in this class 
(or subclasses).
+* The returns null if no entity ID was specified in the request.
+*
+* @throws MessageException
+* @throws UserInputException
+*
+* @return EntityDocument|null
+*/
+   protected function getEntityForDisplay() {
+   if ( $this->entityId ) {
+   $revision = $this->getBaseRevision();
+   return $revision->getEntity();
+   }
+
+   return null;
}
 
/**
@@ -197,34 +215,39 @@
$this->outputHeader();
 
$summary = false;
-   $entity = null;
+   $updatedEntity = null;
 
try {
-   $this->prepareArguments( $subPage );
-
+   $this->processArguments( $subPage );
$valid = $this->validateInput();
-   $entity = $this->getEntityId() ? 
$this->getEntityForModification() : null;
 
-   if ( $valid && $entity ) {
-   $summary = $this->modifyEntity( $entity );
+   if ( $valid && $this->isModificationRequested() ) {
+   $updatedEntity = 
$this->getEntityForModification();
+   $summary = $this->modifyEntity( $updatedEntity 
);
+
+   if ( !$summary ) {
+   $updatedEntity = null;
+   }
}
} catch ( UserInputException $ex ) {
$error = $this->msg( $ex->getKey(), $ex->getParams() 
)->parse();
$this->showErrorHTML( $error );
}
 
-   if ( !$entity || !$summary ) {
+   if ( !$updatedEntity ) {
+   $entity = $this->getEntityForDisplay();
$this->setForm( $entity );
} else {
-   $status = $this->saveEntity( $entity, $summary, 
$this->getRequest()->getVal( 'wpEditToken' ) );
+   $token = $this->getRequest()->getVal( 'wpEditToken' );
+   $status = $this->saveEntity( $updatedEntity, $summary, 
$token );
 
-   if ( !$status->isOK() && $status->getErrorsArray() ) {
+   if ( $status->isOK() ) {
+   $entityUrl = $this->getEntityTitle( 
$this->getEntityId() )->getFullURL();
+   $this->getOutput()->redirect( $entityUrl );
+   } else {
$errors = $status->getErrorsArray();
$this->showErrorHTML( $this->msg( 
$errors[0][0], array_slice( $errors[0], 1 ) )->parse() );
-   $this->setForm( $entity );
-   } else {
-   $entityUrl = $this->getEntityTitle( 
$entity->getId() )->getFullURL();
-   $this->getOutput()->redirect( $entityUrl );
+   $this->setForm( $updatedEntity );
}

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Simplify edit conflict detection in EditEntity.

2017-07-21 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/366879 )

Change subject: Simplify edit conflict detection in EditEntity.
..

Simplify edit conflict detection in EditEntity.

This change does two things:
* Always check for "late" conflicts: when a new revision was added while
  the edit was in progress, always fail.

* If no base revision is given, always use the latest revision as base
  revision. That removes the "no base revision" mode.

Change-Id: I514a4acfa4e6ead356a5a7f0480a172f2086e012
---
M repo/includes/Api/EntitySavingHelper.php
M repo/includes/EditEntity.php
M repo/includes/EditEntityFactory.php
M repo/includes/Specials/SpecialWikibaseRepoPage.php
M repo/includes/UpdateRepo/UpdateRepoJob.php
M repo/tests/phpunit/includes/EditEntityTest.php
6 files changed, 76 insertions(+), 69 deletions(-)


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

diff --git a/repo/includes/Api/EntitySavingHelper.php 
b/repo/includes/Api/EntitySavingHelper.php
index 845e2b5..831bfb3 100644
--- a/repo/includes/Api/EntitySavingHelper.php
+++ b/repo/includes/Api/EntitySavingHelper.php
@@ -333,7 +333,7 @@
}
 
if ( !$this->baseRevisionId ) {
-   $this->baseRevisionId = isset( $params['baserevid'] ) ? 
(int)$params['baserevid'] : null;
+   $this->baseRevisionId = isset( $params['baserevid'] ) ? 
(int)$params['baserevid'] : 0;
}
 
$editEntityHandler = $this->editEntityFactory->newEditEntity(
diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index b51c76e..3b9b66a 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -8,6 +8,7 @@
 use MWException;
 use ReadOnlyError;
 use RequestContext;
+use RuntimeException;
 use Status;
 use Title;
 use User;
@@ -173,12 +174,12 @@
 *May be null when creating a new entity.
 * @param User $user the user performing the edit
 * @param EditFilterHookRunner $editFilterHookRunner
-* @param int|bool $baseRevId the base revision ID for conflict 
checking.
-*Defaults to false, disabling conflict checks.
-*`true` can be used to set the base revision to the latest 
revision:
-*This will detect "late" edit conflicts, i.e. someone 
squeezing in an edit
-*just before the actual database transaction for saving beings.
-*The empty string and 0 are both treated as `false`, disabling 
conflict checks.
+* @param int $baseRevId the base revision ID for conflict checking.
+*Use 0 to indicate that the current revision should be used as 
the base revision,
+*effectively disabling conflict detections. true and false 
will be accepted for
+*backwards compatibility, but both will be treated like 0. 
Note that the behavior
+*of this class changed so that "late" conflicts that arise 
between edit conflict
+*detection and database update are always detected, and result 
in the update to fail.
 * @param IContextSource|null $context the context to use while 
processing
 *the edit; defaults to RequestContext::getMain().
 *
@@ -194,7 +195,7 @@
EntityId $entityId = null,
User $user,
EditFilterHookRunner $editFilterHookRunner,
-   $baseRevId = false,
+   $baseRevId = 0,
IContextSource $context = null
) {
$this->entityId = $entityId;
@@ -203,8 +204,8 @@
$baseRevId = (int)$baseRevId;
}
 
-   if ( $baseRevId === 0 ) {
-   $baseRevId = false;
+   if ( is_bool( $baseRevId ) ) {
+   $baseRevId = 0;
}
 
$this->user = $user;
@@ -313,13 +314,14 @@
}
 
/**
-* If no base revision was supplied to the constructor, this will 
return false.
-* In the trivial non-conflicting case, this will be the same as 
$this->getLatestRevisionId().
+* Return the ID of the base revision for the edit. If no base revision 
ID was supplied to
+* the constructor, this returns the ID of the latest revision. If the 
entity does not exist
+* yet, this returns 0.
 *
-* @return int|bool
+* @return int
 */
private function getBaseRevisionId() {
-   if ( $this->baseRevId === null || $this->baseRevId === true ) {
+   if ( $this->baseRevId === 0 ) {
$this->baseRevId = $this->getLatestRevisionId();
}
 
@@ -327,9 +329,9 @@
}
 
/**
-* Returns the edits base revision.
-* If no base revision was 

[MediaWiki-commits] [Gerrit] operations/mediawiki-config[master]: Add P279 to $wgPropertySuggesterClassifyingPropertyIds

2017-07-21 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/366866 )

Change subject: Add P279 to $wgPropertySuggesterClassifyingPropertyIds
..

Add P279 to $wgPropertySuggesterClassifyingPropertyIds

The data produced by the PropertySuggester analyzer script treats
P279 as a classifying property. This change makes the configuration
of the PropertySuggester extension consistent with the data.

This should be configured a bug fix, since it ensures that the data
is interpreted consistently.

DEPLOY: confirm that property suggestion works properly on items with
P279 (subclass-of) set.

Bug: T169060
Change-Id: I30630c75893149c7c784e80733429975aeeafe87
---
M wmf-config/Wikibase-production.php
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/mediawiki-config 
refs/changes/66/366866/1

diff --git a/wmf-config/Wikibase-production.php 
b/wmf-config/Wikibase-production.php
index 14c803c..44315c8 100644
--- a/wmf-config/Wikibase-production.php
+++ b/wmf-config/Wikibase-production.php
@@ -35,7 +35,7 @@
],
];
} else {
-   $wgPropertySuggesterClassifyingPropertyIds = [ 31 ]; // T169058
+   $wgPropertySuggesterClassifyingPropertyIds = [ 31, 279 ]; // 
T169060
 
$wgWBRepoSettings['sparqlEndpoint'] = 
'https://query.wikidata.org/sparql';
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I30630c75893149c7c784e80733429975aeeafe87
Gerrit-PatchSet: 1
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...PropertySuggester[master]: Add P279 to PropertySuggesterClassifyingPropertyIds per defa...

2017-07-21 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/366864 )

Change subject: Add P279 to PropertySuggesterClassifyingPropertyIds per default.
..

Add P279 to PropertySuggesterClassifyingPropertyIds per default.

The default of PropertySuggesterClassifyingPropertyIds should be
the same as the default of the classifying_properties setting in
analyzer.ini in PropertySuggester-Python.

Bug: T169057
Change-Id: Id2b1626a930e662fed334f9848bc6ceb6c912315
---
M extension.json
1 file changed, 2 insertions(+), 1 deletion(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PropertySuggester 
refs/changes/64/366864/1

diff --git a/extension.json b/extension.json
index 7f86413..ffc8e80 100644
--- a/extension.json
+++ b/extension.json
@@ -48,7 +48,8 @@
107
],
"PropertySuggesterClassifyingPropertyIds": [
-   31
+   31,
+   279
],
"PropertySuggesterInitialSuggestions": [
31,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id2b1626a930e662fed334f9848bc6ceb6c912315
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PropertySuggester
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Refactor SpecialModifyEntity to use EditPage.

2017-07-20 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/366606 )

Change subject: Refactor SpecialModifyEntity to use EditPage.
..

Refactor SpecialModifyEntity to use EditPage.

SpecialModifyEntity and friends can now make proper use of the
state managed inside the EditEntity interactor object.

Change-Id: I35a32c186db5c4a7ae2553124988b5ccca43e429
---
M repo/Wikibase.php
M repo/includes/EditEntity.php
M repo/includes/Specials/SpecialModifyEntity.php
M repo/includes/Specials/SpecialModifyTerm.php
M repo/includes/Specials/SpecialNewEntity.php
M repo/includes/Specials/SpecialSetAliases.php
M repo/includes/Specials/SpecialSetDescription.php
M repo/includes/Specials/SpecialSetLabel.php
M repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
M repo/includes/Specials/SpecialSetSiteLink.php
M repo/includes/Specials/SpecialWikibaseRepoPage.php
M repo/tests/phpunit/includes/Specials/SpecialSetAliasesTest.php
M repo/tests/phpunit/includes/Specials/SpecialSetDescriptionTest.php
M repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php
M repo/tests/phpunit/includes/Specials/SpecialSetLabelTest.php
15 files changed, 197 insertions(+), 93 deletions(-)


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

diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index 76a74c9..a7e1675 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -789,7 +789,6 @@
return new Wikibase\Repo\Specials\SpecialSetLabel(
$copyrightView,
$wikibaseRepo->getSummaryFormatter(),
-   $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
$wikibaseRepo->getEntityTitleLookup(),
$wikibaseRepo->newEditEntityFactory()
);
@@ -807,7 +806,6 @@
return new Wikibase\Repo\Specials\SpecialSetDescription(
$copyrightView,
$wikibaseRepo->getSummaryFormatter(),
-   $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
$wikibaseRepo->getEntityTitleLookup(),
$wikibaseRepo->newEditEntityFactory()
);
@@ -825,7 +823,6 @@
return new Wikibase\Repo\Specials\SpecialSetAliases(
$copyrightView,
$wikibaseRepo->getSummaryFormatter(),
-   $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
$wikibaseRepo->getEntityTitleLookup(),
$wikibaseRepo->newEditEntityFactory()
);
@@ -843,7 +840,6 @@
return new 
Wikibase\Repo\Specials\SpecialSetLabelDescriptionAliases(
$copyrightView,
$wikibaseRepo->getSummaryFormatter(),
-   $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
$wikibaseRepo->getEntityTitleLookup(),
$wikibaseRepo->newEditEntityFactory(),

$wikibaseRepo->getChangeOpFactoryProvider()->getFingerprintChangeOpFactory(),
@@ -871,7 +867,6 @@
return new Wikibase\Repo\Specials\SpecialSetSiteLink(
$copyrightView,
$wikibaseRepo->getSummaryFormatter(),
-   $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
$wikibaseRepo->getEntityTitleLookup(),
$wikibaseRepo->newEditEntityFactory(),
$siteLookup,
diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index b51c76e..e44aa10 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -344,7 +344,11 @@
$this->baseRev = $this->getLatestRevision();
} else {
$id = $this->getEntityId();
-   $this->baseRev = 
$this->entityRevisionLookup->getEntityRevision( $id, $baseRevId );
+   $this->baseRev = 
$this->entityRevisionLookup->getEntityRevision(
+   $id,
+   $baseRevId,
+   
EntityRevisionLookup::LATEST_FROM_SLAVE_WITH_FALLBACK
+   );
 
if ( $this->baseRev === null ) {
throw new MWException( 'Base revision 
ID not found: rev ' . $baseRevId
diff --git a/repo/includes/Specials/SpecialModifyEntity.php 
b/repo/includes/Specials/SpecialModifyEntity.php
index 34c455b..a28601c 100644
--- a/repo/includes/Specials/SpecialModifyEntity.php
+++ b/repo/includes/Specials/SpecialModifyEntity.php
@@ -4,15 +4,15 @@
 
 use HTMLForm;
 use Html;
+use 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Refactor EditEntity interactor

2017-07-20 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/366590 )

Change subject: Refactor EditEntity interactor
..

Refactor EditEntity interactor

This change allows the EditEntity interactor to be constructed without
the new EntityDocument. That way, EditEntity can be used to load and
track the base revision before modifying it to create the new
EntityDocument.

Change-Id: Idb3c17fd19494f0f29e9496cb1d52bdf3287cb69
Depends-On: I5aaeffca3df8b4209276a82605e132f02d0128f6
---
M repo/includes/Api/EntitySavingHelper.php
M repo/includes/EditEntity.php
M repo/includes/EditEntityFactory.php
M repo/includes/Specials/SpecialWikibaseRepoPage.php
M repo/includes/UpdateRepo/UpdateRepoJob.php
M repo/tests/phpunit/includes/EditEntityTest.php
6 files changed, 94 insertions(+), 80 deletions(-)


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

diff --git a/repo/includes/Api/EntitySavingHelper.php 
b/repo/includes/Api/EntitySavingHelper.php
index 51d488a..845e2b5 100644
--- a/repo/includes/Api/EntitySavingHelper.php
+++ b/repo/includes/Api/EntitySavingHelper.php
@@ -338,13 +338,14 @@
 
$editEntityHandler = $this->editEntityFactory->newEditEntity(
$user,
-   $entity,
+   $entity->getId(),
$this->baseRevisionId
);
 
$token = $this->evaluateTokenParam( $params );
 
$status = $editEntityHandler->attemptSave(
+   $entity,
$summary,
$this->entitySavingFlags | $flags,
$token
diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index 6fe10e3..b51c76e 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -64,11 +64,11 @@
private $entityPatcher;
 
/**
-* The modified entity we are trying to save
+* The ID of the entity to edit. May be null if a new entity is being 
created.
 *
-* @var EntityDocument|null
+* @var EntityId|null
 */
-   private $newEntity = null;
+   private $entityId = null;
 
/**
 * @var EntityRevision|null
@@ -169,7 +169,8 @@
 * @param EntityPermissionChecker $permissionChecker
 * @param EntityDiffer $entityDiffer
 * @param EntityPatcher $entityPatcher
-* @param EntityDocument $newEntity the new entity object
+* @param EntityId|null $entityId the ID of the entity being edited.
+*May be null when creating a new entity.
 * @param User $user the user performing the edit
 * @param EditFilterHookRunner $editFilterHookRunner
 * @param int|bool $baseRevId the base revision ID for conflict 
checking.
@@ -190,13 +191,13 @@
EntityPermissionChecker $permissionChecker,
EntityDiffer $entityDiffer,
EntityPatcher $entityPatcher,
-   EntityDocument $newEntity,
+   EntityId $entityId = null,
User $user,
EditFilterHookRunner $editFilterHookRunner,
$baseRevId = false,
IContextSource $context = null
) {
-   $this->newEntity = $newEntity;
+   $this->entityId = $entityId;
 
if ( is_string( $baseRevId ) ) {
$baseRevId = (int)$baseRevId;
@@ -229,13 +230,13 @@
}
 
/**
-* Returns the new entity object to be saved. May be different from the 
entity supplied
-* to the constructor in case the entity was patched to resolve edit 
conflicts.
+* Returns the ID of the entity being edited.
+* May be null if a new entity is to be created.
 *
-* @return EntityDocument
+* @return null|EntityId
 */
-   public function getNewEntity() {
-   return $this->newEntity;
+   public function getEntityId() {
+   return $this->entityId;
}
 
/**
@@ -245,7 +246,7 @@
 */
private function getTitle() {
if ( $this->title === null ) {
-   $id = $this->newEntity->getId();
+   $id = $this->getEntityId();
 
if ( $id !== null ) {
$this->title = 
$this->titleLookup->getTitleForId( $id );
@@ -262,7 +263,7 @@
 */
public function getLatestRevision() {
if ( $this->latestRev === null ) {
-   $id = $this->newEntity->getId();
+   $id = $this->getEntityId();
 
if ( $id !== null ) {
// NOTE: It's important to remember this, if 
someone calls clear() on
@@ -285,7 +286,7 @@
// Don't do 

[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Avoid use of EditEntity in test case

2017-07-20 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/366588 )

Change subject: Avoid use of EditEntity in test case
..

Avoid use of EditEntity in test case

Change-Id: I5aaeffca3df8b4209276a82605e132f02d0128f6
---
M tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php
1 file changed, 2 insertions(+), 3 deletions(-)


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

diff --git a/tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php 
b/tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php
index 2519c42..5e8fae8 100644
--- a/tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php
+++ b/tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php
@@ -198,10 +198,9 @@
$wikibaseRepo = WikibaseRepo::getDefaultInstance();
$existingItem = new Item( new ItemId( $itemId ) );
 
-   $editEntityFactory = $wikibaseRepo->newEditEntityFactory()
-   ->newEditEntity( new User(), $existingItem );
+   $store = $wikibaseRepo->getEntityStore();
 
-   $editEntityFactory->attemptSave( '', EDIT_NEW, false );
+   $store->saveEntity( $existingItem, '', new User(), EDIT_UPDATE, 
false );
}
 
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5aaeffca3df8b4209276a82605e132f02d0128f6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Remove overengineered page update code from ChangeHandler

2017-07-13 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/365031 )

Change subject: Remove overengineered page update code from ChangeHandler
..

Remove overengineered page update code from ChangeHandler

We initially anticipated that we could optimize page updates
based on the kind of change that was propagated from the repository.

We ended up always performign all updates for all changes anyway.
This made a whole lot of code redundant.

Change-Id: I19f29d7784fae19c544a6a69c220cc2ccb0edcdc
---
M client/includes/Changes/ChangeHandler.php
M client/tests/phpunit/includes/Changes/ChangeHandlerTest.php
2 files changed, 11 insertions(+), 179 deletions(-)


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

diff --git a/client/includes/Changes/ChangeHandler.php 
b/client/includes/Changes/ChangeHandler.php
index 7e2e40e..d30344a 100644
--- a/client/includes/Changes/ChangeHandler.php
+++ b/client/includes/Changes/ChangeHandler.php
@@ -8,6 +8,7 @@
 use MWException;
 use SiteLookup;
 use Title;
+use Traversable;
 use Wikibase\Change;
 use Wikibase\Client\Store\TitleFactory;
 use Wikibase\Client\Usage\EntityUsage;
@@ -24,27 +25,6 @@
  * @author Daniel Kinzler
  */
 class ChangeHandler {
-
-   /**
-* The change requites a LinksUpdate job to be scheduled to update any 
links
-* associated with the page.
-*/
-   const LINKS_UPDATE_ACTION = 'links';
-
-   /**
-* The change requites any HTML output generated from the page to be 
purged from web cached.
-*/
-   const WEB_PURGE_ACTION = 'web';
-
-   /**
-* The change requites an entry to be injected into the recentchanges 
table.
-*/
-   const RC_ENTRY_ACTION = 'rc';
-
-   /**
-* The change requites an entry to be injected into the revision table.
-*/
-   const HISTORY_ENTRY_ACTION = 'history';
 
/**
 * @var AffectedPagesFinder
@@ -152,117 +132,26 @@
wfDebugLog( __CLASS__, __FUNCTION__ . ': updating ' . count( 
$usagesPerPage )
. " page(s) for change #$changeId." );
 
-   // Pre-populate the bucket array, so the actions are processed 
in the correct order.
-   $actionBuckets = [
-   self::LINKS_UPDATE_ACTION => [],
-   self::WEB_PURGE_ACTION => [],
-   self::RC_ENTRY_ACTION => [],
-   self::HISTORY_ENTRY_ACTION => [],
-   ];
+   // Run all updates on all affected pages
+   $titlesToUpdate = $this->getTitlesForUsages( $usagesPerPage );
 
-   /** @var PageEntityUsages $usages */
-   foreach ( $usagesPerPage as $usages ) {
-   $actions = $this->getUpdateActions( 
$usages->getAspects() );
-   $this->updateActionBuckets( $actionBuckets, 
$usages->getPageId(), $actions );
-   }
-
-   foreach ( $actionBuckets as $action => $bucket ) {
-   $this->applyUpdateAction( $action, $bucket, $change );
-   }
+   $this->updater->purgeWebCache( $titlesToUpdate );
+   $this->updater->scheduleRefreshLinks( $titlesToUpdate );
+   $this->updater->injectRCRecords( $titlesToUpdate, $change );
+   // TODO: inject dummy revisions
}
 
/**
-* @param string[] $aspects List of usage aspects (without modifiers), 
as defined by the
-* EntityUsage::..._USAGE constants.
-*
-* @return string[] List of actions, as defined by the 
ChangeHandler::..._ACTION constants.
-*/
-   public function getUpdateActions( array $aspects ) {
-   $actions = [];
-   $aspects = array_flip( $aspects );
-
-   $all = isset( $aspects[EntityUsage::ALL_USAGE] );
-
-   if ( isset( $aspects[EntityUsage::SITELINK_USAGE] ) || $all ) {
-   // TODO: introduce an update action that updates just 
the metadata
-   // in the cached ParserOutput, without re-parsing the 
page!
-   $actions[self::LINKS_UPDATE_ACTION] = true;
-   }
-
-   if ( isset( $aspects[EntityUsage::LABEL_USAGE] ) || $all ) {
-   $actions[self::LINKS_UPDATE_ACTION] = true;
-   }
-
-   if ( isset( $aspects[EntityUsage::TITLE_USAGE] ) || $all ) {
-   $actions[self::LINKS_UPDATE_ACTION] = true;
-   }
-
-   if ( isset( $aspects[EntityUsage::OTHER_USAGE] ) || $all ) {
-   $actions[self::LINKS_UPDATE_ACTION] = true;
-   }
-
-   // Purge caches and inject log entries if we have reason
-   // to update the cached ParserOutput object in some way.
-

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Use RefreshLinksJob instead of Title:invalidateCache

2017-07-10 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364205 )

Change subject: Use RefreshLinksJob instead of Title:invalidateCache
..

Use RefreshLinksJob instead of Title:invalidateCache

Bug: T164173
Change-Id: I3a59486808b699ad0f9463e2af56d69fd37f8bf7
---
M client/includes/Changes/ChangeHandler.php
M client/includes/Changes/PageUpdater.php
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/ChangeHandlerTest.php
M client/tests/phpunit/includes/Changes/MockPageUpdater.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
6 files changed, 14 insertions(+), 86 deletions(-)


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

diff --git a/client/includes/Changes/ChangeHandler.php 
b/client/includes/Changes/ChangeHandler.php
index 884c30e..fb66ce8 100644
--- a/client/includes/Changes/ChangeHandler.php
+++ b/client/includes/Changes/ChangeHandler.php
@@ -26,11 +26,6 @@
 class ChangeHandler {
 
/**
-* The change requites any rendered version of the page to be purged 
from the parser cache.
-*/
-   const PARSER_PURGE_ACTION = 'parser';
-
-   /**
 * The change requites a LinksUpdate job to be scheduled to update any 
links
 * associated with the page.
 */
@@ -183,28 +178,26 @@
$all = isset( $aspects[EntityUsage::ALL_USAGE] );
 
if ( isset( $aspects[EntityUsage::SITELINK_USAGE] ) || $all ) {
-   $actions[self::LINKS_UPDATE_ACTION] = true;
-
// TODO: introduce an update action that updates just 
the metadata
// in the cached ParserOutput, without re-parsing the 
page!
-   $actions[self::PARSER_PURGE_ACTION] = true;
+   $actions[self::LINKS_UPDATE_ACTION] = true;
}
 
if ( isset( $aspects[EntityUsage::LABEL_USAGE] ) || $all ) {
-   $actions[self::PARSER_PURGE_ACTION] = true;
+   $actions[self::LINKS_UPDATE_ACTION] = true;
}
 
if ( isset( $aspects[EntityUsage::TITLE_USAGE] ) || $all ) {
-   $actions[self::PARSER_PURGE_ACTION] = true;
+   $actions[self::LINKS_UPDATE_ACTION] = true;
}
 
if ( isset( $aspects[EntityUsage::OTHER_USAGE] ) || $all ) {
-   $actions[self::PARSER_PURGE_ACTION] = true;
+   $actions[self::LINKS_UPDATE_ACTION] = true;
}
 
// Purge caches and inject log entries if we have reason
// to update the cached ParserOutput object in some way.
-   if ( isset( $actions[self::PARSER_PURGE_ACTION] ) || isset( 
$actions[self::LINKS_UPDATE_ACTION] ) ) {
+   if ( isset( $actions[self::LINKS_UPDATE_ACTION] ) ) {
$actions[self::WEB_PURGE_ACTION] = true;
$actions[self::RC_ENTRY_ACTION] = true;
$actions[self::HISTORY_ENTRY_ACTION] = true;
@@ -233,10 +226,6 @@
$titlesToUpdate = $this->getTitlesForPageIds( $pageIds );
 
switch ( $action ) {
-   case self::PARSER_PURGE_ACTION:
-   $this->updater->purgeParserCache( 
$titlesToUpdate );
-   break;
-
case self::WEB_PURGE_ACTION:
$this->updater->purgeWebCache( $titlesToUpdate 
);
break;
diff --git a/client/includes/Changes/PageUpdater.php 
b/client/includes/Changes/PageUpdater.php
index ec74351..391f122 100644
--- a/client/includes/Changes/PageUpdater.php
+++ b/client/includes/Changes/PageUpdater.php
@@ -17,13 +17,6 @@
 interface PageUpdater {
 
/**
-* Invalidates local cached of the given pages.
-*
-* @param Title[] $titles The Titles of the pages to update
-*/
-   public function purgeParserCache( array $titles );
-
-   /**
 * Invalidates external web cached of the given pages.
 *
 * @param Title[] $titles The Titles of the pages to update
diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index 7293723..69c6876 100644
--- a/client/includes/Changes/WikiPageUpdater.php
+++ b/client/includes/Changes/WikiPageUpdater.php
@@ -95,22 +95,6 @@
}
 
/**
-* Invalidates local cached of the given pages.
-*
-* @param Title[] $titles The Titles of the pages to update
-*/
-   public function purgeParserCache( array $titles ) {
-   /* @var Title $title */
-   foreach ( $titles as $title ) {
-   wfDebugLog( __CLASS__, __FUNCTION__ . ": 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Use multi-page RefreshLinksJobs in WikiPageUpdater

2017-07-10 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364198 )

Change subject: Use multi-page RefreshLinksJobs in WikiPageUpdater
..

Use multi-page RefreshLinksJobs in WikiPageUpdater

Bug: T164173
Change-Id: If704b86a42487c7849487ecb00073c7e44091ecb
---
M client/includes/Changes/WikiPageUpdater.php
M client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
2 files changed, 83 insertions(+), 42 deletions(-)


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

diff --git a/client/includes/Changes/WikiPageUpdater.php 
b/client/includes/Changes/WikiPageUpdater.php
index ff0ccce..7293723 100644
--- a/client/includes/Changes/WikiPageUpdater.php
+++ b/client/includes/Changes/WikiPageUpdater.php
@@ -130,22 +130,49 @@
 * @param Title[] $titles The Titles of the pages to update
 */
public function scheduleRefreshLinks( array $titles ) {
-   /* @var Title $title */
-   foreach ( $titles as $title ) {
-   wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
refresh links for "
-   . $title->getText() );
-
-   $job = new RefreshLinksJob(
-   $title,
-   Job::newRootJobParams(
-   $title->getPrefixedDBkey()
-   )
-   );
-
-   $this->jobQueueGroup->push( $job );
-   $this->jobQueueGroup->deduplicateRootJob( $job );
+   if ( empty( $titles ) ) {
+   return;
}
-   $this->incrementStats( 'RefreshLinksJob', count( $titles ) );
+
+   $jobs = [];
+   $titleBatches = array_chunk( $titles, $this->dbBatchSize );
+
+   /* @var Title[] $batch */
+   foreach ( $titleBatches as $batch ) {
+   wfDebugLog( __CLASS__, __FUNCTION__ . ": scheduling 
refresh links for "
+   . count( $batch ) . " titles" );
+
+   // NOTE: nominal title, will be ignored because the 
'pages' parameter is set.
+   $title = reset( $batch );
+
+   $jobs[] = new RefreshLinksJob(
+   $title,
+   [ 'pages' => 
$this->getPageParamForRefreshLinksJob( $batch ) ]
+   );
+   }
+
+   $this->jobQueueGroup->lazyPush( $jobs );
+   $this->incrementStats( 'RefreshLinks-jobs', count( $jobs ) );
+   $this->incrementStats( 'RefreshLinks-titles', count( $titles ) 
);
+   }
+
+   /**
+* @param Title[] $titles
+*
+* @returns array[] A Map of pageId => [ namespace, dbKey ]
+*/
+   private function getPageParamForRefreshLinksJob( array $titles ) {
+   $pages = [];
+
+   foreach ( $titles as $t ) {
+   $id = $t->getArticleID();
+   $pages[$id] = [
+   $t->getNamespace(),
+   $t->getDBkey()
+   ];
+   }
+
+   return $pages;
}
 
/**
diff --git a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php 
b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
index f73f61f..407cd98 100644
--- a/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
+++ b/client/tests/phpunit/includes/Changes/WikiPageUpdaterTest.php
@@ -69,14 +69,14 @@
 *
 * @return Title
 */
-   private function getTitleMock( $text ) {
+   private function getTitleMock( $text, $id = 23 ) {
$title = $this->getMockBuilder( Title::class )
->disableOriginalConstructor()
->getMock();
 
$title->expects( $this->any() )
->method( 'getArticleID' )
-   ->will( $this->returnValue( 23 ) );
+   ->will( $this->returnValue( $id ) );
 
$title->expects( $this->any() )
->method( 'exists' )
@@ -85,6 +85,22 @@
$title->expects( $this->any() )
->method( 'getPrefixedDBkey' )
->will( $this->returnValue( $text ) );
+
+   $title->expects( $this->any() )
+   ->method( 'getDBkey' )
+   ->will( $this->returnValue( $text ) );
+
+   $title->expects( $this->any() )
+   ->method( 'getText' )
+   ->will( $this->returnValue( $text ) );
+
+   $title->expects( $this->any() )
+   ->method( 'getNamespace' )
+   

[MediaWiki-commits] [Gerrit] operations/mediawiki-config[master]: Temporarily set $wgPropertySuggesterClassifyingPropertyIds t...

2017-06-28 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/361851 )

Change subject: Temporarily set $wgPropertySuggesterClassifyingPropertyIds to [ 
31 ].
..

Temporarily set $wgPropertySuggesterClassifyingPropertyIds to [ 31 ].

Bug: T169058
Change-Id: I5106bce9d577288a32477515ff7b3bbfe240bd16
---
M wmf-config/Wikibase-production.php
1 file changed, 2 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/mediawiki-config 
refs/changes/51/361851/1

diff --git a/wmf-config/Wikibase-production.php 
b/wmf-config/Wikibase-production.php
index 6fc320b..e697ae2 100644
--- a/wmf-config/Wikibase-production.php
+++ b/wmf-config/Wikibase-production.php
@@ -25,6 +25,8 @@
'P185',
];
} else {
+   $wgPropertySuggesterClassifyingPropertyIds = [ 31 ]; // T169058
+
$wgWBRepoSettings['sparqlEndpoint'] = 
'https://query.wikidata.org/sparql';
 
$wgWBRepoSettings['formatterUrlProperty'] = 'P1630';

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5106bce9d577288a32477515ff7b3bbfe240bd16
Gerrit-PatchSet: 1
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] purtle[master]: Remove MediaWiki framework integration

2017-06-20 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/360365 )

Change subject: Remove MediaWiki framework integration
..

Remove MediaWiki framework integration

Bug: T168359
Change-Id: I362e55c67d663634e620ca843e7786ebfa649e6e
---
D Purtle.php
M composer.json
D init.mw.php
3 files changed, 0 insertions(+), 48 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/purtle refs/changes/65/360365/1

diff --git a/Purtle.php b/Purtle.php
deleted file mode 100644
index 8733494..000
--- a/Purtle.php
+++ /dev/null
@@ -1,19 +0,0 @@
- __FILE__,
-   'name' => 'Purtle',
-   'version' => PURTLE_VERSION,
-   'author' => array(
-   'Daniel Kinzler',
-   'Stas Malyshev',
-   'Thiemo Mättig'
-   ),
-   'url' => 'https://mediawiki.org/wiki/Purtle',
-   'description' => 'Fast streaming RDF serializer',
-   'license-name' => 'GPL-2.0+'
-);
-
-
-$GLOBALS['wgHooks']['UnitTestsList'][] = function( array &$paths ) {
-   $paths[] = __DIR__ . '/tests/phpunit';
-};

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I362e55c67d663634e620ca843e7786ebfa649e6e
Gerrit-PatchSet: 1
Gerrit-Project: purtle
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Deprecate Content::getNativeData, add TextContent::getText

2017-06-15 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/359184 )

Change subject: Deprecate Content::getNativeData, add TextContent::getText
..

Deprecate Content::getNativeData, add TextContent::getText

getNativeData() is under-specified - callers can do nothing with the
value returned by getNativeData without knowing the concrete Content
class. If the know the concrete class, the should use a specialized
getter.

Basically, getNativeData is overly generic, an example of plymorphism
done wrong. My bad. Sorry about that. Can we fix it now?

Bug: T155582
Change-Id: I6cf13e6cfe57124ff5af71761d3988bc3c82795d
---
M RELEASE-NOTES-1.30
M includes/api/ApiParse.php
M includes/api/ApiQueryRevisionsBase.php
M includes/content/AbstractContent.php
M includes/content/Content.php
M includes/content/ContentHandler.php
M includes/content/CssContent.php
M includes/content/JavaScriptContent.php
M includes/content/JsonContent.php
M includes/content/MessageContent.php
M includes/content/TextContent.php
M includes/content/TextContentHandler.php
M includes/content/WikitextContent.php
M includes/specials/SpecialUndelete.php
M languages/LanguageConverter.php
M maintenance/compareParsers.php
M maintenance/preprocessDump.php
M tests/phpunit/includes/RevisionStorageTest.php
M tests/phpunit/includes/api/ApiEditPageTest.php
M tests/phpunit/includes/content/ContentHandlerTest.php
M tests/phpunit/includes/content/JavaScriptContentTest.php
M tests/phpunit/includes/content/TextContentTest.php
M tests/phpunit/includes/content/WikitextContentHandlerTest.php
M tests/phpunit/includes/content/WikitextContentTest.php
M tests/phpunit/includes/import/ImportTest.php
M tests/phpunit/includes/page/WikiPageTest.php
M tests/phpunit/mocks/content/DummyContentForTesting.php
M tests/phpunit/mocks/content/DummyNonTextContent.php
28 files changed, 152 insertions(+), 91 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/84/359184/1

diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30
index cd800da..7f63bc7 100644
--- a/RELEASE-NOTES-1.30
+++ b/RELEASE-NOTES-1.30
@@ -88,6 +88,7 @@
   deprecated. There are no known callers.
 * File::getStreamHeaders() was deprecated.
 * MediaHandler::getStreamHeaders() was deprecated.
+* Content::getNativeData() was deprecated.
 * The ExtractThumbParameters hook (deprecated in 1.21) was removed.
 * The OutputPage::addParserOutputNoText and ::getHeadLinks methods (both
   deprecated in 1.24) were removed.
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index 91e49ab..3f1a79c 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -477,12 +477,12 @@
}
 
if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) {
-   if ( $this->content->getModel() != 
CONTENT_MODEL_WIKITEXT ) {
+   if ( !$this->content instanceof WikitextContent ) {
$this->dieWithError( 
'apierror-parsetree-notwikitext', 'notwikitext' );
}
 
$wgParser->startExternalParse( $titleObj, $popts, 
Parser::OT_PREPROCESS );
-   $dom = $wgParser->preprocessToDom( 
$this->content->getNativeData() );
+   $dom = $wgParser->preprocessToDom( 
$this->content->getText() );
if ( is_callable( [ $dom, 'saveXML' ] ) ) {
$xml = $dom->saveXML();
} else {
diff --git a/includes/api/ApiQueryRevisionsBase.php 
b/includes/api/ApiQueryRevisionsBase.php
index 696ec87..440df36 100644
--- a/includes/api/ApiQueryRevisionsBase.php
+++ b/includes/api/ApiQueryRevisionsBase.php
@@ -278,8 +278,8 @@
}
if ( $this->fld_parsetree || ( $this->fld_content && 
$this->generateXML ) ) {
if ( $content ) {
-   if ( $content->getModel() === 
CONTENT_MODEL_WIKITEXT ) {
-   $t = $content->getNativeData(); # note: 
don't set $text
+   if ( $content instanceof WikitextContent ) {
+   $t = $content->getText(); # note: don't 
set $text
 
$wgParser->startExternalParse(
$title,
@@ -312,8 +312,8 @@
 
if ( $this->expandTemplates && !$this->parseContent ) {
# XXX: implement template expansion for all 
content types in ContentHandler?
-   if ( $content->getModel() === 
CONTENT_MODEL_WIKITEXT ) {
-   $text = $content->getNativeData();
+   if ( $content instanceof WikitextContent ) {
+   $text = $content->getText();
 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Fix call to makeContent in SpecialChangeContentModel

2017-06-15 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/359156 )

Change subject: Fix call to makeContent in SpecialChangeContentModel
..

Fix call to makeContent in SpecialChangeContentModel

ContentHandler::makeContent expects serialized content as the first
parameter, not native data.

Change-Id: Ibf1825a191d10b4dd8b9a5cee95b02b2b91f3d92
---
M includes/specials/SpecialChangeContentModel.php
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/56/359156/1

diff --git a/includes/specials/SpecialChangeContentModel.php 
b/includes/specials/SpecialChangeContentModel.php
index a36b414..8eaae4c 100644
--- a/includes/specials/SpecialChangeContentModel.php
+++ b/includes/specials/SpecialChangeContentModel.php
@@ -198,7 +198,7 @@
$oldContent = $this->oldRevision->getContent();
try {
$newContent = ContentHandler::makeContent(
-   $oldContent->getNativeData(), 
$this->title, $data['model']
+   $oldContent->serialize(), $this->title, 
$data['model']
);
} catch ( MWException $e ) {
return Status::newFatal(

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibf1825a191d10b4dd8b9a5cee95b02b2b91f3d92
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Add redirect=force option to Special:EntitData

2017-06-14 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/359004 )

Change subject: Add redirect=force option to Special:EntitData
..

Add redirect=force option to Special:EntitData

This allows us to use an internal path rewrite for resolving data URIs
while guaranteeing that no data will be served from the canonical URI.

Bug: T119536
Change-Id: I13373c8859be885237cd9c50b864c437c0d7676e
---
M repo/includes/LinkedData/EntityDataRequestHandler.php
M repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php
2 files changed, 54 insertions(+), 0 deletions(-)


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

diff --git a/repo/includes/LinkedData/EntityDataRequestHandler.php 
b/repo/includes/LinkedData/EntityDataRequestHandler.php
index aaba4a8..a29d5b0 100644
--- a/repo/includes/LinkedData/EntityDataRequestHandler.php
+++ b/repo/includes/LinkedData/EntityDataRequestHandler.php
@@ -188,6 +188,7 @@
$id = $request->getText( 'id', $id );
$revision = $request->getInt( 'oldid', $revision );
$revision = $request->getInt( 'revision', $revision );
+   $redirectMode = $request->getText( 'redirect' );
//TODO: malformed revision IDs should trigger a code 400
 
// If there is no ID, fail
@@ -235,6 +236,13 @@
return;
}
 
+   // if redirection was force, redirect
+   if ( $redirectMode === 'force' ) {
+   $url = $this->uriManager->getDocUrl( $entityId, 
$format, $revision );
+   $output->redirect( $url, 303 );
+   return;
+   }
+
$this->showData( $request, $output, $format, $entityId, 
$revision );
}
 
diff --git a/repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php 
b/repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php
index b331086..3e8af5d 100644
--- a/repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php
+++ b/repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php
@@ -459,6 +459,52 @@
200,   // http code
);
 
+   // redirect=force
+
+   // #41: format=application/json with forced redirect
+   $cases[] = array(
+   '',  // subpage
+   array( // parameters
+   'id' => 'Q42',
+   'format' => 'application/json',
+   'redirect' => 'force',
+   ),
+   array(), // headers
+   '!!', // output regex
+   303,  // http code
+   array( // headers
+   'Location' => '!/Q42\.json$!'
+   )
+   );
+
+   // #42: /Q42.json with forced redirect
+   $cases[] = array(
+   'Q42.json',  // subpage
+   array( // parameters
+   'redirect' => 'force',
+   ),
+   array(), // headers
+   '!!', // output regex
+   303,  // http code
+   array( // headers
+   'Location' => '!/Q42\.json!'
+   )
+   );
+
+   // #43: /q5.json with forced redirect triggers a 301, not a 303
+   $cases[] = array(
+   'q42.JSON',  // subpage
+   array( // parameters
+   'redirect' => 'force',
+   ),
+   array(), // headers
+   '!!', // output regex
+   301,  // http code
+   array( // headers
+   'Location' => '!/Q42\.json$!'
+   )
+   );
+
return $cases;
}
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I13373c8859be885237cd9c50b864c437c0d7676e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: makeEmptyContent must return empty content.

2017-06-14 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358915 )

Change subject: makeEmptyContent must return empty content.
..

makeEmptyContent must return empty content.

This adds a sanity test that asserts that the Content object returned by
ContentHandler::makeEmptyContent will return true from the isEmpty and isValid
methods.

Change-Id: Id3ed9fa1d684d737fe12e73ef20b6e336c7411a5
---
M includes/content/JsonContent.php
M tests/phpunit/includes/content/JsonContentTest.php
M tests/phpunit/structure/ContentHandlerSanityTest.php
3 files changed, 24 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/15/358915/1

diff --git a/includes/content/JsonContent.php b/includes/content/JsonContent.php
index 14c8182..4033369 100644
--- a/includes/content/JsonContent.php
+++ b/includes/content/JsonContent.php
@@ -61,6 +61,17 @@
}
 
/**
+* @return bool Whether content is an empty JSON object or array
+*/
+   public function isEmpty() {
+   // NOTE: casting to array turns an empty stdClass instance into 
an empty array,
+   // but will turn an empty string, 0, or false into a non-empty 
array.
+   // This exactly matches the intended semantics of isEmpty for 
JSON.
+   $data = (array)$this->getData()->getValue();
+   return empty( $data );
+   }
+
+   /**
 * Pretty-print JSON.
 *
 * If called before validation, it may return JSON "null".
diff --git a/tests/phpunit/includes/content/JsonContentTest.php 
b/tests/phpunit/includes/content/JsonContentTest.php
index de8e371..1349a00 100644
--- a/tests/phpunit/includes/content/JsonContentTest.php
+++ b/tests/phpunit/includes/content/JsonContentTest.php
@@ -8,23 +8,24 @@
 
public static function provideValidConstruction() {
return [
-   [ 'foo', false, null ],
-   [ '[]', true, [] ],
-   [ '{}', true, (object)[] ],
-   [ '""', true, '' ],
-   [ '"0"', true, '0' ],
-   [ '"bar"', true, 'bar' ],
-   [ '0', true, '0' ],
-   [ '{ "0": "bar" }', true, (object)[ 'bar' ] ],
+   [ 'foo', false, true, null ],
+   [ '[]', true, true, [] ],
+   [ '{}', true, true, (object)[] ],
+   [ '""', true, false, '' ],
+   [ '"0"', true, false, '0' ],
+   [ '"bar"', true, false, 'bar' ],
+   [ '0', true, false, '0' ],
+   [ '{ "0": "bar" }', true, false, (object)[ 'bar' ] ],
];
}
 
/**
 * @dataProvider provideValidConstruction
 */
-   public function testIsValid( $text, $isValid, $expected ) {
+   public function testIsValid( $text, $isValid, $isEmpty, $expected ) {
$obj = new JsonContent( $text, CONTENT_MODEL_JSON );
-   $this->assertEquals( $isValid, $obj->isValid() );
+   $this->assertEquals( $isValid, $obj->isValid(), 'isValid()' );
+   $this->assertEquals( $isEmpty, $obj->isEmpty(), 'isEmpty()' );
$this->assertEquals( $expected, $obj->getData()->getValue() );
}
 
diff --git a/tests/phpunit/structure/ContentHandlerSanityTest.php 
b/tests/phpunit/structure/ContentHandlerSanityTest.php
index 88257f9..d3dcf92 100644
--- a/tests/phpunit/structure/ContentHandlerSanityTest.php
+++ b/tests/phpunit/structure/ContentHandlerSanityTest.php
@@ -54,6 +54,8 @@
);
} else {
$this->assertInstanceOf( Content::class, $content );
+   $this->assertTrue( $content->isValid(), 'isValid()' );
+   $this->assertTrue( $content->isEmpty(), 'isEmpty()' );
}
}
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id3ed9fa1d684d737fe12e73ef20b6e336c7411a5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add Title::isValid method.

2017-06-12 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358423 )

Change subject: Add Title::isValid method.
..

Add Title::isValid method.

Make the notion of Title objects representing invalid titles explicit.

Bug: T165149
Change-Id: I89aaabdff9614fe63bd1244784a1d677dbc26f9e
---
M includes/Title.php
M tests/phpunit/includes/TitleTest.php
2 files changed, 78 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/23/358423/1

diff --git a/includes/Title.php b/includes/Title.php
index d34da7d..6e9c32c 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -253,6 +253,9 @@
 * Create a new Title from text, such as what one would find in a link. 
De-
 * codes any HTML entities in the text.
 *
+* Title objects returned by this method are guaranteed to be valid, and
+* thus return true from the isValid() method.
+*
 * @param string|int|null $text The link text; spaces, prefixes, and an
 *   initial ':' indicating the main namespace are accepted.
 * @param int $defaultNamespace The namespace to use if none is 
specified
@@ -283,6 +286,9 @@
 * rather than returning null.
 *
 * The exception subclasses encode detailed information about why the 
title is invalid.
+*
+* Title objects returned by this method are guaranteed to be valid, and
+* thus return true from the isValid() method.
 *
 * @see Title::newFromText
 *
@@ -500,10 +506,19 @@
 
/**
 * Create a new Title from a namespace index and a DB key.
-* It's assumed that $ns and $title are *valid*, for instance when
-* they came directly from the database or a special page name.
-* For convenience, spaces are converted to underscores so that
-* eg user_text fields can be used directly.
+*
+* It's assumed that $ns and $title are safe, for instance when
+* they came directly from the database or a special page name,
+* not from user input.
+*
+* To validation is applied. For convenience, spaces are normalized
+* to underscores, so that e.g. user_text fields can be used directly.
+*
+* @note This method may return Title objects that are "invalid"
+* according to the isValid() method. This is usually caused by
+* configuration changes: e.g. a namespace that was once defined is
+* no longer configured, or a character that was once allowed in
+* titles is now forbidden.
 *
 * @param int $ns The namespace of the article
 * @param string $title The unprefixed database key form
@@ -529,6 +544,10 @@
 * The parameters will be checked for validity, which is a bit slower
 * than makeTitle() but safer for user-provided data.
 *
+* Title objects returned by makeTitleSafe() are guaranteed to be valid,
+* that is, they return true from the isValid() method. If no valid 
Title
+* can be constructed from the input, this method returns null.
+*
 * @param int $ns The namespace of the article
 * @param string $title Database key form
 * @param string $fragment The link fragment (after the "#")
@@ -536,6 +555,9 @@
 * @return Title|null The new object, or null on an error
 */
public static function makeTitleSafe( $ns, $title, $fragment = '', 
$interwiki = '' ) {
+   // NOTE: ideally, this would just call makeTitle() and then 
isValid(),
+   // but presently, that means more overhead on a potential 
performance hotspot.
+
if ( !MWNamespace::exists( $ns ) ) {
return null;
}
@@ -776,6 +798,36 @@
}
 
/**
+* Returns true if the title is valid, false if it is invalid.
+*
+* Valid titles can be round-tripped via makeTitleSafe() and 
newFromText().
+* Invalid titles may get returned from makeTitle(), and it may be 
useful to
+* allow them to exist, e.g. in order to process log entries about 
pages in
+* namespaces that belong to extensions that are no longer installed.
+*
+* @note that this method is relatively expensive. When constructing 
Title
+* objects that need to be valid, use an instantiator method that is 
guaranteed
+* to return valid titles, such as makeTitleSafe() or newFromText().
+*
+* @return bool
+*/
+   public function isValid() {
+   $ns = $this->getNamespace();
+
+   if ( !MWNamespace::exists( $ns ) ) {
+   return false;
+   }
+
+   try {
+   $parser = 
MediaWikiServices::getInstance()->getTitleParser();
+  

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Rename canTalk methods

2017-06-10 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358163 )

Change subject: Rename canTalk methods
..

Rename canTalk methods

This renames Title::canTalk to Title::canHaveTalkPage
and MWNamespace::canTalk to MWNamespace::hasTalkNamespace.

Bug: T165149
Change-Id: I342a273a497b31282388b13bf76dadfb1122dcbb
---
M RELEASE-NOTES-1.30
M includes/MWNamespace.php
M includes/Title.php
M tests/phpunit/includes/MWNamespaceTest.php
M tests/phpunit/includes/TitleTest.php
5 files changed, 111 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/63/358163/1

diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30
index 27acb8a..c2cd8a2 100644
--- a/RELEASE-NOTES-1.30
+++ b/RELEASE-NOTES-1.30
@@ -66,6 +66,8 @@
   deprecated. There are no known callers.
 * File::getStreamHeaders() was deprecated.
 * MediaHandler::getStreamHeaders() was deprecated.
+* Title::canTalk was deprecated in favor of Title::canHaveTalkPage
+* MWNamespace::canTalk was deprecated in favor of MWNamespace::hasTalkNamespace
 
 == Compatibility ==
 MediaWiki 1.30 requires PHP 5.5.9 or later. There is experimental support for
diff --git a/includes/MWNamespace.php b/includes/MWNamespace.php
index 4c5561f..a84cdb8 100644
--- a/includes/MWNamespace.php
+++ b/includes/MWNamespace.php
@@ -278,12 +278,28 @@
}
 
/**
-* Can this namespace ever have a talk namespace?
+* Does this namespace ever have a talk namespace?
+* Note that this also returns true if $index itself is a talk 
namespace.
+*
+* @deprecated since 1.30, use hasTalkNamespace() instead.
 *
 * @param int $index Namespace index
 * @return bool
 */
public static function canTalk( $index ) {
+   return self::hasTalkNamespace( $index );
+   }
+
+   /**
+* Does this namespace ever have a talk namespace?
+* Note that this also returns true if $index itself is a talk 
namespace.
+*
+* @since 1.30
+*
+* @param int $index Namespace ID
+* @return bool
+*/
+   public static function hasTalkNamespace( $index ) {
return $index >= NS_MAIN;
}
 
diff --git a/includes/Title.php b/includes/Title.php
index a8cfad8..f92a757 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -1020,12 +1020,27 @@
}
 
/**
-* Could this title have a corresponding talk page?
+* Can this title have a corresponding talk page?
+* Note that this methods also returns true if this Title itself is in 
a talk namespace.
+*
+* @deprecated since 1.30, use canHaveTalkPage() instead.
 *
 * @return bool
 */
public function canTalk() {
-   return MWNamespace::canTalk( $this->mNamespace );
+   return $this->canHaveTalkPage();
+   }
+
+   /**
+* Can this title have a corresponding talk page?
+* Note that this methods also returns true if this Title itself is in 
a talk namespace.
+*
+* @see MWNamespace::hasTalkNamespace
+*
+* @return bool
+*/
+   public function canHaveTalkPage() {
+   return MWNamespace::hasTalkNamespace( $this->mNamespace );
}
 
/**
diff --git a/tests/phpunit/includes/MWNamespaceTest.php 
b/tests/phpunit/includes/MWNamespaceTest.php
index 5977652..2685a3f 100644
--- a/tests/phpunit/includes/MWNamespaceTest.php
+++ b/tests/phpunit/includes/MWNamespaceTest.php
@@ -262,21 +262,43 @@
}
*/
 
+   public function provideHasTalkNamespace() {
+   return [
+   [ NS_MEDIA, false ],
+   [ NS_SPECIAL, false ],
+
+   [ NS_MAIN, true ],
+   [ NS_TALK, true ],
+   [ NS_USER, true ],
+   [ NS_USER_TALK, true ],
+
+   [ 100, true ],
+   [ 101, true ],
+   ];
+   }
+
/**
-* @covers MWNamespace::canTalk
+* @dataProvider provideHasTalkNamespace
+* @covers MWNamespace::hasTalkNamespace
+*
+* @param int $index
+* @param bool $expected
 */
-   public function testCanTalk() {
-   $this->assertCanNotTalk( NS_MEDIA );
-   $this->assertCanNotTalk( NS_SPECIAL );
+   public function testHasTalkNamespace( $index, $expected ) {
+   $actual = MWNamespace::hasTalkNamespace( $index );
+   $this->assertEquals( $actual, $expected, "NS $index" );
+   }
 
-   $this->assertCanTalk( NS_MAIN );
-   $this->assertCanTalk( NS_TALK );
-   $this->assertCanTalk( NS_USER );
-   $this->assertCanTalk( NS_USER_TALK );
-
-   // User 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make Titles with an unknown namespace ID refer to Special:Ba...

2017-06-09 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358047 )

Change subject: Make Titles with an unknown namespace ID refer to 
Special:Badtitle.
..

Make Titles with an unknown namespace ID refer to Special:Badtitle.

Without this patch, Title::getPrefixedText() would return ":Foo"
if the namespace was unknown, potentially creating a misleading
link to the main namespace. With this change, getPrefixedText()
will return something like "Special:Badtitle/NS12345:Foo".

Note that round trip behavior is broken either way.

Bug: T165149
Change-Id: I0d491a2b58ff45f207f83ee62ca6e7e6ffbf790a
---
M includes/Title.php
M tests/phpunit/includes/TitleTest.php
2 files changed, 67 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/47/358047/1

diff --git a/includes/Title.php b/includes/Title.php
index a8cfad8..d34da7d 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -1425,7 +1425,15 @@
}
 
if ( 0 != $this->mNamespace ) {
-   $p .= $this->getNsText() . ':';
+   $nsText = $this->getNsText();
+
+   if ( $nsText === false ) {
+   // See T165149. Awkward, but better than 
erroneously linking to the main namespace.
+   $dummy = Title::makeTitle( NS_SPECIAL, 
'Badtitle/NS' . $this->mNamespace );
+   $nsText = $dummy->getPrefixedDBkey();
+   }
+
+   $p .= $nsText . ':';
}
return $p . $name;
}
diff --git a/tests/phpunit/includes/TitleTest.php 
b/tests/phpunit/includes/TitleTest.php
index 238b65f..6c44999 100644
--- a/tests/phpunit/includes/TitleTest.php
+++ b/tests/phpunit/includes/TitleTest.php
@@ -716,28 +716,33 @@
return [
// ns = 0
[
-   Title::makeTitle( NS_MAIN, 'Foobar' ),
-   'Foobar'
+   Title::makeTitle( NS_MAIN, 'Foo bar' ),
+   'Foo bar'
],
// ns = 2
[
-   Title::makeTitle( NS_USER, 'Foobar' ),
-   'User:Foobar'
+   Title::makeTitle( NS_USER, 'Foo bar' ),
+   'User:Foo bar'
+   ],
+   // ns = 3
+   [
+   Title::makeTitle( NS_USER_TALK, 'Foo bar' ),
+   'User talk:Foo bar'
],
// fragment not included
[
-   Title::makeTitle( NS_MAIN, 'Foobar', 'fragment' 
),
-   'Foobar'
+   Title::makeTitle( NS_MAIN, 'Foo bar', 
'fragment' ),
+   'Foo bar'
],
// ns = -2
[
-   Title::makeTitle( NS_MEDIA, 'Foobar' ),
-   'Media:Foobar'
+   Title::makeTitle( NS_MEDIA, 'Foo bar' ),
+   'Media:Foo bar'
],
// non-existent namespace
[
-   Title::makeTitle( 10, 'Foobar' ),
-   ':Foobar'
+   Title::makeTitle( 100777, 'Foo bar' ),
+   'Special:Badtitle/NS100777:Foo bar'
],
];
}
@@ -749,4 +754,47 @@
public function testGetPrefixedText( Title $title, $expected ) {
$this->assertEquals( $expected, $title->getPrefixedText() );
}
+
+   public function provideGetPrefixedDBKey() {
+   return [
+   // ns = 0
+   [
+   Title::makeTitle( NS_MAIN, 'Foo_bar' ),
+   'Foo_bar'
+   ],
+   // ns = 2
+   [
+   Title::makeTitle( NS_USER, 'Foo_bar' ),
+   'User:Foo_bar'
+   ],
+   // ns = 3
+   [
+   Title::makeTitle( NS_USER_TALK, 'Foo_bar' ),
+   'User_talk:Foo_bar'
+   ],
+   // fragment not included
+   [
+   Title::makeTitle( NS_MAIN, 'Foo_bar', 
'fragment' ),
+   'Foo_bar'
+   ],

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Check that function hook is callable whe4n registering.

2017-06-07 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/357584 )

Change subject: Check that function hook is callable whe4n registering.
..

Check that function hook is callable whe4n registering.

This is to dafeguard against issues like T167238.

In general, type checks should be applied when things get
registered for later use. Fail early, stay sane.

Change-Id: Ifb7005ee214829c98cec534261c0db7d13f50f35
---
M includes/parser/Parser.php
1 file changed, 3 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/84/357584/1

diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 34f6232..bba8702 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -22,6 +22,7 @@
  */
 use MediaWiki\Linker\LinkRenderer;
 use MediaWiki\MediaWikiServices;
+use Wikimedia\Assert\Assert;
 use Wikimedia\ScopedCallback;
 
 /**
@@ -4858,6 +4859,8 @@
public function setFunctionHook( $id, $callback, $flags = 0 ) {
global $wgContLang;
 
+   Assert::parameterType( 'callable', $callback, '$callback' );
+
$oldVal = isset( $this->mFunctionHooks[$id] ) ? 
$this->mFunctionHooks[$id][0] : null;
$this->mFunctionHooks[$id] = [ $callback, $flags ];
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb7005ee214829c98cec534261c0db7d13f50f35
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler 

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Allow makeEmptyContent to return null for some kinds of cont...

2017-05-30 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/356228 )

Change subject: Allow makeEmptyContent to return null for some kinds of content.
..

Allow makeEmptyContent to return null for some kinds of content.

ContentHandler::makeEmptyContent() is needed to initialize empty pages
for direct editing. Content models that do not support direct editing
may also not support empty content at all (e.g. Wikibase Property pages).

This patch allows makeEmptyContent to return null for such kinds of content.

Change-Id: I028a80db8a54234ab82fd1434c0e1429d50904de
BREAKING: ContentHandler::makeEmptyContent may return null.
---
M RELEASE-NOTES-1.30
M includes/FeedUtils.php
M includes/content/ContentHandler.php
M includes/jobqueue/jobs/RefreshLinksJob.php
M includes/specials/SpecialChangeContentModel.php
M maintenance/cleanupSpam.php
M tests/phpunit/structure/ContentHandlerSanityTest.php
7 files changed, 55 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/28/356228/1

diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30
index e61277a..f7fffe2 100644
--- a/RELEASE-NOTES-1.30
+++ b/RELEASE-NOTES-1.30
@@ -87,6 +87,8 @@
   As a result of the new uniform handling, '-{' may need to be escaped
   (for example, as '-{') where it occurs inside template arguments
   or wikilinks.
+* ContentHandler::makeEmptyContent() may now return null for content models
+  that do not support direct editing.
 
 == Compatibility ==
 MediaWiki 1.30 requires PHP 5.5.9 or later. There is experimental support for
diff --git a/includes/FeedUtils.php b/includes/FeedUtils.php
index 3268291..020be1f 100644
--- a/includes/FeedUtils.php
+++ b/includes/FeedUtils.php
@@ -165,6 +165,7 @@
} else {
$rev = Revision::newFromId( $newid );
if ( $wgFeedDiffCutoff <= 0 || is_null( $rev ) ) {
+   // NOTE: makeEmptyContent() can return null for 
some kinds of content
$newContent = ContentHandler::getForTitle( 
$title )->makeEmptyContent();
} else {
$newContent = $rev->getContent();
diff --git a/includes/content/ContentHandler.php 
b/includes/content/ContentHandler.php
index bccb147..ddd1075 100644
--- a/includes/content/ContentHandler.php
+++ b/includes/content/ContentHandler.php
@@ -464,9 +464,14 @@
 * Creates an empty Content object of the type supported by this
 * ContentHandler.
 *
-* @since 1.21
+* @note This method is guaranteed to return a Content object if 
supportsDirectEditing()
+* or supportsDirectApiEditing() returns true. If both of these methods 
return false
+* (meaning no direct editing is supported), implementations of this 
method MAY return
+* null.
 *
-* @return Content
+* @since 1.21 (may return null since 1.30)
+*
+* @return Content|null
 */
abstract public function makeEmptyContent();
 
@@ -1074,7 +1079,10 @@
}
 
/**
-* Return true if this content model supports direct editing, such as 
via EditPage.
+* Return true if this content model supports direct editing via 
EditPage.
+*
+* @note ContentHandlers that return true from this method MUST return 
a Content
+* object from makeEmptyContent().
 *
 * @return bool Default is false, and true for TextContent and it's 
derivatives.
 */
@@ -1085,6 +1093,9 @@
/**
 * Whether or not this content model supports direct editing via 
ApiEditPage
 *
+* @note ContentHandlers that return true from this method MUST return 
a Content
+* object from makeEmptyContent().
+*
 * @return bool Default is false, and true for TextContent and 
derivatives.
 */
public function supportsDirectApiEditing() {
diff --git a/includes/jobqueue/jobs/RefreshLinksJob.php 
b/includes/jobqueue/jobs/RefreshLinksJob.php
index 02bb829..b5a9227 100644
--- a/includes/jobqueue/jobs/RefreshLinksJob.php
+++ b/includes/jobqueue/jobs/RefreshLinksJob.php
@@ -175,7 +175,8 @@
 
$content = $revision->getContent( Revision::RAW );
if ( !$content ) {
-   // If there is no content, pretend the content is empty
+   // If there is no content, pretend the content is empty.
+   // NOTE: makeEmptyContent() can return null for some 
kinds of content.
$content = 
$revision->getContentHandler()->makeEmptyContent();
}
 
@@ -223,7 +224,7 @@
} else {
$start = microtime( true );
// Revision ID must be passed to the parser output to 
get revision variables correct
- 

  1   2   3   4   5   6   7   8   9   10   >