Undelete bug partially fixed; Sysop ability to block users; various code formatting...
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 31 Aug 2003 14:30:24 +0000 (14:30 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 31 Aug 2003 14:30:24 +0000 (14:30 +0000)
includes/Article.php
includes/OutputPage.php
includes/Skin.php
includes/SpecialBlockip.php
includes/SpecialIpblocklist.php
includes/SpecialUndelete.php
includes/User.php
languages/Language.php

index 116a8ef..ee6e10c 100644 (file)
@@ -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 );
index 378e563..3021fa6 100644 (file)
@@ -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 = "<br break=all>\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 .= "<h2>".wfMsg("subcategories")."</h2>\n" ;
-     $r .= implode ( ", " , $children ) ;
-   }
-
-# Articles
- if ( count ( $articles ) > 0 )
-   {
-     asort ( $articles ) ;
-     $h = str_replace ( "$1" , $ti[1] , wfMsg("category_header") ) ;
-     $r .= "<h2>{$h}</h2>\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 = "<br break=all>\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 .= "<h2>".wfMsg("subcategories")."</h2>\n" ;
+                       $r .= implode ( ", " , $children ) ;
+               }
+
+               # Articles
              if ( count ( $articles ) > 0 )
+               {
+                       asort ( $articles ) ;
+                       $h = str_replace ( "$1" , $ti[1] , wfMsg("category_header") ) ;
+                       $r .= "<h2>{$h}</h2>\n" ;
+                       $r .= implode ( ", " , $articles ) ;
+               }
+
+
+               return $r ;
+       }
 
 
        # Well, OK, it's actually about 14 passes.  But since all the
index 30b114a..2f758e4 100644 (file)
@@ -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 = "" )
        {
index 6d1cb59..87acf24 100644 (file)
@@ -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 );
index e46748f..70e4b08 100644 (file)
@@ -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 );
 
index 8f786c7..b4d66ea 100644 (file)
@@ -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
index 1fefe2b..e1dc80e 100644 (file)
@@ -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 );
+       }
 }
 
 ?>
index 25e179a..e6fc108 100644 (file)
@@ -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.
 <br>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
 #