r412 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r411‎ | r412 | r413 >
Date:07:41, 22 May 2002
Author:lcrocker
Status:old
Tags:
Comment:
Several changes to login system at Brion's suggestion.
Modified paths:
  • /trunk/phpwiki/newcodebase/Article.php (modified) (history)
  • /trunk/phpwiki/newcodebase/DatabaseFunctions.php (modified) (history)
  • /trunk/phpwiki/newcodebase/GlobalFunctions.php (modified) (history)
  • /trunk/phpwiki/newcodebase/Language.php (modified) (history)
  • /trunk/phpwiki/newcodebase/OutputPage.php (modified) (history)
  • /trunk/phpwiki/newcodebase/Skin.php (modified) (history)
  • /trunk/phpwiki/newcodebase/SpecialUserlogin.php (modified) (history)
  • /trunk/phpwiki/newcodebase/SpecialUserlogout.php (modified) (history)
  • /trunk/phpwiki/newcodebase/Title.php (modified) (history)
  • /trunk/phpwiki/newcodebase/User.php (modified) (history)
  • /trunk/phpwiki/newcodebase/sql/buildtables.sql (modified) (history)
  • /trunk/phpwiki/newcodebase/wiki.phtml (modified) (history)

Diff [purge]

Index: trunk/phpwiki/newcodebase/SpecialUserlogin.php
@@ -17,49 +17,45 @@
1818
1919 /* private */ function addNewAccount()
2020 {
21 - global $wgUser, $wpPassword2, $wpRetype, $wpName2, $wpRemember2;
 21+ global $wgUser, $wpPassword, $wpRetype, $wpName, $wpRemember;
2222 global $wpEmail, $wgDeferredUpdateList;
2323
24 - if ( 0 != strcmp( $wpPassword2, $wpRetype ) ) {
 24+ if ( 0 != strcmp( $wpPassword, $wpRetype ) ) {
2525 mainLoginForm( wfMsg( "badretype" ) );
2626 return;
2727 }
28 - if ( "" == $wpName2 ) {
 28+ if ( "" == $wpName ) {
2929 mainLoginForm( wfMsg( "noname" ) );
3030 return;
3131 }
32 - $u = User::newFromName( $wpName2 );
 32+ $u = User::newFromName( $wpName );
3333
3434 if ( 0 != $u->idForName() ) {
3535 mainLoginForm( wfMsg( "userexists" ) );
3636 return;
3737 }
3838 $u->addToDatabase();
39 -
40 - $u->setPassword( $wpPassword2 );
41 - if ( 1 == $wpRemember2 ) {
42 - $u->setOption( "rememberPassword", 1 );
43 - }
 39+ $u->setPassword( $wpPassword );
4440 $u->setEmail( $wpEmail );
 41+ if ( 1 == $wpRemember ) { $r = 1; }
 42+ else { $r = 0; }
 43+ $u->setOption( "rememberPassword", $r );
4544
4645 $wgUser = $u;
47 - $wgUser->setCookies();
48 - $up = new UserUpdate();
49 - array_push( $wgDeferredUpdateList, $up );
50 -
5146 $m = str_replace( "$1", $wgUser->getName(), wfMsg( "welcomecreation" ) );
5247 successfulLogin( $m );
5348 }
5449
5550 /* private */ function processLogin()
5651 {
57 - global $wgUser, $wpName1, $wpPassword1, $wpRemember1;
 52+ global $wgUser, $wpName, $wpPassword, $wpRemember;
 53+ global $returnto;
5854
59 - if ( "" == $wpName1 ) {
 55+ if ( "" == $wpName ) {
6056 mainLoginForm( wfMsg( "noname" ) );
6157 return;
6258 }
63 - $u = User::newFromName( $wpName1 );
 59+ $u = User::newFromName( $wpName );
6460 $id = $u->idForName();
6561 if ( 0 == $id ) {
6662 $m = str_replace( "$1", $u->getName(), wfMsg( "nosuchuser" ) );
@@ -68,30 +64,30 @@
6965 }
7066 $u->setId( $id );
7167 $u->loadFromDatabase();
72 - if ( 0 != strcmp( $u->getPassword(), $wpPassword1 ) ) {
 68+ if ( 0 != strcmp( $u->getPassword(), $wpPassword ) ) {
7369 mainLoginForm( wfMsg( "wrongpassword" ) );
7470 return;
7571 }
7672 # We've verified now, update the real record
7773 #
 74+ if ( 1 == $wpRemember ) { $r = 1; }
 75+ else { $r = 0; }
 76+ $u->setOption( "rememberPassword", $r );
 77+
7878 $wgUser = $u;
79 - if ( 1 == $wpRemember1 ) {
80 - $wgUser->setOption( "rememberPassword", 1 );
81 - }
82 - $wgUser->setCookies();
8379 $m = str_replace( "$1", $wgUser->getName(), wfMsg( "loginsuccess" ) );
8480 successfulLogin( $m );
8581 }
8682
8783 /* private */ function mailPassword()
8884 {
89 - global $wpName1;
 85+ global $wpName;
9086
91 - if ( "" == $wpName1 ) {
 87+ if ( "" == $wpName ) {
9288 mainLoginForm( wfMsg( "noname" ) );
9389 return;
9490 }
95 - $u = User::newFromName( $wpName1 );
 91+ $u = User::newFromName( $wpName );
9692 $id = $u->idForName();
9793 if ( 0 == $id ) {
9894 $m = str_replace( "$1", $u->getName(), wfMsg( "nosuchuser" ) );
@@ -116,21 +112,31 @@
117113
118114 /* private */ function successfulLogin( $msg )
119115 {
120 - global $wgOut;
 116+ global $wgUser, $wgOut, $returnto;
 117+ global $wgDeferredUpdateList;
121118
 119+ $wgUser->setCookies();
 120+ $up = new UserUpdate();
 121+ array_push( $wgDeferredUpdateList, $up );
 122+
122123 $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) );
123124 $wgOut->setRobotpolicy( "noindex,nofollow" );
124125 $wgOut->addHTML( $msg . "\n<p>" );
125 - $wgOut->addWikiText( wfMsg( "returntomain" ) );
 126+
 127+ if ( "" == $returnto ) {
 128+ $r = wfMsg( "returntomain" );
 129+ } else {
 130+ $r = str_replace( "$1", $returnto, wfMsg( "returnto" ) );
 131+ $wgOut->addMeta( "http:Refresh", "5;url=" . wfLocalLink( $returnto ) );
 132+ }
 133+ $wgOut->addWikiText( $r );
126134 }
127135
128136 /* private */ function mainLoginForm( $err )
129137 {
130 - global $wgUser, $wgOut;
131 - global $wpName1, $wpPassword1, $wpRemember1;
132 - global $wpName2, $wpPassword2, $wpRetype, $wpRemember2;
133 - global $wpEmail;
134 - global $HTTP_COOKIE_VARS;
 138+ global $wgUser, $wgOut, $returnto;
 139+ global $wpName, $wpPassword, $wpRetype, $wpRemember;
 140+ global $wpEmail, $HTTP_COOKIE_VARS;
135141
136142 $le = wfMsg( "loginerror" );
137143 $yn = wfMsg( "yourname" );
@@ -145,7 +151,7 @@
146152 $efl = wfMsg( "emailforlost" );
147153 $mmp = wfMsg( "mailmypassword" );
148154
149 - $name = $wpName1;
 155+ $name = $wpName;
150156 if ( "" == $name ) {
151157 if ( 0 != $wgUser->getID() ) {
152158 $name = $wgUser->getName();
@@ -153,7 +159,7 @@
154160 $name = $HTTP_COOKIE_VARS["wcUserName"];
155161 }
156162 }
157 - $pwd = $wpPassword1;
 163+ $pwd = $wpPassword;
158164 if ( "" == $pwd ) {
159165 if ( 0 != $wgUser->getID() ) {
160166 $pwd = $wgUser->getPassword();
@@ -163,10 +169,11 @@
164170 }
165171 $wgOut->setPageTitle( wfMsg( "userlogin" ) );
166172 $wgOut->setRobotpolicy( "noindex,nofollow" );
 173+
167174 if ( "" == $err ) {
168 - $wgOut->addHTML( "<h2>$li</h2>\n" );
 175+ $wgOut->addHTML( "<h2>$li:</h2>\n" );
169176 } else {
170 - $wgOut->addHTML( "<h2>$le</h2>\n<font size='+1' color='red'>$err</font>\n<p>" );
 177+ $wgOut->addHTML( "<h2>$le:</h2>\n<font size='+1' color='red'>$err</font>\n" );
171178 }
172179 if ( 1 == $wgUser->getOption( "rememberPassword" ) ) {
173180 $checked = " checked";
@@ -174,29 +181,44 @@
175182 $checked = "";
176183 }
177184 $action = wfLocalLink( "Special:Userlogin" );
 185+ if ( "" != $returnto ) { $action .= "&returnto=$returnto"; }
178186
179187 $wgOut->addHTML( "
180 -<form action='$action' method=post><tt>
181 -$yn<input tabindex=1 type=text name='wpName1' value='$name' size=20><br>
182 -$yp<input tabindex=2 type=password name='wpPassword1' value='$pwd' size=20><br>
183 -<input tabindex=4 type=checkbox name='wpRemember1' value='1'$checked>$rmp<br>
184 -<input tabindex=5 type=submit name='wpLoginattempt' value='$li'>
185 -<input tabindex=6 type=submit name='wpMailmypassword' value='$mmp'>
186 -</tt></form>\n" );
187 -
188 - if ( isset( $wpRemember2 ) ) { $checked = " checked"; }
189 - else { $checked = ""; }
190 -
191 - $wgOut->addHTML( "<hr>
192 -<h2>$ca</h2><p>$ayn<br>
193 -<form action='$action' method=post><tt>
194 -$yn<input tabindex=6 type=text name='wpName2' value='$wpName2' size=20><br>
195 -$yp<input tabindex=7 type=password name='wpPassword2' value='$wpPassword2' size=20><br>
196 -$ypa<input tabindex=8 type=password name='wpRetype' value='$wpRetype' size=20>$nuo<br>
197 -$ye<input tabindex=9 type=text name='wpEmail' value='$wpEmail' size=20>$efl<br>
198 -<input tabindex=10 type=checkbox name='wpRemember2' value='1'$checked>$rmp<br>
199 -<input tabindex=11 type=submit name='wpCreateaccount' value='$ca'>
200 -</tt></form>\n" );
 188+<form method=post action='$action'>
 189+<table border=0><tr>
 190+<td align=right>$yn:</td>
 191+<td colspan=2 align=left>
 192+<input tabindex=1 type=text name='wpName' value='$name' size=20>
 193+</td></tr><tr>
 194+<td align=right>$yp:</td>
 195+<td align=left>
 196+<input tabindex=2 type=password name='wpPassword' value='$pwd' size=20>
 197+</td>
 198+<td align=left>
 199+<input tabindex=3 type=submit name='wpLoginattempt' value='$li'>
 200+</td></tr>
 201+<tr><td colspan=3>&nbsp;</td></tr><tr>
 202+<td align=right>$ypa:</td>
 203+<td align=left>
 204+<input tabindex=4 type=password name='wpRetype' value='$wpRetype' size=20>
 205+</td><td>$nuo</td></tr>
 206+<tr>
 207+<td align=right>$ye:</td>
 208+<td align=left>
 209+<input tabindex=5 type=text name='wpEmail' value='$wpEmail' size=20>
 210+</td><td align=left>
 211+<input tabindex=6 type=submit name='wpCreateaccount' value='$ca'>
 212+</td></tr>
 213+<tr>
 214+<td colspan=3 align=left>
 215+<input tabindex=7 type=checkbox name='wpRemember' value='1'$checked>$rmp
 216+</td></tr>
 217+<tr><td colspan=3>&nbsp;</td></tr><tr>
 218+<td colspan=3 align=left>
 219+<p>$efl<br>
 220+<input tabindex=8 type=submit name='wpMailmypassword' value='$mmp'>
 221+</td></tr></table>
 222+</form>\n" );
201223 }
202224
203225 ?>
Index: trunk/phpwiki/newcodebase/Title.php
@@ -90,17 +90,23 @@
9191
9292 function getPrefixedDBkey()
9393 {
94 - return $this->prefixes( false ) . $this->mDbkeyform;
 94+ $s = $this->prefix( $this->mDbkeyform );
 95+ $s = str_replace( " ", "_", $s );
 96+ return $s;
9597 }
9698
9799 function getPrefixedText()
98100 {
99 - return $this->prefixes( true ) . $this->mTextform;
 101+ $s = $this->prefix( $this->mTextform );
 102+ $s = str_replace( "_", " ", $s );
 103+ return $s;
100104 }
101105
102106 function getPrefixedURL()
103107 {
104 - return $this->prefixes( false ) . $this->mUrlform;
 108+ $s = $this->prefix( $this->mDbkeyform );
 109+ $s = str_replace( " ", "_", $s );
 110+ return urlencode( $s );
105111 }
106112
107113 function getFullURL()
@@ -112,7 +118,7 @@
113119 } else {
114120 $p = $wgValidInterwikis[$this->mInterwiki];
115121 }
116 - if ( "" != $this->mNamespace ) { $n = $this->mNamespace . ":"; }
 122+ if ( "" != $this->mNamespace ) { $n = $this->mNamespace . "%3a"; }
117123 return str_replace( "$1", $n . $this->mUrlform, $p );
118124 }
119125
@@ -154,7 +160,7 @@
155161 wfDebug( "Title: 2: $sql\n" );
156162
157163 $res = mysql_query( $sql, $conn );
158 - if ( ! $res || 0 == mysql_num_rows( $res ) ) {
 164+ if ( ( false === $res ) || 0 == mysql_num_rows( $res ) ) {
159165 return $this->mOtherNamespaces;
160166 }
161167
@@ -197,7 +203,7 @@
198204 # wfDebug( "Title: 1: $sql\n" );
199205 $res = mysql_query( $sql, $conn );
200206
201 - if ( ! $res || 0 == mysql_num_rows( $res ) ) {
 207+ if ( ( false === $res ) || 0 == mysql_num_rows( $res ) ) {
202208 $this->mArticleID = 0;
203209 } else {
204210 $s = mysql_fetch_object( $res );
@@ -209,19 +215,16 @@
210216 return $this->mArticleID;
211217 }
212218
213 - /* private */ function prefixes( $textform )
 219+ /* private */ function prefix( $name )
214220 {
 221+ $p = "";
215222 if ( "" != $this->mInterwiki ) {
216223 $p = $this->mInterwiki . ":";
217224 }
218225 if ( "" != $this->mNamespace ) {
219 - if ( $textform ) {
220 - $p .= str_replace( "_", " ", $this->mNamespace ) . ":";
221 - } else {
222226 $p .= $this->mNamespace . ":";
223 - }
224227 }
225 - return $p;
 228+ return $p . $name;
226229 }
227230
228231 # Assumes that mDbkeyform has been set, and is urldecoded
@@ -240,7 +243,7 @@
241244 $done = false;
242245 $t = trim( $this->mDbkeyform );
243246 if ( ":" == $t{0} ) {
244 - $r = substr( $t, 2 );
 247+ $r = substr( $t, 1 );
245248 } else {
246249 if ( preg_match( "/^([A-Za-z][A-Za-z0-9 _]*):(.*)$/", $t, $m ) ) {
247250 $p = strtolower( $m[1] );
Index: trunk/phpwiki/newcodebase/Article.php
@@ -5,14 +5,16 @@
66 /* private */ var $mTitle; # WikiTitle object
77 /* private */ var $mContent, $mContentLoaded;
88 /* private */ var $mUser, $mTimestamp, $mParams;
9 - /* private */ var $mCounter;
 9+ /* private */ var $mCounter, $mComment, $mOldversion;
 10+ /* private */ var $mMinorEdit;
1011
1112 function Article( $t )
1213 {
1314 $this->mTitle = $t;
1415 $this->mContentLoaded = false;
1516 $this->mUser = $this->mCounter = -1; # Not loaded
16 - $this->mTimestamp = "";
 17+ $this->mTimestamp = $this->mComment = "";
 18+ $this->mOldversion = 0;
1719 }
1820
1921 function getContent()
@@ -36,19 +38,19 @@
3739 $sql = "SELECT cur_text,cur_timestamp,cur_user,cur_counter, " .
3840 "cur_params FROM cur WHERE cur_id=$id";
3941 wfDebug( "Art: 1: $sql\n" );
40 - $result = mysql_query( $sql, $conn );
 42+ $res = mysql_query( $sql, $conn );
4143
42 - if ( ! $result || 0 == mysql_num_rows( $result ) ) {
 44+ if ( ( false === $res ) || ( 0 == mysql_num_rows( $res ) ) ) {
4345 $this->mContent = "Fatal database error.\n";
4446 } else {
45 - $s = mysql_fetch_object( $result );
 47+ $s = mysql_fetch_object( $res );
4648 $this->mContent = $s->cur_text;
4749 $this->mUser = $s->cur_user;
4850 $this->mCounter = $s->cur_counter;
4951 $this->mParams = $s->cur_params;
5052 $this->mTimestamp = $s->cur_timestamp;
5153 }
52 - mysql_free_result( $result );
 54+ mysql_free_result( $res );
5355 $this->mContentLoaded = true;
5456 }
5557
@@ -68,15 +70,19 @@
6971 if ( -1 != $this->mUser ) return;
7072
7173 $conn = wfGetDB();
72 - $sql = "SELECT cur_user,cur_timestamp FROM cur WHERE " .
 74+ $sql = "SELECT cur_user,cur_timestamp,cur_old_version," .
 75+ "cur_comment,cur_minor_edit FROM cur WHERE " .
7376 "cur_id=" . $this->getID();
7477 wfDebug( "Art: 3: $sql\n" );
7578
7679 $res = mysql_query( $sql, $conn );
77 - if ( "" != $res ) {
 80+ if ( ! ( false === $res ) ) {
7881 $s = mysql_fetch_object( $res );
7982 $this->mUser = $s->cur_user;
80 - $this->mTimestamp = $s->mTimestamp;
 83+ $this->mTimestamp = $s->cur_timestamp;
 84+ $this->mComment = $s->cur_comment;
 85+ $this->mOldversion = $s->cur_old_version;
 86+ $this->mMinorEdit = $s->cur_minor_edit;
8187 }
8288 }
8389
@@ -227,10 +233,12 @@
228234
229235 $conn = wfGetDB();
230236 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
231 - "cur_comment,cur_user,cur_timestamp,cur_minor_edit) VALUES ('" .
232 - $wgTitle->getNamespace() . "', '" . $wgTitle->getDBKey() . "', '" .
 237+ "cur_comment,cur_user,cur_timestamp,cur_minor_edit," .
 238+ "cur_old_version,cur_counter) VALUES ('" .
 239+ $this->mTitle->getNamespace() . "', '" .
 240+ $this->mTitle->getDBKey() . "', '" .
233241 wfStrencode( $text ) . "', '" . wfStrencode( $summary ) . "', '" .
234 - $wgUser->getID() . "', '" . date( "YmdHis" ) . "', 0)";
 242+ $wgUser->getID() . "', '" . date( "YmdHis" ) . "', 0, 0, 0)";
235243
236244 wfDebug( "Art: 2: $sql\n" );
237245 $res = mysql_query( $sql, $conn );
@@ -246,18 +254,44 @@
247255 {
248256 global $wgOut, $wgUser, $wgTitle;
249257
250 - if ( $minor) { $me = 1; } else { $me = 0; }
 258+ if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
 259+ if ( $minor ) { $me2 = 1; } else { $me2 = 0; }
251260
252 - # TODO: Backup to old table
253 - #
 261+ $this->loadLastEdit();
254262 $conn = wfGetDB();
 263+ $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
 264+ "old_comment,old_user,old_old_version,old_timestamp," .
 265+ "old_minor_edit) VALUES ('" .
 266+ $this->mTitle->getNamespace() . "', '" .
 267+ $this->mTitle->getDBKey() . "', '" .
 268+ wfStrencode( $this->getContent() ) . "', '" .
 269+ wfStrencode( $this->mComment ) . "', " .
 270+ $this->mUser . ", " . $this->mOldversion . ", '" .
 271+ $this->mTimestamp . "', " . $me1 . ")";
 272+
 273+ wfDebug( "Art: 4: $sql\n" );
 274+ $res = mysql_query( $sql, $conn );
 275+ if ( false === $res ) {
 276+ $wgOut->databaseError( wfMsg( "updatingarticle" ) );
 277+ return;
 278+ }
 279+ $cond = "(old_namespace='" . $this->mTitle->getNamespace() .
 280+ "' AND old_title='" . $this->mTitle->getDBKey() .
 281+ "' AND old_old_version={$this->mOldversion})";
 282+ $newid = wfGetSQL( "old", "old_id", $cond );
 283+ if ( 0 == $newid ) {
 284+ $wgOut->databaseError( wfMsg( "updatingarticle" ) );
 285+ return;
 286+ }
 287+ $conn = wfGetDB();
255288 $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
256289 "',cur_comment='" . wfStrencode( $summary ) .
257 - "',cur_minor_edit=$me, cur_user=" . $wgUser->getID() .
258 - ", cur_timestamp='" . date( "YmdHis" ) . "' " .
 290+ "',cur_minor_edit={$me2}, cur_user=" . $wgUser->getID() .
 291+ ", cur_timestamp='" . date( "YmdHis" ) .
 292+ "',cur_old_version=$newid " .
259293 "WHERE cur_id=" . $this->getID();
260294
261 - wfDebug( "Art: 4: $sql\n" );
 295+ wfDebug( "Art: 5: $sql\n" );
262296 $res = mysql_query( $sql, $conn );
263297 $this->editUpdates();
264298
Index: trunk/phpwiki/newcodebase/GlobalFunctions.php
@@ -16,7 +16,7 @@
1717 #
1818 $wgFormTextFields = array(
1919 # Login form
20 - "wpName1", "wpPassword1", "wpName2", "wpPassword2",
 20+ "wpName", "wpPassword", "wpName", "wpPassword",
2121 "wpRetype", "wpEmail",
2222 # Edit form
2323 "wpTextbox1", "wpSummary", "wpTextbox2"
@@ -126,7 +126,7 @@
127127 wfDebug( "Glob: 1: $sql\n" );
128128
129129 $res = mysql_query( $sql, $conn );
130 - if ( ! $res || 0 == mysql_num_rows( $res) ) { return; }
 130+ if ( ( false === $res ) || ( 0 == mysql_num_rows( $res) ) ) { return; }
131131 else {
132132 $s = mysql_fetch_object( $res );
133133 $wgTotalViews = $s->ss_total_views;
Index: trunk/phpwiki/newcodebase/DatabaseFunctions.php
@@ -19,7 +19,7 @@
2020 {
2121 $conn = wfGetDB();
2222 $sql = "UPDATE $table SET $var = '" .
23 - wfStrencode( $value ) . "' WHERE $cond";
 23+ wfStrencode( $value ) . "' WHERE ($cond)";
2424
2525 wfDebug( "DB: 1: $sql\n" );
2626 $result = mysql_query( $sql, $conn );
@@ -28,12 +28,12 @@
2929 function wfGetSQL( $table, $var, $cond )
3030 {
3131 $conn = wfGetDB();
32 - $sql = "SELECT $var FROM $table WHERE $cond";
 32+ $sql = "SELECT $var FROM $table WHERE ($cond)";
3333
3434 wfDebug( "DB: 2: $sql\n" );
3535 $result = mysql_query( $sql, $conn );
3636 $ret = "";
37 - if ( "" != $result ) {
 37+ if ( ! ( false === $result ) ) {
3838 if ( $s = mysql_fetch_object( $result ) ) {
3939 $ret = $s->$var;
4040 }
Index: trunk/phpwiki/newcodebase/Skin.php
@@ -162,9 +162,9 @@
163163 if ( $wgOut->isArticle() ) {
164164 $s .= "<p class=\"subtitle\">"
165165 . $this->makeLink( wfMsg( "mainpage" ),
166 - WfMsg( "printableversion" ), "print" )
 166+ WfMsg( "printableversion" ), "action=print" )
167167 . " | " . $this->makeLink( "Special:Whatlinkshere",
168 - wfMsg( "whatlinkshere" ), "", $wgTitle->getPrefixedURL() );
 168+ wfMsg( "whatlinkshere" ), "target=" . $wgTitle->getPrefixedURL() );
169169
170170 $s .= $this->otherLanguages();
171171 }
@@ -174,15 +174,18 @@
175175
176176 function nameAndLogin()
177177 {
178 - global $wgUser;
 178+ global $wgUser, $wgTitle;
179179
180 - $n = $wgUser->getName();
181180 if ( 0 == $wgUser->getID() ) {
182 - $s .= $n . "\n<br>" . $this->specialLink( "userlogin" );
 181+ $n = getenv( "REMOTE_ADDR" );
 182+ $s .= $n . "\n<br>" . $this->makeLink( "Special:Userlogin",
 183+ wfMsg( "login" ), "returnto=" . $wgTitle->getPrefixedURL() );
183184 } else {
184 - $s .= $this->makeLink( "User:$n", $n ) . "<br>"
185 - . $this->specialLink( "userlogout" ) . " | "
186 - . $this->specialLink( "preferences" );
 185+ $n = $wgUser->getName();
 186+ $s .= $this->makeLink( "User:$n", $n ) . "<br>" .
 187+ $this->makeLink( "Special:Userlogout", wfMsg( "logout" ),
 188+ "returnto=" . $wgTitle->getPrefixedURL() ) . " | " .
 189+ $this->specialLink( "preferences" );
187190 }
188191 $s .= " | " . $this->makeLink( "Wikipedia:Help", wfMsg( "help" ) );
189192
@@ -289,7 +292,7 @@
290293 $s = "(Special page)";
291294 } else if ( $wgTitle->userCanEdit() ) {
292295 $s = $this->makeLink( $wgTitle->getPrefixedText(),
293 - wfMsg( "editthispage" ), "edit" );
 296+ wfMsg( "editthispage" ), "action=edit" );
294297 } else {
295298 $s = "Protected page";
296299 }
@@ -301,7 +304,7 @@
302305 global $wgTitle;
303306
304307 $s = $this->makeLink( $wgTitle->getPrefixedText(),
305 - wfMsg( "history" ), "history" );
 308+ wfMsg( "history" ), "action=history" );
306309 return $s;
307310 }
308311
@@ -313,7 +316,7 @@
314317 $s = "(Special page)";
315318 } else {
316319 $s = $this->makeLink( "Special:Recentchangeslinked",
317 - wfMsg( "recentchangeslinked" ), "", $wgTitle->getPrefixedURL() );
 320+ wfMsg( "recentchangeslinked" ), "target=" . $wgTitle->getPrefixedURL() );
318321 }
319322 return $s;
320323 }
@@ -412,39 +415,43 @@
413416 return $text;
414417 }
415418
416 - function makeInternalLink( $title, $text= "", $action = "", $target = "" )
 419+ function makeInternalLink( $title, $text= "", $action = "", $target = "",
 420+ $trail = "" )
417421 {
418422 $nt = Title::newFromText( $title );
419423 if ( "Special" == $nt->getNamespace() ) {
420424 return $this->makeLink( $title, $text );
421425 }
422426 if ( 0 == $nt->getArticleID() ) {
423 - return $this->makeBrokenLink( $title, $text );
 427+ return $this->makeBrokenLink( $title, $text ) . $trail;
424428 } else {
425 - return $this->makeLink( $title, $text, $action, $target );
 429+ return $this->makeLink( $title, $text, $query, $trail );
426430 }
427431 }
428432
429 - function makeLink( $title, $text = "", $action = "", $target = "" )
 433+ function makeLink( $title, $text = "", $query = "", $trail = "" )
430434 {
431435 global $wgServer, $wgScript, $wgArticlePath, $wgTitle;
432436
433437 $nt = Title::newFromText( $title );
434438 $link = $nt->getPrefixedURL();
435439
436 - if ( "" == $action && "" == $target ) {
 440+ if ( "" == $query ) {
437441 $u = str_replace( "$1", $link, $wgArticlePath );
438 - } else if ( "" != $action ) {
439 - $u = "$wgServer$wgScript?title=$link&action=$action";
440 - } else if ( "" != $target ) {
441 - $tt = Title::newFromURL( $target );
442 - $t = $tt->getPrefixedURL();
443 - $u = "$wgServer$wgScript?title=$link&target=$t";
 442+ } else {
 443+ $u = "$wgServer$wgScript?title=$link&$query";
444444 }
445445 if ( "" == $text ) { $text = $nt->getPrefixedText(); }
446446 $style = $this->getInternalLinkAttributes( $link, $text );
447447
448 - $r = "<a href=\"$u\"$style>$text</a>";
 448+ $inside = "";
 449+ if ( "" != $trail ) {
 450+ if ( preg_match( "/^([a-z]+)(.*)$$/sD", $trail, $m ) ) {
 451+ $inside = $m[1];
 452+ $trail = $m[2];
 453+ }
 454+ }
 455+ $r = "<a href=\"$u\"$style>$text$inside</a>$trail";
449456 return $r;
450457 }
451458
Index: trunk/phpwiki/newcodebase/SpecialUserlogout.php
@@ -2,11 +2,20 @@
33
44 function wfSpecialUserlogout()
55 {
6 - global $wgUser, $wgOut;
 6+ global $wgUser, $wgOut, $returnto;
77
88 $wgUser->logout();
99 $wgOut->setPageTitle( wfMsg( "userlogout" ) );
10 - $wgOut->addHTML( wfMsg( "logouttext" ) );
 10+ $wgOut->setRobotpolicy( "noindex,nofollow" );
 11+ $wgOut->addHTML( wfMsg( "logouttext" ) . "\n<p>" );
 12+
 13+ if ( "" == $returnto ) {
 14+ $r = wfMsg( "returntomain" );
 15+ } else {
 16+ $r = str_replace( "$1", $returnto, wfMsg( "returnto" ) );
 17+ $wgOut->addMeta( "http:Refresh", "5;url=" . wfLocalLink( $returnto ) );
 18+ }
 19+ $wgOut->addWikiText( $r );
1120 }
1221
1322 ?>
Index: trunk/phpwiki/newcodebase/sql/buildtables.sql
@@ -45,6 +45,7 @@
4646
4747 CREATE TABLE old (
4848 old_id mediumint(8) unsigned NOT NULL auto_increment,
 49+ old_namespace varchar(20) binary NOT NULL default '',
4950 old_title varchar(255) binary NOT NULL default '',
5051 old_text mediumtext,
5152 old_comment tinyblob,
Index: trunk/phpwiki/newcodebase/User.php
@@ -70,7 +70,7 @@
7171 wfDebug( "User: 5: $sql\n" );
7272
7373 $res = mysql_query( $sql, $conn );
74 - if ( ( ! $res ) || ( 0 == mysql_num_rows( $res ) ) ) {
 74+ if ( ( false === $res ) || ( 0 == mysql_num_rows( $res ) ) ) {
7575 if ( 0 == $this->mId ) {
7676 $this->mBlockedby = 0;
7777 return;
@@ -81,7 +81,7 @@
8282 wfDebug( "User: 6: $sql\n" );
8383
8484 $res = mysql_query( $sql, $conn );
85 - if ( ( ! $res ) || ( 0 == mysql_num_rows( $res ) ) ) {
 85+ if ( ( false === $res ) || ( 0 == mysql_num_rows( $res ) ) ) {
8686 $this->mBlockedby = 0;
8787 return;
8888 }
@@ -164,10 +164,10 @@
165165 "user_rights FROM user WHERE user_id=" . $this->mId;
166166
167167 wfDebug( "User: 1: $sql\n" );
168 - $result = mysql_query( $sql, $conn );
 168+ $res = mysql_query( $sql, $conn );
169169
170 - if ( $result ) {
171 - $s = mysql_fetch_object( $result );
 170+ if ( ! ( false === $res ) ) {
 171+ $s = mysql_fetch_object( $res );
172172 $this->mName = $s->user_name;
173173 $this->mEmail = $s->user_email;
174174
@@ -175,7 +175,7 @@
176176 $this->decodeOptions( $s->user_options );
177177 $this->mRights = explode( ",", strtolower( $s->user_rights ) );
178178 }
179 - mysql_free_result( $result );
 179+ mysql_free_result( $res );
180180 $this->mDataLoaded = true;
181181 }
182182
@@ -326,14 +326,14 @@
327327 $exp = time() + $wgCookieExpiration;
328328
329329 $wsUserID = $this->mId;
330 - setcookie( "wcUserID", $this->mId, $exp );
 330+ setcookie( "wcUserID", $this->mId, $exp, "/" );
331331
332332 $wsUserName = $this->mName;
333 - setcookie( "wcUserName", $this->mName, $exp );
 333+ setcookie( "wcUserName", $this->mName, $exp, "/" );
334334
335335 $wsUserPassword = $this->mPassword;
336336 if ( 1 == $this->getOption( "rememberPassword" ) ) {
337 - setcookie( "wcUserPassword", $this->mPassword, $exp );
 337+ setcookie( "wcUserPassword", $this->mPassword, $exp, "/" );
338338 } else {
339339 setcookie( "wcUserPassword", "", time() - 3600 );
340340 }
@@ -364,7 +364,7 @@
365365 wfDebug( "User: 2: $sql\n" );
366366
367367 $conn = wfGetDB();
368 - $result = mysql_query( $sql, $conn );
 368+ $res = mysql_query( $sql, $conn );
369369
370370 if ( isset( $this->mWatchlist ) ) {
371371 wfSetSQL( "user", "user_watch", implode( "\n", $this->mWatchlist ),
@@ -385,14 +385,14 @@
386386 wfStrencode( $s ) . "'";
387387
388388 wfDebug( "User: 3: $sql\n" );
389 - $result = mysql_query( $sql , $conn );
390 - if ( "" == $result ) return 0;
 389+ $res = mysql_query( $sql , $conn );
 390+ if ( false === $res ) return 0;
391391
392 - $s = mysql_fetch_object( $result );
 392+ $s = mysql_fetch_object( $res );
393393 if ( "" == $s ) return 0;
394394
395395 $gotid = $s->user_id;
396 - mysql_free_result( $result );
 396+ mysql_free_result( $res );
397397 return $gotid;
398398 }
399399
@@ -408,7 +408,7 @@
409409 $this->encodeOptions() . "', '' )";
410410
411411 wfDebug( "User: 4: $sql\n" );
412 - $result = mysql_query( $sql, $conn );
 412+ $res = mysql_query( $sql, $conn );
413413 $this->mId = $this->idForName();
414414
415415 if ( isset( $this->mWatchlist ) ) {
Index: trunk/phpwiki/newcodebase/Language.php
@@ -42,6 +42,7 @@
4343 "mainpage" => "Main Page",
4444 "errorpagetitle" => "Erorr",
4545 "returntomain" => "Return to the [[Main Page]].",
 46+"returnto" => "Return to [[$1]].",
4647 "fromwikipedia" => "From Wikipedia, the free encyclopedia.",
4748 "whatlinkshere" => "Pages that link here",
4849 "help" => "Help",
@@ -64,8 +65,13 @@
6566
6667 # Database errors
6768 #
 69+"databaseerror" => "Database error",
 70+"dberrortext" => "An unrecoverable database error has occurred.
 71+Please report this to an administrator.
 72+The operation being attempted was: $1.",
6873 "noconnect" => "Could not connect to DB on $1",
6974 "nodb" => "Could not select database $1",
 75+"updatingarticle" => "updating an article",
7076
7177 # Login and logout pages
7278 #
@@ -78,9 +84,9 @@
7985 Don't forget to personalize your wikipedia preferences.",
8086
8187 "loginpagetitle" => "User login",
82 -"yourname" => "Your user name&nbsp; : ",
83 -"yourpassword" => "Your password&nbsp;&nbsp; : ",
84 -"yourpasswordagain" => "Retype password : ",
 88+"yourname" => "Your user name",
 89+"yourpassword" => "Your password",
 90+"yourpasswordagain" => "Retype password",
8591 "newusersonly" => " (new users only)",
8692 "remembermypassword" => "Remember my password across sessions.",
8793 "loginproblem" => "<b>There has been a problem with your login.</b><br>Try again!",
@@ -98,8 +104,8 @@
99105 "createaccount" => "Create new account",
100106 "badretype" => "The passwords you entered do not match.",
101107 "userexists" => "The user name you entered is already in use. Please choosea different name.",
102 -"youremail" => "Your e-mail: ",
103 -"emailforlost" => "If you forget your password, you can have it mailed to this e-mail address.",
 108+"youremail" => "Your e-mail",
 109+"emailforlost" => "If you forget your password, you can have it mailed to your e-mail address.",
104110
105111 "loginerror" => "Login error",
106112 "noname" => "You must specify a user name.",
@@ -134,9 +140,9 @@
135141 "blockedtext" => "Your user name or IP address has been blocked by $1.
136142 The reason given is this:<br>$2<p>You may contact the administrator to
137143 discuss the block.",
138 -"newarticle" => "New article: $1",
 144+"newarticle" => "(New) $1",
139145 "newarticletext" => "Describe the new page here.",
140 -"updated" => "Updated: $1",
 146+"updated" => "(Updated) $1",
141147 "note" => "<strong>Note:</strong> ",
142148 "previewnote" => "Remember that this is only a preview, and has not yet been saved!",
143149 "previewconflict" => "This preview reflects the text in the upper
Index: trunk/phpwiki/newcodebase/OutputPage.php
@@ -72,7 +72,7 @@
7373 }
7474 $exp = time() + $wgCookieExpiration;
7575 foreach( $this->mCookies as $name => $val ) {
76 - setcookie( $name, $val, $exp );
 76+ setcookie( $name, $val, $exp, "/" );
7777 }
7878 $sk->initPage();
7979 print $this->headElement();
@@ -104,12 +104,24 @@
105105 $wgTitle->getText() . "\n";
106106 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
107107 $this->setPageTitle( wfMsg( $title ) );
 108+ $this->setRobotpolicy( "noindex,nofollow" );
108109
109110 $this->mBodytext = "";
110111 $this->addHTML( "<p>" . wfMsg( $msg ) . "\n" );
111112 $this->addWikiText( "\n" . wfMsg( "returntomain" ) . "\n" );
112113 }
113114
 115+ function databaseError( $op )
 116+ {
 117+ $this->mDebugtext .= "MySQL: " . mysql_errno() . ": " .
 118+ mysql_error() . "\n";
 119+ $this->setPageTitle( wfMsg( "databaseerror" ) );
 120+ $this->setRobotpolicy( "noindex,nofollow" );
 121+
 122+ $this->mBodytext = str_replace( "$1", $op, wfMsg( "dberrortext" ) );
 123+ $this->addWikiText( "\n" . wfMsg( "returntomain" ) . "\n" );
 124+ }
 125+
114126 # Well, OK, it's actually about 14 passes. But since all the
115127 # hard lifting is done inside PHP's regex code, it probably
116128 # wouldn't speed things up much to add a real parser.
@@ -290,18 +302,20 @@
291303 if ( "image" == $pre ) {
292304 $s .= $sk->makeImageLink( "$wgServer$wgUploadPath/" .
293305 $suf, $text );
 306+ $s .= $trail;
294307 } else {
295308 $l = $wgLang->getLanguageName( $pre );
296309 if ( "" == $l ) {
297 - $s .= $sk->makeInternalLink( $link, $text );
 310+ $s .= $sk->makeInternalLink( $link, $text,
 311+ "", "", $trail );
298312 } else {
299313 array_push( $this->mLanguageLinks, "$pre:$suf" );
 314+ $s .= $trail;
300315 }
301316 }
302317 } else {
303 - $s .= $sk->makeInternalLink( $link, $text );
 318+ $s .= $sk->makeInternalLink( $link, $text, "", "", $trail );
304319 }
305 - $s .= $trail;
306320 }
307321 return $s;
308322 }
@@ -409,9 +423,7 @@
410424
411425 if ( ";" == substr( $pref, -1 ) ) {
412426 $cpos = strpos( $t, ":" );
413 - if ( false === $cpos ) {
414 - # PHP weirdness: need empty block here.
415 - } else {
 427+ if ( ! false === $cpos ) {
416428 $term = substr( $t, 0, $cpos );
417429 $text .= $term . "</dt><dd>";
418430 $t = substr( $t, $cpos + 1 );
@@ -431,8 +443,7 @@
432444
433445 if ( ";" == $char ) {
434446 $cpos = strpos( $t, ":" );
435 - if ( false === $cpos ) {
436 - } else {
 447+ if ( ! false === $cpos ) {
437448 $term = substr( $t, 0, $cpos );
438449 $text .= $term . "</dt><dd>";
439450 $t = substr( $t, $cpos + 1 );
@@ -682,7 +693,7 @@
683694 }
684695 $ret .= "<html><head><title>{$this->mHTMLtitle}</title>\n";
685696 foreach ( $this->mMetatags as $tag ) {
686 - if ( 0 == stricmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
 697+ if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
687698 $a = "http-equiv";
688699 $tag[0] = substr( $tag[0], 5 );
689700 } else {
Index: trunk/phpwiki/newcodebase/wiki.phtml
@@ -13,7 +13,8 @@
1414 include_once( "./Title.php" );
1515 include_once( "./Article.php" );
1616
17 -global $action, $title, $search, $target; # From query string
 17+global $action, $title, $search, $target;
 18+global $target, $returnto;
1819 global $wgUser, $wgLang, $wgOut, $wgTitle; # Objects to handle output
1920 global $wgArticle, $wgDeferredUpdateList;
2021

Status & tagging log