mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 16:04:35 +00:00
57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
class EchoLinkNormalizer {
|
||
|
|
||
|
/**
|
||
|
* Utility method to ensure B/C compat with previous getPrimaryLink return
|
||
|
* types, until all of them have been fixed.
|
||
|
*
|
||
|
* @deprecated
|
||
|
* @param string|array|bool $link
|
||
|
* @return string|bool
|
||
|
*/
|
||
|
public static function normalizePrimaryLink( $link ) {
|
||
|
// B/C for old format: [url, label]
|
||
|
if ( !isset( $link['url'] ) ) {
|
||
|
return array(
|
||
|
'url' => $link[0],
|
||
|
'label' => $link[1],
|
||
|
);
|
||
|
}
|
||
|
|
||
|
// current primary link format: ['url' => ..., 'label' => ...]
|
||
|
return $link;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Utility method to ensure B/C compat with previous getSecondaryLinks
|
||
|
* return types, until all of them have been fixed.
|
||
|
*
|
||
|
* @deprecated
|
||
|
* @param array $link
|
||
|
* @return array
|
||
|
*/
|
||
|
public static function normalizeSecondaryLinks( array $link ) {
|
||
|
// B/C for old secondary links format: [url => label, ...]
|
||
|
if ( !isset( $link[0] ) || !isset( $link[0]['url'] ) ) {
|
||
|
$links = array();
|
||
|
foreach ( $link as $url => $text ) {
|
||
|
$links[] = array(
|
||
|
'url' => $url,
|
||
|
'label' => $text,
|
||
|
'description' => '',
|
||
|
'icon' => false,
|
||
|
'prioritized' => true,
|
||
|
);
|
||
|
}
|
||
|
return $links;
|
||
|
}
|
||
|
|
||
|
// current secondary links format: [['url' => ..., 'label' => ..., ...], ...]
|
||
|
return $link;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|