Reorganization of SearchEngine for legibility
[lhc/web/wiklou.git] / includes / SpecialContributions.php
index cf3e4cb..9a97865 100644 (file)
@@ -1,10 +1,20 @@
 <?php
-
-function wfSpecialContributions( $par = "" )
-{
-       global $wgUser, $wgOut, $wgLang, $wgRequest;
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ * Special page "user contributions".
+ * Shows a list of the contributions of a user.
+ *
+ * @return     none
+ * @param      string  $par    (optional) user name of the user for which to show the contributions
+ */
+function wfSpecialContributions( $par = '' ) {
+       global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
        $fname = "wfSpecialContributions";
-       $sysop = $wgUser->isSysop();
 
        if( $par )
                $target = $par;
@@ -15,7 +25,7 @@ function wfSpecialContributions( $par = "" )
                $wgOut->errorpage( "notargettitle", "notargettext" );
                return;
        }
-       
+
        # FIXME: Change from numeric offsets to date offsets
        list( $limit, $offset ) = wfCheckLimits( 50, "" );
        $offlimit = $limit + $offset;
@@ -26,6 +36,10 @@ function wfSpecialContributions( $par = "" )
        $userCond = "";
 
        $nt = Title::newFromURL( $target );
+       if ( !$nt ) {
+               $wgOut->errorpage( "notargettitle", "notargettext" );
+               return;
+       }
        $nt->setNamespace( Namespace::getUser() );
 
        $id = User::idFromName( $nt->getText() );
@@ -37,16 +51,16 @@ function wfSpecialContributions( $par = "" )
                $userCond = "=" . $id;
        }
        $talk = $nt->getTalkPage();
-       if( $talk )
+       if( $talk ) {
                $ul .= " (" . $sk->makeLinkObj( $talk, $wgLang->getNsText(Namespace::getTalk(0)) ) . ")";
-       else
-               $ul .= "brrrp";
+       }
+
 
        if ( $target == 'newbies' ) {
                # View the contributions of all recently created accounts
                $max = $dbr->selectField( 'user', 'max(user_id)', false, $fname );
                $userCond = ">" . ($max - $max / 100);
-               $ul = "";
+               $ul = wfMsg ( 'newbies' );
                $id = 0;
        }
 
@@ -55,13 +69,13 @@ function wfSpecialContributions( $par = "" )
        if ( $hideminor ) {
                $cmq = "AND cur_minor_edit=0";
                $omq = "AND old_minor_edit=0";
-               $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
-                 WfMsg( "show" ), "target=" . wfEscapeHTML( $nt->getPrefixedURL() ) .
+               $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
+                 WfMsg( "show" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
                  "&offset={$offset}&limit={$limit}&hideminor=0" );
        } else {
                $cmq = $omq = "";
-               $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
-                 WfMsg( "hide" ), "target=" . wfEscapeHTML( $nt->getPrefixedURL() ) .
+               $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
+                 WfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
                  "&offset={$offset}&limit={$limit}&hideminor=1" );
        }
 
@@ -72,7 +86,7 @@ function wfSpecialContributions( $par = "" )
                  "ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res1 = $dbr->query( $sql, $fname );
 
-               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text FROM $old " .
+               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
                  "WHERE old_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$omq} " .
                  "ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res2 = $dbr->query( $sql, $fname );
@@ -81,7 +95,7 @@ function wfSpecialContributions( $par = "" )
                  "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res1 = $dbr->query( $sql, $fname );
 
-               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text FROM $old " .
+               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
                  "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res2 = $dbr->query( $sql, $fname );
        }
@@ -92,7 +106,7 @@ function wfSpecialContributions( $par = "" )
        $wgOut->addHTML( "<p>{$top}\n" );
 
        $sl = wfViewPrevNext( $offset, $limit,
-         $wgLang->specialpage( "Contributions" ),
+         $wgContLang->specialpage( "Contributions" ),
          "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
          ($nCur + $nOld) <= $offlimit);
 
@@ -121,9 +135,10 @@ function wfSpecialContributions( $par = "" )
                        $me = $obj1->cur_minor_edit;
                        $isnew = $obj1->cur_is_new;
                        $usertext = $obj1->cur_user_text;
-                       
+
                        $obj1 = $dbr->fetchObject( $res1 );
                        $topmark = true;
+                       $oldid = false;
                        --$nCur;
                } else {
                        $ns = $obj2->old_namespace;
@@ -132,6 +147,7 @@ function wfSpecialContributions( $par = "" )
                        $comment =$obj2->old_comment;
                        $me = $obj2->old_minor_edit;
                        $usertext = $obj2->old_user_text;
+                       $oldid = $obj2->old_id;
 
                        $obj2 = $dbr->fetchObject( $res2 );
                        $topmark = false;
@@ -139,94 +155,102 @@ function wfSpecialContributions( $par = "" )
                        --$nOld;
                }
                if( $n >= $offset )
-                       ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext );
+                       ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext, $oldid );
        }
        $wgOut->addHTML( "</ul>\n" );
-       
+
        # Validations
-       $val = new Validation ;
-       $val = $val->countUserValidations ( $id ) ;
-       $val = str_replace ( "$1" , $val , wfMsg ( 'val_user_validations' ) ) ;
-       $wgOut->addHTML( $val );
+       global $wgUseValidation;
+       if( $wgUseValidation ) {
+               require_once( 'SpecialValidate.php' );
+               $val = new Validation ;
+               $val = $val->countUserValidations ( $id ) ;
+               $wgOut->addHTML( wfMsg ( 'val_user_validations', $val ) );
+       }
 }
 
 
-/*
-
-Generates each row in the contributions list.
-
-Contributions which are marked "top" are currently on top of the history.
-For these contributions, a [rollback] link is shown for users with sysop
-privileges. The rollback link restores the most recent version that was not
-written by the target user.
-
-If the contributions page is called with the parameter &bot=1, all rollback
-links also get that parameter. It causes the edit itself and the rollback
-to be marked as "bot" edits. Bot edits are hidden by default from recent
-changes, so this allows sysops to combat a busy vandal without bothering
-other users.
-
-TODO: This would probably look a lot nicer in a table.
-
-*/
-function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target )
-{
+/**
+ * Generates each row in the contributions list.
+ *
+ * Contributions which are marked "top" are currently on top of the history.
+ * For these contributions, a [rollback] link is shown for users with sysop
+ * privileges. The rollback link restores the most recent version that was not
+ * written by the target user.
+ * 
+ * If the contributions page is called with the parameter &bot=1, all rollback
+ * links also get that parameter. It causes the edit itself and the rollback
+ * to be marked as "bot" edits. Bot edits are hidden by default from recent
+ * changes, so this allows sysops to combat a busy vandal without bothering
+ * other users.
+ * 
+ * @todo This would probably look a lot nicer in a table.
+ */
+function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
        global $wgLang, $wgOut, $wgUser, $wgRequest;
        $page = Title::makeName( $ns, $t );
-       $link = $sk->makeKnownLink( $page, "" );
-       $topmarktext="";
+       $link = $sk->makeKnownLink( $page, '' );
+       $difftext = $topmarktext = '';
        if($topmark) {
+               $topmarktext .= '<strong>' . wfMsg('uctop') . '</strong>';
                if(!$isnew) {
-                       $topmarktext .= $sk->makeKnownLink( $page, wfMsg("uctop"), "diff=0" );
+                       $difftext .= $sk->makeKnownLink( $page, '(' . wfMsg('diff') . ')', 'diff=0' );
                } else {
-                       $topmarktext .= wfMsg("newarticle");
+                       $difftext .= wfMsg('newarticle');
                }
                $sysop = $wgUser->isSysop();
                if($sysop ) {
-                       $extraRollback = $wgRequest->getBool( "bot" ) ? '&bot=1' : '';
+                       $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
                        # $target = $wgRequest->getText( 'target' );
-                       $topmarktext .= " [". $sk->makeKnownLink( $page,
-                       wfMsg( "rollbacklink" ),
-                       "action=rollback&from=" . urlencode( $target ) . $extraRollback ) ."]";
+                       $topmarktext .= ' ['. $sk->makeKnownLink( $page,
+                       wfMsg( 'rollbacklink' ),
+                       'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
                }
 
        }
-       $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
+       if ( $oldid ) {
+               $difftext= $sk->makeKnownLink( $page, '('.wfMsg('diff').')', 'diff=prev&oldid='.$oldid );
+       } 
+       $histlink='('.$sk->makeKnownLink($page,wfMsg('hist'),'action=history').')';
 
        if($comment) {
 
-               $comment="<em>(". $sk->formatComment($comment ) .")</em> ";
+               $comment='<em>('. $sk->formatComment($comment, Title::newFromText($t) ) .')</em> ';
 
        }
        $d = $wgLang->timeanddate( $ts, true );
 
        if ($isminor) {
-               $mflag = "<strong>" . wfMsg( "minoreditletter" ) . "</strong> ";
+               $mflag = '<span class="minor">'.wfMsg( 'minoreditletter' ).'</span> ';
        } else {
-               $mflag = "";
+               $mflag = '';
        }
 
-       $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}</li>\n" );
+       $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
 }
 
-function ucCountLink( $lim, $d )
-{
-       global $wgUser, $wgLang, $wgRequest;
+/**
+ *
+ */
+function ucCountLink( $lim, $d ) {
+       global $wgUser, $wgContLang, $wgRequest;
 
        $target = $wgRequest->getText( 'target' );
        $sk = $wgUser->getSkin();
-       $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
+       $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
          "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
        return $s;
 }
 
-function ucDaysLink( $lim, $d )
-{
-       global $wgUser, $wgLang, $wgRequest;
+/**
+ *
+ */
+function ucDaysLink( $lim, $d ) {
+       global $wgUser, $wgContLang, $wgRequest;
 
        $target = $wgRequest->getText( 'target' );
        $sk = $wgUser->getSkin();
-       $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
+       $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
          "{$d}", "target={$target}&days={$d}&limit={$lim}" );
        return $s;
 }