ParsoidParser: Record ParserOptions watcher on ParserOutput object
[mediawiki.git] / includes / ExternalLinks / ExternalLinksLookup.php
blob494bfa6f8dcee7aefdc6ff4a1d39fef8165eeb3c
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.
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
18 * @file
21 namespace MediaWiki\ExternalLinks;
23 use MediaWiki\MainConfigNames;
24 use MediaWiki\MediaWikiServices;
25 use Wikimedia\Rdbms\IReadableDatabase;
27 /**
28 * Functions for looking up externallinks table
30 class ExternalLinksLookup {
32 /**
33 * Return an array of external links for a given page id
35 * @stable to call
36 * @param int $pagId
37 * @param IReadableDatabase $dbr
38 * @param string $fname
39 * @return string[] array of external links
41 public static function getExternalLinksForPage( int $pagId, IReadableDatabase $dbr, $fname ) {
42 $extlinkStage = MediaWikiServices::getInstance()->getMainConfig()->get(
43 MainConfigNames::ExternalLinksSchemaMigrationStage
45 if ( $extlinkStage & SCHEMA_COMPAT_READ_OLD ) {
46 return $dbr->newSelectQueryBuilder()
47 ->select( 'el_to' )
48 ->distinct()
49 ->from( 'externallinks' )
50 ->where( [ 'el_from' => $pagId ] )
51 ->caller( $fname )->fetchFieldValues();
52 } else {
53 $links = [];
54 $res = $dbr->newSelectQueryBuilder()
55 ->select( [ 'el_to_domain_index', 'el_to_path' ] )
56 ->from( 'externallinks' )
57 ->where( [ 'el_from' => $pagId ] )
58 ->caller( $fname )->fetchResultSet();
59 foreach ( $res as $row ) {
60 $links[] = LinkFilter::reverseIndexe( $row->el_to_domain_index ) . $row->el_to_path;
62 return $links;