More revision delete cleanup
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 16 Apr 2008 18:44:15 +0000 (18:44 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 16 Apr 2008 18:44:15 +0000 (18:44 +0000)
includes/LogEventsList.php
includes/SpecialRevisiondelete.php

index 77d66f6..02bcb6b 100644 (file)
@@ -228,7 +228,7 @@ class LogEventsList {
                                                '&wpMovetalk=0' ) . ')';
                                }
                        // Show undelete link
-                       } else if( self::typeAction($row,'delete','delete') && $wgUser->isAllowed( 'delete' ) ) {
+                       } else if( self::typeAction($row,array('delete','suppress'),'delete') && $wgUser->isAllowed( 'delete' ) ) {
                                $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
                                        $this->message['undeletelink'], 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
                        // Show unblock link
@@ -243,13 +243,11 @@ class LogEventsList {
                        } else if ( self::typeAction($row,'merge','merge') ) {
                                $merge = SpecialPage::getTitleFor( 'Mergehistory' );
                                $revert = '(' .  $this->skin->makeKnownLinkObj( $merge, $this->message['revertmerge'],
-                                       wfArrayToCGI(
-                                               array('target' => $paramArray[0], 'dest' => $title->getPrefixedText(), 'mergepoint' => $paramArray[1] )
-                                       )
-                               ) . ')';
+                                       wfArrayToCGI( array('target' => $paramArray[0], 'dest' => urlencode( $title->getPrefixedDBkey() ), 
+                                               'mergepoint' => $paramArray[1] ) ) ) . ')';
                        // If an edit was hidden from a page give a review link to the history
                        } else if( self::typeAction($row,array('delete','suppress'),'revision') && $wgUser->isAllowed( 'deleterevision' ) ) {
-                               if( isset($paramArray[2]) ) {
+                               if( count($paramArray) == 2 ) {
                                        $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                                        // Different revision types use different URL params...
                                        $subtype = isset($paramArray[2]) ? $paramArray[1] : '';
@@ -257,30 +255,30 @@ class LogEventsList {
                                        $Ids = explode( ',', $paramArray[2] );
                                        if( count($Ids) == 1 ) {
                                                $revert = $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
-                                               wfArrayToCGI( array('target' => $paramArray[0], $paramArray[1] => $Ids[0] ) ) );
+                                               wfArrayToCGI( array('target' => urlencode( $title->getPrefixedDBkey() ), $paramArray[1] => $Ids[0] ) ) );
                                        } else {
                                                $revert .= $this->message['revdel-restore'].':';
                                                foreach( $Ids as $n => $id ) {
                                                        $revert .= ' '.$this->skin->makeKnownLinkObj( $revdel, '#'.($n+1),
-                                                               wfArrayToCGI( array('target' => $paramArray[0], $paramArray[1] => $id ) ) );
+                                                               wfArrayToCGI( array('target' => urlencode( $title->getPrefixedDBkey() ), $paramArray[1] => $id ) ) );
                                                }
                                        }
                                        $revert = "($revert)";
                                }
                        // Hidden log items, give review link
                        } else if( self::typeAction($row,array('delete','suppress'),'event') && $wgUser->isAllowed( 'deleterevision' ) ) {
-                               if( isset($paramArray[0]) ) {
+                               if( count($paramArray) == 1 ) {
                                        $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                                        $revert .= $this->message['revdel-restore'];
                                        $Ids = explode( ',', $paramArray[0] );
                                        // Link to each hidden object ID, $paramArray[1] is the url param. List if several...
                                        if( count($Ids) == 1 ) {
                                                $revert = $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
-                                                       wfArrayToCGI( array('logid' => $Ids[0] ) ) );
+                                                       wfArrayToCGI( array('target' => urlencode( $title->getPrefixedDBkey() ),'logid' => $Ids[0] ) ) );
                                        } else {
                                                foreach( $Ids as $n => $id ) {
                                                        $revert .= $this->skin->makeKnownLinkObj( $revdel, '#'.($n+1),
-                                                               wfArrayToCGI( array('logid' => $id ) ) );
+                                                               wfArrayToCGI( array('target' => urlencode( $title->getPrefixedDBkey() ),'logid' => $id ) ) );
                                                }
                                        }
                                        $revert = "($revert)";
@@ -320,7 +318,9 @@ class LogEventsList {
                        // No one should be hiding from the oversight log
                        $del = $this->message['rev-delundel'];
                } else {
-                       $del = $this->skin->makeKnownLinkObj( $revdel, $this->message['rev-delundel'], 'logid='.$row->log_id );
+                       $target = SpecialPage::getTitleFor( 'Log', $row->log_type );
+                       $del = $this->skin->makeKnownLinkObj( $revdel, $this->message['rev-delundel'],
+                               'target=' . urlencode( $target->getPrefixedDBkey() ) . '&logid='.$row->log_id );
                        // Bolden oversighted content
                        if( self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) )
                                $del = "<strong>$del</strong>";
index b24a9f8..6fb46f0 100644 (file)
@@ -20,7 +20,7 @@ function wfSpecialRevisiondelete( $par = null ) {
        $file = $wgRequest->getVal( 'file' );
        # If this is a revision, then we need a target page
        $page = Title::newFromUrl( $target );
-       if( is_null($page) && is_null($logid) ) {
+       if( is_null($page) ) {
                $wgOut->addWikiText( wfMsgHtml( 'undelete-header' ) );
                return;
        }
@@ -30,6 +30,11 @@ function wfSpecialRevisiondelete( $par = null ) {
                $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
                return;
        }
+       # Logs must have a type given
+       if( $logid && !strpos($page->getDBKey(),'/') ) {
+               $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
+               return;
+       }
        # Either submit or create our form
        $form = new RevisionDeleteForm( $page, $oldid, $logid, $artimestamp, $fileid, $img, $file );
        if( $wgRequest->wasPosted() ) {
@@ -43,13 +48,11 @@ function wfSpecialRevisiondelete( $par = null ) {
        }
        # Show relevant lines from the deletion log. This will show even if said ID
        # does not exist...might be helpful
-       if( !is_null($page) ) {
-               $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
-               LogEventsList::showLogExtract( $wgOut, 'delete', $page->getPrefixedText() );
-               if( $wgUser->isAllowed( 'suppress' ) ){
-                       $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
-                       LogEventsList::showLogExtract( $wgOut, 'suppress', $page->getPrefixedText() );
-               }
+       $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
+       LogEventsList::showLogExtract( $wgOut, 'delete', $page->getPrefixedText() );
+       if( $wgUser->isAllowed( 'suppress' ) ){
+               $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
+               LogEventsList::showLogExtract( $wgOut, 'suppress', $page->getPrefixedText() );
        }
 }
 
@@ -271,7 +274,8 @@ class RevisionDeleteForm {
                }
                $special = SpecialPage::getTitleFor( 'Revisiondelete' );
                $wgOut->addHtml(
-                       Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-revisions' ) ) .
+                       Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ), 
+                               'id' => 'mw-revdel-form-revisions' ) ) .
                        Xml::openElement( 'fieldset' ) .
                        xml::element( 'legend', null,  wfMsg( 'revdelete-legend' ) )
                );
@@ -407,7 +411,8 @@ class RevisionDeleteForm {
                }
                $special = SpecialPage::getTitleFor( 'Revisiondelete' );
                $wgOut->addHtml(
-                       Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-filerevisions' ) ) .
+                       Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ), 
+                               'id' => 'mw-revdel-form-filerevisions' ) ) .
                        Xml::openElement( 'fieldset' ) .
                        xml::element( 'legend', null,  wfMsg( 'revdelete-legend' ) )
                );
@@ -448,7 +453,8 @@ class RevisionDeleteForm {
                foreach( $this->events as $logid ) {
                        $where[] = intval($logid);
                }
-               $whereClause = 'log_id IN(' . implode(',',$where) . ')';
+               list($log,$logtype) = explode( '/',$this->page->getDBKey(), 2 );
+               $whereClause = "log_type = '$logtype' AND log_id IN(" . implode(',',$where) . ")";
                $result = $dbr->select( 'logging', '*',
                        array( $whereClause ),
                        __METHOD__ );
@@ -483,6 +489,7 @@ class RevisionDeleteForm {
                        Xml::submitButton( wfMsg( 'revdelete-submit' ) ) );
                $hidden = array(
                        Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
+                       Xml::hidden( 'target', $this->page->getPrefixedText() ),
                        Xml::hidden( 'type', $this->deleteKey ) );
                foreach( $this->events as $logid ) {
                        $hidden[] = Xml::hidden( 'logid[]', $logid );
@@ -490,7 +497,8 @@ class RevisionDeleteForm {
 
                $special = SpecialPage::getTitleFor( 'Revisiondelete' );
                $wgOut->addHtml(
-                       Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
+                       Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ), 
+                               'id' => 'mw-revdel-form-logs' ) ) .
                        Xml::openElement( 'fieldset' ) .
                        xml::element( 'legend', null,  wfMsg( 'revdelete-legend' ) )
                );
@@ -756,7 +764,7 @@ class RevisionDeleteForm {
                } else if( isset($this->afiles) ) {
                        return $deleter->setArchFileVisibility( $title, $this->afiles, $bitfield, $reason );
                } else if( isset($this->events) ) {
-                       return $deleter->setEventVisibility( $this->events, $bitfield, $reason );
+                       return $deleter->setEventVisibility( $title, $this->events, $bitfield, $reason );
                }
        }
 }
@@ -1048,22 +1056,24 @@ class RevisionDeleter {
        }
 
        /**
+        * @param $title, the log page these events apply to
         * @param array $items list of log ID numbers
         * @param int $bitfield new log_deleted value
         * @param string $comment Comment for log records
         */
-       function setEventVisibility( $items, $bitfield, $comment ) {
+       function setEventVisibility( $title, $items, $bitfield, $comment ) {
                global $wgOut;
 
                $userAllowedAll = $success = true;
-               $logs_count = array();
-               $logs_Ids = array();
+               $count = 0;
+               $log_Ids = array();
 
                // Run through and pull all our data in one query
                foreach( $items as $logid ) {
                        $where[] = intval($logid);
                }
-               $whereClause = 'log_id IN(' . implode(',',$where) . ')';
+               list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
+               $whereClause = "log_type ='$logtype' AND log_id IN(" . implode(',',$where) . ")";
                $result = $this->dbw->select( 'logging', '*',
                        array( $whereClause ),
                        __METHOD__ );
@@ -1075,34 +1085,25 @@ class RevisionDeleter {
                        if( !isset($logRows[$logid]) ) {
                                $success = false;
                                continue; // Must exist
-                       } else if( !LogEventsList::userCan($logRows[$logid], Revision::DELETED_RESTRICTED)
+                       } else if( !LogEventsList::userCan($logRows[$logid], LogPage::DELETED_RESTRICTED)
                                 || $logRows[$logid]->log_type == 'suppress' ) {
                        // Don't hide from oversight log!!!
                        $userAllowedAll=false;
                        continue;
                        }
-                       $logtype = $logRows[$logid]->log_type;
-                       // For logging, maintain a count of events per log type
-                       if( !isset( $logs_count[$logtype] ) ) {
-                               $logs_count[$logtype]=0;
-                               $logs_Ids[$logtype]=array();
-                       }
                        // Which logs did we change anything about?
                        if( $logRows[$logid]->log_deleted != $bitfield ) {
-                               $logs_Ids[$logtype][]=$logid;
-                               $logs_count[$logtype]++;
+                               $log_Ids[]=$logid;
+                               $count++;
 
                                $this->updateLogs( $logRows[$logid], $bitfield );
                                $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
                        }
                }
-               foreach( $logs_count as $logtype => $count ) {
-                       // Don't log or touch if nothing changed
-                       if( $count > 0 ) {
-                               $target = SpecialPage::getTitleFor( 'Log', $logtype );
-                               $this->updateLog( $target, $count, $bitfield, $logRows[$logid]->log_deleted,
-                               $comment, $target, 'logid', $logs_Ids[$logtype] );
-                       }
+               // Don't log or touch if nothing changed
+               if( $count > 0 ) {
+                       $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted,
+                               $comment, $title, 'logid', $log_Ids );
                }
                // Where all revs allowed to be set?
                if( !$userAllowedAll ) {
@@ -1452,7 +1453,7 @@ class RevisionDeleter {
                        $log->addEntry( 'event', $title, $reason, $params );
                } else {
                        // Add params for effected page and ids
-                       $params = array( $target->getPrefixedText(), $param, implode( ',', $items) );
+                       $params = array( $param, implode( ',', $items) );
                        $log->addEntry( 'revision', $title, $reason, $params );
                }
        }