以前要修改MediaWiki的页面输出内容,都是通过修改页面或者模板的代码来实现的,但最近在做手机版的时候,原始网站中有一些内容不是通过模板来实现的,而是直接嵌入文本在页面中,例如--~~~~这样的签名、时间,就不好通过修改模板删除。
今天咨询了同事,再仔细查看MediaWiki的相关PHP程序文件,终于是找到了修改的办法和地方,可以修改includes/OutputPage.php这个程序:
/**
* Append $text to the body HTML
*
* @param $text String: HTML
*/
public function addHTML( $text ) {
//jamesqi 2012-5
$start=strpos($text,'<dl><dd>--<a href=');
$end=strpos($text,'(CST)
</dd></dl>');
if ($start>1 and $end>$start+1) {
$text=substr($text,0,$start).substr($text,$end+16);
}
//jamesqi 2012-5$this->mBodytext .= $text;
}
在页面HTML源文件中找到需要删除的内容前后的特征字符串,然后很简单就可以去掉这中间的签名、时间信息。
另外,MediaWiki的分类页中每页200个条目的列表是分成了3列显示的,这在手机屏幕上显示也很拥挤了,我尝试在includes/CategoryPage.php中修改一点地方就可以改为单列显示:
/**
* Format a list of articles chunked by letter in a three-column
* list, ordered vertically.
*
* TODO: Take the headers into account when creating columns, so they're
* more visually equal.
*
* More distant TODO: Scrap this and use CSS columns, whenever IE finally
* supports those.
*
* @param $articles Array
* @param $articles_start_char Array
* @return String
* @private
*/
function columnList( $articles, $articles_start_char ) {
$columns = array_combine( $articles, $articles_start_char );
# Split into three columns
$columns = array_chunk( $columns, ceil( count( $columns ) / 3 ), true /* preserve keys */ );
$ret = '<table width="100%"><tr valign="top"><td>';
$prevchar = null;
foreach ( $columns as $column ) {
$colContents = array();
# Kind of like array_flip() here, but we keep duplicates in an
# array instead of dropping them.
foreach ( $column as $article => $char ) {
if ( !isset( $colContents[$char] ) ) {
$colContents[$char] = array();
}
$colContents[$char][] = $article;
}
$first = true;
foreach ( $colContents as $char => $articles ) {
$ret .= '<h3>' . htmlspecialchars( $char );
if ( $first && $char === $prevchar ) {
# We're continuing a previous chunk at the top of a new
# column, so add " cont." after the letter.
$ret .= ' ' . wfMsgHtml( 'listingcontinuesabbrev' );
}
$ret .= "</h3>\n";
$ret .= '<ul><li>';
$ret .= implode( "</li>\n<li>", $articles );
$ret .= '</li></ul>';
$first = false;
$prevchar = $char;
}
$ret .= "\n";//jamesqi 2012-5
// $ret .= "</td>\n<td>";
}$ret .= '</td></tr></table>';
return $ret;
}
可以看到,将最好几句中分列的td标签去掉后,这个表格就成为单行单列的了。
评论