Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1429394
ExternalLinksTable.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
ExternalLinksTable.php
View Options
<?php
namespace
MediaWiki\Deferred\LinksUpdate
;
use
MediaWiki\ExternalLinks\LinkFilter
;
use
MediaWiki\Parser\ParserOutput
;
/**
* externallinks
*
* Link ID format: string URL
*
* @since 1.38
*/
class
ExternalLinksTable
extends
LinksTable
{
/** @var array<string,array<string,true>> */
private
$newLinks
=
[];
/** @var array<string,array<string,true>>|null */
private
$existingLinks
;
public
function
setParserOutput
(
ParserOutput
$parserOutput
)
{
foreach
(
$parserOutput
->
getExternalLinks
()
as
$url
=>
$unused
)
{
foreach
(
LinkFilter
::
makeIndexes
(
$url
)
as
[
$domainIndex
,
$path
]
)
{
$this
->
newLinks
[
$domainIndex
][
$path
]
=
true
;
}
}
}
protected
function
getTableName
()
{
return
'externallinks'
;
}
protected
function
getFromField
()
{
return
'el_from'
;
}
protected
function
getExistingFields
()
{
return
[
'el_to_domain_index'
,
'el_to_path'
];
}
/**
* Get the existing links as an array
*
* @return array
*/
private
function
getExistingLinks
()
{
if
(
$this
->
existingLinks
===
null
)
{
$this
->
existingLinks
=
[];
foreach
(
$this
->
fetchExistingRows
()
as
$row
)
{
$this
->
existingLinks
[
$row
->
el_to_domain_index
][
$row
->
el_to_path
]
=
true
;
}
}
return
$this
->
existingLinks
;
}
protected
function
getNewLinkIDs
()
{
foreach
(
$this
->
newLinks
as
$domainIndex
=>
$paths
)
{
foreach
(
$paths
as
$path
=>
$unused
)
{
yield
[
(
string
)
$domainIndex
,
(
string
)
$path
];
}
}
}
protected
function
getExistingLinkIDs
()
{
foreach
(
$this
->
getExistingLinks
()
as
$domainIndex
=>
$paths
)
{
foreach
(
$paths
as
$path
=>
$unused
)
{
yield
[
(
string
)
$domainIndex
,
(
string
)
$path
];
}
}
}
protected
function
isExisting
(
$linkId
)
{
[
$domainIndex
,
$path
]
=
$linkId
;
return
isset
(
$this
->
getExistingLinks
()[
$domainIndex
][
$path
]
);
}
protected
function
isInNewSet
(
$linkId
)
{
[
$domainIndex
,
$path
]
=
$linkId
;
return
isset
(
$this
->
newLinks
[
$domainIndex
][
$path
]
);
}
protected
function
insertLink
(
$linkId
)
{
[
$domainIndex
,
$path
]
=
$linkId
;
$params
=
[
'el_to_domain_index'
=>
substr
(
$domainIndex
,
0
,
255
),
'el_to_path'
=>
$path
,
];
$this
->
insertRow
(
$params
);
}
protected
function
deleteLink
(
$linkId
)
{
[
$domainIndex
,
$path
]
=
$linkId
;
$this
->
deleteRow
(
[
'el_to_domain_index'
=>
substr
(
$domainIndex
,
0
,
255
),
'el_to_path'
=>
$path
]
);
if
(
$path
===
''
)
{
// el_to_path is nullable, but null is not valid in php arrays,
// so both values are handled as one key, delete both rows when exists
$this
->
deleteRow
(
[
'el_to_domain_index'
=>
substr
(
$domainIndex
,
0
,
255
),
'el_to_path'
=>
null
]
);
}
}
/**
* Get an array of URLs of the given type
*
* @param int $setType One of the link set constants as in LinksTable::getLinkIDs()
* @return string[]
*/
public
function
getStringArray
(
$setType
)
{
$ids
=
$this
->
getLinkIDs
(
$setType
);
$stringArray
=
[];
foreach
(
$ids
as
$linkId
)
{
[
$domainIndex
,
$path
]
=
$linkId
;
$stringArray
[]
=
LinkFilter
::
reverseIndexes
(
$domainIndex
)
.
$path
;
}
return
$stringArray
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 17:30 (10 h, 23 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
af/91/22493aa73b33a98a40e2a4c93dc5
Default Alt Text
ExternalLinksTable.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment