为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
001 |
<?php |
002 |
$wgHooks [ 'ParserFirstCallInit' ][] = 'efCodingWikiTagParserInit' ; |
003 |
|
004 |
function efCodingWikiTagParserInit( & $parser ) { |
005 |
$parser ->setHook( 'hotpages' , 'efHotPageRender' ); |
006 |
$parser ->setHook( 'hotcategories' , 'efHotCategoryRender' ); |
007 |
$parser ->setHook( 'newpage' , 'efNewPageRender' ); |
008 |
return true; |
009 |
} |
010 |
011 |
function makePageListItem( $row ) { |
012 |
global $wgUser ; |
013 |
$title = Title::makeTitleSafe( $row ->page_namespace, $row ->page_title ); |
014 |
if ( ! is_null ( $title ) ) { |
015 |
$skin = $wgUser ->getSkin(); |
016 |
$link = $row ->page_is_redirect |
017 |
? '<span class="allpagesredirect">' . $skin ->makeKnownLinkObj( $title ) . '</span>' |
018 |
: $skin ->makeKnownLinkObj( $title ); |
019 |
return ( "<li>{$link}({$row->page_counter}次)</li>\n" ); |
020 |
} else { |
021 |
return ( "<!-- Invalid title " . htmlspecialchars( $row ->page_title ) . " in namespace " . htmlspecialchars( $row ->page_namespace ) . " -->\n" ); |
022 |
} |
023 |
} |
024 |
|
025 |
function efHotPageRender( $input , $args , $parser , $frame ) { |
026 |
global $wgRequest , $wgOut , $wgContLang , $wgLang ; |
027 |
$dbr = wfGetDB( DB_SLAVE ); |
028 |
$limit = isset( $args [ "count" ])? $args [ "count" ]:10; |
029 |
$res = null; |
030 |
if (isset( $args [ "category" ])){ |
031 |
$res = $dbr ->select( |
032 |
array ( 'page' , 'categorylinks' ), |
033 |
'*' , |
034 |
array ( 'cl_to' => "{$args['category']}" ), |
035 |
__METHOD__ , |
036 |
array ( |
037 |
'ORDER BY' => 'page_counter DESC' , |
038 |
'LIMIT' => "$limit" , |
039 |
'OFFSET' => '0' , |
040 |
), |
041 |
array ( 'categorylinks' => array ( 'JOIN' , 'page_id=cl_from' ) ) |
042 |
); |
043 |
} else { |
044 |
$res = $dbr ->select( |
045 |
'page' , |
046 |
array ( |
047 |
'page_namespace' , |
048 |
'page_title' , |
049 |
'page_counter' , |
050 |
'page_is_redirect' |
051 |
), |
052 |
array ( 'page_namespace' => '0' ), |
053 |
__METHOD__ , |
054 |
array ( |
055 |
'ORDER BY' => 'page_counter DESC' , |
056 |
'LIMIT' => "$limit" , |
057 |
'OFFSET' => '0' , |
058 |
) |
059 |
); |
060 |
} |
061 |
$result = "<ul>" ; |
062 |
foreach ( $res as $row ) { |
063 |
$result .= makePageListItem( $row ); |
064 |
} |
065 |
$result .= "</ul>" ; |
066 |
return $result ; |
067 |
} |
068 |
069 |
function efHotCategoryRender( $input , $args , $parser , $frame ) { |
070 |
global $wgRequest , $wgOut , $wgContLang , $wgLang ; |
071 |
$dbr = wfGetDB( DB_SLAVE ); |
072 |
$limit = isset( $args [ "count" ])? $args [ "count" ]:10; |
073 |
$res = $dbr ->select( |
074 |
'category' , |
075 |
'*' , |
076 |
array (), |
077 |
__METHOD__ , |
078 |
array ( |
079 |
'ORDER BY' => 'cat_pages DESC' , |
080 |
'LIMIT' => "$limit" , |
081 |
'OFFSET' => '0' , |
082 |
) |
083 |
); |
084 |
$result = "<ul>" ; |
085 |
foreach ( $res as $row ) { |
086 |
$result .= "<li><a href='/分类:{$row->cat_title}'>{$row->cat_title}</a>(<a href='/分类:{$row->cat_title}'>{$row->cat_pages}</a>)< /li>\n" ; |
087 |
} |
088 |
$result .= "</ul>" ; |
089 |
return $result ; |
090 |
} |
091 |
092 |
function efNewPageRender( $input , $args , $parser , $frame ) { |
093 |
global $wgRequest , $wgOut , $wgContLang , $wgLang ; |
094 |
$dbr = wfGetDB( DB_SLAVE ); |
095 |
$limit = isset( $args [ "count" ])? $args [ "count" ]:10; |
096 |
$res = null; |
097 |
|
098 |
if (isset( $args [ "category" ])){ |
099 |
$res = $dbr ->select( |
100 |
array ( 'page' , 'categorylinks' ), |
101 |
'*' , |
102 |
array ( 'cl_to' => "{$args['category']}" ), |
103 |
__METHOD__ , |
104 |
array ( |
105 |
'ORDER BY' => 'page_id DESC' , |
106 |
'LIMIT' => "$limit" , |
107 |
'OFFSET' => '0' , |
108 |
), |
109 |
array ( 'categorylinks' => array ( 'JOIN' , 'page_id=cl_from' ) ) |
110 |
); |
111 |
} else { |
112 |
$res = $dbr ->select( |
113 |
'page' , |
114 |
array ( |
115 |
'page_namespace' , |
116 |
'page_title' , |
117 |
'page_counter' , |
118 |
'page_is_redirect' |
119 |
), |
120 |
array (), |
121 |
__METHOD__ , |
122 |
array ( |
123 |
'ORDER BY' => 'page_id DESC' , |
124 |
'LIMIT' => "$limit" , |
125 |
'OFFSET' => '0' , |
126 |
) |
127 |
); |
128 |
} |
129 |
$result = "<ul>" ; |
130 |
foreach ( $res as $row ) { |
131 |
$result .= makePageListItem( $row ); |
132 |
} |
133 |
$result .= "</ul>" ; |
134 |
return $result ; |
135 |
} |