Skip to content

Commit

Permalink
Fix code style issues in PHP entry points
Browse files Browse the repository at this point in the history
Since we want to migrate to extension registration and get rid of the
PHP entry points in the long run (T88258), all of this code will
eventually have to move somewhere else, where it will be subject to the
usual phpcs code style requirements; those moves will be easier to do
and understand if we already fix the code style issues now, so that the
moves can be as clean as possible.

Most of the fixes are to use imports instead of fully qualified names;
there were also a few other issues, such as using require like a
function, or using the old array() syntax.

Change-Id: I3feb1794a3c542c627232719f30e5da5678c799f
  • Loading branch information
lucaswerkmeister committed Nov 25, 2019
1 parent f658176 commit 6b6e5a6
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 196 deletions.
1 change: 0 additions & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
<exclude-pattern>PerRepositoryServiceWiring\.php</exclude-pattern>
<exclude-pattern>SearchEntitiesIntegrationTest\.php</exclude-pattern>
<exclude-pattern>TermLookupSearcher\.php</exclude-pattern>
<exclude-pattern>Wikibase\.php</exclude-pattern>
<exclude-pattern>WikibasePrefixSearcher\.php</exclude-pattern>
<exclude-pattern>WikibaseRepo\.entitytypes\.php</exclude-pattern>
<exclude-pattern>WikibaseStringValueNormalizer\.php</exclude-pattern>
Expand Down
91 changes: 53 additions & 38 deletions client/WikibaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@
* @license GPL-2.0-or-later
*/

// @codingStandardsIgnoreFile
use MediaWiki\MediaWikiServices;
use Wikibase\Client\Api\ApiClientInfo;
use Wikibase\Client\Api\ApiListEntityUsage;
use Wikibase\Client\Api\ApiPropsEntityUsage;
use Wikibase\Client\Api\Description;
use Wikibase\Client\Api\PageTerms;
use Wikibase\Client\ChangeNotificationJob;
use Wikibase\Client\Changes\InjectRCRecordsJob;
use Wikibase\Client\Specials\SpecialEntityUsage;
use Wikibase\Client\Specials\SpecialPagesWithBadges;
use Wikibase\Client\Specials\SpecialUnconnectedPages;
use Wikibase\Client\Store\AddUsagesForPageJob;
use Wikibase\Client\WikibaseClient;
use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
use Wikibase\Repo\WikibaseRepo;

if ( !defined( 'MEDIAWIKI' ) ) {
die( "Not an entry point.\n" );
Expand All @@ -51,7 +65,7 @@
require_once __DIR__ . '/../lib/WikibaseLib.php';

// Load autoload info as long as extension classes are not PSR-4-autoloaded
require_once __DIR__ . '/autoload.php';
require_once __DIR__ . '/autoload.php';

call_user_func( function() {
global $wgAPIListModules,
Expand All @@ -72,8 +86,8 @@
$wgWBClientSettings;

// Registry and definition of data types
$wgWBClientDataTypes = require ( __DIR__ . '/../lib/WikibaseLib.datatypes.php' );
$clientDatatypes = require ( __DIR__ . '/WikibaseClient.datatypes.php' );
$wgWBClientDataTypes = require __DIR__ . '/../lib/WikibaseLib.datatypes.php';
$clientDatatypes = require __DIR__ . '/WikibaseClient.datatypes.php';

// merge WikibaseClient.datatypes.php into $wgWBClientDataTypes
foreach ( $clientDatatypes as $type => $clientDef ) {
Expand Down Expand Up @@ -160,19 +174,20 @@
// magic words
$wgHooks['MagicWordwgVariableIDs'][] = '\Wikibase\Client\Hooks\MagicWordHookHandlers::onMagicWordwgVariableIDs';
$wgHooks['ParserGetVariableValueSwitch'][] = '\Wikibase\Client\Hooks\MagicWordHookHandlers::onParserGetVariableValueSwitch';
$wgHooks['ResourceLoaderJqueryMsgModuleMagicWords'][] = '\Wikibase\Client\Hooks\MagicWordHookHandlers::onResourceLoaderJqueryMsgModuleMagicWords';
$wgHooks['ResourceLoaderJqueryMsgModuleMagicWords'][]
= '\Wikibase\Client\Hooks\MagicWordHookHandlers::onResourceLoaderJqueryMsgModuleMagicWords';

// update hooks
$wgHooks['LoadExtensionSchemaUpdates'][] = '\Wikibase\Client\Usage\Sql\SqlUsageTrackerSchemaUpdater::onSchemaUpdate';

// job classes
$wgJobClasses['wikibase-addUsagesForPage'] = Wikibase\Client\Store\AddUsagesForPageJob::class;
$wgJobClasses['ChangeNotification'] = Wikibase\Client\ChangeNotificationJob::class;
$wgJobClasses['wikibase-addUsagesForPage'] = AddUsagesForPageJob::class;
$wgJobClasses['ChangeNotification'] = ChangeNotificationJob::class;
$wgJobClasses['wikibase-InjectRCRecords'] = function ( Title $unused, array $params ) {
$mwServices = MediaWiki\MediaWikiServices::getInstance();
$wbServices = Wikibase\Client\WikibaseClient::getDefaultInstance();
$mwServices = MediaWikiServices::getInstance();
$wbServices = WikibaseClient::getDefaultInstance();

$job = new Wikibase\Client\Changes\InjectRCRecordsJob(
$job = new InjectRCRecordsJob(
$mwServices->getDBLoadBalancerFactory(),
$wbServices->getStore()->getEntityChangeLookup(),
$wbServices->getEntityChangeFactory(),
Expand All @@ -189,19 +204,19 @@
};

// api modules
$wgAPIMetaModules['wikibase'] = array(
'class' => Wikibase\Client\Api\ApiClientInfo::class,
$wgAPIMetaModules['wikibase'] = [
'class' => ApiClientInfo::class,
'factory' => function( ApiQuery $apiQuery, $moduleName ) {
return new Wikibase\Client\Api\ApiClientInfo(
Wikibase\Client\WikibaseClient::getDefaultInstance()->getSettings(),
return new ApiClientInfo(
WikibaseClient::getDefaultInstance()->getSettings(),
$apiQuery,
$moduleName
);
}
);
];

$wgAPIPropModules['pageterms'] = array(
'class' => Wikibase\Client\Api\PageTerms::class,
$wgAPIPropModules['pageterms'] = [
'class' => PageTerms::class,
'factory' => function ( ApiQuery $apiQuery, $moduleName ) {
// FIXME: HACK: make pageterms work directly on entity pages on the repo.
// We should instead use an EntityIdLookup that combines the repo and the client
Expand All @@ -210,31 +225,31 @@
// self-documentation of the API module in the "apihelp-query+pageterms-description"
// message and the PageTerms::getExamplesMessages() method.
if ( defined( 'WB_VERSION' ) ) {
$repo = Wikibase\Repo\WikibaseRepo::getDefaultInstance();
$repo = WikibaseRepo::getDefaultInstance();
$termIndex = $repo->getStore()->getTermIndex();
$entityIdLookup = $repo->getEntityContentFactory();
} else {
$client = Wikibase\Client\WikibaseClient::getDefaultInstance();
$client = WikibaseClient::getDefaultInstance();
$termIndex = $client->getItemTermIndex();
$entityIdLookup = $client->getStore()->getEntityIdLookup();
}

return new Wikibase\Client\Api\PageTerms(
return new PageTerms(
$termIndex,
$entityIdLookup,
$apiQuery,
$moduleName
);
}
);
];

$wgAPIPropModules['description'] = [
'class' => Wikibase\Client\Api\Description::class,
'class' => Description::class,
'factory' => function( ApiQuery $apiQuery, $moduleName ) {
$client = Wikibase\Client\WikibaseClient::getDefaultInstance();
$client = WikibaseClient::getDefaultInstance();
$allowLocalShortDesc = $client->getSettings()->getSetting( 'allowLocalShortDesc' );
$descriptionLookup = $client->getDescriptionLookup();
return new Wikibase\Client\Api\Description(
return new Description(
$apiQuery,
$moduleName,
$allowLocalShortDesc,
Expand All @@ -244,34 +259,34 @@
];

$wgAPIPropModules['wbentityusage'] = [
'class' => Wikibase\Client\Api\ApiPropsEntityUsage::class,
'class' => ApiPropsEntityUsage::class,
'factory' => function ( ApiQuery $query, $moduleName ) {
$repoLinker = Wikibase\Client\WikibaseClient::getDefaultInstance()->newRepoLinker();
return new Wikibase\Client\Api\ApiPropsEntityUsage(
$repoLinker = WikibaseClient::getDefaultInstance()->newRepoLinker();
return new ApiPropsEntityUsage(
$query,
$moduleName,
$repoLinker
);
}
];
$wgAPIListModules['wblistentityusage'] = [
'class' => Wikibase\Client\Api\ApiListEntityUsage::class,
'class' => ApiListEntityUsage::class,
'factory' => function ( ApiQuery $apiQuery, $moduleName ) {
return new Wikibase\Client\Api\ApiListEntityUsage(
return new ApiListEntityUsage(
$apiQuery,
$moduleName,
Wikibase\Client\WikibaseClient::getDefaultInstance()->newRepoLinker()
WikibaseClient::getDefaultInstance()->newRepoLinker()
);
}
];

// Special page registration
$wgSpecialPages['UnconnectedPages'] = Wikibase\Client\Specials\SpecialUnconnectedPages::class;
$wgSpecialPages['UnconnectedPages'] = SpecialUnconnectedPages::class;
$wgSpecialPages['PagesWithBadges'] = function() {
$wikibaseClient = Wikibase\Client\WikibaseClient::getDefaultInstance();
$wikibaseClient = WikibaseClient::getDefaultInstance();
$settings = $wikibaseClient->getSettings();
return new Wikibase\Client\Specials\SpecialPagesWithBadges(
new Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory(
return new SpecialPagesWithBadges(
new LanguageFallbackLabelDescriptionLookupFactory(
$wikibaseClient->getLanguageFallbackChainFactory(),
$wikibaseClient->getTermLookup(),
$wikibaseClient->getTermBuffer()
Expand All @@ -281,8 +296,8 @@
);
};
$wgSpecialPages['EntityUsage'] = function () {
return new Wikibase\Client\Specials\SpecialEntityUsage(
Wikibase\Client\WikibaseClient::getDefaultInstance()->getEntityIdParser()
return new SpecialEntityUsage(
WikibaseClient::getDefaultInstance()->getEntityIdParser()
);
};

Expand All @@ -299,10 +314,10 @@
require __DIR__ . '/config/WikibaseClient.default.php'
);

$wgRecentChangesFlags['wikibase-edit'] = array(
$wgRecentChangesFlags['wikibase-edit'] = [
'letter' => 'wikibase-rc-wikibase-edit-letter',
'title' => 'wikibase-rc-wikibase-edit-title',
'legend' => 'wikibase-rc-wikibase-edit-legend',
'grouping' => 'all',
);
];
} );
Loading

0 comments on commit 6b6e5a6

Please sign in to comment.