r405 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r404‎ | r405 | r406 >
Date:22:14, 20 May 2002
Author:lcrocker
Status:old
Tags:
Comment:
Fixed add new page functionality in edit form.
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/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/User.php
@@ -16,6 +16,7 @@
1717 /* private */ var $mRights, $mOptions;
1818 /* private */ var $mDataLoaded;
1919 /* private */ var $mSkin, $mWatchlist;
 20+ /* private */ var $mBlockedby, $mBlockreason;
2021
2122 function User()
2223 {
@@ -35,6 +36,11 @@
3637 return $u;
3738 }
3839
 40+ /* static */ function whoIs( $id )
 41+ {
 42+ return wfGetSQL( "user", "user_name", "user_id=$id" );
 43+ }
 44+
3945 function loadDefaults()
4046 {
4147 global $wgDefaultOptions;
@@ -51,8 +57,55 @@
5258 unset( $this->mSkin );
5359 unset( $this->mWatchlist );
5460 $this->mDataLoaded = false;
 61+ $this->mBlockedby = -1; # Unset
5562 }
5663
 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+
57110 function loadFromSession()
58111 {
59112 global $HTTP_COOKIE_VARS, $wsUserID, $wsUserName, $wsUserPassword;
Index: trunk/phpwiki/newcodebase/Language.php
@@ -117,6 +117,12 @@
118118 "savearticle" => "Save article",
119119 "preview" => "Preview",
120120 "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.",
121127
122128 # Preferences page
123129 #
Index: trunk/phpwiki/newcodebase/Article.php
@@ -17,8 +17,9 @@
1818
1919 function getContent()
2020 {
21 - if ( 0 == $this->getID() ) { return "(Non-existent article.)\n"; }
22 - else {
 21+ if ( 0 == $this->getID() ) {
 22+ return wfMsg( "newarticletext" );
 23+ } else {
2324 $this->loadContent();
2425 return $this->mContent;
2526 }
@@ -72,15 +73,19 @@
7374
7475 function view()
7576 {
76 - global $wgOut, $wgUser;
 77+ global $wgOut;
 78+ $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
7779
78 - $n = $this->mTitle->getPrefixedText();
79 - $wgOut->setPageTitle( $n );
80 - $wgOut->addWikiText( $this->getContent() );
81 -
 80+ $this->showArticle();
8281 $this->viewUpdates();
8382 }
8483
 84+ /* private */ function showArticle()
 85+ {
 86+ global $wgOut;
 87+ $wgOut->addWikiText( $this->getContent() );
 88+ }
 89+
8590 function edit()
8691 {
8792 global $wgOut, $wgUser, $wgTitle;
@@ -92,7 +97,7 @@
9398 return;
9499 }
95100 if ( isset( $wpSave ) ) {
96 - $this->editSave();
 101+ $this->editForm( "save" );
97102 } else if ( isset( $wpPreview ) ) {
98103 $this->editForm( "preview" );
99104 } else { # First time through
@@ -107,15 +112,49 @@
108113 global $wpTextbox1, $wpSummary, $wpSave, $wpPreview;
109114 global $wpMinoredit, $wpEdittime, $wpTextbox2;
110115
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" ) . "')";
114131
 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+ }
115150 if ( "initial" == $formtype ) {
116151 $wpEdittime = time( "YmdHis" );
117152 $wpTextbox1 = $this->getContent();
118153 $wpSummary = "*";
119154 }
 155+ $wgOut->setPageTitle( "Editing " . $wgTitle->getPrefixedText() );
 156+ $wgOut->setRobotpolicy( "noindex,nofollow" );
 157+ $wgOut->setArticleFlag( false );
 158+
120159 $rows = $wgUser->getOption( "rows" );
121160 $cols = $wgUser->getOption( "cols" );
122161 $action = "$wgServer$wgScript?title=" .
@@ -144,15 +183,6 @@
145184 }
146185 }
147186
148 - function editSave()
149 - {
150 - $this->editUpdates();
151 - }
152 -
153 - function editPreview()
154 - {
155 - }
156 -
157187 function viewprintable()
158188 {
159189 global $wgOut, $wgUser;
@@ -173,10 +203,6 @@
174204 {
175205 }
176206
177 - function edit_conflict()
178 - {
179 - }
180 -
181207 # Do standard deferred updates after page view
182208 #
183209 /* private */ function viewUpdates()
@@ -201,6 +227,22 @@
202228 $u = new SiteStatsUpdate( 0, 1, 0 );
203229 array_push( $wgDeferredUpdateList, $u );
204230 }
 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+ }
205247 }
206248
207249 ?>
Index: trunk/phpwiki/newcodebase/GlobalFunctions.php
@@ -27,12 +27,13 @@
2828 $wgTotalEdits = -1;
2929
3030 include_once( "./DatabaseFunctions.php" );
 31+include_once( "./UpdateClasses.php" );
3132
3233 function wfLocalLink( $a )
3334 {
3435 global $wgArticlePath;
3536
36 - $a = str_replace( " ", "+", $a );
 37+ $a = str_replace( " ", "_", $a );
3738 $a = str_replace( "$1", $a, $wgArticlePath );
3839 return $a;
3940 }
Index: trunk/phpwiki/newcodebase/wiki.phtml
@@ -12,7 +12,6 @@
1313 include_once( "./User.php" );
1414 include_once( "./Title.php" );
1515 include_once( "./Article.php" );
16 -include_once( "./UpdateClasses.php" );
1716
1817 global $action, $title, $search; # From query string
1918 global $wgUser, $wgLang, $wgOut, $wgTitle; # Objects to handle output
@@ -26,7 +25,7 @@
2726 $wgUser->loadFromSession();
2827 $wgDeferredUpdateList = array();
2928
30 -wfStripTextFields(); # Clean up PHP's mess
 29+wfStripTextFields(); # Clean up PHP mess
3130
3231 $action = strtolower( trim( $action ) );
3332 if ( "" == $action ) { $action = "view"; }
Index: trunk/phpwiki/newcodebase/sql/buildtables.sql
@@ -94,3 +94,11 @@
9595 UNIQUE KEY ss_row_id (ss_row_id)
9696 ) TYPE=MyISAM;
9797
 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+

Status & tagging log