Index: trunk/phpwiki/newcodebase/User.php |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | /* private */ var $mRights, $mOptions; |
18 | 18 | /* private */ var $mDataLoaded; |
19 | 19 | /* private */ var $mSkin, $mWatchlist; |
| 20 | + /* private */ var $mBlockedby, $mBlockreason; |
20 | 21 | |
21 | 22 | function User() |
22 | 23 | { |
— | — | @@ -35,6 +36,11 @@ |
36 | 37 | return $u; |
37 | 38 | } |
38 | 39 | |
| 40 | + /* static */ function whoIs( $id ) |
| 41 | + { |
| 42 | + return wfGetSQL( "user", "user_name", "user_id=$id" ); |
| 43 | + } |
| 44 | + |
39 | 45 | function loadDefaults() |
40 | 46 | { |
41 | 47 | global $wgDefaultOptions; |
— | — | @@ -51,8 +57,55 @@ |
52 | 58 | unset( $this->mSkin ); |
53 | 59 | unset( $this->mWatchlist ); |
54 | 60 | $this->mDataLoaded = false; |
| 61 | + $this->mBlockedby = -1; # Unset |
55 | 62 | } |
56 | 63 | |
| 64 | + /* private */ function getBlockedStatus() |
| 65 | + { |
| 66 | + if ( -1 != $this->mBlockedby ) { return ; } |
| 67 | + |
| 68 | + $remaddr = getenv( "REMOTE_ADDR" ); |
| 69 | + $conn = wfGetDB(); |
| 70 | + $sql = "SELECT ipb_by,ipb_reason FROM ipblocks WHERE " . |
| 71 | + "ipb_address='$remaddr'"; |
| 72 | + wfDebug( "User: 5: $sql\n" ); |
| 73 | + |
| 74 | + $res = mysql_query( $sql, $conn ); |
| 75 | + if ( ! $res ) { |
| 76 | + if ( 0 == $this->mId ) { |
| 77 | + $this->mBlockedby = 0; |
| 78 | + return; |
| 79 | + } |
| 80 | + $sql = "SELECT ipb_by,ipb_reason FROM ipblocks WHERE " . |
| 81 | + "ipb_user={$this->mId}"; |
| 82 | + wfDebug( "User: 6: $sql\n" ); |
| 83 | + if ( ! $res ) { |
| 84 | + $this->mBlockedby = 0; |
| 85 | + return; |
| 86 | + } |
| 87 | + } |
| 88 | + $s = mysql_fetch_object( $res ); |
| 89 | + $this->mBlockedby = $s->ipb_by; |
| 90 | + $this->mBlockreason = $s->ipb_reason; |
| 91 | + } |
| 92 | + |
| 93 | + function isBlocked() |
| 94 | + { |
| 95 | + $this->getBlockedStatus(); |
| 96 | + if ( 0 == $this->mBlockedby ) { return false; } |
| 97 | + return true; |
| 98 | + } |
| 99 | + |
| 100 | + function blockedBy() { |
| 101 | + $this->getBlockedStatus(); |
| 102 | + return $this->mBlockedby; |
| 103 | + } |
| 104 | + |
| 105 | + function blockedFor() { |
| 106 | + $this->getBlockedStatus(); |
| 107 | + return $this->mBlockreason; |
| 108 | + } |
| 109 | + |
57 | 110 | function loadFromSession() |
58 | 111 | { |
59 | 112 | global $HTTP_COOKIE_VARS, $wsUserID, $wsUserName, $wsUserPassword; |
Index: trunk/phpwiki/newcodebase/Language.php |
— | — | @@ -117,6 +117,12 @@ |
118 | 118 | "savearticle" => "Save article", |
119 | 119 | "preview" => "Preview", |
120 | 120 | "showpreview" => "Show preview", |
| 121 | +"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 |
| 124 | +discuss the block.", |
| 125 | +"newarticle" => "New article", |
| 126 | +"newarticletext" => "Describe the new page here.", |
121 | 127 | |
122 | 128 | # Preferences page |
123 | 129 | # |
Index: trunk/phpwiki/newcodebase/Article.php |
— | — | @@ -17,8 +17,9 @@ |
18 | 18 | |
19 | 19 | function getContent() |
20 | 20 | { |
21 | | - if ( 0 == $this->getID() ) { return "(Non-existent article.)\n"; } |
22 | | - else { |
| 21 | + if ( 0 == $this->getID() ) { |
| 22 | + return wfMsg( "newarticletext" ); |
| 23 | + } else { |
23 | 24 | $this->loadContent(); |
24 | 25 | return $this->mContent; |
25 | 26 | } |
— | — | @@ -72,15 +73,19 @@ |
73 | 74 | |
74 | 75 | function view() |
75 | 76 | { |
76 | | - global $wgOut, $wgUser; |
| 77 | + global $wgOut; |
| 78 | + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); |
77 | 79 | |
78 | | - $n = $this->mTitle->getPrefixedText(); |
79 | | - $wgOut->setPageTitle( $n ); |
80 | | - $wgOut->addWikiText( $this->getContent() ); |
81 | | - |
| 80 | + $this->showArticle(); |
82 | 81 | $this->viewUpdates(); |
83 | 82 | } |
84 | 83 | |
| 84 | + /* private */ function showArticle() |
| 85 | + { |
| 86 | + global $wgOut; |
| 87 | + $wgOut->addWikiText( $this->getContent() ); |
| 88 | + } |
| 89 | + |
85 | 90 | function edit() |
86 | 91 | { |
87 | 92 | global $wgOut, $wgUser, $wgTitle; |
— | — | @@ -92,7 +97,7 @@ |
93 | 98 | return; |
94 | 99 | } |
95 | 100 | if ( isset( $wpSave ) ) { |
96 | | - $this->editSave(); |
| 101 | + $this->editForm( "save" ); |
97 | 102 | } else if ( isset( $wpPreview ) ) { |
98 | 103 | $this->editForm( "preview" ); |
99 | 104 | } else { # First time through |
— | — | @@ -107,15 +112,49 @@ |
108 | 113 | global $wpTextbox1, $wpSummary, $wpSave, $wpPreview; |
109 | 114 | global $wpMinoredit, $wpEdittime, $wpTextbox2; |
110 | 115 | |
111 | | - $wgOut->setPageTitle( "Editing " . $wgTitle->getPrefixedText() ); |
112 | | - $wgOut->setRobotpolicy( "noindex,nofollow" ); |
113 | | - $wgOut->setArticleFlag( false ); |
| 116 | + if ( "save" == $formtype ) { |
| 117 | + if ( $wgUser->isBlocked() ) { |
| 118 | + $this->blockedIPpage(); |
| 119 | + return; |
| 120 | + } |
| 121 | + $aid = $wgTitle->getArticleID(); |
| 122 | + 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" ) . "')"; |
114 | 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 ); |
| 139 | + return; |
| 140 | + } |
| 141 | + # Check for edit conflict |
| 142 | + # |
| 143 | + |
| 144 | + # All's well: save the article here |
| 145 | + # |
| 146 | + $conn = wfGetDB(); |
| 147 | + $sql = ""; |
| 148 | + $this->editUpdates(); |
| 149 | + } |
115 | 150 | if ( "initial" == $formtype ) { |
116 | 151 | $wpEdittime = time( "YmdHis" ); |
117 | 152 | $wpTextbox1 = $this->getContent(); |
118 | 153 | $wpSummary = "*"; |
119 | 154 | } |
| 155 | + $wgOut->setPageTitle( "Editing " . $wgTitle->getPrefixedText() ); |
| 156 | + $wgOut->setRobotpolicy( "noindex,nofollow" ); |
| 157 | + $wgOut->setArticleFlag( false ); |
| 158 | + |
120 | 159 | $rows = $wgUser->getOption( "rows" ); |
121 | 160 | $cols = $wgUser->getOption( "cols" ); |
122 | 161 | $action = "$wgServer$wgScript?title=" . |
— | — | @@ -144,15 +183,6 @@ |
145 | 184 | } |
146 | 185 | } |
147 | 186 | |
148 | | - function editSave() |
149 | | - { |
150 | | - $this->editUpdates(); |
151 | | - } |
152 | | - |
153 | | - function editPreview() |
154 | | - { |
155 | | - } |
156 | | - |
157 | 187 | function viewprintable() |
158 | 188 | { |
159 | 189 | global $wgOut, $wgUser; |
— | — | @@ -173,10 +203,6 @@ |
174 | 204 | { |
175 | 205 | } |
176 | 206 | |
177 | | - function edit_conflict() |
178 | | - { |
179 | | - } |
180 | | - |
181 | 207 | # Do standard deferred updates after page view |
182 | 208 | # |
183 | 209 | /* private */ function viewUpdates() |
— | — | @@ -201,6 +227,22 @@ |
202 | 228 | $u = new SiteStatsUpdate( 0, 1, 0 ); |
203 | 229 | array_push( $wgDeferredUpdateList, $u ); |
204 | 230 | } |
| 231 | + |
| 232 | + function blockedIPpage() |
| 233 | + { |
| 234 | + global $wgOut, $wgUser; |
| 235 | + |
| 236 | + $wgOut->setPageTitle( wfMsg( "blockedtitle" ) ); |
| 237 | + $id = $wgUser->blockedBy(); |
| 238 | + $reason = $wgUser->blockedFor(); |
| 239 | + |
| 240 | + $name = User::whoIs( $id ); |
| 241 | + $link = "[[User:$name|$name]]"; |
| 242 | + |
| 243 | + $text = str_replace( "$1", $link, wfMsg( "blockedtext" ) ); |
| 244 | + $text = str_replace( "$2", $reason, $text ); |
| 245 | + $wgOut->addWikiText( $text ); |
| 246 | + } |
205 | 247 | } |
206 | 248 | |
207 | 249 | ?> |
Index: trunk/phpwiki/newcodebase/GlobalFunctions.php |
— | — | @@ -27,12 +27,13 @@ |
28 | 28 | $wgTotalEdits = -1; |
29 | 29 | |
30 | 30 | include_once( "./DatabaseFunctions.php" ); |
| 31 | +include_once( "./UpdateClasses.php" ); |
31 | 32 | |
32 | 33 | function wfLocalLink( $a ) |
33 | 34 | { |
34 | 35 | global $wgArticlePath; |
35 | 36 | |
36 | | - $a = str_replace( " ", "+", $a ); |
| 37 | + $a = str_replace( " ", "_", $a ); |
37 | 38 | $a = str_replace( "$1", $a, $wgArticlePath ); |
38 | 39 | return $a; |
39 | 40 | } |
Index: trunk/phpwiki/newcodebase/wiki.phtml |
— | — | @@ -12,7 +12,6 @@ |
13 | 13 | include_once( "./User.php" ); |
14 | 14 | include_once( "./Title.php" ); |
15 | 15 | include_once( "./Article.php" ); |
16 | | -include_once( "./UpdateClasses.php" ); |
17 | 16 | |
18 | 17 | global $action, $title, $search; # From query string |
19 | 18 | global $wgUser, $wgLang, $wgOut, $wgTitle; # Objects to handle output |
— | — | @@ -26,7 +25,7 @@ |
27 | 26 | $wgUser->loadFromSession(); |
28 | 27 | $wgDeferredUpdateList = array(); |
29 | 28 | |
30 | | -wfStripTextFields(); # Clean up PHP's mess |
| 29 | +wfStripTextFields(); # Clean up PHP mess |
31 | 30 | |
32 | 31 | $action = strtolower( trim( $action ) ); |
33 | 32 | if ( "" == $action ) { $action = "view"; } |
Index: trunk/phpwiki/newcodebase/sql/buildtables.sql |
— | — | @@ -94,3 +94,11 @@ |
95 | 95 | UNIQUE KEY ss_row_id (ss_row_id) |
96 | 96 | ) TYPE=MyISAM; |
97 | 97 | |
| 98 | +CREATE TABLE ipblocks ( |
| 99 | + ipb_address varchar(40) binary default '', |
| 100 | + ipb_user mediumint(8) unsigned default '0', |
| 101 | + ipb_reason mediumtext, |
| 102 | + INDEX ipb_address (ipb_address), |
| 103 | + INDEX ipb_user (ipb_user) |
| 104 | +) TYPE=MyISAM; |
| 105 | + |