r18 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17‎ | r18 | r19 >
Date:13:42, 2 October 2001
Author:magnus_manske
Status:old
Tags:
Comment:
bugfixes
Modified paths:
  • /trunk/phpwiki/fpw/specialPages.php (modified) (history)
  • /trunk/phpwiki/fpw/wiki.phtml (modified) (history)
  • /trunk/phpwiki/fpw/wikiPage.php (modified) (history)
  • /trunk/phpwiki/fpw/wikiTitle.php (modified) (history)
  • /trunk/phpwiki/fpw/wikiUser.php (modified) (history)

Diff [purge]

Index: trunk/phpwiki/fpw/specialPages.php
@@ -20,15 +20,16 @@
2121 $text = $EditBox ;
2222 $text = str_replace ( "\\'" , "'" , $text ) ;
2323 $text = str_replace ( "\\\"" , "\"" , $text ) ;
24 - if ( $user->isLoggedIn )
25 - $text = str_replace ( "~~~" , "[[user:$user->name|$user->name]]" , $text ) ;
 24+ if ( $user->isLoggedIn ) $text = str_replace ( "~~~" , "[[user:$user->name|$user->name]]" , $text ) ;
 25+ else $text = str_replace ( "~~~" , $user->getLink() , $text ) ;
2626 $title = str_replace ( "\\'" , "'" , $title ) ;
2727 $title = str_replace ( "\\\"" , "\"" , $title ) ;
2828 $npage->title = $title ;
2929 $npage->makeAll () ;
3030 if ( $npage->doesTopicExist() ) $npage->backup() ;
3131 else { $MinorEdit = 2 ; $npage->ensureExistence () ; }
32 - $npage->setEntry ( $text , $CommentBox , $user->id , $user->name , $MinorEdit*1 ) ;
 32+ if ( !$user->isLoggedIn ) $npage->setEntry ( $text , $CommentBox , 0 , $user->getLink() , $MinorEdit*1 ) ;
 33+ else $npage->setEntry ( $text , $CommentBox , $user->id , $user->name , $MinorEdit*1 ) ;
3334 global $wasSaved ;
3435 $wasSaved = true ;
3536 return "" ;
@@ -94,14 +95,14 @@
9596 function userLogout () {
9697 global $user , $vpage ;
9798 $vpage->title = "User logout" ;
98 - setcookie ( "WikiLoggedIn" , "" ) ;
99 - if ( $user->options["rememberPassword"] != "on" ) setcookie ( "WikiUserPassword" , "" ) ;
 99+ setcookie ( "WikiLoggedIn" , "" , time()-3600 ) ;
 100+ if ( $user->options["rememberPassword"] != "on" ) setcookie ( "WikiUserPassword" , "" , time()-3600 ) ;
100101 $user->isLoggedIn = false ;
101102 return "<h1>Goodbye, $user->name!</h1>" ;
102103 }
103104
104105 function userLogin () {
105 - global $loginattempt , $user , $vpage , $WikiUserID ;
 106+ global $loginattempt , $user , $vpage , $WikiUserID , $expiration ;
106107 $vpage->title = "User login" ;
107108
108109 if ( isset ( $loginattempt ) ) {
@@ -118,18 +119,18 @@
119120 if ( $nu->isLoggedIn ) {
120121 $user = new WikiUser ;
121122 $user = $nu ;
122 - setcookie ( "WikiUserID" , $user->id ) ;
123 - setcookie ( "WikiLoggedIn" , "yes" ) ;
124 - setcookie ( "WikiUserPassword" , $user->password ) ;
 123+ setcookie ( "WikiUserID" , $user->id , $expiration ) ;
 124+ setcookie ( "WikiLoggedIn" , "yes" , $expiration ) ;
 125+ setcookie ( "WikiUserPassword" , $user->password , $expiration ) ;
125126 $user->options["rememberPassword"] = $REMEMBERPASSWORD ;
126127 $user->saveSettings() ;
127128 } else if ( $USERPASSWORD == $RETYPE and !($nu->doesUserExist()) ) {
128129 $nu->addToDatabase () ;
129130 $user = $nu ;
130131 $s = "<h1>Welcome, $user->name!</h1><font color=red>Don't forget to personalize your wikipedia perferences!</font>" ;
131 - setcookie ( "WikiLoggedIn" , "yes" ) ;
132 - setcookie ( "WikiUserID" , $user->id ) ;
133 - if ( $user->options["rememberPassword"] == "on" ) setcookie ( "WikiUserPassword" , $user->password ) ;
 132+ setcookie ( "WikiLoggedIn" , "yes" , $expiration ) ;
 133+ setcookie ( "WikiUserID" , $user->id , $expiration ) ;
 134+ if ( $user->options["rememberPassword"] == "on" ) setcookie ( "WikiUserPassword" , $user->password , $expiration ) ;
134135 $user->options["rememberPassword"] = $REMEMBERPASSWORD ;
135136 $user->saveSettings() ;
136137 } else {
@@ -379,7 +380,7 @@
380381 $v = trim(str_replace("\n","",$v)) ;
381382 $v = str_replace ( "'''" , "" , $v ) ;
382383 $v = str_replace ( "''" , "" , $v ) ;
383 - $v = ereg_replace ( "{{{.*}}}" , "?" , $v ) ;
 384+ $v = ereg_replace ( "\{\{\{.*\}\}\}" , "?" , $v ) ;
384385 $v = trim ( $v ) ;
385386 while ( substr($v,0,1) == ":" ) $v = substr($v,1) ;
386387 while ( substr($v,0,1) == "*" ) $v = substr($v,1) ;
@@ -467,6 +468,53 @@
468469 return $vpage->renderPage () ;
469470 }
470471
 472+function listUsers () {
 473+ global $user , $vpage , $startat ;
 474+ if ( !isset ( $startat ) ) $startat = 1 ;
 475+ $perpage = $user->options["resultsPerPage"] ;
 476+ if ( $perpage == 0 ) $perpage = 20 ;
 477+
 478+ $vpage->special ( "User List" ) ;
 479+ $vpage->namespace = "" ;
 480+ $ret = "'''These are all wikipedia users (that have an account)!'''\n\n" ;
 481+ $connection = getDBconnection () ;
 482+ mysql_select_db ( "wikipedia" , $connection ) ;
 483+ $sql = "SELECT COUNT(*) AS number FROM cur WHERE cur_title LIKE \"User:%\"" ;
 484+ $result = mysql_query ( $sql , $connection ) ;
 485+ $s = mysql_fetch_object ( $result ) ;
 486+ $total = $s->number ;
 487+ $sql = "SELECT * FROM cur WHERE cur_title LIKE \"User:%\" ORDER BY cur_title" ;
 488+ $result = mysql_query ( $sql , $connection ) ;
 489+ $cnt = 1 ;
 490+ $color1 = $user->options["tabLine1"] ;
 491+ $color2 = $user->options["tabLine2"] ;
 492+ $color = $color1 ;
 493+ $ret .= "<table width=100%>\n" ;
 494+ while ( $s = mysql_fetch_object ( $result ) and $cnt < $startat+$perpage ) {
 495+ if ( $cnt >= $startat ) {
 496+ $u = $s->cur_title ;
 497+ $u = substr ( strstr ( $u , ":" ) , 1 ) ;
 498+ $u = $vpage->getNiceTitle ( $u ) ;
 499+ $ret .= "<tr><td$color align=right nowrap>$cnt</td>" ;
 500+ $ret .= "<td$color width=100% valign=top>[[$s->cur_title|$u]]</td></tr>\n";
 501+ if ( $color == $color1 ) $color = $color2 ;
 502+ else $color = $color1 ;
 503+ }
 504+ $cnt++ ;
 505+ }
 506+ $ret .= "</table>\n" ;
 507+
 508+ $ret .= "<nowiki>" ;
 509+ $before = $startat - $perpage ; $fin = $before + $perpage - 1 ;
 510+ if ( $startat > 1 ) $ret .= "<a href=\"$PHP_SELF?title=special:UserList&startat=$before\">$before-$fin&lt;&lt;</a> &nbsp;" ;
 511+ $after = $startat + $perpage ; $fin = $after+$perpage - 1 ; if ( $fin > $total ) $fin = $total ;
 512+ if ( $after-1 < $total ) $ret .= "<a href=\"$PHP_SELF?title=special:UserList&startat=$after\">&gt;&gt;$after-$fin</a>" ;
 513+ $ret .= "</nowiki>" ;
 514+ mysql_free_result ( $result ) ;
 515+ mysql_close ( $connection ) ;
 516+ return $ret ;
 517+ }
 518+
471519 function randompage () {
472520 global $vpage ;
473521 $connection=getDBconnection() ;
@@ -892,4 +940,49 @@
893941 $ret .= $vpage->getQuickBar () ;
894942 return $ret ;
895943 }
 944+
 945+function ShortPages () {
 946+ global $user , $vpage , $startat ;
 947+ if ( !isset ( $startat ) ) $startat = 1 ;
 948+ $perpage = $user->options["resultsPerPage"] ;
 949+ if ( $perpage == 0 ) $perpage = 20 ;
 950+
 951+ $vpage->special ( "Short 'stub' articles" ) ;
 952+ $vpage->namespace = "" ;
 953+ $ret = "'''These are all the articles in the database, sorted by length!'''\n\n" ;
 954+ $connection = getDBconnection () ;
 955+ mysql_select_db ( "wikipedia" , $connection ) ;
 956+ $sql = "SELECT COUNT(*) AS number FROM cur" ;
 957+ $result = mysql_query ( $sql , $connection ) ;
 958+ $s = mysql_fetch_object ( $result ) ;
 959+ $total = $s->number ;
 960+ $sql = "SELECT * FROM cur ORDER BY LENGTH(cur_text)" ;
 961+ $result = mysql_query ( $sql , $connection ) ;
 962+ $cnt = 1 ;
 963+ $color1 = $user->options["tabLine1"] ;
 964+ $color2 = $user->options["tabLine2"] ;
 965+ $color = $color1 ;
 966+ $ret .= "<table width=100%>\n" ;
 967+ while ( $s = mysql_fetch_object ( $result ) and $cnt < $startat+$perpage ) {
 968+ if ( $cnt >= $startat ) {
 969+ $ret .= "<tr><td$color align=right nowrap>$cnt</td>" ;
 970+ $ret .= "<td$color align=right nowrap>(".strlen($s->cur_text)." chars)</td>\n" ;
 971+ $ret .= "<td$color width=100% valign=top>[[$s->cur_title]]</td></tr>\n";
 972+ if ( $color == $color1 ) $color = $color2 ;
 973+ else $color = $color1 ;
 974+ }
 975+ $cnt++ ;
 976+ }
 977+ $ret .= "</table>\n" ;
 978+
 979+ $ret .= "<nowiki>" ;
 980+ $before = $startat - $perpage ; $fin = $before + $perpage - 1 ;
 981+ if ( $startat > 1 ) $ret .= "<a href=\"$PHP_SELF?title=special:ShortPages&startat=$before\">$before-$fin&lt;&lt;</a> &nbsp;" ;
 982+ $after = $startat + $perpage ; $fin = $after+$perpage - 1 ; if ( $fin > $total ) $fin = $total ;
 983+ if ( $after-1 < $total ) $ret .= "<a href=\"$PHP_SELF?title=special:ShortPages&startat=$after\">&gt;&gt;$after-$fin</a>" ;
 984+ $ret .= "</nowiki>" ;
 985+ mysql_free_result ( $result ) ;
 986+ mysql_close ( $connection ) ;
 987+ return $ret ;
 988+ }
896989 ?>
\ No newline at end of file
Index: trunk/phpwiki/fpw/wiki.phtml
@@ -7,13 +7,19 @@
88
99 # Main program
1010 global $action , $title , $pageTitle ;
11 - global $user , $search ;
 11+ global $user , $search , $expiration ;
 12+ $expiration = time()+315360000 ; # Cookies set will expire in ten years from now
1213 $pageTitle = "" ;
1314 $user = new WikiUser ;
1415 $user->scanCookies () ;
1516 if ( $action == "" ) $action = "view" ;
1617 if ( $title == "" ) $title = "HomePage" ;
1718
 19+ $theTitle = new wikiTitle ;
 20+ $theTitle->title = urldecode ( $title ) ;
 21+ $theTitle->makeSecureTitle () ;
 22+ $title = $theTitle->secureTitle ;
 23+
1824 $action = strtolower ( trim ( $action ) ) ;
1925 $title = urldecode ( $title ) ;
2026
Index: trunk/phpwiki/fpw/wikiPage.php
@@ -133,15 +133,17 @@
134134 if ( count($b) < 2 ) $s .= "Illegal link : ?$b[0]?" ;
135135 else {
136136 $c = explode ( "|" , $b[0] , 2 ) ;
137 - if ( count ( $c ) == 1 ) array_push ( $c , $c[0] ) ;
138137 $link = $c[0] ;
139 - $text = $c[1] ;
140138
141139 $topic = new WikiTitle ;
142140 $topic->setTitle ( $link ) ;
143141 $link = $this->getLinkTo ( $topic ) ;
144142 $topic->setTitle ( $link ) ;
145143
 144+ if ( count ( $c ) == 1 ) array_push ( $c , $topic->getNiceTitle($topic->secureTitle) ) ;
 145+ $text = $c[1] ;
 146+
 147+
146148 if ( $topic->doesTopicExist() ) {
147149 $linkedLinks[$topic->secureTitle]++ ;
148150 if ( $user->options["showHover"] == "yes" ) $hover = "title=\"$link\"" ;
@@ -206,7 +208,7 @@
207209 function replaceVariables ( $s ) {
208210 $var=date("m"); $s = str_replace ( "{{{CURRENTMONTH}}}" , $var , $s ) ;
209211 $var=date("F"); $s = str_replace ( "{{{CURRENTMONTHNAME}}}" , $var , $s ) ;
210 - $var=date("d"); $s = str_replace ( "{{{CURRENTDAY}}}" , $var , $s ) ;
 212+ $var=date("j"); $s = str_replace ( "{{{CURRENTDAY}}}" , $var , $s ) ;
211213 $var=date("l"); $s = str_replace ( "{{{CURRENTDAYNAME}}}" , $var , $s ) ;
212214 $var=date("Y"); $s = str_replace ( "{{{CURRENTYEAR}}}" , $var , $s ) ;
213215 if ( strstr ( $s , "{{{NUMBEROFARTICLES}}}" ) ) {
@@ -250,7 +252,11 @@
251253 foreach ( $a as $x ) {
252254 $b = spliti ( "</nowiki>" , $x , 2 ) ;
253255 $s .= $b[0] ;
254 - if ( count ( $b ) == 2 ) $s .= $this->subParseContents ( $b[1] ) ;
 256+ if ( count ( $b ) == 2 ) {
 257+ $sub = $this->subParseContents ( $b[1] ) ;
 258+ $sub = substr ( strstr ( $sub , ">" ) , 1 ) ;
 259+ $s .= $sub ;
 260+ }
255261 }
256262 return $s ;
257263 }
@@ -361,7 +367,7 @@
362368 }
363369 function getHeader () {
364370 global $user , $action ;
365 - $t = $this->title ;
 371+ $t = $this->getNiceTitle ( $this->title ) ;
366372 if ( substr_count ( $t , ":" ) > 0 ) $t = ucfirst ( $t ) ;
367373 $ret = "<table ".$user->options["quickBarBackground"]." width=100% border=1 frame=below rules=none bordercolor=black cellspacing=0>\n<tr>" ;
368374 if ( $user->options["leftImage"] != "" )
@@ -406,6 +412,8 @@
407413 $column .= "<br>\n<a href=\"$PHP_SELF?title=special:WantedPages\">Most wanted</a>" ;
408414 $column .= "<br>\n<a href=\"$PHP_SELF?title=special:AllPages\">All pages</a>" ;
409415 $column .= "<br>\n<a href=\"$PHP_SELF?title=special:RandomPage\">Random Page</a>" ;
 416+ $column .= "<br>\n<a href=\"$PHP_SELF?title=special:ShortPages\">Stub articles</a>" ;
 417+ $column .= "<br>\n<a href=\"$PHP_SELF?title=special:ListUsers\">List users</a>" ;
410418 if ( $user->isLoggedIn ) {
411419 $column .= "<br>\n<a href=\"$PHP_SELF?title=special:WatchList\">My watchlist</a>" ;
412420 }
Index: trunk/phpwiki/fpw/wikiUser.php
@@ -88,6 +88,7 @@
8989 $this->skin () ;
9090 }
9191 function saveSettings () {
 92+ global $expiration ;
9293 if ( !$this->isLoggedIn ) return ;
9394 $t = "" ;
9495 $a = array_keys ( $this->options ) ;
@@ -100,15 +101,15 @@
101102 setMySQL ( "user" , "user_options" , urlencode ( $t ) , "user_id=".$this->id ) ;
102103 setMySQL ( "user" , "user_password" , $this->password , "user_id=".$this->id ) ;
103104 setMySQL ( "user" , "user_email" , $this->email , "user_id=".$this->id ) ;
104 - if ( $this->options["rememberPassword"] == "on" ) setcookie ( "WikiUserPassword" , $this->password ) ;
 105+ if ( $this->options["rememberPassword"] == "on" ) setcookie ( "WikiUserPassword" , $this->password , $expiration ) ;
105106 }
106107 function getLink () {
107108 global $REMOTE_ADDR ;
108109 if ( $this->isLoggedIn ) {
109110 $s = new WikiPage ;
110 - $s->setTitle ( "user:$this->name" ) ;
111 - $s = $s->parseContents ( "[[$this->name]]" ) ;
112 - $s = str_replace ( "<p>" , "" , $s ) ;
 111+# $s->setTitle ( "user:$this->name" ) ;
 112+ $s = $s->parseContents ( "[[user:$this->name|$this->name]]" ) ;
 113+ $s = substr ( strstr ( $s , ">" ) , 1 ) ;
113114 $s = str_replace ( "</p>" , "" , $s ) ;
114115 return $s ;
115116 }
Index: trunk/phpwiki/fpw/wikiTitle.php
@@ -45,11 +45,12 @@
4646 if ( $s != "" ) $s .= ":" ;
4747 $s .= ucfirst ( trim ( $this->mainTitle ) ) ;
4848 if ( trim ( $this->subpageTitle ) != "" ) $s .= "/".trim($this->subpageTitle) ;
49 - $s = str_replace ( "\"" , "_" , $s ) ;
 49+ $s = str_replace ( "\\\"" , "" , $s ) ;
 50+ $s = str_replace ( "\"" , "" , $s ) ;
5051 $s = str_replace ( "\\'" , "'" , $s ) ;
5152
5253 # Make it compatible with old wiki
53 - $s = str_replace ( "'" , "" , $s ) ;
 54+# $s = str_replace ( "'" , "" , $s ) ;
5455 $s = str_replace ( " " , "_" , $s ) ;
5556
5657 $this->secureTitle = $s ;
@@ -61,7 +62,7 @@
6263 if ( !isset ( $s ) ) $s = $this->secureTitle ;
6364 $s = str_replace ( "_" , " " , $s ) ;
6465 $s = str_replace ( "\\'" , "'" , $s ) ;
65 - $s = str_replace ( "\\\"" , "\"" , $s ) ;
 66+ $s = str_replace ( "\\\\" , "\\" , $s ) ;
6667 return ucfirst ( $s ) ;
6768 }
6869 function splitTitle () {

Follow-up revisions

RevisionCommit summaryAuthorDate
r100158Import wfMsg statistics script by Seb35,...platonides20:52, 18 October 2011

Status & tagging log