De-tablify toggles. Not only do tables suck, but many uses of toggles were not in...
[lhc/web/wiklou.git] / includes / SpecialContributions.php
index e670797..5c98e1c 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 /**
- *
  * @package MediaWiki
  * @subpackage SpecialPage
  */
@@ -16,11 +15,13 @@ function wfSpecialContributions( $par = '' ) {
        global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
        $fname = 'wfSpecialContributions';
 
-       if( $par )
-               $target = $par;
-       else
-               $target = $wgRequest->getVal( 'target' );
-
+       // GET values
+       $target = $par ? $par : $wgRequest->getVal( 'target' );
+       $namespace = $wgRequest->getInt( 'namespace', '' );
+       $namespace = ($namespace == '') ? NULL : $namespace;
+       $invert = $wgRequest->getBool( 'invert' );
+       $hideminor = ($wgRequest->getBool( 'hideminor' ) ? true : false);
+       
        if ( '' == $target ) {
                $wgOut->errorpage( 'notargettitle', 'notargettext' );
                return;
@@ -30,16 +31,9 @@ function wfSpecialContributions( $par = '' ) {
        list( $limit, $offset ) = wfCheckLimits( 50, '' );
        $offlimit = $limit + $offset;
        $querylimit = $offlimit + 1;
-       $hideminor = ($wgRequest->getVal( 'hideminor' ) ? 1 : 0);
        $sk = $wgUser->getSkin();
        $dbr =& wfGetDB( DB_SLAVE );
        $userCond = "";
-       $namespace = $wgRequest->getVal( 'namespace', '' );
-       if( $namespace != '' ) {
-               $namespace = IntVal( $namespace );
-       } else {
-               $namespace = NULL;
-       }
 
        $nt = Title::newFromURL( $target );
        if ( !$nt ) {
@@ -85,7 +79,7 @@ function wfSpecialContributions( $par = '' ) {
        }
        
        if( !is_null($namespace) ) {
-               $minorQuery .= " AND page_namespace = {$namespace}";
+               $minorQuery .= ' AND page_namespace ' . ($invert ? '!' : '') . "= {$namespace}";
        }
        
        extract( $dbr->tableNames( 'page', 'revision' ) );
@@ -101,14 +95,15 @@ function wfSpecialContributions( $par = '' ) {
        $use_index = $dbr->useIndexClause( $index );
        $sql = "SELECT
                page_namespace,page_title,page_is_new,page_latest,
-               rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text
+               rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text,
+               rev_deleted
                FROM $page,$revision $use_index
                WHERE page_id=rev_page AND $condition $minorQuery " .
          "ORDER BY rev_timestamp DESC LIMIT {$querylimit}";
        $res = $dbr->query( $sql, $fname );
        $numRows = $dbr->numRows( $res );
 
-       $wgOut->addHTML( namespaceForm( $target, $hideminor, $namespace ) );
+       $wgOut->addHTML( namespaceForm( $target, $hideminor, $namespace, $invert ) );
 
        $top = wfShowingResults( $offset, $limit );
        $wgOut->addHTML( "<p>{$top}\n" );
@@ -129,16 +124,7 @@ function wfSpecialContributions( $par = '' ) {
 
        $wgOut->addHTML( "<ul>\n" );
        while( $obj = $dbr->fetchObject( $res ) ) {
-               ucListEdit( $sk,
-                       $obj->page_namespace,
-                       $obj->page_title,
-                       $obj->rev_timestamp,
-                       ($obj->rev_id == $obj->page_latest),
-                       $obj->rev_comment,
-                       ($obj->rev_minor_edit),
-                       $obj->page_is_new,
-                       $obj->rev_user_text,
-                       $obj->rev_id );
+               $wgOut->addHTML( ucListEdit( $sk, $obj ) );
        }
        $wgOut->addHTML( "</ul>\n" );
 
@@ -162,7 +148,7 @@ function wfSpecialContributions( $par = '' ) {
  * 
  * @todo This would probably look a lot nicer in a table.
  */
-function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
+function ucListEdit( $sk, $row ) {
        $fname = 'ucListEdit';
        wfProfileIn( $fname );
        
@@ -174,12 +160,12 @@ function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $t
                }
        }
        
-       $page =& Title::makeTitle( $ns, $t );
+       $page =& Title::makeTitle( $row->page_namespace, $row->page_title );
        $link = $sk->makeKnownLinkObj( $page, '' );
        $difftext = $topmarktext = '';
-       if($topmark) {
+       if( $row->rev_id == $row->page_latest ) {
                $topmarktext .= '<strong>' . $messages['uctop'] . '</strong>';
-               if(!$isnew) {
+               if( !$row->page_is_new ) {
                        $difftext .= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'] . ')', 'diff=0' );
                } else {
                        $difftext .= $messages['newarticle'];
@@ -188,30 +174,36 @@ function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $t
                if( $wgUser->isAllowed('rollback') ) {
                        $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
                        $extraRollback .= '&token=' . urlencode(
-                               $wgUser->editToken( array( $page->getPrefixedText(), $target ) ) );
-                       # $target = $wgRequest->getText( 'target' );
+                               $wgUser->editToken( array( $page->getPrefixedText(), $row->rev_user_text ) ) );
                        $topmarktext .= ' ['. $sk->makeKnownLinkObj( $page,
                                $messages['rollbacklink'],
-                               'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
+                               'action=rollback&from=' . urlencode( $row->rev_user_text ) . $extraRollback ) .']';
                }
 
        }
-       if ( $oldid ) {
-               $difftext= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'].')', 'diff=prev&oldid='.$oldid );
-       } 
+       if( $row->rev_deleted && !$wgUser->isAllowed( 'undelete' ) ) {
+               $difftext = '(' . $messages['diff'] . ')';
+       } else {
+               $difftext = $sk->makeKnownLinkObj( $page, '(' . $messages['diff'].')', 'diff=prev&oldid='.$row->rev_id );
+       }
        $histlink='('.$sk->makeKnownLinkObj( $page, $messages['hist'], 'action=history' ) . ')';
 
-       $comment = $sk->commentBlock( $comment, $page );
-       $d = $wgLang->timeanddate( $ts, true );
+       $comment = $sk->commentBlock( $row->rev_comment, $page );
+       $d = $wgLang->timeanddate( $row->rev_timestamp, true );
 
-       if ($isminor) {
+       if( $row->rev_minor_edit ) {
                $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
        } else {
                $mflag = '';
        }
 
-       $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
+       $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
+       if( $row->rev_deleted ) {
+               $ret = '<span class="deleted">' . $ret . '</span> ' . htmlspecialchars( wfMsg( 'deletedrev' ) );
+       }
+       $ret = "<li>$ret</li>\n";
        wfProfileOut( $fname );
+       return $ret;
 }
 
 /**
@@ -222,8 +214,9 @@ function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $t
  * @param      string  $target target user to show contributions for
  * @param      string  $hideminor whether minor contributions are hidden
  * @param      string  $namespace currently selected namespace, NULL for show all
+ * @param      bool    $invert  inverts the namespace selection on true (default null)
  */
-function namespaceForm ( $target, $hideminor, $namespace ) {
+function namespaceForm ( $target, $hideminor, $namespace, $invert ) {
        global $wgContLang, $wgScript;
 
        $namespaceselect = '<select name="namespace">';
@@ -233,7 +226,7 @@ function namespaceForm ( $target, $hideminor, $namespace ) {
                if( $i < 0 ) {
                        continue;
                }
-               $namespacename = str_replace ( "_", " ", $arr[$i] );
+               $namespacename = str_replace ( '_', ' ', $arr[$i] );
                $n = ($i == 0) ? wfMsg ( 'articlenamespace' ) : $namespacename;
                $sel = ($i === $namespace) ? ' selected="selected"' : '';
                $namespaceselect .= "<option value='{$i}'{$sel}>{$n}</option>";
@@ -241,12 +234,13 @@ function namespaceForm ( $target, $hideminor, $namespace ) {
        $namespaceselect .= '</select>';
 
        $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
+       $invertbox = "<input type='checkbox' name='invert' value='1'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
 
        $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
        $out .= '<input type="hidden" name="title" value="'.$wgContLang->specialpage( 'Contributions' ).'" />';
        $out .= '<input type="hidden" name="target" value="'.htmlspecialchars( $target ).'" />';
        $out .= '<input type="hidden" name="hideminor" value="'.$hideminor.'" />';      
-       $out .= wfMsg ( 'allpagesformtext2', $namespaceselect, $submitbutton );
+       $out .= wfMsg ( 'contributionsformtext', $namespaceselect, $submitbutton, $invertbox );
        $out .= '</form></div>';
        return $out;
 }