From f3c64eca2f28d0d3df9bedbadadac41a29304a2a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 25 Nov 2004 06:04:16 +0000 Subject: [PATCH] Separate the HTML guts of the user login form into a template to keep the code more or less legibile. --- includes/OutputPage.php | 13 +++ includes/SkinTemplate.php | 2 +- includes/SpecialUserlogin.php | 135 +++++-------------------------- includes/templates/Userlogin.php | 103 +++++++++++++++++++++++ 4 files changed, 139 insertions(+), 114 deletions(-) create mode 100644 includes/templates/Userlogin.php diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 64035761b2..f9859e6f9e 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -259,6 +259,17 @@ class OutputPage { $this->addHTML( $text ); } + /** + * Add the output of a QuickTemplate to the output buffer + * @param QuickTemplate $template + */ + function addTemplate( &$template ) { + ob_start(); + $template->execute(); + $this->addHtml( ob_get_contents() ); + ob_end_clean(); + } + /** * @param $article * @param $user @@ -398,7 +409,9 @@ class OutputPage { setcookie( $name, $val, $exp, '/' ); } + wfProfileIn( 'Output-skin' ); $sk->outputPage( $this ); + wfProfileOut( 'Output-skin' ); $this->sendCacheControl(); ob_end_flush(); diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 8dddf57540..4082c67587 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -878,7 +878,7 @@ class QuickTemplate { */ function QuickTemplate() { $this->data = array(); - $this->translator = null; + $this->translator = new MediaWiki_I18N(); } /** diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 463e82d4a8..b36c28b29d 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -49,8 +49,9 @@ class LoginForm { $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' ); $this->mAction = $request->getVal( 'action' ); $this->mRemember = $request->getCheck( 'wpRemember' ); + $this->mEmail = $request->getText( 'wpEmail' ); - if ($wgAllowRealName) { + if( $wgAllowRealName ) { $this->mRealName = $request->getText( 'wpRealName' ); } else { $this->mRealName = ''; @@ -380,29 +381,6 @@ class LoginForm { global $wgUser, $wgOut, $wgLang; global $wgDBname, $wgAllowRealName; - $le = wfMsg( 'loginerror' ); - $yn = wfMsg( 'yourname' ); - $yp = wfMsg( 'yourpassword' ); - $ypa = wfMsg( 'yourpasswordagain' ); - $rmp = wfMsg( 'remembermypassword' ); - $nuo = wfMsg( 'newusersonly' ); - $li = wfMsg( 'login' ); - $ca = wfMsg( 'createaccount' ); - $cam = wfMsg( 'createaccountmail' ); - $ye = wfMsg( 'youremail' ); - if( $wgAllowRealName ) { - $yrn = wfMsg( 'yourrealname' ); - } else { - $yrn = ''; - } - $efl = wfMsg( 'emailforlost' ); - $mmp = wfMsg( 'mailmypassword' ); - $endText = wfMsg( 'loginend' ); - - if ( $endText == '<loginend>' ) { - $endText = ''; - } - if ( '' == $this->mName ) { if ( 0 != $wgUser->getID() ) { $this->mName = $wgUser->getName(); @@ -411,102 +389,33 @@ class LoginForm { } } - $wgOut->setPageTitle( wfMsg( 'userlogin' ) ); - $wgOut->setRobotpolicy( 'noindex,nofollow' ); - $wgOut->setArticleRelated( false ); - - if ( '' == $err ) { - $lp = wfMsg( 'loginprompt' ); - $wgOut->addHTML( "

$li:

\n

$lp

" ); - } else { - $wgOut->addHTML( "

$le:

\n$err\n" ); - } - if ( 1 == $wgUser->getOption( 'rememberpassword' ) ) { - $checked = ' checked'; - } else { - $checked = ''; - } - $q = 'action=submit'; if ( !empty( $this->mReturnto ) ) { $q .= '&returnto=' . wfUrlencode( $this->mReturnto ); } - $titleObj = Title::makeTitle( NS_SPECIAL, 'Userlogin' ); - $action = $titleObj->escapeLocalUrl( $q ); - $encName = htmlspecialchars( $this->mName ); - $encPassword = htmlspecialchars( $this->mPassword ); - $encRetype = htmlspecialchars( $this->mRetype ); - $encEmail = htmlspecialchars( $this->mEmail ); - $encRealName = htmlspecialchars( $this->mRealName ); - if ($wgUser->getID() != 0) { - $cambutton = ""; - } else { - $cambutton = ''; - } - - $wgOut->addHTML( " -
- - - - - - - - - - "); - - if ($wgUser->isAllowedToCreateAccount()) { - $encRetype = htmlspecialchars( $this->mRetype ); - $encEmail = htmlspecialchars( $this->mEmail ); - $wgOut->addHTML(" - - - - - "); - - if ($wgAllowRealName) { - $wgOut->addHTML(" - - - "); - } - - $wgOut->addHTML(""); - } - - $wgOut->addHTML(" - -
$yn: - - - -
$yp: - - - -
 
$ypa: - - $nuo
$ye: - -  
$yrn: - - - - $cambutton -
 
-

$efl
-

-
-
\n" ); - $wgOut->addHTML( $endText ); + require_once( 'templates/Userlogin.php' ); + $template =& new UserloginTemplate(); + + $template->set( 'name', $this->mName ); + $template->set( 'password', $this->mPassword ); + $template->set( 'retype', $this->mRetype ); + $template->set( 'email', $this->mEmail ); + $template->set( 'realname', $this->mRealName ); + + $template->set( 'action', $titleObj->getLocalUrl( $q ) ); + $template->set( 'error', $err ); + $template->set( 'create', $wgUser->isAllowedToCreateAccount() ); + $template->set( 'createemail', $wgUser->getID() != 0 ); + $template->set( 'userealname', $wgAllowRealName ); + $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) ); + + $wgOut->setPageTitle( wfMsg( 'userlogin' ) ); + $wgOut->setRobotpolicy( 'noindex,nofollow' ); + $wgOut->setArticleRelated( false ); + $wgOut->addTemplate( $template ); } /** diff --git a/includes/templates/Userlogin.php b/includes/templates/Userlogin.php new file mode 100644 index 0000000000..746d5a7ead --- /dev/null +++ b/includes/templates/Userlogin.php @@ -0,0 +1,103 @@ +data['error'] ) { +?> +

msg('loginerror') ?>:

+

html('error') ?>

+ +

msg('login' ) ?>:

+

msg('loginprompt') ?>

+ +
+ + + + + + + + + + + + data['create'] ) { ?> + + + + + + + + + + + + data['userealname'] ) { ?> + + + + + + + + + + + + + + + + +
msg('yourname') ?>: + + + +
msg('yourpassword') ?>: + + + data['remember'] ) { ?>checked="checked" + /> +
 
msg('yourpasswordagain') ?>: + + msg('newusersonly') ?>
msg('youremail') ?>: + +  
msg('yourrealname') ?>: + + + + data['createemail'] ) { ?> + + +
 
+

+ msgHtml( 'emailforlost' ) ?>
+ +

+
+
+msgHtml( 'loginend' ); + } +} + +?> \ No newline at end of file -- 2.20.1