/** * TODO: Add an option to disallow this extension to access your Facebook * information. This option could simply point you to your Facebook privacy * settings. This is necessary in case the user wants to perpetually browse * the wiki anonymously, while still being logged in to Facebook. * * NOTE: The above might be done now that we have checkboxes for which options * to update from fb. Haven't tested it though. */ private function chooseNameForm($messagekey = 'fbconnect-chooseinstructions') { // Permissions restrictions. global $wgUser, $wgOut; $titleObj = SpecialPage::getTitleFor('Connect'); if (wfReadOnly()) { $wgOut->readOnlyPage(); return false; } elseif ($wgUser->isBlockedFromCreateAccount()) { LoginForm::userBlockedMessage(); //this is not an explicitly static method but doesn't use $this and can be called like static (fixes RT#75589) return false; } elseif (count($permErrors = $titleObj->getUserPermissionsErrors('createaccount', $wgUser, true)) > 0) { $wgOut->showPermissionsErrorPage($permErrors, 'createaccount'); return false; } // Allow other code to have a custom form here (so that this extension can be integrated with existing custom login screens). if (!wfRunHooks('SpecialConnect::chooseNameForm', array(&$this, &$messagekey))) { return false; } global $wgOut, $fbConnectOnly; // Connect to the Facebook API $fb = new FBConnectAPI(); $fb_user = $fb->user(); $userinfo = $fb->getUserInfo($fb_user); // Keep track of when the first option visible to the user is checked $checked = false; // Outputs the canonical name of the special page at the top of the page $this->outputHeader(); // If a different $messagekey was passed (like 'wrongpassword'), use it instead $wgOut->addWikiMsg($messagekey); // TODO: Format the html a little nicer $wgOut->addHTML(' <form action="' . $this->getTitle('ChooseName')->getLocalUrl() . '" method="POST"> <fieldset id="mw-fbconnect-choosename"> <legend>' . wfMsg('fbconnect-chooselegend') . '</legend> <table>'); // Let them attach to an existing user if $fbConnectOnly allows it if (!$fbConnectOnly) { // Grab the UserName from the cookie if it exists global $wgCookiePrefix; $name = isset($_COOKIE[$wgCookiePrefix . 'UserName']) ? trim($_COOKIE[$wgCookiePrefix . 'UserName']) : ''; // Build an array of attributes to update $updateOptions = array(); foreach (self::$availableUserUpdateOptions as $option) { // Translate the MW parameter into a FB parameter $value = FBConnectUser::getOptionFromInfo($option, $userinfo); // If no corresponding value was received from Facebook, then continue if (!$value) { continue; } // Build the list item for the update option $updateOptions[] = "<li><input name=\"wpUpdateUserInfo{$option}\" type=\"checkbox\" " . "value=\"1\" id=\"wpUpdateUserInfo{$option}\" /><label for=\"wpUpdateUserInfo{$option}\">" . wfMsgHtml("fbconnect-{$option}") . wfMsgExt('colon-separator', array('escapenoentities')) . " <i>{$value}</i></label></li>"; } // Implode the update options into an unordered list $updateChoices = count($updateOptions) > 0 ? "<br />\n" . wfMsgHtml('fbconnect-updateuserinfo') . "\n<ul>\n" . implode("\n", $updateOptions) . "\n</ul>\n" : ''; // Create the HTML for the "existing account" option $html = '<tr><td class="wm-label"><input name="wpNameChoice" type="radio" ' . 'value="existing" id="wpNameChoiceExisting"/></td><td class="mw-input">' . '<label for="wnNameChoiceExisting">' . wfMsg('fbconnect-chooseexisting') . '<br/>' . wfMsgHtml('fbconnect-chooseusername') . '<input name="wpExistingName" size="16" value="' . $name . '" id="wpExistingName"/>' . wfMsgHtml('fbconnect-choosepassword') . '<input name="wpExistingPassword" ' . 'size="" value="" type="password"/>' . $updateChoices . '</td></tr>'; $wgOut->addHTML($html); } // Add the options for nick name, first name and full name if we can get them // TODO: Wikify the usernames (i.e. Full name should have an _ ) foreach (array('nick', 'first', 'full') as $option) { $nickname = FBConnectUser::getOptionFromInfo($option . 'name', $userinfo); if ($nickname && $this->userNameOK($nickname)) { $wgOut->addHTML('<tr><td class="mw-label"><input name="wpNameChoice" type="radio" value="' . $option . ($checked ? '' : '" checked="checked') . '" id="wpNameChoice' . $option . '"/></td><td class="mw-input"><label for="wpNameChoice' . $option . '">' . wfMsg('fbconnect-choose' . $option, $nickname) . '</label></td></tr>'); // When the first radio is checked, this flag is set and subsequent options aren't checked $checked = true; } } // The options for auto and manual usernames are always available $wgOut->addHTML('<tr><td class="mw-label"><input name="wpNameChoice" type="radio" value="auto" ' . ($checked ? '' : 'checked="checked" ') . 'id="wpNameChoiceAuto"/></td><td class="mw-input">' . '<label for="wpNameChoiceAuto">' . wfMsg('fbconnect-chooseauto', $this->generateUserName()) . '</label></td></tr><tr><td class="mw-label"><input name="wpNameChoice" type="radio" ' . 'value="manual" id="wpNameChoiceManual"/></td><td class="mw-input"><label ' . 'for="wpNameChoiceManual">' . wfMsg('fbconnect-choosemanual') . '</label> ' . '<input name="wpName2" size="16" value="" id="wpName2"/></td></tr>' . '<tr><td></td><td class="mw-submit"><input type="submit" value="Log in" name="wpOK"/>' . '<input type="submit" value="Cancel" name="wpCancel"/></td></tr></table></fieldset></form>'); }
/** * The user is logged in to Facebook, but not MediaWiki. The Facebook user * is new to MediaWiki. * * If $messageKey is left blank, and a hook doesn't modify its value, then * the 'facebook-chooseinstructions' message will be used. */ private function connectNewUserView($messagekey = '') { global $wgUser, $wgOut, $wgFbDisableLogin; if (wfReadOnly()) { // The wiki is in read-only mode $wgOut->readOnlyPage(); return; } if (empty($wgFbDisableLogin)) { // These two permissions don't apply in $wgFbDisableLogin mode because // then technically no users can create accounts if ($wgUser->isBlockedFromCreateAccount()) { wfDebug("Facebook: Blocked user was attempting to create account via Facebook Connect.\n"); // This is not an explicitly static method but doesn't use $this and can be called like static LoginForm::userBlockedMessage(); return; } else { $titleObj = SpecialPage::getTitleFor('Connect'); $permErrors = $titleObj->getUserPermissionsErrors('createaccount', $wgUser, true); if (count($permErrors) > 0) { // Special case for permission errors $this->sendError($permErrors, 'createaccount'); return; } } } // Allow other code to have a custom form here (so that this extension // can be integrated with existing custom login screens). Hook must // output content if it returns false. if (!wfRunHooks('SpecialConnect::chooseNameForm', array(&$this, &$messagekey))) { return; } $fbUser = new FacebookUser(); $userinfo = $fbUser->getUserInfo(); // Outputs the canonical name of the special page at the top of the page $this->outputHeader(); // Grab the UserName from the cookie if it exists global $wgCookiePrefix; $existingName = isset($_COOKIE["{$wgCookiePrefix}UserName"]) ? trim($_COOKIE["{$wgCookiePrefix}UserName"]) : ''; $form = $this->getChooseNameForm($userinfo, $messagekey, $existingName); $wgOut->addHTML($form . "\n\n"); }