Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
ForeignDBFile | |
0.00% |
0 / 49 |
|
0.00% |
0 / 8 |
240 | |
0.00% |
0 / 1 |
getRepo | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
publish | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
restore | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
deleteFile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
move | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDescriptionUrl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDescriptionText | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
42 | |||
getDescriptionShortUrl | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\FileRepo\File; |
22 | |
23 | use MediaWiki\FileRepo\ForeignDBRepo; |
24 | use MediaWiki\Language\Language; |
25 | use MediaWiki\MediaWikiServices; |
26 | use MediaWiki\Status\Status; |
27 | use MediaWiki\Title\Title; |
28 | use MediaWiki\User\UserIdentity; |
29 | use Wikimedia\ObjectCache\WANObjectCache; |
30 | use Wikimedia\Rdbms\DBUnexpectedError; |
31 | |
32 | /** |
33 | * Foreign file from a reachable database in the same wiki farm. |
34 | * |
35 | * @ingroup FileAbstraction |
36 | */ |
37 | class ForeignDBFile extends LocalFile { |
38 | |
39 | /** |
40 | * @return ForeignDBRepo|false |
41 | */ |
42 | public function getRepo() { |
43 | return $this->repo; |
44 | } |
45 | |
46 | /** |
47 | * @param string $srcPath |
48 | * @param int $flags |
49 | * @param array $options |
50 | * @return Status |
51 | */ |
52 | public function publish( $srcPath, $flags = 0, array $options = [] ) { |
53 | $this->readOnlyError(); |
54 | } |
55 | |
56 | /** |
57 | * @param int[] $versions |
58 | * @param bool $unsuppress |
59 | * @return Status |
60 | */ |
61 | public function restore( $versions = [], $unsuppress = false ) { |
62 | $this->readOnlyError(); |
63 | } |
64 | |
65 | /** |
66 | * @param string $reason |
67 | * @param UserIdentity $user |
68 | * @param bool $suppress |
69 | * @return Status |
70 | */ |
71 | public function deleteFile( $reason, UserIdentity $user, $suppress = false ) { |
72 | $this->readOnlyError(); |
73 | } |
74 | |
75 | /** |
76 | * @param Title $target |
77 | * @return Status |
78 | */ |
79 | public function move( $target ) { |
80 | $this->readOnlyError(); |
81 | } |
82 | |
83 | /** |
84 | * @return string |
85 | */ |
86 | public function getDescriptionUrl() { |
87 | // Restore remote behavior |
88 | return File::getDescriptionUrl(); |
89 | } |
90 | |
91 | /** |
92 | * @param Language|null $lang Optional language to fetch description in. |
93 | * @return string|false |
94 | */ |
95 | public function getDescriptionText( ?Language $lang = null ) { |
96 | global $wgLang; |
97 | |
98 | if ( !$this->repo->fetchDescription ) { |
99 | return false; |
100 | } |
101 | |
102 | $lang ??= $wgLang; |
103 | $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() ); |
104 | if ( !$renderUrl ) { |
105 | return false; |
106 | } |
107 | |
108 | $touched = $this->repo->getReplicaDB()->newSelectQueryBuilder() |
109 | ->select( 'page_touched' ) |
110 | ->from( 'page' ) |
111 | ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] ) |
112 | ->caller( __METHOD__ )->fetchField(); |
113 | if ( $touched === false ) { |
114 | return false; // no description page |
115 | } |
116 | |
117 | $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
118 | $fname = __METHOD__; |
119 | |
120 | return $cache->getWithSetCallback( |
121 | $this->repo->getLocalCacheKey( |
122 | 'file-foreign-description', |
123 | $lang->getCode(), |
124 | md5( $this->getName() ), |
125 | $touched |
126 | ), |
127 | $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE, |
128 | static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) { |
129 | wfDebug( "Fetching shared description from $renderUrl" ); |
130 | $res = MediaWikiServices::getInstance()->getHttpRequestFactory()-> |
131 | get( $renderUrl, [], $fname ); |
132 | if ( !$res ) { |
133 | $ttl = WANObjectCache::TTL_UNCACHEABLE; |
134 | } |
135 | |
136 | return $res; |
137 | } |
138 | ); |
139 | } |
140 | |
141 | /** |
142 | * Get short description URL for a file based on the page ID. |
143 | * |
144 | * @return string|null |
145 | * @throws DBUnexpectedError |
146 | * @since 1.27 |
147 | */ |
148 | public function getDescriptionShortUrl() { |
149 | $dbr = $this->repo->getReplicaDB(); |
150 | $pageId = $dbr->newSelectQueryBuilder() |
151 | ->select( 'page_id' ) |
152 | ->from( 'page' ) |
153 | ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] ) |
154 | ->caller( __METHOD__ )->fetchField(); |
155 | |
156 | if ( $pageId !== false ) { |
157 | $url = $this->repo->makeUrl( [ 'curid' => $pageId ] ); |
158 | if ( $url !== false ) { |
159 | return $url; |
160 | } |
161 | } |
162 | return null; |
163 | } |
164 | |
165 | } |
166 | |
167 | /** @deprecated class alias since 1.44 */ |
168 | class_alias( ForeignDBFile::class, 'ForeignDBFile' ); |