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.
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.
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
20 namespace MediaWiki\Linker
;
24 use Wikimedia\Rdbms\IDatabase
;
29 interface LinkTargetLookup
{
31 * Instantiate a new LinkTarget object based on a $row from the linktarget table.
33 * Use this method when a linktarget row was already fetched from the DB via a join.
34 * This method just constructs a new instance and does not try fetching missing
35 * values from the DB again.
37 * @param stdClass $row with the following fields:
43 public function newLinkTargetFromRow( stdClass
$row ): LinkTarget
;
46 * Find a link target by $id.
48 * @param int $linkTargetId
49 * @return LinkTarget|null Returns null if no link target with this $linkTargetId exists in the database.
51 public function getLinkTargetById( int $linkTargetId ): ?LinkTarget
;
54 * Attempt to assign an link target ID to the given $linkTarget. If it is already assigned,
55 * return the existing ID.
57 * @note If called within a transaction, the returned ID might become invalid
58 * if the transaction is rolled back, so it should not be passed outside of the
59 * transaction context.
61 * @param LinkTarget $linkTarget
62 * @param IDatabase $dbw The database connection to acquire the ID from.
63 * @return int linktarget ID greater then 0
64 * @throws RuntimeException if no linktarget ID has been assigned to this $linkTarget
66 public function acquireLinkTargetId( LinkTarget
$linkTarget, IDatabase
$dbw ): int;
69 * Return link target id if exists
71 * @param LinkTarget $linkTarget
72 * @return int|null linktarget ID greater then 0, null if not found
74 public function getLinkTargetId( LinkTarget
$linkTarget ): ?
int;