Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/322647
Change subject: Documentation, deprecation and code style fixes
......................................................................
Documentation, deprecation and code style fixes
Change-Id: Idd3875347bc252e9bbff912c2a10d05c20a0c08d
---
M includes/Api.php
M includes/ApiHooks.php
M includes/ApiQueryORES.php
M includes/Cache.php
M includes/FetchScoreJob.php
M includes/Hooks.php
M includes/Scoring.php
M includes/WatchedItemQueryServiceExtension.php
M maintenance/CheckModelVersions.php
M maintenance/CleanDuplicateScores.php
M maintenance/PopulateDatabase.php
M maintenance/PurgeScoreCache.php
M tests/phpunit/includes/ApiTest.php
M tests/phpunit/includes/CacheTest.php
M tests/phpunit/includes/HooksTest.php
15 files changed, 69 insertions(+), 27 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ORES
refs/changes/47/322647/1
diff --git a/includes/Api.php b/includes/Api.php
index c0aae84..9ac1bc9 100644
--- a/includes/Api.php
+++ b/includes/Api.php
@@ -11,6 +11,7 @@
* Common methods for accessing an ORES server.
*/
class Api {
+
/**
* @return string Base URL plus your wiki's `scores` API path.
*/
@@ -54,4 +55,5 @@
}
return $data;
}
+
}
diff --git a/includes/ApiHooks.php b/includes/ApiHooks.php
index 31071dc..4fd3a46 100644
--- a/includes/ApiHooks.php
+++ b/includes/ApiHooks.php
@@ -18,7 +18,11 @@
use WatchedItem;
use WatchedItemQueryService;
+/**
+ * @author Brad Jorsch <[email protected]>
+ */
class ApiHooks {
+
/**
* Inject parameters into certain API modules
*
diff --git a/includes/ApiQueryORES.php b/includes/ApiQueryORES.php
index a9a4ca3..947264c 100644
--- a/includes/ApiQueryORES.php
+++ b/includes/ApiQueryORES.php
@@ -1,6 +1,5 @@
<?php
/**
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -87,4 +86,5 @@
public function getHelpUrls() {
return 'https://www.mediawiki.org/wiki/Extension:ORES';
}
+
}
diff --git a/includes/Cache.php b/includes/Cache.php
index b457251..4513902 100644
--- a/includes/Cache.php
+++ b/includes/Cache.php
@@ -2,10 +2,13 @@
namespace ORES;
+use MediaWiki\MediaWikiServices;
use RuntimeException;
class Cache {
+
static protected $modelIds;
+
protected $errorCallback;
public function __construct() {
@@ -26,12 +29,11 @@
/**
* Save scores to the database
*
- * @param array $scores in the same structure as is returned by ORES.
- * @param bool $batch either to skip errors or not.
+ * @param array[] $scores in the same structure as is returned by ORES.
*
* @throws RuntimeException
*/
- public function storeScores( $scores ) {
+ public function storeScores( array $scores ) {
$dbData = [];
foreach ( $scores as $revision => $revisionData ) {
$this->processRevision( $dbData, $revision,
$revisionData );
@@ -80,7 +82,7 @@
[ 'oresc_id' => $ids ],
__METHOD__
);
- wfWaitForSlaves();
+
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
}
} while ( $ids );
}
@@ -88,6 +90,7 @@
/**
* @param string $model
*
+ * @throws RuntimeException
* @return string cached id of last seen version
*/
protected function getModelId( $model ) {
@@ -115,6 +118,8 @@
* @param array &$dbData Rows for insertion into ores_classification
are added to this array
* @param int $revision Revision being processed
* @param array $revisionData Data returned by Scoring::getScores() for
the revision.
+ *
+ * @throws RuntimeException
*/
public function processRevision( &$dbData, $revision, array
$revisionData ) {
global $wgOresModelClasses;
@@ -172,4 +177,5 @@
public static function instance() {
return new self();
}
+
}
diff --git a/includes/FetchScoreJob.php b/includes/FetchScoreJob.php
index 30b7c62..f18b255 100644
--- a/includes/FetchScoreJob.php
+++ b/includes/FetchScoreJob.php
@@ -7,6 +7,7 @@
use Title;
class FetchScoreJob extends Job {
+
/**
* @param Title $title
* @param array $params 'revid' key
@@ -63,4 +64,5 @@
}
return $success;
}
+
}
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 65a58d8..2a5cdc5 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -24,6 +24,7 @@
use Xml;
class Hooks {
+
/**
* @param DatabaseUpdater $updater
* @return bool
@@ -351,8 +352,9 @@
* Internal helper to label matching rows
*
* @param RCCacheEntry $rcObj
- * @param string[]
- * @param string[]
+ * @param string[] &$data
+ * @param string[] &$classes
+ * @param IContextSource $context
*/
protected static function processRecentChangesList(
RCCacheEntry $rcObj,
@@ -487,7 +489,7 @@
* Make a beta feature
*
* @param User $user
- * @param string[]
+ * @param string[] &$prefs
*/
public static function onGetBetaFeaturePreferences( User $user, array
&$prefs ) {
global $wgExtensionAssetsPath;
@@ -585,5 +587,5 @@
$join_conds["ores_${type}_cls"][0] = 'INNER JOIN';
}
}
-}
+}
diff --git a/includes/Scoring.php b/includes/Scoring.php
index 09579c8..b573e9f 100644
--- a/includes/Scoring.php
+++ b/includes/Scoring.php
@@ -3,11 +3,13 @@
namespace ORES;
class Scoring {
+
/**
* @param integer|array $revisions Single or multiple revisions
* @param string|array|null $models Single or multiple model names. If
* left empty, all configured models are queries.
- * @param array $params extra params to be passed to ORES endpoint
+ * @param array $extra_params to be passed to ORES endpoint
+ *
* @return array Results in the form returned by ORES
* @throws \RuntimeException
*/
@@ -29,4 +31,5 @@
public static function instance() {
return new self();
}
+
}
diff --git a/includes/WatchedItemQueryServiceExtension.php
b/includes/WatchedItemQueryServiceExtension.php
index f8788a3..f1bbd66 100644
--- a/includes/WatchedItemQueryServiceExtension.php
+++ b/includes/WatchedItemQueryServiceExtension.php
@@ -5,9 +5,10 @@
use IDatabase;
use ResultWrapper;
use User;
-use WatchedItem;
-use WatchedItemQueryService;
+/**
+ * @author Brad Jorsch <[email protected]>
+ */
class WatchedItemQueryServiceExtension implements
\WatchedItemQueryServiceExtension {
/**
diff --git a/maintenance/CheckModelVersions.php
b/maintenance/CheckModelVersions.php
index 9fccfb2..fd1dc60 100644
--- a/maintenance/CheckModelVersions.php
+++ b/maintenance/CheckModelVersions.php
@@ -12,6 +12,7 @@
* @ingroup Maintenance
*/
class CheckModelVersions extends Maintenance {
+
public function __construct() {
parent::__construct();
@@ -49,8 +50,8 @@
],
__METHOD__
);
-
}
+
$this->output( "done.\n" );
}
@@ -67,6 +68,7 @@
}
return $modelData['models'];
}
+
}
$maintClass = 'ORES\CheckModelVersions';
diff --git a/maintenance/CleanDuplicateScores.php
b/maintenance/CleanDuplicateScores.php
index 578aac0..d6edee2 100644
--- a/maintenance/CleanDuplicateScores.php
+++ b/maintenance/CleanDuplicateScores.php
@@ -3,6 +3,7 @@
namespace ORES;
use Maintenance;
+use MediaWiki\MediaWikiServices;
require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
@@ -12,11 +13,11 @@
* @ingroup Maintenance
*/
class CleanDuplicateScores extends Maintenance {
+
public function __construct() {
parent::__construct();
$this->addDescription( 'Clean up duplicate data in ORES scores'
);
-
}
public function execute() {
@@ -53,10 +54,12 @@
[ 'oresc_id' => $chunk ],
__METHOD__
);
- wfWaitForSlaves();
+
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
}
- $this->output( "Done" );
+
+ $this->output( 'Done' );
}
+
}
$maintClass = 'ORES\CleanDuplicateScores';
diff --git a/maintenance/PopulateDatabase.php b/maintenance/PopulateDatabase.php
index 4e56ad4..ce97788 100644
--- a/maintenance/PopulateDatabase.php
+++ b/maintenance/PopulateDatabase.php
@@ -3,6 +3,7 @@
namespace ORES;
use Maintenance;
+use MediaWiki\MediaWikiServices;
require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
@@ -30,7 +31,6 @@
'the latest edits in recentchanges table that are not
scored' );
$this->addOption( 'number', 'Number of revisions to be scored',
false, true, 'n' );
$this->addOption( 'batch', 'Batch size for select sql query',
false, true, 'b' );
-
}
public function execute() {
@@ -52,8 +52,8 @@
$count = 0;
while ( $count < $this->revisionLimit ) {
-
$conditions = [ 'oresc_id IS NULL', 'rc_type' => [
RC_EDIT, RC_NEW ] ];
+
if ( $wgOresExcludeBots === true ) {
$conditions['rc_bot'] = 0;
}
@@ -84,12 +84,13 @@
}
$count += $this->batchSize;
- wfGetLBFactory()->waitForReplication();
+
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
if ( $res->numRows() < $this->batchSize ) {
break;
}
}
+
$this->output( "Finished processing the revisions\n" );
}
@@ -107,6 +108,7 @@
$scores = $scoring->getScores( $revs );
$cache->storeScores( $scores );
}
+
}
$maintClass = 'ORES\PopulateDatabase';
diff --git a/maintenance/PurgeScoreCache.php b/maintenance/PurgeScoreCache.php
index 9059076..ce318ee 100644
--- a/maintenance/PurgeScoreCache.php
+++ b/maintenance/PurgeScoreCache.php
@@ -12,6 +12,7 @@
* @ingroup Maintenance
*/
class PurgeScoreCache extends Maintenance {
+
public function __construct() {
parent::__construct();
@@ -34,6 +35,7 @@
}
// @todo this script needs some output
}
+
}
$maintClass = 'ORES\PurgeScoreCache';
diff --git a/tests/phpunit/includes/ApiTest.php
b/tests/phpunit/includes/ApiTest.php
index 76863ec..2cb1b15 100644
--- a/tests/phpunit/includes/ApiTest.php
+++ b/tests/phpunit/includes/ApiTest.php
@@ -1,4 +1,5 @@
<?php
+
namespace ORES\Tests;
use ORES;
@@ -8,6 +9,10 @@
* @covers ORES\Api
*/
class OresApiTest extends \MediaWikiTestCase {
+
+ /**
+ * @var ORES\Api
+ */
protected $api;
protected function setUp() {
@@ -24,5 +29,5 @@
$url = $this->api->getUrl();
$this->assertSame(
"https://ores-beta.wmflabs.org/scores/testwiki/", $url );
}
-}
+}
diff --git a/tests/phpunit/includes/CacheTest.php
b/tests/phpunit/includes/CacheTest.php
index 1af544c..f474973 100644
--- a/tests/phpunit/includes/CacheTest.php
+++ b/tests/phpunit/includes/CacheTest.php
@@ -1,4 +1,5 @@
<?php
+
namespace ORES\Tests;
use MediaWikiLangTestCase;
@@ -11,6 +12,9 @@
*/
class OresCacheTest extends MediaWikiLangTestCase {
+ /**
+ * @var ORES\Cache
+ */
protected $cache;
protected function setUp() {
@@ -189,11 +193,11 @@
]
];
}
+
/**
* @dataProvider storeScoresProvider
*/
public function testStoreScores( $scores, $expected, $revIds ) {
-
$this->cache->storeScores( $scores );
$dbr = \wfGetDB( DB_REPLICA );
@@ -213,4 +217,5 @@
$this->assertEquals( $expected, iterator_to_array( $res, false
) );
}
+
}
diff --git a/tests/phpunit/includes/HooksTest.php
b/tests/phpunit/includes/HooksTest.php
index 2384297..9834c1f 100644
--- a/tests/phpunit/includes/HooksTest.php
+++ b/tests/phpunit/includes/HooksTest.php
@@ -1,4 +1,5 @@
<?php
+
namespace ORES\Tests;
use ChangesList;
@@ -11,13 +12,14 @@
use RCCacheEntry;
use RecentChange;
use RequestContext;
-use SpecialContributions;
+use User;
/**
* @group ORES
* @covers ORES\Hooks
*/
class OresHooksTest extends \MediaWikiTestCase {
+
protected $user;
protected $context;
@@ -160,7 +162,7 @@
$block = [];
$classes = [];
- ORES\Hooks::OnEnhancedChangesListModifyLineData( $ecl, $data,
$block, $rc, $classes );
+ ORES\Hooks::onEnhancedChangesListModifyLineData( $ecl, $data,
$block, $rc, $classes );
$this->assertSame( [ 'recentChangesFlags' => [ 'damaging' =>
true ] ], $data );
$this->assertSame( [], $block );
@@ -193,7 +195,7 @@
$block = [];
$classes = [];
- ORES\Hooks::OnEnhancedChangesListModifyLineData( $ecl, $data,
$block, $rc, $classes );
+ ORES\Hooks::onEnhancedChangesListModifyLineData( $ecl, $data,
$block, $rc, $classes );
$this->assertSame( [], $data );
$this->assertSame( [], $block );
@@ -435,14 +437,14 @@
$prefs = [];
ORES\Hooks::onGetBetaFeaturePreferences( $this->user, $prefs );
$this->assertArrayHasKey( 'ores-enabled', $prefs );
-
}
/**
+ * @param User $user
+ *
* @return IContextSource
*/
- private static function getContext( $user ) {
-
+ private static function getContext( User $user ) {
$context = new RequestContext();
$context->setLanguage( 'en' );
@@ -450,4 +452,5 @@
return $context;
}
+
}
--
To view, visit https://gerrit.wikimedia.org/r/322647
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd3875347bc252e9bbff912c2a10d05c20a0c08d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits