미디어위키:Liberty-Navbar는 다음과 같이 적용했습니다.
protected function parseNavbar() {
global $wgArticlePath;
$headings = [];
$skin = $this->getSkin();
$userName = $skin->getUser()->getName();
$userLang = $skin->getLanguage()->mCode;
$globalData = ContentHandler::getContentText( WikiPage::factory(
Title::newFromText( 'Liberty-Navbar', NS_MEDIAWIKI )
)->getContent( RevisionRecord::RAW ) );
$globalLangData = ContentHandler::getContentText( WikiPage::factory(
Title::newFromText( 'Liberty-Navbar/' . $userLang, NS_MEDIAWIKI )
)->getContent( RevisionRecord::RAW ) );
$userData = ContentHandler::getContentText( WikiPage::factory(
Title::newFromText( $userName . '/Liberty-Navbar', NS_USER )
)->getContent( RevisionRecord::RAW ) );
if ( !empty( $userData ) ) {
$data = $userData;
} elseif ( !empty( $globalLangData ) ) {
$data = $globalLangData;
} else {
$data = $globalData;
}
if ( empty( $data ) ) {
return $headings;
}
$lines = explode( "\n", $data );
$types = [ 'icon', 'display', 'title', 'link', 'access', 'class' ];
foreach ( $lines as $line ) {
$line = rtrim( $line, "\r" );
if ( $line[0] !== '*' ) {
continue;
}
if ( $line[1] !== '*' ) {
// First level menu
$data = [];
$split = explode( '|', $line );
$split[0] = substr( $split[0], 1 );
foreach ( $split as $key => $value ) {
$valueArr = explode( '=', trim( $value ) );
if ( isset( $valueArr[1] ) ) {
$data[$valueArr[0]] = $valueArr[1];
} else {
$data[$types[$key]] = trim( $value );
}
}
$icon = isset( $data['icon'] ) ? htmlentities( $data['icon'], ENT_QUOTES, 'UTF-8' ) : null;
$group = isset( $data['group'] ) ? htmlentities( $data['group'], ENT_QUOTES, 'UTF-8' ) : null;
$right = isset( $data['right'] ) ? htmlentities( $data['right'], ENT_QUOTES, 'UTF-8' ) : null;
if ( isset( $data['display'] ) ) {
$textObj = $skin->msg( $data['display'] );
if ( $textObj->isDisabled() ) {
$text = htmlentities( $data['display'], ENT_QUOTES, 'UTF-8' );
} else {
$text = $textObj->text();
}
} else {
$text = '';
}
if ( empty( $icon ) && empty( $text ) ) {
continue;
}
if ( isset( $data['title'] ) ) {
$titleObj = $skin->msg( $data['title'] );
if ( $titleObj->isDisabled() ) {
$title = htmlentities( $data['title'], ENT_QUOTES, 'UTF-8' );
} else {
$title = $titleObj->text();
}
} else {
$title = $text;
}
if ( isset( $data['link'] ) ) {
if ( preg_match( '/^((?:(?:http(?:s)?)?:)?\/\/(?:.{4,}))$/i', $data['link'] ) ) {
$href = htmlentities( $data['link'], ENT_QUOTES, 'UTF-8' );
} else {
$href = str_replace( '%3A', ':', urlencode( $data['link'] ) );
$href = str_replace( '$1', $href, $wgArticlePath );
}
} else {
$href = null;
}
$access = isset( $data['access'] ) ? preg_match( '/^([0-9a-z]{1})$/i', $data['access'] ) ? $data['access'] : '' : null;
$classes = isset( $data['class'] ) ? array_map( 'trim', explode( ',', htmlentities( $data['class'], ENT_QUOTES, 'UTF-8' ) ) ) : [];protected function parseNavbar() {
global $wgArticlePath;
$headings = [];
$currentHeading = null;
$skin = $this->getSkin();
$userName = $skin->getUser()->getName();
$userLang = $skin->getLanguage()->mCode;
$globalData = ContentHandler::getContentText( WikiPage::factory(
Title::newFromText( 'Liberty-Navbar', NS_MEDIAWIKI )
)->getContent( RevisionRecord::RAW ) );
$globalLangData = ContentHandler::getContentText( WikiPage::factory(
Title::newFromText( 'Liberty-Navbar/' . $userLang, NS_MEDIAWIKI )
)->getContent( RevisionRecord::RAW ) );
$userData = ContentHandler::getContentText( WikiPage::factory(
Title::newFromText( $userName . '/Liberty-Navbar', NS_USER )
)->getContent( RevisionRecord::RAW ) );
if ( !empty( $userData ) ) {
$data = $userData;
} elseif ( !empty( $globalLangData ) ) {
$data = $globalLangData;
} else {
$data = $globalData;
}
// Well, [[MediaWiki:Liberty-Navbar]] *should* have some content, but
// if it doesn't, bail out here so that we don't trigger E_NOTICEs
// about undefined indexes later on
if ( empty( $data ) ) {
return $headings;
}
$lines = explode( "\n", $data );
$types = [ 'icon', 'display', 'title', 'link', 'access', 'class' ];
foreach ( $lines as $line ) {
$line = rtrim( $line, "\r" );
if ( $line[0] !== '*' ) {
// Line does not start with '*'
continue;
}
if ( $line[1] !== '*' ) {
// First level menu
$data = [];
$split = explode( '|', $line );
$split[0] = substr( $split[0], 1 );
foreach ( $split as $key => $value ) {
$valueArr = explode( '=', trim( $value ) );
if ( isset( $valueArr[1] ) ) {
$data[$valueArr[0]] = $valueArr[1];
} else {
$data[$types[$key]] = trim( $value );
}
}
// Icon
$icon = isset( $data['icon'] ) ? htmlentities( $data['icon'], ENT_QUOTES, 'UTF-8' ) : null;
// Group
$group = isset( $data['group'] ) ? htmlentities( $data['group'], ENT_QUOTES, 'UTF-8' ) : null;
// Right
$right = isset( $data['right'] ) ? htmlentities( $data['right'], ENT_QUOTES, 'UTF-8' ) : null;
// support the usual [[MediaWiki:Sidebar]] syntax of
// ** link target|<some MW: message name> and if the
// thing on the right side of the pipe isn't the name of a MW:
// message, then and _only_ then render it as-is
if ( isset( $data['display'] ) ) {
$textObj = $skin->msg( $data['display'] );
if ( $textObj->isDisabled() ) {
$text = htmlentities( $data['display'], ENT_QUOTES, 'UTF-8' );
} else {
$text = $textObj->text();
}
} else {
$text = '';
}
// If icon and text both empty
if ( empty( $icon ) && empty( $text ) ) {
continue;
}
// Title
if ( isset( $data['title'] ) ) {
$titleObj = $skin->msg( $data['title'] );
if ( $titleObj->isDisabled() ) {
$title = htmlentities( $data['title'], ENT_QUOTES, 'UTF-8' );
} else {
$title = $titleObj->text();
}
} else {
$title = $text;
}
// Link href
if ( isset( $data['link'] ) ) {
// @todo CHECKME: Should this use wfUrlProtocols() or somesuch instead?
if ( preg_match( '/^((?:(?:http(?:s)?)?:)?\/\/(?:.{4,}))$/i', $data['link'] ) ) {
$href = htmlentities( $data['link'], ENT_QUOTES, 'UTF-8' );
} else {
$href = str_replace( '%3A', ':', urlencode( $data['link'] ) );
$href = str_replace( '$1', $href, $wgArticlePath );
}
} else {
$href = null;
}
if ( isset( $data['access'] ) ) {
// Access
$access = preg_match( '/^([0-9a-z]{1})$/i', $data['access'] ) ? $data['access'] : '';
} else {
$access = null;
}
if ( isset( $data['class'] ) ) {
// Classes
$classes = explode( ',', htmlentities( $data['class'], ENT_QUOTES, 'UTF-8' ) );
foreach ( $classes as $key => $value ) {
$classes[$key] = trim( $value );
}
} else {
$classes = [];
}
$item = [
'access' => $access,
'classes' => $classes,
'href' => $href,
'icon' => $icon,
'text' => $text,
'title' => $title,
'group' => $group,
'right' => $right
];
$level2Children = &$item['children'];
$headings[] = $item;
continue;
}
if ( $line[2] !== '*' ) {
// Second level menu
$data = [];
$split = explode( '|', $line );
$split[0] = substr( $split[0], 2 );
foreach ( $split as $key => $value ) {
$valueArr = explode( '=', trim( $value ) );
if ( isset( $valueArr[1] ) ) {
$data[$valueArr[0]] = $valueArr[1];
} else {
$data[$types[$key]] = trim( $value );
}
}
// Icon
$icon = isset( $data['icon'] ) ? htmlentities( $data['icon'], ENT_QUOTES, 'UTF-8' ) : null;
// Group
$group = isset( $data['group'] ) ? htmlentities( $data['group'], ENT_QUOTES, 'UTF-8' ) : null;
// Right
$right = isset( $data['right'] ) ? htmlentities( $data['right'], ENT_QUOTES, 'UTF-8' ) : null;
// support the usual [[MediaWiki:Sidebar]] syntax of
// ** link target|<some MW: message name> and if the
// thing on the right side of the pipe isn't the name of a MW:
// message, then and _only_ then render it as-is
if ( isset( $data['display'] ) ) {
$textObj = $skin->msg( $data['display'] );
if ( $textObj->isDisabled() ) {
$text = htmlentities( $data['display'], ENT_QUOTES, 'UTF-8' );
} else {
$text = $textObj->text();
}
} else {
$text = '';
}
// If icon and text both empty
if ( empty( $icon ) && empty( $text ) ) {
continue;
}
// Title
if ( isset( $data['title'] ) ) {
$titleObj = $skin->msg( $data['title'] );
if ( $titleObj->isDisabled() ) {
$title = htmlentities( $data['title'], ENT_QUOTES, 'UTF-8' );
} else {
$title = $titleObj->text();
}
} else {
$title = $text;
}
if ( isset( $data['link'] ) ) {
// Link href
// @todo CHECKME: Should this use wfUrlProtocols() or somesuch instead?
if ( preg_match( '/^((?:(?:http(?:s)?)?:)?\/\/(?:.{4,}))$/i', $data['link'] ) ) {
$href = htmlentities( $data['link'], ENT_QUOTES, 'UTF-8' );
} else {
$href = str_replace( '%3A', ':', urlencode( $data['link'] ) );
$href = str_replace( '$1', $href, $wgArticlePath );
}
}
if ( isset( $data['access'] ) ) {
// Access
$access = preg_match( '/^([0-9a-z]{1})$/i', $data['access'] ) ? $data['access'] : '';
} else {
$access = null;
}
if ( isset( $data['class'] ) ) {
// Classes
$classes = explode( ',', htmlentities( $data['class'], ENT_QUOTES, 'UTF-8' ) );
foreach ( $classes as $key => $value ) {
$classes[$key] = trim( $value );
}
} else {
$classes = [];
}
$item = [
'access' => $access,
'classes' => $classes,
'href' => $href,
'icon' => $icon,
'text' => $text,
'title' => $title,
'group' => $group,
'right' => $right
];
$level3Children = &$item['children'];
$level2Children[] = $item;
continue;
}
if ( $line[3] !== '*' ) {
// Third level menu
$data = [];
$split = explode( '|', $line );
$split[0] = substr( $split[0], 3 );
foreach ( $split as $key => $value ) {
$valueArr = explode( '=', trim( $value ) );
if ( isset( $valueArr[1] ) ) {
$data[$valueArr[0]] = $valueArr[1];
} else {
$data[$types[$key]] = trim( $value );
}
}
// Icon
$icon = isset( $data['icon'] ) ? htmlentities( $data['icon'], ENT_QUOTES, 'UTF-8' ) : null;
// Group
$group = isset( $data['group'] ) ? htmlentities( $data['group'], ENT_QUOTES, 'UTF-8' ) : null;
// Right
$right = isset( $data['right'] ) ? htmlentities( $data['right'], ENT_QUOTES, 'UTF-8' ) : null;
// support the usual [[MediaWiki:Sidebar]] syntax of
// ** link target|<some MW: message name> and if the
// thing on the right side of the pipe isn't the name of a MW:
// message, then and _only_ then render it as-is
if ( isset( $data['display'] ) ) {
$textObj = $skin->msg( $data['display'] );
if ( $textObj->isDisabled() ) {
$text = htmlentities( $data['display'], ENT_QUOTES, 'UTF-8' );
} else {
$text = $textObj->text();
}
} else {
$text = '';
}
// If icon and text both empty
if ( empty( $icon ) && empty( $text ) ) {
continue;
}
// Title
if ( isset( $data['title'] ) ) {
$titleObj = $skin->msg( $data['title'] );
if ( $titleObj->isDisabled() ) {
$title = htmlentities( $data['title'], ENT_QUOTES, 'UTF-8' );
} else {
$title = $titleObj->text();
}
} else {
$title = $text;
}
// Link href
// @todo CHECKME: Should this use wfUrlProtocols() or somesuch instead?
if ( preg_match( '/^((?:(?:http(?:s)?)?:)?\/\/(?:.{4,}))$/i', $data['link'] ) ) {
$href = htmlentities( $data['link'], ENT_QUOTES, 'UTF-8' );
} else {
$href = str_replace( '%3A', ':', urlencode( $data['link'] ) );
$href = str_replace( '$1', $href, $wgArticlePath );
}
// Access
if ( isset( $data['access'] ) ) {
$access = preg_match( '/^([0-9a-z]{1})$/i', $data['access'] ) ? $data['access'] : '';
} else {
$access = null;
}
if ( isset( $data['class'] ) ) {
// Classes
$classes = explode( ',', htmlentities( $data['class'], ENT_QUOTES, 'UTF-8' ) );
foreach ( $classes as $key => $value ) {
$classes[$key] = trim( $value );
}
} else {
$classes = [];
}
$item = [
'access' => $access,
'classes' => $classes,
'href' => $href,
'icon' => $icon,
'text' => $text,
'title' => $title,
'group' => $group,
'right' => $right
];
$level3Children[] = $item;
continue;
} else {
// Not supported
continue;
}
}
return $headings;
}