From 1412a6885c0c7caf7e4c2895b6002ff09e0e8fb7 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 31 Aug 2003 14:30:24 +0000 Subject: [PATCH] Undelete bug partially fixed; Sysop ability to block users; various code formatting changes --- includes/Article.php | 3 +- includes/OutputPage.php | 110 ++++++++++++++++---------------- includes/Skin.php | 46 ++++++------- includes/SpecialBlockip.php | 18 ++++-- includes/SpecialIpblocklist.php | 5 -- includes/SpecialUndelete.php | 24 +++++-- includes/User.php | 39 +++++++++++ languages/Language.php | 21 +++--- 8 files changed, 162 insertions(+), 104 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 116a8ef4e0..ee6e10cc47 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -507,7 +507,8 @@ class Article { $wgLinkCache->clear(); } - # Now update the link cache by parsing the text + # Now update the link cache by parsing the text + $wgOut = new OutputPage(); $wgOut->addWikiText( $text ); $this->editUpdates( $text ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 378e563c65..3021fa6c59 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -565,61 +565,61 @@ class OutputPage { } -function categoryMagic () -{ -global $wgTitle , $wgUseCategoryMagic ; -if ( !isset ( $wgUseCategoryMagic ) || !$wgUseCategoryMagic ) return ; -$id = $wgTitle->getArticleID() ; -$cat = ucfirst ( wfMsg ( "category" ) ) ; -$ti = $wgTitle->getText() ; -$ti = explode ( ":" , $ti , 2 ) ; -if ( $cat != $ti[0] ) return "" ; -$r = "
\n" ; - -$articles = array() ; -$parents = array () ; -$children = array() ; - - -global $wgUser ; -$sk = $wgUser->getSkin() ; -$sql = "SELECT l_from FROM links WHERE l_to={$id}" ; -$res = wfQuery ( $sql ) ; -while ( $x = wfFetchObject ( $res ) ) -{ -# $t = new Title ; -# $t->newFromDBkey ( $x->l_from ) ; -# $t = $t->getText() ; - $t = $x->l_from ; - $y = explode ( ":" , $t , 2 ) ; - if ( count ( $y ) == 2 && $y[0] == $cat ) - { - array_push ( $children , $sk->makeLink ( $t , $y[1] ) ) ; - } - else array_push ( $articles , $sk->makeLink ( $t ) ) ; -} -wfFreeResult ( $res ) ; - -# Children - if ( count ( $children ) > 0 ) - { - asort ( $children ) ; - $r .= "

".wfMsg("subcategories")."

\n" ; - $r .= implode ( ", " , $children ) ; - } - -# Articles - if ( count ( $articles ) > 0 ) - { - asort ( $articles ) ; - $h = str_replace ( "$1" , $ti[1] , wfMsg("category_header") ) ; - $r .= "

{$h}

\n" ; - $r .= implode ( ", " , $articles ) ; - } - - -return $r ; -} + function categoryMagic () + { + global $wgTitle , $wgUseCategoryMagic ; + if ( !isset ( $wgUseCategoryMagic ) || !$wgUseCategoryMagic ) return ; + $id = $wgTitle->getArticleID() ; + $cat = ucfirst ( wfMsg ( "category" ) ) ; + $ti = $wgTitle->getText() ; + $ti = explode ( ":" , $ti , 2 ) ; + if ( $cat != $ti[0] ) return "" ; + $r = "
\n" ; + + $articles = array() ; + $parents = array () ; + $children = array() ; + + + global $wgUser ; + $sk = $wgUser->getSkin() ; + $sql = "SELECT l_from FROM links WHERE l_to={$id}" ; + $res = wfQuery ( $sql ) ; + while ( $x = wfFetchObject ( $res ) ) + { + # $t = new Title ; + # $t->newFromDBkey ( $x->l_from ) ; + # $t = $t->getText() ; + $t = $x->l_from ; + $y = explode ( ":" , $t , 2 ) ; + if ( count ( $y ) == 2 && $y[0] == $cat ) + { + array_push ( $children , $sk->makeLink ( $t , $y[1] ) ) ; + } + else array_push ( $articles , $sk->makeLink ( $t ) ) ; + } + wfFreeResult ( $res ) ; + + # Children + if ( count ( $children ) > 0 ) + { + asort ( $children ) ; + $r .= "

".wfMsg("subcategories")."

\n" ; + $r .= implode ( ", " , $children ) ; + } + + # Articles + if ( count ( $articles ) > 0 ) + { + asort ( $articles ) ; + $h = str_replace ( "$1" , $ti[1] , wfMsg("category_header") ) ; + $r .= "

{$h}

\n" ; + $r .= implode ( ", " , $articles ) ; + } + + + return $r ; + } # Well, OK, it's actually about 14 passes. But since all the diff --git a/includes/Skin.php b/includes/Skin.php index 30b114a5ab..2f758e42b1 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1086,31 +1086,31 @@ class Skin { return $this->makeKnownLink( $title, $text, $query, $trail ); } if ( ( -1 == $nt->getNamespace() ) || - ( Namespace::getImage() == $nt->getNamespace() ) ) { + ( Namespace::getImage() == $nt->getNamespace() ) ) { return $this->makeKnownLink( $title, $text, $query, $trail ); } - $aid = $nt->getArticleID() ; - if ( 0 == $aid ) { - return $this->makeBrokenLink( $title, $text, $query, $trail ); - } else { - $threshold = $wgUser->getOption("stubthreshold") ; - if ( $threshold > 0 ) { - $res = wfQuery ( "SELECT HIGH_PRIORITY length(cur_text) AS x, cur_namespace, cur_is_redirect FROM cur WHERE cur_id='{$aid}'" ) ; - - if ( wfNumRows( $res ) > 0 ) { - $s = wfFetchObject( $res ); - $size = $s->x; - if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) - $size = $threshold*2 ; # Really big - wfFreeResult( $res ); - } else $size = $threshold*2 ; # Really big - } else $size = 1 ; - - if ( $size < $threshold ) - return $this->makeStubLink( $title, $text, $query, $trail ); - return $this->makeKnownLink( $title, $text, $query, $trail ); - } - } + $aid = $nt->getArticleID() ; + if ( 0 == $aid ) { + return $this->makeBrokenLink( $title, $text, $query, $trail ); + } else { + $threshold = $wgUser->getOption("stubthreshold") ; + if ( $threshold > 0 ) { + $res = wfQuery ( "SELECT HIGH_PRIORITY length(cur_text) AS x, cur_namespace, cur_is_redirect FROM cur WHERE cur_id='{$aid}'" ) ; + + if ( wfNumRows( $res ) > 0 ) { + $s = wfFetchObject( $res ); + $size = $s->x; + if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) + $size = $threshold*2 ; # Really big + wfFreeResult( $res ); + } else $size = $threshold*2 ; # Really big + } else $size = 1 ; + + if ( $size < $threshold ) + return $this->makeStubLink( $title, $text, $query, $trail ); + return $this->makeKnownLink( $title, $text, $query, $trail ); + } + } function makeKnownLink( $title, $text = "", $query = "", $trail = "" ) { diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index 6d1cb59da1..87acf24660 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -61,18 +61,26 @@ class IPBlockForm { global $wgOut, $wgUser, $wgLang; global $ip, $wpBlockAddress, $wpBlockReason; $fname = "IPBlockForm::doSubmit"; - + + $userId = 0; if ( ! preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", - $wpBlockAddress ) ) { - $this->showForm( wfMsg( "badipaddress" ) ); - return; + $wpBlockAddress ) ) + { + $userId = User::idFromName( $wpBlockAddress ); + if ( $userId == 0 ) { + $this->showForm( wfMsg( "badipaddress" ) ); + return; + } } if ( "" == $wpBlockReason ) { $this->showForm( wfMsg( "noblockreason" ) ); return; } + + # Note: for a user block, ipb_address is only for display purposes + $sql = "INSERT INTO ipblocks (ipb_address, ipb_user, ipb_by, " . - "ipb_reason, ipb_timestamp ) VALUES ('{$wpBlockAddress}', 0, " . + "ipb_reason, ipb_timestamp ) VALUES ('{$wpBlockAddress}', {$userId}, " . $wgUser->getID() . ", '" . wfStrencode( $wpBlockReason ) . "','" . wfTimestampNow() . "')"; wfQuery( $sql, $fname ); diff --git a/includes/SpecialIpblocklist.php b/includes/SpecialIpblocklist.php index e46748f88c..70e4b0821c 100644 --- a/includes/SpecialIpblocklist.php +++ b/includes/SpecialIpblocklist.php @@ -64,11 +64,6 @@ class IPUnblockForm { global $ip, $wpUnblockAddress; $fname = "IPUnblockForm::doSubmit"; - if ( ! preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", - $wpUnblockAddress ) ) { - $this->showForm( wfMsg( "badipaddress" ) ); - return; - } $sql = "DELETE FROM ipblocks WHERE ipb_address='{$wpUnblockAddress}'"; wfQuery( $sql, $fname ); diff --git a/includes/SpecialUndelete.php b/includes/SpecialUndelete.php index 8f786c75e3..b4d66ea8c1 100644 --- a/includes/SpecialUndelete.php +++ b/includes/SpecialUndelete.php @@ -103,7 +103,7 @@ function wfSpecialUndelete( ) /* private */ function doUndeleteArticle( $namespace, $title ) { - global $wgUser, $wgOut, $wgLang, $target; + global $wgUser, $wgOut, $wgLang, $target, $wgDeferredUpdateList; $fname = "doUndeleteArticle"; @@ -141,10 +141,24 @@ function wfSpecialUndelete( ) "FROM archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' {$oldones}"; wfQuery( $sql, $fname ); - # Finally, clean up the link tables - if( $newid ) { - $to = Title::newFromDBKey( $target ); - $to->resetArticleID( $newid ); + # Finally, clean up the link tables + if( $newid ) { + # Create a dummy OutputPage to update the outgoing links + # This works at the moment due to good luck. It may stop working in the + # future. Damn globals. + $dummyOut = new OutputPage(); + $to = Title::newFromDBKey( $target ); + $res = wfQuery( "SELECT cur_text FROM cur WHERE cur_id={$newid} " . + "AND cur_namespace={$namespace}", $fname ); + $row = wfFetchObject( $res ); + $text = $row->cur_text; + $dummyOut->addWikiText( $text ); + wfFreeResult( $res ); + + $u = new LinksUpdate( $newid, $to->getPrefixedDBkey() ); + array_push( $wgDeferredUpdateList, $u ); + + #TODO: SearchUpdate, etc. } # Now that it's safely stored, take it out of the archive diff --git a/includes/User.php b/includes/User.php index 1fefe2b8de..e1dc80eb37 100644 --- a/includes/User.php +++ b/includes/User.php @@ -183,6 +183,7 @@ class User { else wfDebug( "User::loadFromSession() unable to save to memcached\n" ); } + $user->spreadBlock(); return $user; } return new User(); # Can't log in from session @@ -570,6 +571,44 @@ class User { wfQuery( $sql, "User::addToDatabase" ); $this->mId = $this->idForName(); } + + function spreadBlock() + { + # If the (non-anonymous) user is blocked, this function will block any IP address + # that they successfully log on from. + $fname = "User::spreadBlock"; + + if ( $this->mId == 0 || !$this->isBlocked()) { + return; + } + + $sql = "SELECT * FROM ipblocks WHERE ipb_user={$this->mId}"; + $res = wfQuery( $sql, $fname ); + if ( wfNumRows( $res ) == 0 ) { + return; + } + + # Check if this IP address is already blocked + $addr = getenv( "REMOTE_ADDR" ); + $sql = "SELECT * FROM ipblocks WHERE ipb_address='{$addr}'"; + $res2 = wfQuery( $sql, $fname ); + if ( wfNumRows( $res2 ) != 0 ) { + return; + } + + $row = wfFetchObject( $res ); + $reason = str_replace( "$1", $this->getName(), wfMsg( "autoblocker" ) ); + $reason = str_replace( "$2", $row->ipb_reason, $reason ); + + $addr = getenv( "REMOTE_ADDR" ); + $sql = "INSERT INTO ipblocks(ipb_address, ipb_user, ipb_by, " . + "ipb_reason, ipb_timestamp) VALUES ('{$addr}', 0, {$row->ipb_by}," . + "'{$reason}', '" . wfTimestampNow() . "')"; + wfQuery( $sql, $fname ); + + wfFreeResult( $res ); + wfFreeResult( $res2 ); + } } ?> diff --git a/languages/Language.php b/languages/Language.php index 25e179a25a..e6fc10845b 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1077,31 +1077,32 @@ to perform this function on.", # Block/unblock IP # -"blockip" => "Block IP address", +"blockip" => "Block user", "blockiptext" => "Use the form below to block write access -from a specific IP address. +from a specific IP address or username. This should be done only only to prevent vandalism, and in accordance with [[Wikipedia:Policy|Wikipedia policy]]. Fill in a specific reason below (for example, citing particular pages that were vandalized).", -"ipaddress" => "IP Address", +"ipaddress" => "IP Address/username", "ipbreason" => "Reason", -"ipbsubmit" => "Block this address", -"badipaddress" => "The IP address is badly formed.", +"ipbsubmit" => "Block this user", +"badipaddress" => "No user exists by that name", "noblockreason" => "You must supply a reason for the block.", "blockipsuccesssub" => "Block succeeded", -"blockipsuccesstext" => "The IP address \"$1\" has been blocked. +"blockipsuccesstext" => "\"$1\" has been blocked.
See [[Special:Ipblocklist|IP block list]] to review blocks.", -"unblockip" => "Unblock IP address", +"unblockip" => "Unblock user", "unblockiptext" => "Use the form below to restore write access -to a previously blocked IP address.", +to a previously blocked IP address or username.", "ipusubmit" => "Unblock this address", -"ipusuccess" => "IP address \"$1\" unblocked", -"ipblocklist" => "List of blocked IP addresses", +"ipusuccess" => "\"$1\" unblocked", +"ipblocklist" => "List of blocked IP addresses and usernames", "blocklistline" => "$1, $2 blocked $3", "blocklink" => "block", "unblocklink" => "unblock", "contribslink" => "contribs", +"autoblocker" => "Autoblocked because you share an IP address with \"$1\". Reason \"$2\".", # Developer tools # -- 2.20.1