为coder建立了一个“编程百科”http://codingwiki.info,codingwiki采用mediawiki,这里记录详细的配置:
1、首先,配置logo
# logo
$wgLogo = "/logo.png";
2、配置时间
## Timezone Settings
$wgLocaltimezone = "Asia/Shanghai";
$oldtz = getenv("TZ");
putenv("TZ=$wgLocaltimezone");
$wgLocalTZoffset = date("Z") / 3600;
putenv("TZ=$oldtz");
3、配置上传
#开启图片上传
$wgEnableUploads= true;
#上传文件类型
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg','doc','ppt','pdf' );
4、urlrewrite Url重写
#url REWRITE
$wgScriptPath = "";
$wgArticlePath = "/$1";
$wgUsePathInfo = true;
$wgScriptExtension = ".php";
服务器采用nginx,添加下面的配置
location / {
if (!-e $request_filename) {
rewrite ^/([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last;
}
}
5、添加常用扩展
#SyntaxHighlight
require_once("$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php");
#ParserFunctions
require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );
6、实现自己的扩展——找出wiki最热条目和最新条目,以及热门分类,通过扩展tag实现
直接贴代码,详细效果见
http://codingwiki.info/%E9%A6%96%E9%A1%B5,
http://codingwiki.info/%E5%88%86%E7%B1%BB:.NET
<?php $wgHooks['ParserFirstCallInit'][] = 'efCodingWikiTagParserInit'; function efCodingWikiTagParserInit( &$parser ) { $parser->setHook( 'hotpages', 'efHotPageRender' ); $parser->setHook( 'hotcategories', 'efHotCategoryRender' ); $parser->setHook( 'newpage', 'efNewPageRender' ); return true; } function makePageListItem( $row ) { global $wgUser; $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); if( !is_null( $title ) ) { $skin = $wgUser->getSkin(); $link = $row->page_is_redirect ? '<span class="allpagesredirect">' . $skin->makeKnownLinkObj( $title ) . '</span>' : $skin->makeKnownLinkObj( $title ); return( "<li>{$link}({$row->page_counter}次)</li>\n" ); } else { return( "<!-- Invalid title " . htmlspecialchars( $row->page_title ) . " in namespace " . htmlspecialchars( $row->page_namespace ) . " -->\n" ); } } function efHotPageRender( $input, $args, $parser, $frame ) { global $wgRequest, $wgOut, $wgContLang, $wgLang; $dbr = wfGetDB( DB_SLAVE ); $limit = isset($args["count"])?$args["count"]:10; $res = null; if(isset($args["category"])){ $res = $dbr->select( array('page','categorylinks'), '*', array('cl_to' => "{$args['category']}"), __METHOD__, array( 'ORDER BY' => 'page_counter DESC', 'LIMIT' => "$limit", 'OFFSET' => '0', ), array( 'categorylinks' => array('JOIN','page_id=cl_from') ) ); }else{ $res = $dbr->select( 'page', array( 'page_namespace', 'page_title', 'page_counter', 'page_is_redirect' ), array('page_namespace'=>'0'), __METHOD__, array( 'ORDER BY' => 'page_counter DESC', 'LIMIT' => "$limit", 'OFFSET' => '0', ) ); } $result = "<ul>"; foreach ( $res as $row ) { $result .= makePageListItem( $row ); } $result .= "</ul>"; return $result; } function efHotCategoryRender( $input, $args, $parser, $frame ) { global $wgRequest, $wgOut, $wgContLang, $wgLang; $dbr = wfGetDB( DB_SLAVE ); $limit = isset($args["count"])?$args["count"]:10; $res = $dbr->select( 'category', '*', array(), __METHOD__, array( 'ORDER BY' => 'cat_pages DESC', 'LIMIT' => "$limit", 'OFFSET' => '0', ) ); $result = "<ul>"; foreach ( $res as $row ) { $result.= "<li><a href='/分类:{$row->cat_title}'>{$row->cat_title}</a>(<a href='/分类:{$row->cat_title}'>{$row->cat_pages}</a>)</li>\n" ; } $result .= "</ul>"; return $result; } function efNewPageRender( $input, $args, $parser, $frame ) { global $wgRequest, $wgOut, $wgContLang, $wgLang; $dbr = wfGetDB( DB_SLAVE ); $limit = isset($args["count"])?$args["count"]:10; $res = null; if(isset($args["category"])){ $res = $dbr->select( array('page','categorylinks'), '*', array('cl_to' => "{$args['category']}"), __METHOD__, array( 'ORDER BY' => 'page_id DESC', 'LIMIT' => "$limit", 'OFFSET' => '0', ), array( 'categorylinks' => array('JOIN','page_id=cl_from') ) ); }else{ $res = $dbr->select( 'page', array( 'page_namespace', 'page_title', 'page_counter', 'page_is_redirect' ), array(), __METHOD__, array( 'ORDER BY' => 'page_id DESC', 'LIMIT' => "$limit", 'OFFSET' => '0', ) ); } $result = "<ul>"; foreach ( $res as $row ) { $result .= makePageListItem( $row ); } $result .= "</ul>"; return $result; }