@@ -28,36 +28,36 @@ discard block |
||
| 28 | 28 | /** |
| 29 | 29 | * @param DatabaseUpdater $updater |
| 30 | 30 | */ |
| 31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
| 32 | - $updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/../sql/create_wbqc_constraints.sql' ); |
|
| 33 | - $updater->addExtensionField( 'wbqc_constraints', 'constraint_id', __DIR__ . '/../sql/patch-wbqc_constraints-constraint_id.sql' ); |
|
| 31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
| 32 | + $updater->addExtensionTable('wbqc_constraints', __DIR__.'/../sql/create_wbqc_constraints.sql'); |
|
| 33 | + $updater->addExtensionField('wbqc_constraints', 'constraint_id', __DIR__.'/../sql/patch-wbqc_constraints-constraint_id.sql'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public static function onWikibaseChange( Change $change ) { |
|
| 36 | + public static function onWikibaseChange(Change $change) { |
|
| 37 | 37 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
| 38 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
| 39 | - self::isConstraintStatementsChange( $config, $change ) |
|
| 38 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
| 39 | + self::isConstraintStatementsChange($config, $change) |
|
| 40 | 40 | ) { |
| 41 | 41 | /** @var EntityChange $change */ |
| 42 | 42 | $title = Title::newMainPage(); |
| 43 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
| 43 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
| 44 | 44 | JobQueueGroup::singleton()->push( |
| 45 | - new JobSpecification( 'constraintsTableUpdate', $params, [], $title ) |
|
| 45 | + new JobSpecification('constraintsTableUpdate', $params, [], $title) |
|
| 46 | 46 | ); |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
| 51 | - if ( !( $change instanceof EntityChange ) || |
|
| 50 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
| 51 | + if (!($change instanceof EntityChange) || |
|
| 52 | 52 | $change->getAction() !== EntityChange::UPDATE || |
| 53 | - !( $change->getEntityId() instanceof PropertyId ) |
|
| 53 | + !($change->getEntityId() instanceof PropertyId) |
|
| 54 | 54 | ) { |
| 55 | 55 | return false; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $info = $change->getInfo(); |
| 59 | 59 | |
| 60 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
| 60 | + if (!array_key_exists('compactDiff', $info)) { |
|
| 61 | 61 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
| 62 | 62 | // so we only know that the change *might* affect the constraint statements |
| 63 | 63 | return true; |
@@ -66,19 +66,19 @@ discard block |
||
| 66 | 66 | /** @var EntityDiffChangedAspects $aspects */ |
| 67 | 67 | $aspects = $info['compactDiff']; |
| 68 | 68 | |
| 69 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
| 70 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
| 69 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
| 70 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
| 73 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
| 74 | 74 | $repo = WikibaseRepo::getDefaultInstance(); |
| 75 | 75 | |
| 76 | 76 | $entityContentFactory = $repo->getEntityContentFactory(); |
| 77 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
| 78 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
| 79 | - if ( $entityId !== null ) { |
|
| 77 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
| 78 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
| 79 | + if ($entityId !== null) { |
|
| 80 | 80 | $resultsCache = ResultsCache::getDefaultInstance(); |
| 81 | - $resultsCache->delete( $entityId ); |
|
| 81 | + $resultsCache->delete($entityId); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -88,18 +88,18 @@ discard block |
||
| 88 | 88 | * @param int $timestamp UTC timestamp (seconds since the Epoch) |
| 89 | 89 | * @return bool |
| 90 | 90 | */ |
| 91 | - public static function isGadgetEnabledForUserName( $userName, $timestamp ) { |
|
| 91 | + public static function isGadgetEnabledForUserName($userName, $timestamp) { |
|
| 92 | 92 | $initial = $userName[0]; |
| 93 | 93 | |
| 94 | - if ( $initial === 'Z' ) { |
|
| 94 | + if ($initial === 'Z') { |
|
| 95 | 95 | $firstWeek = 0; |
| 96 | - } elseif ( $initial >= 'W' && $initial < 'Z' ) { |
|
| 96 | + } elseif ($initial >= 'W' && $initial < 'Z') { |
|
| 97 | 97 | $firstWeek = 1; |
| 98 | - } elseif ( $initial >= 'T' && $initial < 'W' ) { |
|
| 98 | + } elseif ($initial >= 'T' && $initial < 'W') { |
|
| 99 | 99 | $firstWeek = 2; |
| 100 | - } elseif ( $initial >= 'N' && $initial < 'T' ) { |
|
| 100 | + } elseif ($initial >= 'N' && $initial < 'T') { |
|
| 101 | 101 | $firstWeek = 3; |
| 102 | - } elseif ( $initial >= 'E' && $initial < 'N' ) { |
|
| 102 | + } elseif ($initial >= 'E' && $initial < 'N') { |
|
| 103 | 103 | $firstWeek = 4; |
| 104 | 104 | } else { |
| 105 | 105 | $firstWeek = 5; |
@@ -117,29 +117,29 @@ discard block |
||
| 117 | 117 | return $timestamp >= $threshold; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
| 120 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
| 121 | 121 | $repo = WikibaseRepo::getDefaultInstance(); |
| 122 | 122 | |
| 123 | 123 | $lookup = $repo->getEntityNamespaceLookup(); |
| 124 | 124 | $title = $out->getTitle(); |
| 125 | - if ( $title === null ) { |
|
| 125 | + if ($title === null) { |
|
| 126 | 126 | return; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
| 129 | + if (!$lookup->isEntityNamespace($title->getNamespace())) { |
|
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
| 132 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
| 136 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
| 137 | 137 | |
| 138 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
| 138 | + if (!$out->getUser()->isLoggedIn()) { |
|
| 139 | 139 | return; |
| 140 | 140 | } |
| 141 | - if ( self::isGadgetEnabledForUserName( $out->getUser()->getName(), time() ) ) { |
|
| 142 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
| 141 | + if (self::isGadgetEnabledForUserName($out->getUser()->getName(), time())) { |
|
| 142 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
@@ -148,12 +148,12 @@ discard block |
||
| 148 | 148 | * @param array &$vars |
| 149 | 149 | * @param OutputPage $out |
| 150 | 150 | */ |
| 151 | - public static function addVariables( &$vars, OutputPage $out ) { |
|
| 151 | + public static function addVariables(&$vars, OutputPage $out) { |
|
| 152 | 152 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
| 153 | 153 | |
| 154 | - $vars['wbQualityConstraintsPropertyConstraintId'] = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
| 155 | - $vars['wbQualityConstraintsOneOfConstraintId'] = $config->get( 'WBQualityConstraintsOneOfConstraintId' ); |
|
| 156 | - $vars['wbQualityConstraintsQualifierOfPropertyConstraintId'] = $config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
| 154 | + $vars['wbQualityConstraintsPropertyConstraintId'] = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
| 155 | + $vars['wbQualityConstraintsOneOfConstraintId'] = $config->get('WBQualityConstraintsOneOfConstraintId'); |
|
| 156 | + $vars['wbQualityConstraintsQualifierOfPropertyConstraintId'] = $config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | } |
@@ -9,10 +9,10 @@ discard block |
||
| 9 | 9 | use Wikibase\Repo\WikibaseRepo; |
| 10 | 10 | |
| 11 | 11 | // @codeCoverageIgnoreStart |
| 12 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
| 13 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
| 12 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
| 13 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
| 14 | 14 | |
| 15 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
| 15 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
| 16 | 16 | // @codeCoverageIgnoreEnd |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -38,39 +38,39 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function __construct() { |
| 40 | 40 | parent::__construct(); |
| 41 | - $this->newUpdateConstraintsTableJob = function ( $propertyIdSerialization ) { |
|
| 41 | + $this->newUpdateConstraintsTableJob = function($propertyIdSerialization) { |
|
| 42 | 42 | return UpdateConstraintsTableJob::newFromGlobalState( |
| 43 | 43 | Title::newMainPage(), |
| 44 | - [ 'propertyId' => $propertyIdSerialization ] |
|
| 44 | + ['propertyId' => $propertyIdSerialization] |
|
| 45 | 45 | ); |
| 46 | 46 | }; |
| 47 | 47 | |
| 48 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
| 49 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
| 48 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
| 49 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
| 50 | 50 | |
| 51 | 51 | // Wikibase classes are not yet loaded, so setup services in a callback run in execute |
| 52 | 52 | // that can be overridden in tests. |
| 53 | - $this->setupServices = function () { |
|
| 53 | + $this->setupServices = function() { |
|
| 54 | 54 | $repo = WikibaseRepo::getDefaultInstance(); |
| 55 | 55 | $this->propertyInfoLookup = $repo->getStore()->getPropertyInfoLookup(); |
| 56 | 56 | }; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public function execute() { |
| 60 | - ( $this->setupServices )(); |
|
| 61 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
| 62 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
| 60 | + ($this->setupServices)(); |
|
| 61 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
| 62 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - foreach ( $this->propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info ) { |
|
| 67 | - $this->output( sprintf( 'Importing constraint statements for % 6s... ', $propertyIdSerialization ), $propertyIdSerialization ); |
|
| 68 | - $startTime = microtime( true ); |
|
| 69 | - $job = call_user_func( $this->newUpdateConstraintsTableJob, $propertyIdSerialization ); |
|
| 66 | + foreach ($this->propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info) { |
|
| 67 | + $this->output(sprintf('Importing constraint statements for % 6s... ', $propertyIdSerialization), $propertyIdSerialization); |
|
| 68 | + $startTime = microtime(true); |
|
| 69 | + $job = call_user_func($this->newUpdateConstraintsTableJob, $propertyIdSerialization); |
|
| 70 | 70 | $job->run(); |
| 71 | - $endTime = microtime( true ); |
|
| 72 | - $millis = ( $endTime - $startTime ) * 1000; |
|
| 73 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
| 71 | + $endTime = microtime(true); |
|
| 72 | + $millis = ($endTime - $startTime) * 1000; |
|
| 73 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |