/**
  * This function is called when the special page is accessed
  * @param $par parameters
  * @see includes/SpecialPage.php
  */
 function execute($par)
 {
     global $wgRequest, $wgOut;
     $this->setHeaders();
     $param = $wgRequest->getText('param');
     wfDebugLog(basename(__FILE__, ".php"), __METHOD__ . ': ' . "Parameters: {$param}");
     // build the page
     $html = "";
     if ($this->multiAuthPlugin->isLoggedIn()) {
         // login success
         $html .= "<p>" . wfMsg('msg_loginSuccess') . "</p>\n";
     } else {
         if (isset($_GET['method']) && $this->multiAuthPlugin->isValidMethod($_GET['method'])) {
             $this->initLogin($_GET['method']);
             // the above function will issue a redirect
         } else {
             if (!is_null($this->multiAuthPlugin->getCurrentMethodName()) && $this->multiAuthPlugin->getCurrentMethodName() != 'local') {
                 // external authentication success but not authorized
                 $html .= "<p>" . wfMsg('msg_notAuthorized') . "</p>\n";
                 unset($_SESSION['MA_methodName']);
             } else {
                 $this->addLoginLinks($html);
             }
         }
     }
     $wgOut->addHTML($html);
     $wgOut->returnToMain();
 }
 /**
  * This function is called if the special page is accessed
  * inspired by @see includes/special/SpecialUserlogout.php
  * @param $par parameters
  * @see includes/SpecialPage.php
  */
 function execute($par)
 {
     global $wgRequest, $wgOut, $wgUser;
     $this->setHeaders();
     $param = $wgRequest->getText('param');
     // build the page
     $html = "";
     if (!$this->multiAuthPlugin->isLoggedIn()) {
         // check if we should be redirected to an external URL after complete logout
         if ($this->multiAuthPlugin->config['internal']['redirectAfterLogoutComplete'] != '') {
             // do the redirect
             header('Location: ' . $this->multiAuthPlugin->config['internal']['redirectAfterLogoutComplete']);
             exit;
             // Stop execution here
         } else {
             $html .= "<p>" . wfMsg('msg_logoutSuccess') . "</p>\n";
         }
     } else {
         // get information about the currently active authentication method
         $currentMethodName = $this->multiAuthPlugin->getCurrentMethodName();
         if (!empty($currentMethodName) && $currentMethodName != 'local') {
             $this->doExternalLogout($html);
         } else {
             $this->doLocalLogout($html);
         }
     }
     $wgOut->addHTML($html);
     $wgOut->returnToMain();
 }
 /**
  * Initiates a two-stage logout process.
  * At first the external logout URL is called for external logout.
  * After return to this logout page a local logout is performed additionally.
  * @param string $html the variable containing the HTML code for the page
  */
 private function doExternalLogout(&$html)
 {
     global $wgUser;
     $oldName = $wgUser->getName();
     $currentMethod = $this->multiAuthPlugin->getCurrentMethod();
     $currentMethodName = $this->multiAuthPlugin->getCurrentMethodName();
     $libName = $this->multiAuthPlugin->getCurrentAuthLib();
     // first: local
     $success = $this->multiAuthPlugin->logout();
     if ($success) {
         // finish off the local logout
         wfRunHooks('UserLogoutComplete', array(&$wgUser, &$injectedHtml, $oldName));
         $return_url = $this->buildReturnURL($currentMethodName);
         wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . ': ' . "authLib = {$libName}");
         // second: external
         switch ($libName) {
             case 'simplesamlphp':
                 $ssphpPath = $this->multiAuthPlugin->config['paths']['libs']['simplesamlphp'];
                 require_once $ssphpPath . "/lib/_autoload.php";
                 $as = new SimpleSAML_Auth_Simple($currentMethod['auth']['spentityid']);
                 wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . ': ' . "Redirecting to SLO logout process: [SimpleSamlPHP] ReturnTo = {$return_url}");
                 $as->logout(array('ReturnTo' => $return_url));
                 exit;
                 // no execution past here!
                 break;
             default:
                 // prepare data
                 $link = $currentMethod['logout'];
                 $link_text = $link['text'];
                 $link_href = $link['href'];
                 // build the logout url
                 if (strstr($link_href, '{RETURN_URL}')) {
                     $link_href = str_replace('{RETURN_URL}', wfUrlencode($return_url), $link_href);
                 }
                 wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . "Redirecting to SLO login process: [URL] {$link_href}");
                 header("Location: " . $target);
                 exit;
                 break;
         }
     } else {
         $html .= "<p>" . wfMsg('multiauthspeciallogout-msg_logoutFailure') . "</p>\n";
         return false;
     }
 }