Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
66.67% |
10 / 15 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
BacklinkCacheFactory | |
66.67% |
10 / 15 |
|
50.00% |
1 / 2 |
4.59 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getBacklinkCache | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | /** |
3 | * Remember the page that was previously loaded. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | * @ingroup Cache |
22 | */ |
23 | |
24 | namespace MediaWiki\Cache; |
25 | |
26 | use BacklinkCache; |
27 | use MediaWiki\Config\ServiceOptions; |
28 | use MediaWiki\HookContainer\HookContainer; |
29 | use MediaWiki\Linker\LinksMigration; |
30 | use MediaWiki\Page\PageReference; |
31 | use WANObjectCache; |
32 | use Wikimedia\Rdbms\IConnectionProvider; |
33 | |
34 | /** |
35 | * @since 1.37 |
36 | */ |
37 | class BacklinkCacheFactory { |
38 | /** @var BacklinkCache */ |
39 | private $latestBacklinkCache; |
40 | |
41 | /** @var WANObjectCache */ |
42 | private $wanCache; |
43 | |
44 | /** @var HookContainer */ |
45 | private $hookContainer; |
46 | |
47 | private IConnectionProvider $dbProvider; |
48 | private ServiceOptions $options; |
49 | private LinksMigration $linksMigration; |
50 | |
51 | public function __construct( |
52 | ServiceOptions $options, |
53 | LinksMigration $linksMigration, |
54 | WANObjectCache $wanCache, |
55 | HookContainer $hookContainer, |
56 | IConnectionProvider $dbProvider |
57 | ) { |
58 | $this->options = $options; |
59 | $this->linksMigration = $linksMigration; |
60 | $this->wanCache = $wanCache; |
61 | $this->hookContainer = $hookContainer; |
62 | $this->dbProvider = $dbProvider; |
63 | } |
64 | |
65 | /** |
66 | * Returns a BacklinkCache for $page. May re-use previously |
67 | * created instances. |
68 | * |
69 | * Currently, only one cache instance can exist; callers that |
70 | * need multiple backlink cache objects should keep them in scope. |
71 | * |
72 | * @param PageReference $page Page to get a backlink cache for |
73 | * @return BacklinkCache |
74 | */ |
75 | public function getBacklinkCache( PageReference $page ): BacklinkCache { |
76 | if ( !$this->latestBacklinkCache || !$this->latestBacklinkCache->getPage()->isSamePageAs( $page ) ) { |
77 | $this->latestBacklinkCache = new BacklinkCache( |
78 | $this->options, |
79 | $this->linksMigration, |
80 | $this->wanCache, |
81 | $this->hookContainer, |
82 | $this->dbProvider, |
83 | $page |
84 | ); |
85 | } |
86 | return $this->latestBacklinkCache; |
87 | } |
88 | } |