Search code examples
phpmediawikiradiusmediawiki-extensions

Mediawiki Error: Call to undefined method User::saveToCache()


I recently updated a mediawiki installation to 1.30 and are now working on the plugin errors that came in the trail of the update.

My most immediate error is with the RadiusAuthPlugin for Mediawiki. When trying to login the following error is displayed on the page but the login was successful:

[3d3906e176c5476982ff8037] /MEDIAWIKI/index.php?title=Spezial:Login&returnto=Mainpage Error from line 75 of /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/extensions/RadiusAuthPlugin/RadiusAuthPlugin.php: Call to undefined method User::saveToCache()

Backtrace:

#0 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/auth/AuthPluginPrimaryAuthenticationProvider.php(145): RadiusAuthPlugin->updateUser(User)

#1 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/Hooks.php(177): MediaWiki\Auth\AuthPluginPrimaryAuthenticationProvider->onUserLoggedIn(User)

#2 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/Hooks.php(205): Hooks::callHook(string, array, array, NULL)

#3 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/auth/AuthManager.php(2388): Hooks::run(string, array)

#4 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/auth/AuthManager.php(690): MediaWiki\Auth\AuthManager->setSessionDataForUser(User, boolean)

#5 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/auth/AuthManager.php(382): MediaWiki\Auth\AuthManager->continueAuthentication(array)

#6 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/specialpage/AuthManagerSpecialPage.php(353): MediaWiki\Auth\AuthManager->beginAuthentication(array, string)

#7 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/specialpage/AuthManagerSpecialPage.php(482): AuthManagerSpecialPage->performAuthenticationStep(string, array)

#8 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/htmlform/HTMLForm.php(669): AuthManagerSpecialPage->handleFormSubmit(array, VFormHTMLForm)

#9 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/specialpage/AuthManagerSpecialPage.php(416): HTMLForm->trySubmit()

#10 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/specialpage/LoginSignupSpecialPage.php(316): AuthManagerSpecialPage->trySubmit()

#11 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/specialpage/SpecialPage.php(522): LoginSignupSpecialPage->execute(NULL)

#12 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/specialpage/SpecialPageFactory.php(578): SpecialPage->run(NULL)

#13 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/MediaWiki.php(287): SpecialPageFactory::executePath(Title, RequestContext)

#14 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/MediaWiki.php(851): MediaWiki->performRequest()

#15 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/includes/MediaWiki.php(523): MediaWiki->main()

#16 /usr/srv/www/vhosts/HOSTNAME/htdocs-ssl/MEDIAWIKI/index.php(43): MediaWiki->run()

#17 {main}

(I censored identifying parts of the path for security reasons)

The RadiusAuthPlugin.php:

<?php
require_once("$IP/includes/AuthPlugin.php");
require_once("radius.class.php");
require_once("$IP/includes/GlobalFunctions.php");

error_reporting(E_ALL);

class RadiusAuthPlugin extends AuthPlugin
{
    function userExists($username)
    {
        return TRUE;
    }

    function authenticate($username, $password)
    {
        global $wgRadiusAuthPluginServers, $wgRadiusAuthPluginSecret;

        $username = strtolower($username);
        //$handle=fopen("/tmp/radius","w");
        //fwrite($handle,"$username;$password;\n");

        foreach($wgRadiusAuthPluginServers as $server)
        {
          $radius = new Radius($server, $wgRadiusAuthPluginSecret);
          //$radius->SetNasIpAddress('NAS_IP_ADDRESS'); // Needed for some devi$
          //fwrite($handle,"Radius Objekt angelegt\n");
          if ($radius->AccessRequest($username, $password))
          {
              return TRUE;
              //fwrite($handle,"Auth successful\n");
          }
          //else{
          //    fwrite($handle,"Auth not successful\n");
          //  }

        }
        //fclose($handle);
        return FALSE;
    }

    function modifyUITemplate(&$template, &$type)
    {
        global $wgRadiusAuthPluginExtrafields;
        $template->set('usedomain', FALSE);
        $template->set('useemail', FALSE);
        $template->set('create', FALSE);
        //$template->set('create', TRUE);
        $template->set('canremember', FALSE);
        $template->set('extrafields', $wgRadiusAuthPluginExtrafields);
    }

    function autoCreate()
    {
        global $wgRadiusAuthPluginAutoCreate;
        if(isset($wgRadiusAuthPluginAutoCreate))
        {
            if(is_bool($wgRadiusAuthPluginAutoCreate))
            {
                return $wgRadiusAuthPluginAutoCreate;
            }
        }
        return FALSE;
    }

    function validDomain($domain)
    {
        return TRUE;
    }

    function updateUser(&$user)
    {
        global $wgRadiusAuthPluginMaildomain;
        $user->setEmail($user->getName()."@".$wgRadiusAuthPluginMaildomain);
        $user->saveToCache();
        return TRUE;
    }

    function allowPasswordChange()
    {
        //return false;
        return TRUE; // since Ubuntu 14.04
    }

    function allowPropChange($prop = '')
    {
        return FALSE;
    }

    function allowSetLocalPassword()
    {
        return true;
    }

    function setPassword($user, $password)
    {
        return true;
    }

    function updateExternalDB($user)
    {
        return true;
    }

    function canCreateAccounts()
    {
#       return FALSE;
        return TRUE;
    }

    function adduser($user, $password, $email = '', $realname = '')
    {
        return false;
#        return true;
    }

    function strict()
    {
        global $wgRadiusAuthPluginStrict;
        if(isset($wgRadiusAuthPluginStrict))
        {
            if(is_bool($wgRadiusAuthPluginStrict))
            {
                return $wgRadiusAuthPluginStrict;
            }
        }
        return TRUE;
    }

    function strictUserAuth($user)
    {
        global $wgRadiusAuthPluginStrictUserAuth;
        if(isset($wgRadiusAuthPluginStrictUserAuth))
        {
            if(is_bool($wgRadiusAuthPluginStrictUserAuth))
            {
                return $wgRadiusAuthPluginStrictUserAuth;
            }
            }
        }
        return TRUE;
    }

    function initUser(&$user, $autocreate = false)
    {
        global $wgRadiusAuthPluginMaildomain, $wgSitename, $wgRadiusAuthPluginM$
        $user->setEmail($user->getName()."@".$wgRadiusAuthPluginMaildomain);
        $user->setEmailAuthenticationTimestamp(wfTimestamp(TS_MW));
        $user->sendMail("[".$wgSitename."] ".$wgRadiusAuthPluginMailSubject,$wg$
        $user->removeGroup("User");
        //$user->removeGroup("auto-registered User");
        //$user->addGroup("USER");
    }
}

$wgExtensionCredits['other'][] = array(
    'name' => 'RadiusAuthPlugin',
    'version' => '1.1.0',
    'author' => 'James Young',
    'author' => 'edited by Andreas Ihrig',
    'description' => 'Automatic login with a RADIUS server; now with Setting-Op$
);

?>

I have no idea what to do about that and I'm grateful for any help.

Thanks so far


Solution

  • User::saveToCache was removed two years ago. (Before that, its documentation said "This method should not be called outside the User class". Those warnings are there for a reason.) Why would somebody save changes to the cache but not to the disk anyway? Frankly, the author of that plugin does not seem to have much idea of what they are doing.

    You could try replacing saveToCache with saveSettings. Although ideally it should check first whether the email address is already correct to avoid a pointless DB write. And probably call confirmEmail too since the email address comes from an authoritative source.