r406 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r405‎ | r406 | r407 >
Date:01:08, 21 May 2002
Author:lcrocker
Status:old
Tags:
Comment:
More fixes for article editing.
Modified paths:
  • /trunk/phpwiki/newcodebase/Article.php (modified) (history)
  • /trunk/phpwiki/newcodebase/GlobalFunctions.php (modified) (history)
  • /trunk/phpwiki/newcodebase/Language.php (modified) (history)
  • /trunk/phpwiki/newcodebase/SpecialPreferences.php (modified) (history)
  • /trunk/phpwiki/newcodebase/SpecialUserlogin.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)

Diff [purge]

Index: trunk/phpwiki/newcodebase/User.php
@@ -46,8 +46,7 @@
4747 global $wgDefaultOptions;
4848
4949 $this->mId = 0;
50 - $remaddr = getenv( "REMOTE_ADDR" );
51 - $this->mName = preg_replace( "/\d+$/", "xxx", $remaddr );
 50+ $this->mName = getenv( "REMOTE_ADDR" );
5251 $this->mEmail = "";
5352 $this->mPassword = "";
5453 $this->mRights = array();
@@ -62,7 +61,7 @@
6362
6463 /* private */ function getBlockedStatus()
6564 {
66 - if ( -1 != $this->mBlockedby ) { return ; }
 65+ if ( -1 != $this->mBlockedby ) { return; }
6766
6867 $remaddr = getenv( "REMOTE_ADDR" );
6968 $conn = wfGetDB();
@@ -71,15 +70,18 @@
7271 wfDebug( "User: 5: $sql\n" );
7372
7473 $res = mysql_query( $sql, $conn );
75 - if ( ! $res ) {
 74+ if ( ( ! $res ) || ( 0 == mysql_num_rows( $res ) ) ) {
7675 if ( 0 == $this->mId ) {
7776 $this->mBlockedby = 0;
7877 return;
7978 }
 79+ $conn = wfGetDB();
8080 $sql = "SELECT ipb_by,ipb_reason FROM ipblocks WHERE " .
8181 "ipb_user={$this->mId}";
8282 wfDebug( "User: 6: $sql\n" );
83 - if ( ! $res ) {
 83+
 84+ $res = mysql_query( $sql, $conn );
 85+ if ( ( ! $res ) || ( 0 == mysql_num_rows( $res ) ) ) {
8486 $this->mBlockedby = 0;
8587 return;
8688 }
@@ -368,7 +370,6 @@
369371 wfSetSQL( "user", "user_watch", implode( "\n", $this->mWatchlist ),
370372 "user_id={$this->mId}" );
371373 }
372 - $this->setCookies();
373374 }
374375
375376 # Checks if a user with the given name exists
Index: trunk/phpwiki/newcodebase/Title.php
@@ -145,7 +145,9 @@
146146 wfDebug( "Title: 2: $sql\n" );
147147
148148 $res = mysql_query( $sql, $conn );
149 - if ( ! $res ) { return $this->mOtherNamespaces; }
 149+ if ( ! $res || 0 == mysql_num_rows( $res ) ) {
 150+ return $this->mOtherNamespaces;
 151+ }
150152
151153 while ( $row = mysql_fetch_object( $res ) ) {
152154 $ns = $row->cur_namespace;
@@ -186,7 +188,7 @@
187189 # wfDebug( "Title: 1: $sql\n" );
188190 $res = mysql_query( $sql, $conn );
189191
190 - if ( ! $res ) {
 192+ if ( ! $res || 0 == mysql_num_rows( $res ) ) {
191193 $this->mArticleID = 0;
192194 } else {
193195 $s = mysql_fetch_object( $res );
Index: trunk/phpwiki/newcodebase/Language.php
@@ -118,11 +118,26 @@
119119 "preview" => "Preview",
120120 "showpreview" => "Show preview",
121121 "blockedtitle" => "User is blocked",
122 -"blockedtext" => "Your user name or IP addressed has been blocked by $1.
123 -The reason given is this:<br>$2<p>You may contact that administrator to
 122+"blockedtext" => "Your user name or IP address has been blocked by $1.
 123+The reason given is this:<br>$2<p>You may contact the administrator to
124124 discuss the block.",
125 -"newarticle" => "New article",
 125+"newarticle" => "New article: $1",
126126 "newarticletext" => "Describe the new page here.",
 127+"updated" => "Updated: $1",
 128+"note" => "<strong>Note:</strong> ",
 129+"previewnote" => "Remember that this is only a preview, and has not yet been saved!",
 130+"previewconflict" => "This preview reflects the text in the upper
 131+text editing area as it will appear if you choose to save.",
 132+"editing" => "Editing $1",
 133+"editconflict" => "Edit conflict: $1",
 134+"explainconflict" => "Someone else has changed this article since you
 135+started editing it.
 136+The upper text area contains the article text as it currently exists.
 137+Your changes are shown in the lower text area.
 138+You will have to merge your changes into the existing text.
 139+<b>Only</b> the text in the upper text area will be saved when you
 140+press \"Save\".\n<p>",
 141+"yourtext" => "Your text",
127142
128143 # Preferences page
129144 #
Index: trunk/phpwiki/newcodebase/Article.php
@@ -4,14 +4,14 @@
55 class Article {
66 /* private */ var $mTitle; # WikiTitle object
77 /* private */ var $mContent, $mContentLoaded;
8 - /* private */ var $mTimestamp, $mParams;
 8+ /* private */ var $mUser, $mTimestamp, $mParams;
99 /* private */ var $mCounter;
1010
1111 function Article( $t )
1212 {
1313 $this->mTitle = $t;
1414 $this->mContentLoaded = false;
15 - $this->mCounter = -1; # Not loaded
 15+ $this->mUser = $this->mCounter = -1; # Not loaded
1616 $this->mTimestamp = "";
1717 }
1818
@@ -33,16 +33,17 @@
3434 if ( 0 == $id ) return;
3535
3636 $conn = wfGetDB();
37 - $sql = "SELECT cur_text, cur_timestamp, cur_counter, " .
 37+ $sql = "SELECT cur_text,cur_timestamp,cur_user,cur_counter, " .
3838 "cur_params FROM cur WHERE cur_id=$id";
3939 wfDebug( "Art: 1: $sql\n" );
4040 $result = mysql_query( $sql, $conn );
4141
42 - if ( ! $result ) {
 42+ if ( ! $result || 0 == mysql_num_rows( $result ) ) {
4343 $this->mContent = "Fatal database error.\n";
4444 } else {
4545 $s = mysql_fetch_object( $result );
4646 $this->mContent = $s->cur_text;
 47+ $this->mUser = $s->cur_user;
4748 $this->mCounter = $s->cur_counter;
4849 $this->mParams = $s->cur_params;
4950 $this->mTimestamp = $s->cur_timestamp;
@@ -62,15 +63,35 @@
6364 return $this->mCounter;
6465 }
6566
 67+ /* private */ function loadLastEdit()
 68+ {
 69+ if ( -1 != $this->mUser ) return;
 70+
 71+ $conn = wfGetDB();
 72+ $sql = "SELECT cur_user,cur_timestamp FROM cur WHERE " .
 73+ "cur_id=" . $this->getID();
 74+ wfDebug( "Art: 3: $sql\n" );
 75+
 76+ $res = mysql_query( $sql, $conn );
 77+ if ( "" != $res ) {
 78+ $s = mysql_fetch_object( $res );
 79+ $this->mUser = $s->cur_user;
 80+ $this->mTimestamp = $s->mTimestamp;
 81+ }
 82+ }
 83+
6684 function getTimestamp()
6785 {
68 - if ( "" == $this->mTimestamp ) {
69 - $id = $this->getID();
70 - $this->mTimestamp = wfGetSQL( "cur", "cur_timestamp", "cur_id=$id" );
71 - }
 86+ $this->loadLastEdit();
7287 return $this->mTimestamp;
7388 }
7489
 90+ function getUser()
 91+ {
 92+ $this->loadLastEdit();
 93+ return $this->mTimestamp;
 94+ }
 95+
7596 function view()
7697 {
7798 global $wgOut;
@@ -112,6 +133,7 @@
113134 global $wpTextbox1, $wpSummary, $wpSave, $wpPreview;
114135 global $wpMinoredit, $wpEdittime, $wpTextbox2;
115136
 137+ $isConflict = false;
116138 if ( "save" == $formtype ) {
117139 if ( $wgUser->isBlocked() ) {
118140 $this->blockedIPpage();
@@ -119,42 +141,42 @@
120142 }
121143 $aid = $wgTitle->getArticleID();
122144 if ( 0 == $aid ) { # New aritlce
123 - $conn = wfGetDB();
124 - $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
125 - "cur_comment,cur_user,cur_timestamp) VALUES ('" .
126 - $wgTitle->getNamespace() . "', '" .
127 - $wgTitle->getDBKey() . "', '" .
128 - wfStrencode( $wpTextbox1 ) . "', '" .
129 - wfStrencode( $wpSummary ) . "', '" . $wgUser->getID() .
130 - "', '" . date( "YmdHis" ) . "')";
131 -
132 - wfDebug( "Art: 2: $sql\n" );
133 - $res = mysql_query( $sql, $conn );
134 - $this->editUpdates();
135 -
136 - $wgOut->setPageTitle( wfMsg( "newarticle" ) . ": " .
137 - $wgTitle->getPrefixedText() );
138 - $wgOut->addWikiText( $wpTextbox1 );
 145+ $this->insertArticle( $wpTextbox1, $wpSummary );
139146 return;
140147 }
141148 # Check for edit conflict
142149 #
143 -
144 - # All's well: save the article here
145 - #
146 - $conn = wfGetDB();
147 - $sql = "";
148 - $this->editUpdates();
 150+ if ( $this->getUser() != $wgUser->getID() &&
 151+ $this->mTimestamp > $wpEdittime ) {
 152+ $isConflict = true;
 153+ } else {
 154+ # All's well: save the article here
 155+ $this->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit );
 156+ return;
 157+ }
149158 }
150159 if ( "initial" == $formtype ) {
151 - $wpEdittime = time( "YmdHis" );
 160+ $wpEdittime = $this->getTimestamp();
152161 $wpTextbox1 = $this->getContent();
153162 $wpSummary = "*";
154163 }
155 - $wgOut->setPageTitle( "Editing " . $wgTitle->getPrefixedText() );
156164 $wgOut->setRobotpolicy( "noindex,nofollow" );
157165 $wgOut->setArticleFlag( false );
158166
 167+ if ( $isConflict ) {
 168+ $s = str_replace( "$1", $wgTitle->getPrefixedText(),
 169+ wfMsg( "editconflict" ) );
 170+ $wgOut->setPageTitle( $s );
 171+ $wgOut->addHTML( wfMsg( "explainconflict" ) );
 172+
 173+ $wpTextbox2 = $wpTextbox1;
 174+ $wpTextbox1 = $this->getContent();
 175+ $wpEdittime = $this->getTimestamp();
 176+ } else {
 177+ $s = str_replace( "$1", $wgTitle->getPrefixedText(),
 178+ wfMsg( "editing" ) );
 179+ $wgOut->setPageTitle( $s );
 180+ }
159181 $rows = $wgUser->getOption( "rows" );
160182 $cols = $wgUser->getOption( "cols" );
161183 $action = "$wgServer$wgScript?title=" .
@@ -174,18 +196,78 @@
175197 <input tabindex=3 type=checkbox value=1 name='wpMinoredit'>$minor<br>
176198 <input tabindex=4 type=submit value='$save' name='wpSave'>
177199 <input tabindex=5 type=submit value='$prev' name='wpPreview'>
178 -<input type=hidden value='$wpEdittime' name='wpEdittime'>
179 -</form>\n" );
 200+<input type=hidden value='$wpEdittime' name='wpEdittime'>\n" );
180201
 202+ if ( $isConflict ) {
 203+ $wgOut->AddHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
 204+<textarea tabindex=6 name='wpTextbox2' rows=$rows cols=$cols style='width:100%' wrap=virtual>\n" );
 205+ }
 206+ $wgOut->addHTML( "</form>\n" );
 207+
181208 if ( "preview" == $formtype ) {
182209 $wgOut->addHTML( "<h2>" . wfMsg( "preview" ) . "</h2>\n" );
 210+ if ( $isConflict ) {
 211+ $wgOut->addHTML( "<h2>" . wfMsg( "previewconflict" ) .
 212+ "</h2>\n" );
 213+ }
183214 $wgOut->addWikiText( $wpTextbox1 );
 215+ $wgOut->addHTML( "<p><large>" . wfMsg( "note" ) .
 216+ wfMsg( "previewnote" ) . "</large>\n" );
184217 }
185218 }
186219
 220+ # Theoretically we could defer these whole insert and update
 221+ # functions for after display, but that's taking a big leap
 222+ # leap of faith, and I want to be able to report database
 223+ # errors at some point.
 224+ #
 225+ /* private */ function insertArticle( $text, $summary )
 226+ {
 227+ global $wgOut, $wgUser, $wgTitle;
 228+
 229+ $conn = wfGetDB();
 230+ $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() . "', '" .
 233+ wfStrencode( $text ) . "', '" . wfStrencode( $summary ) . "', '" .
 234+ $wgUser->getID() . "', '" . date( "YmdHis" ) . "', 0)";
 235+
 236+ wfDebug( "Art: 2: $sql\n" );
 237+ $res = mysql_query( $sql, $conn );
 238+ $this->editUpdates();
 239+
 240+ $s = str_replace( "$1", $wgTitle->getPrefixedText,
 241+ wfMsg( "newarticle" ) );
 242+ $wgOut->setPageTitle( $s );
 243+ $wgOut->addWikiText( $text );
 244+ }
 245+
 246+ function updateArticle( $text, $summary, $minor )
 247+ {
 248+ global $wgOut, $wgUser, $wgTitle;
 249+
 250+ if ( $minor) { $me = 1; } else { $me = 0; }
 251+
 252+ $conn = wfGetDB();
 253+ $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
 254+ "',cur_comment='" . wfStrencode( $summary ) .
 255+ "',cur_minor_edit=$me, cur_user=" . $wgUser->getID() .
 256+ ", cur_timestamp='" . date( "YmdHis" ) . "' " .
 257+ "WHERE cur_id=" . $this->getID();
 258+
 259+ wfDebug( "Art: 4: $sql\n" );
 260+ $res = mysql_query( $sql, $conn );
 261+ $this->editUpdates();
 262+
 263+ $s = str_replace( "$1", $wgTitle->getPrefixedText(),
 264+ wfMsg( "updated" ) );
 265+ $wgOut->setPageTitle( $s );
 266+ $wgOut->addWikiText( $text );
 267+ }
 268+
187269 function viewprintable()
188270 {
189 - global $wgOut, $wgUser;
 271+ global $wgOut, $wgUser, $wgTitle;
190272
191273 $n = $this->mTitle->getPrefixedText();
192274 $wgOut->setPageTitle( $n );
Index: trunk/phpwiki/newcodebase/GlobalFunctions.php
@@ -126,7 +126,7 @@
127127 wfDebug( "Glob: 1: $sql\n" );
128128
129129 $res = mysql_query( $sql, $conn );
130 - if ( ! $res ) { return; }
 130+ if ( ! $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/SpecialPreferences.php
@@ -50,7 +50,6 @@
5151 $wgUser->setOption( $tname, $HTTP_POST_VARS["wpOp$tname"] );
5252 }
5353 $wgUser->setCookies();
54 -
5554 $up = new UserUpdate();
5655 array_push( $wgDeferredUpdateList, $up );
5756 mainPrefsForm( wfMsg( "savedprefs" ) );
Index: trunk/phpwiki/newcodebase/SpecialUserlogin.php
@@ -118,7 +118,7 @@
119119 {
120120 global $wgOut;
121121
122 - $wgOut->setPageTitle( "loginsuccesstitle" );
 122+ $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) );
123123 $wgOut->setRobotpolicy( "noindex,nofollow" );
124124 $wgOut->addHTML( $msg . "\n<p>" );
125125 $wgOut->addWikiText( wfMsg( "returntomain" ) );
Index: trunk/phpwiki/newcodebase/sql/buildtables.sql
@@ -97,7 +97,8 @@
9898 CREATE TABLE ipblocks (
9999 ipb_address varchar(40) binary default '',
100100 ipb_user mediumint(8) unsigned default '0',
101 - ipb_reason mediumtext,
 101+ ipb_by mediumint(8) unsigned default '0',
 102+ ipb_reason mediumtext default '',
102103 INDEX ipb_address (ipb_address),
103104 INDEX ipb_user (ipb_user)
104105 ) TYPE=MyISAM;

Status & tagging log