How do I find out how many edits a user has for my MediaWiki extension?

依然范特西╮ 提交于 2019-12-13 08:56:27

问题


I'm writing an extension that will allow me to add the magic words: CURRENTUSER, CURRENTUSERREALNAME, CURRENTUSERLANGABBR, CURRENTUSERGROUPS, and now I want to add CURRENTUSEREDITCOUNT and CURRENTUSEREDITCOUNTALL.

That section of my code is currently:

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;
}

However, I can't seem to find the $GLOBAL for the edit counts. I've done some research based on other extensions that use different edit counts for different reasons and have found:

For 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;
}

and for 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;
}

I have tried to learn PHP on my own in the past, and have struggled with it. I'm signed up for a PHP class at my local community college, but I do not start until Fall `12. Am I looking in the right place, or is there a simpler place to find the user's edit counts? Maybe as part of /trunk/phase3/includes/User.php someplace? I should mention this needs to run on a wiki running MW 1.17.1, so classUser would not work where-as it is MW 1.18+.


回答1:


If what you want is to change the definition of edit count, perhaps you should directly change the code where it reduces the user's editcount after a page is deleted.



来源:https://stackoverflow.com/questions/10219229/how-do-i-find-out-how-many-edits-a-user-has-for-my-mediawiki-extension

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!