Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| WikiLambdaServices | n/a |
0 / 0 |
n/a |
0 / 0 |
26 | n/a |
0 / 0 |
|||
| getMode | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getZObjectStore | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getOrchestratorRequest | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getWikifunctionsClientStore | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getWikifunctionsUsageStore | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getWikifunctionsFragmentStore | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getZObjectAuthorization | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getMemcachedWrapper | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getAbstractWikiRequest | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getPFragmentRenderer | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getAWArticleStore | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getAWFragmentStore | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getWikifunctionsLanguageFactory | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getWikidataEntityLookup | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getAbstractWikiConfigProvider | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| buildZObjectStore | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| buildWikifunctionsFragmentStore | n/a |
0 / 0 |
n/a |
0 / 0 |
4 | |||||
| buildMemcachedWrapper | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| buildAWArticleStore | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| buildAWFragmentStore | n/a |
0 / 0 |
n/a |
0 / 0 |
4 | |||||
| 1 | <?php |
| 2 | /** |
| 3 | * WikiLambda Services |
| 4 | * |
| 5 | * @file |
| 6 | * @ingroup Extensions |
| 7 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
| 8 | * @license MIT |
| 9 | */ |
| 10 | |
| 11 | namespace MediaWiki\Extension\WikiLambda; |
| 12 | |
| 13 | use InvalidArgumentException; |
| 14 | use MediaWiki\Extension\WikiLambda\AbstractContent\AbstractWikiConfigProvider; |
| 15 | use MediaWiki\Extension\WikiLambda\AbstractContent\AbstractWikiRequest; |
| 16 | use MediaWiki\Extension\WikiLambda\Authorization\ZObjectAuthorization; |
| 17 | use MediaWiki\Extension\WikiLambda\AWStorage\AWArticleStore; |
| 18 | use MediaWiki\Extension\WikiLambda\AWStorage\AWFragmentStore; |
| 19 | use MediaWiki\Extension\WikiLambda\AWStorage\MainStashAWArticleStore; |
| 20 | use MediaWiki\Extension\WikiLambda\AWStorage\MainStashAWFragmentStore; |
| 21 | use MediaWiki\Extension\WikiLambda\AWStorage\MemcachedAWFragmentStore; |
| 22 | use MediaWiki\Extension\WikiLambda\Cache\MemcachedWrapper; |
| 23 | use MediaWiki\Extension\WikiLambda\ClientStorage\MainStashWikifunctionsFragmentStore; |
| 24 | use MediaWiki\Extension\WikiLambda\ClientStorage\MemcachedWikifunctionsFragmentStore; |
| 25 | use MediaWiki\Extension\WikiLambda\ClientStorage\WikifunctionsClientStore; |
| 26 | use MediaWiki\Extension\WikiLambda\ClientStorage\WikifunctionsFragmentStore; |
| 27 | use MediaWiki\Extension\WikiLambda\ClientStorage\WikifunctionsUsageStore; |
| 28 | use MediaWiki\Extension\WikiLambda\Language\WikifunctionsLanguageFactory; |
| 29 | use MediaWiki\Extension\WikiLambda\Renderer\WikifunctionsFragmentRenderer; |
| 30 | use MediaWiki\Logger\LoggerFactory; |
| 31 | use MediaWiki\MediaWikiServices; |
| 32 | |
| 33 | /** |
| 34 | * @codeCoverageIgnore |
| 35 | */ |
| 36 | class WikiLambdaServices { |
| 37 | |
| 38 | /** |
| 39 | * @return WikiLambdaMode |
| 40 | */ |
| 41 | public static function getMode(): WikiLambdaMode { |
| 42 | return MediaWikiServices::getInstance()->getService( 'WikiLambdaMode' ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @return ZObjectStore |
| 47 | */ |
| 48 | public static function getZObjectStore(): ZObjectStore { |
| 49 | return MediaWikiServices::getInstance()->getService( 'WikiLambdaZObjectStore' ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @return OrchestratorRequest |
| 54 | */ |
| 55 | public static function getOrchestratorRequest(): OrchestratorRequest { |
| 56 | return MediaWikiServices::getInstance()->getService( 'WikiLambdaOrchestratorRequest' ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Note: Not explicitly typed, as this service is mocked in tests |
| 61 | * |
| 62 | * @return WikifunctionsClientStore |
| 63 | */ |
| 64 | public static function getWikifunctionsClientStore(): WikifunctionsClientStore { |
| 65 | return MediaWikiServices::getInstance()->getService( 'WikifunctionsClientStore' ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return WikifunctionsUsageStore |
| 70 | */ |
| 71 | public static function getWikifunctionsUsageStore(): WikifunctionsUsageStore { |
| 72 | return MediaWikiServices::getInstance()->getService( 'WikifunctionsUsageStore' ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return WikifunctionsFragmentStore |
| 77 | */ |
| 78 | public static function getWikifunctionsFragmentStore(): WikifunctionsFragmentStore { |
| 79 | return MediaWikiServices::getInstance()->getService( 'WikifunctionsFragmentStore' ); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @return ZObjectAuthorization |
| 84 | */ |
| 85 | public static function getZObjectAuthorization(): ZObjectAuthorization { |
| 86 | return MediaWikiServices::getInstance()->getService( 'WikiLambdaZObjectAuthorization' ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @return MemcachedWrapper |
| 91 | */ |
| 92 | public static function getMemcachedWrapper(): MemcachedWrapper { |
| 93 | return MediaWikiServices::getInstance()->getService( 'WikiLambdaMemcachedWrapper' ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @return AbstractWikiRequest |
| 98 | */ |
| 99 | public static function getAbstractWikiRequest(): AbstractWikiRequest { |
| 100 | return MediaWikiServices::getInstance()->getService( 'AbstractWikiRequest' ); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @return WikifunctionsFragmentRenderer |
| 105 | */ |
| 106 | public static function getPFragmentRenderer(): WikifunctionsFragmentRenderer { |
| 107 | return MediaWikiServices::getInstance()->getService( 'WikiLambdaPFragmentRenderer' ); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @return AWArticleStore |
| 112 | */ |
| 113 | public static function getAWArticleStore(): AWArticleStore { |
| 114 | return MediaWikiServices::getInstance()->getService( 'AbstractWikiArticleStore' ); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @return AWFragmentStore |
| 119 | */ |
| 120 | public static function getAWFragmentStore(): AWFragmentStore { |
| 121 | return MediaWikiServices::getInstance()->getService( 'AbstractWikiFragmentStore' ); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @return WikifunctionsLanguageFactory |
| 126 | */ |
| 127 | public static function getWikifunctionsLanguageFactory(): WikifunctionsLanguageFactory { |
| 128 | return MediaWikiServices::getInstance()->getService( 'WikifunctionsLanguageFactory' ); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * @return WikidataEntityLookup |
| 133 | */ |
| 134 | public static function getWikidataEntityLookup(): WikidataEntityLookup { |
| 135 | return MediaWikiServices::getInstance()->getService( 'WikiLambdaWikidataEntityLookup' ); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @return AbstractWikiConfigProvider |
| 140 | */ |
| 141 | public static function getAbstractWikiConfigProvider(): AbstractWikiConfigProvider { |
| 142 | return MediaWikiServices::getInstance()->getService( 'AbstractWikiConfigProvider' ); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Constructs a new instance of ZObjectStore. |
| 147 | * Reused by service wiring and installer bootstrapping. |
| 148 | * |
| 149 | * @internal For use in Service Wiring and early setup on RepoHooks |
| 150 | */ |
| 151 | public static function buildZObjectStore( MediaWikiServices $services ): ZObjectStore { |
| 152 | return new ZObjectStore( |
| 153 | $services->getConnectionProvider(), |
| 154 | $services->getTitleFactory(), |
| 155 | $services->getWikiPageFactory(), |
| 156 | $services->getRevisionStore(), |
| 157 | $services->getUserGroupManager(), |
| 158 | LoggerFactory::getInstance( 'WikiLambda' ) |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Constructs a new instance of the WikifunctionsFragmentStore. |
| 164 | * |
| 165 | * The concrete backend is selected by $wgWikiLambdaClientFragmentStoreBackend: |
| 166 | * * 'memcached': Store backed by the Wikifunctions Memcached instance |
| 167 | * using the MemcachedWrapper interface. |
| 168 | * * 'mainstash': Store backed by MediaWiki MainStash, a durable key/value |
| 169 | * substrate with TTL cleanup and x2 replication. |
| 170 | * |
| 171 | * @internal For use in Service Wiring and early setup on RepoHooks |
| 172 | */ |
| 173 | public static function buildWikifunctionsFragmentStore( MediaWikiServices $services ): WikifunctionsFragmentStore { |
| 174 | $extensionConfig = $services->getConfigFactory()->makeConfig( 'WikiLambda' ); |
| 175 | $backend = $extensionConfig->get( 'WikiLambdaClientFragmentStoreBackend' ); |
| 176 | |
| 177 | switch ( $backend ) { |
| 178 | case 'memcached': |
| 179 | return new MemcachedWikifunctionsFragmentStore( |
| 180 | self::buildMemcachedWrapper( $services ) |
| 181 | ); |
| 182 | case 'mainstash': |
| 183 | return new MainStashWikifunctionsFragmentStore( |
| 184 | $services->getMainObjectStash(), |
| 185 | $services->getStatsFactory() |
| 186 | ); |
| 187 | default: |
| 188 | throw new InvalidArgumentException( |
| 189 | "Unknown WikiLambdaClientFragmentStoreBackend value: '$backend'" |
| 190 | ); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Constructs a new instance of the MemcachedWrapper for WikiLambda's content caching. |
| 196 | * |
| 197 | * @internal For use in Service Wiring and early setup on RepoHooks |
| 198 | */ |
| 199 | public static function buildMemcachedWrapper( MediaWikiServices $services ): MemcachedWrapper { |
| 200 | $extensionConfig = $services->getConfigFactory()->makeConfig( 'WikiLambda' ); |
| 201 | return new MemcachedWrapper( $extensionConfig, $services->getStatsFactory() ); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Constructs a new instance of the AWArticleStore. |
| 206 | * |
| 207 | * The store is backed by MainStash (T426873), a durable key/value substrate |
| 208 | * with TTL cleanup and x2 replication. |
| 209 | * |
| 210 | * @internal For use in Service Wiring and early setup on RepoHooks |
| 211 | */ |
| 212 | public static function buildAWArticleStore( MediaWikiServices $services ): AWArticleStore { |
| 213 | return new MainStashAWArticleStore( |
| 214 | $services->getMainObjectStash(), |
| 215 | $services->getStatsFactory() |
| 216 | ); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Constructs a new instance of the AWFragmentStore. |
| 221 | * |
| 222 | * The concrete backend is selected by $wgWikiLambdaAWFragmentStoreBackend: |
| 223 | * * 'memcached': Store backed by the Wikifunctions Memcached instance |
| 224 | * using the MemcachedWrapper interface. |
| 225 | * * 'mainstash': Store backed by MediaWiki MainStash (T431428), a durable |
| 226 | * key/value substrate with TTL cleanup and x2 replication, using th. |
| 227 | * |
| 228 | * @internal For use in Service Wiring and early setup on RepoHooks |
| 229 | */ |
| 230 | public static function buildAWFragmentStore( MediaWikiServices $services ): AWFragmentStore { |
| 231 | $extensionConfig = $services->getConfigFactory()->makeConfig( 'WikiLambda' ); |
| 232 | $backend = $extensionConfig->get( 'WikiLambdaAWFragmentStoreBackend' ); |
| 233 | |
| 234 | switch ( $backend ) { |
| 235 | case 'memcached': |
| 236 | return new MemcachedAWFragmentStore( |
| 237 | $services->getJobQueueGroup(), |
| 238 | self::buildMemcachedWrapper( $services ), |
| 239 | $services->getStatsFactory() |
| 240 | ); |
| 241 | case 'mainstash': |
| 242 | return new MainStashAWFragmentStore( |
| 243 | $services->getJobQueueGroup(), |
| 244 | $services->getMainObjectStash(), |
| 245 | $services->getStatsFactory() |
| 246 | ); |
| 247 | default: |
| 248 | throw new InvalidArgumentException( |
| 249 | "Unknown WikiLambdaAWFragmentStoreBackend value: '$backend'" |
| 250 | ); |
| 251 | } |
| 252 | } |
| 253 | } |