미디어위키 페이스북 좋아요 버튼 달기

How to add like button in Mediawiki
미디어위키 페이스북 좋아요 버튼 달기
미디어위키 좋아요 버튼 추가

Botón Me gusta.svg

1 파일 생성/업로드

  • FacebookLikeButton.php 파일을 아래 내용으로 생성한다. 이 소스코드는 한국어판(ko_KR)이다.
<?php
/* Wiki FacebookLikeButton MediaWiki extension
 * Installation Instructions: http://www.mediawiki.org/wiki/Extension:FacebookLikeButton
 * 2012-08-16 Article URL support. The tag changed. HTML5 code.
 * For another language support, you can replace "en_US". "de_DE", "ja_JP", "ko_KR" ...
 */
$wgExtensionFunctions[] = "facebooklikebuttonExtension";
function FacebookLikeButtonUrl() {
        $protocol = 'http';
        $port = '80';
        if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) { $protocol =  'https'; $port = '443'; }
        $port = $_SERVER['SERVER_PORT'] == $port ? '' : ':' . $_SERVER['SERVER_PORT'];
        return $protocol . '://' . $_SERVER['HTTP_HOST'] . $port . $_SERVER['SCRIPT_NAME'];
}
function facebooklikebuttonExtension() {
        global $wgParser;
        global $FacebookLikeButtonOnce;
        $wgParser->setHook( "fblike", "renderFacebookLikeButton" ); 
        $FacebookLikeButtonOnce='<div id="fb-root"></div><script src="http://connect.facebook.net/ko_KR/all.js#xfbml=1"></script>';
} 
function renderFacebookLikeButton( $input, $argv ) { 
        global $wgRequest;
        global $FacebookLikeButtonOnce;
        $layout = @$argv['layout'];
        $send = @$argv['send'];
        if( $layout != 'standard' && $layout != 'box_count' ) $layout = 'button_count';
        if( $send != 'true' ) $send = 'false';
        $once = $FacebookLikeButtonOnce;
        $FacebookLikeButtonOnce = '';
        $full_url = FacebookLikeButtonUrl().'/'.$wgRequest->getText('title');
        return $once.'<div>'.$wgRequest->getText('lang').'</div><div class="fb-like" data-href="'.$full_url.'" data-send="'.$send.'" data-layout="'.$layout.'" data-width="400"></div>';
}
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'Wiki FacebookLikeButton',
        'version' => '1.1.0',
        'author' => 'Piotr Zuk, Jmkim dot com',
        'url' => 'http://www.mediawiki.org/wiki/Extension:FacebookLikeButton',
        'description' => 'Mediawiki FacebookLikeButton Extension'
);
?>
  • extensions 폴더에 FacebookLikeButton 폴더를 만들고 위 파일을 그곳에 업로드한다.

2 LocalSettings.php 수정

미디어위키 폴더에 있는 LocalSettings.php의 맨아래에 다음 내용을 추가

require_once("$IP/extensions/FacebookLikeButton/FacebookLikeButton.php");

3 테스트

위키에 좋아요 버튼을 달아보자.

  • <fblike/>
<fblike/>
  • <fblike send="true"/>
<fblike send="true"/>
  • <fblike layout="box_count" send="true"/>
<fblike layout="box_count" send="true"/>
  • <fblike layout="standard" send="true"/>
<fblike layout="standard" send="true"/>

4 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}