注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

神魔破杜梓的叨叨堂

Programming every day!

 
 
 

日志

 
 
 
 

修正Mediawiki 插件 My Blog中的Bug  

2008-07-17 18:08:43|  分类: My Tech |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
安装了My Blog玩,结果发现了不少问题,比如这个错误:
Invalid non-numeric limit passed to limitResult()
还有最新的Mediawiki貌似链接都是 index.php?title=*******
而My Blog中是index.php/******
也可能是我用的IIS做服务器,用tomcat的话可能不会出现这个问题。
于是自己改了一下两个源文件,世界一下清净了 :)
SpecialPagesAllBlogs.php
<?php
$wgExtensionFunctions[] = "loadSpecialListAllBlogs";
require_once("includes/SpecialPage.php");

class SpecialListAllBlogs extends SpecialPage {

function SpecialListAllBlogs() {
SpecialPage::SpecialPage('ListAllBlogs', '', false);
$this->includable(true);
}

function execute( $parent = null ) {
global $wgRequest, $wgOut, $wgUser;
$wgOut->setArticleRelated( false );
$fname = 'listallblogs';


// Handle Errors
$target = $this->including() ? $wgRequest->getVal( 'title' ) :
(isset( $parent ) ? $parent : $wgRequest->getVal( 'target' ));

if (is_null($target)) {


return;
}

$target = Title::newFromURL( $target );
$skin = $wgUser->getSkin();
# if (!$this->including()) {
// Start Page

$wgOut->setPagetitle("Most Recent Blogs" );
$wgOut->addWikiText("__NOTOC__");


# $wgOut->addHTML('< ' . $skin->makeKnownLinkObj($target, '', '' ) . "<br />\n");
# }

// Do query
list($limit, $offset) = $wgRequest->getLimitOffset();
$dbr =& wfGetDB( DB_READ );
$limit = 10;
$offset = 0;

$result = $dbr->select( 'page' ,
array( 'page_namespace', 'page_title', 'page_touched' ),
array( 'page_namespace' => '2',
"page_title LIKE '%BlogEntry%'"),
$fname,
array( 'ORDER BY'=>'page_touched DESC','LIMIT' => $limit,'OFFSET' => $offset,) );

// Output results
if ( 0 == $dbr->numRows( $result ) ) {
$d = date( 'Y F d H:i:s T' );
$wgOut->addWikiText("Currently No Blog Entries.");
return;
}


$rows = array();

$d = date( 'Y F d H:i:s T' );

while ($row = $dbr->fetchObject($result)) {
$wgOut->addHTML('<table width=100% border=1 cellpadding=5 cellspacing=0 ><tr><td>');
$link = Title::makeTitle( $row->page_namespace, $row->page_title);

//这里的链接按照自己的需要修改
list($user1,$date1) = explode("/BlogEntry:_",$row->page_title,2);
$date1 = preg_replace('/_/', ' ', $date1);
$wgOut->addHTML("<table width=100%><tr><td align=left><font size=4><a href=\"/index.php?title=User:". $row->page_title ."\">$date1</a></font><br>Posted By: <a href=\"/index.php?title=User:$user1\">$user1</a></td><td valign=top align=right><a href=\"/index.php?title=User_talk:". $row->page_title ."\">Discussion</a><br><a href=\"/index.php?title=Special:ListSubBlogs/User:$user1\">$user1's Blog</a><td></tr></table>");

$tempvalue = "{{:User:" . $row->page_title . "}}";
$wgOut->addWikiText($tempvalue);
$wgOut->addHTML("<table width=100%><tr><td align=right>Blog Entry: ".$skin->makeKnownLinkObj($link)."</td></tr></table>");

$wgOut->addHTML('</td></tr></table><p>');
}

$dbr->freeResult($result);
$wgOut->addHTML($prevnext);
}
}


function loadSpecialListAllBlogs()
{
SpecialPage::addPage(new SpecialListAllBlogs);
}

?>

SpecialPageSubBlogs.php
<?php
$wgExtensionFunctions[] = "loadSpecialListSubBlogs";
require_once("includes/SpecialPage.php");

class SpecialListSubBlogs extends SpecialPage {

function SpecialListSubBlogs() {
SpecialPage::SpecialPage('ListSubBlogs', '', false);
$this->includable(true);
}

function execute( $parent = null ) {
global $wgRequest, $wgOut, $wgUser;
$wgOut->setArticleRelated( false );
$fname = 'listsubpages';


// Handle Errors
$target = $this->including() ? $wgRequest->getVal( 'title' ) :
(isset( $parent ) ? $parent : $wgRequest->getVal( 'target' ));

if (is_null($target)) {
$wgOut->errorpage( 'notargettitle', 'notargettext' );
return;
}

$target = Title::newFromURL( $target );
if( !$target ) {
$wgOut->errorpage( 'notargettitle', 'notargettext' );
return;
}

$skin = $wgUser->getSkin();
if (!$this->including()) {
// Start Page
$wgOut->setPagetitle( $target->getPrefixedText() );

$wgOut->addHTML('< ' . $skin->makeKnownLinkObj($target, '', '' ) . "<br />\n");
}

// Do query
list($limit, $offset) = $wgRequest->getLimitOffset();

$dbr =& wfGetDB( DB_READ );

$result = $dbr->select( 'page' ,
array( 'page_namespace', 'page_title' ),
array( 'page_namespace' => $target->getNamespace(),
"page_title LIKE " . $dbr->addQuotes($target->getDbKey() . '/%') ),
$fname,
//array( 'ORDER BY'=>'page_touched DESC','LIMIT' => "$offset,$limit" ) );
array( 'ORDER BY'=>'page_touched DESC','LIMIT' => $limit,'OFFSET' => $offset, ) );

// Output results
$wgOut->addWikiText('= ' . $target->getDbKey() . '\'s Blog =');

if ( 0 == $dbr->numRows( $result ) ) {
$d = date( 'Y F d H:i:s T' );
if ($wgUser->getName() == $target->getDbKey()) {
$wgOut->addWikiText('[[User:' . $wgUser->getName() . '/BlogEntry: ' . $d . ' | Add New Blog Entry]]');
}
$wgOut->addWikiText("Currently No Blog Entries.");
return;
}

$prevnext = wfViewPrevNext( $offset, $limit, $specialTitle,
'target=' . urlencode( $target->getPrefixedDbKey() ),
( $dbr->numRows( $res ) <= $limit ) );
$wgOut->addHTML( $prevnext );

$rows = array();

$d = date( 'Y F d H:i:s T' );
if ($wgUser->getName() == $target->getDbKey()) {
$wgOut->addWikiText('[[User:' . $wgUser->getName() . '/BlogEntry: ' . $d . ' | Add New Blog Entry]]');
}


while ($row = $dbr->fetchObject($result)) {
if (ereg("BlogEntry",$row->page_title)) {
$wgOut->addHTML('<table width=100% border=1 cellpadding=5 cellspacing=0 ><tr><td>');
$link = Title::makeTitle( $row->page_namespace, $row->page_title);

//这里的链接按照自己的需要修改
list($user1,$date1) = explode("/BlogEntry:_",$row->page_title,2);
$date1 = preg_replace('/_/', ' ', $date1);
$wgOut->addHTML("<table width=100%><tr><td align=left><font size=4><a href=\"/index.php?title=User:". $row->page_title ."\">$date1</a></font><br>Posted By: <a href=\"/index.php?title=User:$user1\">$user1</a></td><td valign=top align=right><a href=\"/index.php?title=User_talk:". $row->page_title ."\">Discussion</a><br><a href=\"/index.php?title=Special:ListSubBlogs/User:$user1\">$user1's Blog</a><td></tr></table>");

$tempvalue = "{{:User:" . $row->page_title . "}}";
$wgOut->addWikiText($tempvalue);
$wgOut->addHTML("<table width=100%><tr><td align=right>Blog Entry: ".$skin->makeKnownLinkObj($link)."</td></tr></table>");

$wgOut->addHTML('</td></tr></table><p>');


}
}

$dbr->freeResult($result);

$wgOut->addHTML($prevnext);
}
}


function loadSpecialListSubBlogs()
{
SpecialPage::addPage(new SpecialListSubBlogs);
}

?>
  评论这张
 
阅读(600)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017