我正在编写一个扩展,允许我添加魔术词:CURRENTUSER
,CURRENTUSERREALNAME
,CURRENTUSERLANGABBR
,CURRENTUSERGROUPS
,现在我想添加CURRENTUSEREDITCOUNT
和CURRENTUSEREDITCOUNTALL
。
我的代码的这一部分目前是:
function wfGetCustomVariable(&$parser,&$cache,&$index,&$ret) {
switch ($index) {
case MAG_CURRENTUSER:
$parser->disableCache(); # Mark this content as uncacheable
$ret = $GLOBALS['wgUser']->getName();
break;
case MAG_CURRENTUSERREALNAME:
$parser->disableCache(); # Mark this content as uncacheable
$ret = $GLOBALS['wgUser']->getRealName();
break;
case MAG_CURRENTUSERLANGABBR
$parser->disableCache(); # Mark this content as uncacheable
$ret = $GLOBALS['wgLang']->getCode();
break;
case MAG_CURRENTUSERGROUPS
$parser->disableCache(); # Mark this content as uncacheable
$array = $GLOBALS['wgUser']->getEffectiveGroups();
$ret = implode(",", $array);
break;
}
return true;
}
但是,我似乎找不到编辑计数的$GLOBAL。 我根据其他扩展程序进行了一些研究,这些扩展程序出于不同的原因使用不同的编辑计数,并发现:
对于 CURRENTUSEREDITCOUNT:
function wfContributionseditcount( $uid ) {
if ( $uid != 0 ) {
global $wgOut, $wgLang;
$wgOut->addWikiText( wfMsgExt( 'contributionseditcount', array( 'parsemag' ),
$wgLang->formatNum( User::edits( $uid ) ),
User::whoIs( $uid ) ) );
}
return true;
}
对于 CURRENTUSEREDITCOUNTALL:
public function execute( $params ) {
global $wgOut, $wgUser;
$skin = $wgUser->getSkin();
$this->setHeaders();
$this->loadRequest( $params );
$wgOut->addHTML( $this->makeForm() );
if( $this->target ) {
if( User::isIP( $this->target ) ) {
$this->showResults( $this->countEditsReal( 0, $this->target ) );
} else {
$id = User::idFromName( $this->target );
if( $id ) {
$this->showResults( $this->countEditsReal( $id, false ), $id );
} else {
$wgOut->addHTML( '<p>' . wfMsgHtml( 'countedits-nosuchuser', htmlspecialchars( $this->target ) ) . '</p>' );
}
}
}
$this->showTopTen( $wgOut );
return true;
}
我过去曾尝试过自己学习PHP,但一直在努力。 我在当地社区大学报名参加了PHP课程,但直到12年秋天才开始。 我是否找对地方了,或者是否有更简单的地方来查找用户的编辑计数?也许作为/trunk/phase3/include/User.php 的一部分? 我应该提到这需要在运行 MW 1.17.1 的 wiki 上运行,所以 classUser 不会在 MW 1.18+ 的地方工作。
如果你想改变编辑计数的定义,也许你应该直接更改代码,在删除页面后减少用户的编辑计数。