Merge "wfProfileOut() for new return added in c6396 (c4e407c)"
[lhc/web/wiklou.git] / includes / revisiondelete / RevisionDelete.php
index 9f79837..517270a 100644 (file)
@@ -1,4 +1,26 @@
 <?php
+/**
+ * Base implementations for deletable items.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup RevisionDelete
+ */
+
 /**
  * List for revision table items
  *
  */
 class RevDel_RevisionList extends RevDel_List {
        var $currentRevId;
-       var $type = 'revision';
-       var $idField = 'rev_id';
-       var $dateField = 'rev_timestamp';
-       var $authorIdField = 'rev_user';
-       var $authorNameField = 'rev_user_text';
+
+       public function getType() {
+               return 'revision';
+       }
+
+       public static function getRelationType() {
+               return 'rev_id';
+       }
 
        /**
         * @param $db DatabaseBase
@@ -22,14 +47,18 @@ class RevDel_RevisionList extends RevDel_List {
         */
        public function doQuery( $db ) {
                $ids = array_map( 'intval', $this->ids );
-               $live = $db->select( array('revision','page'), '*',
+               $live = $db->select(
+                       array( 'revision', 'page', 'user' ),
+                       array_merge( Revision::selectFields(), Revision::selectUserFields() ),
                        array(
                                'rev_page' => $this->title->getArticleID(),
                                'rev_id'   => $ids,
-                               'rev_page = page_id'
                        ),
                        __METHOD__,
-                       array( 'ORDER BY' => 'rev_id DESC' )
+                       array( 'ORDER BY' => 'rev_id DESC' ),
+                       array(
+                               'page' => Revision::pageJoinCond(),
+                               'user' => Revision::userJoinCond() )
                );
 
                if ( $live->numRows() >= count( $ids ) ) {
@@ -48,7 +77,7 @@ class RevDel_RevisionList extends RevDel_List {
 
                if ( $archived->numRows() == 0 ) {
                        return $live;
-               } else if ( $live->numRows() == 0 ) {
+               } elseif ( $live->numRows() == 0 ) {
                        return $archived;
                } else {
                        // Combine the two! Whee
@@ -112,16 +141,32 @@ class RevDel_RevisionItem extends RevDel_Item {
                $this->revision = new Revision( $row );
        }
 
+       public function getIdField() {
+               return 'rev_id';
+       }
+
+       public function getTimestampField() {
+               return 'rev_timestamp';
+       }
+
+       public function getAuthorIdField() {
+               return 'rev_user';
+       }
+
+       public function getAuthorNameField() {
+               return 'user_name'; // see Revision::selectUserFields()
+       }
+
        public function canView() {
-               return $this->revision->userCan( Revision::DELETED_RESTRICTED );
+               return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->list->getUser() );
        }
 
        public function canViewContent() {
-               return $this->revision->userCan( Revision::DELETED_TEXT );
+               return $this->revision->userCan( Revision::DELETED_TEXT, $this->list->getUser() );
        }
 
        public function getBits() {
-               return $this->revision->mDeleted;
+               return $this->revision->getVisibility();
        }
 
        public function setBits( $bits ) {
@@ -168,14 +213,15 @@ class RevDel_RevisionItem extends RevDel_Item {
        /**
         * Get the HTML link to the revision text.
         * Overridden by RevDel_ArchiveItem.
+        * @return string
         */
        protected function getRevisionLink() {
-               global $wgLang;
-               $date = $wgLang->timeanddate( $this->revision->getTimestamp(), true );
+               $date = $this->list->getLanguage()->userTimeAndDate(
+                       $this->revision->getTimestamp(), $this->list->getUser() );
                if ( $this->isDeleted() && !$this->canViewContent() ) {
                        return $date;
                }
-               return $this->special->skin->link(
+               return Linker::link(
                        $this->list->title,
                        $date,
                        array(),
@@ -189,15 +235,16 @@ class RevDel_RevisionItem extends RevDel_Item {
        /**
         * Get the HTML link to the diff.
         * Overridden by RevDel_ArchiveItem
+        * @return string
         */
        protected function getDiffLink() {
                if ( $this->isDeleted() && !$this->canViewContent() ) {
-                       return wfMsgHtml('diff');
+                       return $this->list->msg( 'diff' )->escaped();
                } else {
                        return
-                               $this->special->skin->link(
+                               Linker::link(
                                        $this->list->title,
-                                       wfMsgHtml('diff'),
+                                       $this->list->msg( 'diff' )->escaped(),
                                        array(),
                                        array(
                                                'diff' => $this->revision->getId(),
@@ -215,8 +262,8 @@ class RevDel_RevisionItem extends RevDel_Item {
        public function getHTML() {
                $difflink = $this->getDiffLink();
                $revlink = $this->getRevisionLink();
-               $userlink = $this->special->skin->revUserLink( $this->revision );
-               $comment = $this->special->skin->revComment( $this->revision );
+               $userlink = Linker::revUserLink( $this->revision );
+               $comment = Linker::revComment( $this->revision );
                if ( $this->isDeleted() ) {
                        $revlink = "<span class=\"history-deleted\">$revlink</span>";
                }
@@ -228,11 +275,13 @@ class RevDel_RevisionItem extends RevDel_Item {
  * List for archive table items, i.e. revisions deleted via action=delete
  */
 class RevDel_ArchiveList extends RevDel_RevisionList {
-       var $type = 'archive';
-       var $idField = 'ar_timestamp';
-       var $dateField = 'ar_timestamp';
-       var $authorIdField = 'ar_user';
-       var $authorNameField = 'ar_user_text';
+       public function getType() {
+               return 'archive';
+       }
+
+       public static function getRelationType() {
+               return 'ar_timestamp';
+       }
 
        /**
         * @param $db DatabaseBase
@@ -274,7 +323,23 @@ class RevDel_ArchiveItem extends RevDel_RevisionItem {
        public function __construct( $list, $row ) {
                RevDel_Item::__construct( $list, $row );
                $this->revision = Revision::newFromArchiveRow( $row,
-                       array( 'page' => $this->list->title->getArticleId() ) );
+                       array( 'page' => $this->list->title->getArticleID() ) );
+       }
+
+       public function getIdField() {
+               return 'ar_timestamp';
+       }
+
+       public function getTimestampField() {
+               return 'ar_timestamp';
+       }
+
+       public function getAuthorIdField() {
+               return 'ar_user';
+       }
+
+       public function getAuthorNameField() {
+               return 'ar_user_text';
        }
 
        public function getId() {
@@ -286,25 +351,26 @@ class RevDel_ArchiveItem extends RevDel_RevisionItem {
                $dbw = wfGetDB( DB_MASTER );
                $dbw->update( 'archive',
                        array( 'ar_deleted' => $bits ),
-                       array( 'ar_namespace' => $this->list->title->getNamespace(),
-                               'ar_title'     => $this->list->title->getDBkey(),
+                       array(
+                               'ar_namespace'  => $this->list->title->getNamespace(),
+                               'ar_title'      => $this->list->title->getDBkey(),
                                // use timestamp for index
-                               'ar_timestamp' => $this->row->ar_timestamp,
-                               'ar_rev_id'    => $this->row->ar_rev_id,
-                               'ar_deleted' => $this->getBits()
+                               'ar_timestamp'  => $this->row->ar_timestamp,
+                               'ar_rev_id'     => $this->row->ar_rev_id,
+                               'ar_deleted'    => $this->getBits()
                        ),
                        __METHOD__ );
                return (bool)$dbw->affectedRows();
        }
 
        protected function getRevisionLink() {
-               global $wgLang;
                $undelete = SpecialPage::getTitleFor( 'Undelete' );
-               $date = $wgLang->timeanddate( $this->revision->getTimestamp(), true );
+               $date = $this->list->getLanguage()->userTimeAndDate(
+                       $this->revision->getTimestamp(), $this->list->getUser() );
                if ( $this->isDeleted() && !$this->canViewContent() ) {
                        return $date;
                }
-               return $this->special->skin->link( $undelete, $date, array(),
+               return Linker::link( $undelete, $date, array(),
                        array(
                                'target' => $this->list->title->getPrefixedText(),
                                'timestamp' => $this->revision->getTimestamp()
@@ -313,10 +379,10 @@ class RevDel_ArchiveItem extends RevDel_RevisionItem {
 
        protected function getDiffLink() {
                if ( $this->isDeleted() && !$this->canViewContent() ) {
-                       return wfMsgHtml( 'diff' );
+                       return $this->list->msg( 'diff' )->escaped();
                }
                $undelete = SpecialPage::getTitleFor( 'Undelete' );
-               return $this->special->skin->link( $undelete, wfMsgHtml('diff'), array(),
+               return Linker::link( $undelete, $this->list->msg( 'diff' )->escaped(), array(),
                        array(
                                'target' => $this->list->title->getPrefixedText(),
                                'diff' => 'prev',
@@ -335,7 +401,11 @@ class RevDel_ArchivedRevisionItem extends RevDel_ArchiveItem {
                RevDel_Item::__construct( $list, $row );
 
                $this->revision = Revision::newFromArchiveRow( $row,
-                       array( 'page' => $this->list->title->getArticleId() ) );
+                       array( 'page' => $this->list->title->getArticleID() ) );
+       }
+
+       public function getIdField() {
+               return 'ar_rev_id';
        }
 
        public function getId() {
@@ -358,11 +428,14 @@ class RevDel_ArchivedRevisionItem extends RevDel_ArchiveItem {
  * List for oldimage table items
  */
 class RevDel_FileList extends RevDel_List {
-       var $type = 'oldimage';
-       var $idField = 'oi_archive_name';
-       var $dateField = 'oi_timestamp';
-       var $authorIdField = 'oi_user';
-       var $authorNameField = 'oi_user_text';
+       public function getType() {
+               return 'oldimage';
+       }
+
+       public static function getRelationType() {
+               return 'oi_archive_name';
+       }
+
        var $storeBatch, $deleteBatch, $cleanupBatch;
 
        /**
@@ -444,17 +517,33 @@ class RevDel_FileItem extends RevDel_Item {
                $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
        }
 
+       public function getIdField() {
+               return 'oi_archive_name';
+       }
+
+       public function getTimestampField() {
+               return 'oi_timestamp';
+       }
+
+       public function getAuthorIdField() {
+               return 'oi_user';
+       }
+
+       public function getAuthorNameField() {
+               return 'oi_user_text';
+       }
+
        public function getId() {
                $parts = explode( '!', $this->row->oi_archive_name );
                return $parts[0];
        }
 
        public function canView() {
-               return $this->file->userCan( File::DELETED_RESTRICTED );
+               return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() );
        }
 
        public function canViewContent() {
-               return $this->file->userCan( File::DELETED_FILE );
+               return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() );
        }
 
        public function getBits() {
@@ -506,22 +595,25 @@ class RevDel_FileItem extends RevDel_Item {
        /**
         * Get the link to the file.
         * Overridden by RevDel_ArchivedFileItem.
+        * @return string
         */
        protected function getLink() {
-               global $wgLang, $wgUser;
-               $date = $wgLang->timeanddate( $this->file->getTimestamp(), true  );
+               $date = $this->list->getLanguage()->userTimeAndDate(
+                       $this->file->getTimestamp(), $this->list->getUser() );
                if ( $this->isDeleted() ) {
                        # Hidden files...
                        if ( !$this->canViewContent() ) {
                                $link = $date;
                        } else {
-                               $link = $this->special->skin->link(
-                                       $this->special->getTitle(),
+                               $revdelete = SpecialPage::getTitleFor( 'Revisiondelete' );
+                               $link = Linker::link(
+                                       $revdelete,
                                        $date, array(),
                                        array(
                                                'target' => $this->list->title->getPrefixedText(),
                                                'file'   => $this->file->getArchiveName(),
-                                               'token'  => $wgUser->editToken( $this->file->getArchiveName() )
+                                               'token'  => $this->list->getUser()->getEditToken(
+                                                       $this->file->getArchiveName() )
                                        )
                                );
                        }
@@ -536,11 +628,11 @@ class RevDel_FileItem extends RevDel_Item {
         * @return string HTML
         */
        protected function getUserTools() {
-               if( $this->file->userCan( Revision::DELETED_USER ) ) {
-                       $link = $this->special->skin->userLink( $this->file->user, $this->file->user_text ) .
-                               $this->special->skin->userToolLinks( $this->file->user, $this->file->user_text );
+               if( $this->file->userCan( Revision::DELETED_USER, $this->list->getUser() ) ) {
+                       $link = Linker::userLink( $this->file->user, $this->file->user_text ) .
+                               Linker::userToolLinks( $this->file->user, $this->file->user_text );
                } else {
-                       $link = wfMsgHtml( 'rev-deleted-user' );
+                       $link = $this->list->msg( 'rev-deleted-user' )->escaped();
                }
                if( $this->file->isDeleted( Revision::DELETED_USER ) ) {
                        return '<span class="history-deleted">' . $link . '</span>';
@@ -555,10 +647,10 @@ class RevDel_FileItem extends RevDel_Item {
         * @return string HTML
         */
        protected function getComment() {
-               if( $this->file->userCan( File::DELETED_COMMENT ) ) {
-                       $block = $this->special->skin->commentBlock( $this->file->description );
+               if( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) {
+                       $block = Linker::commentBlock( $this->file->description );
                } else {
-                       $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
+                       $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
                }
                if( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
                        return "<span class=\"history-deleted\">$block</span>";
@@ -567,16 +659,10 @@ class RevDel_FileItem extends RevDel_Item {
        }
 
        public function getHTML() {
-               global $wgLang;
                $data =
-                       wfMsg(
-                               'widthheight',
-                               $wgLang->formatNum( $this->file->getWidth() ),
-                               $wgLang->formatNum( $this->file->getHeight() )
-                       ) .
-                       ' (' .
-                       wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file->getSize() ) ) .
-                       ')';
+                       $this->list->msg( 'widthheight' )->numParams(
+                               $this->file->getWidth(), $this->file->getHeight() )->text() .
+                       ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')';
 
                return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
                        $data . ' ' . $this->getComment(). '</li>';
@@ -587,11 +673,13 @@ class RevDel_FileItem extends RevDel_Item {
  * List for filearchive table items
  */
 class RevDel_ArchivedFileList extends RevDel_FileList {
-       var $type = 'filearchive';
-       var $idField = 'fa_id';
-       var $dateField = 'fa_timestamp';
-       var $authorIdField = 'fa_user';
-       var $authorNameField = 'fa_user_text';
+       public function getType() {
+               return 'filearchive';
+       }
+
+       public static function getRelationType() {
+               return 'fa_id';
+       }
 
        /**
         * @param $db DatabaseBase
@@ -623,6 +711,22 @@ class RevDel_ArchivedFileItem extends RevDel_FileItem {
                $this->file = ArchivedFile::newFromRow( $row );
        }
 
+       public function getIdField() {
+               return 'fa_id';
+       }
+
+       public function getTimestampField() {
+               return 'fa_timestamp';
+       }
+
+       public function getAuthorIdField() {
+               return 'fa_user';
+       }
+
+       public function getAuthorNameField() {
+               return 'fa_user_text';
+       }
+
        public function getId() {
                return $this->row->fa_id;
        }
@@ -641,19 +745,19 @@ class RevDel_ArchivedFileItem extends RevDel_FileItem {
        }
 
        protected function getLink() {
-               global $wgLang, $wgUser;
-               $date = $wgLang->timeanddate( $this->file->getTimestamp(), true  );
+               $date = $this->list->getLanguage()->userTimeAndDate(
+                       $this->file->getTimestamp(), $this->list->getUser() );
                $undelete = SpecialPage::getTitleFor( 'Undelete' );
                $key = $this->file->getKey();
                # Hidden files...
                if( !$this->canViewContent() ) {
                        $link = $date;
                } else {
-                       $link = $this->special->skin->link( $undelete, $date, array(),
+                       $link = Linker::link( $undelete, $date, array(),
                                array(
                                        'target' => $this->list->title->getPrefixedText(),
                                        'file' => $key,
-                                       'token' => $wgUser->editToken( $key )
+                                       'token' => $this->list->getUser()->getEditToken( $key )
                                )
                        );
                }
@@ -668,11 +772,13 @@ class RevDel_ArchivedFileItem extends RevDel_FileItem {
  * List for logging table items
  */
 class RevDel_LogList extends RevDel_List {
-       var $type = 'logging';
-       var $idField = 'log_id';
-       var $dateField = 'log_timestamp';
-       var $authorIdField = 'log_user';
-       var $authorNameField = 'log_user_text';
+       public function getType() {
+               return 'logging';
+       }
+
+       public static function getRelationType() {
+               return 'log_id';
+       }
 
        /**
         * @param $db DatabaseBase
@@ -712,8 +818,24 @@ class RevDel_LogList extends RevDel_List {
  * Item class for a logging table row
  */
 class RevDel_LogItem extends RevDel_Item {
+       public function getIdField() {
+               return 'log_id';
+       }
+
+       public function getTimestampField() {
+               return 'log_timestamp';
+       }
+
+       public function getAuthorIdField() {
+               return 'log_user';
+       }
+
+       public function getAuthorNameField() {
+               return 'log_user_text';
+       }
+
        public function canView() {
-               return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED );
+               return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED, $this->list->getUser() );
        }
 
        public function canViewContent() {
@@ -749,39 +871,28 @@ class RevDel_LogItem extends RevDel_Item {
        }
 
        public function getHTML() {
-               global $wgLang;
-
-               $date = htmlspecialchars( $wgLang->timeanddate( $this->row->log_timestamp ) );
-               $paramArray = LogPage::extractParams( $this->row->log_params );
+               $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
+                       $this->row->log_timestamp, $this->list->getUser() ) );
                $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
+               $formatter = LogFormatter::newFromRow( $this->row );
+               $formatter->setContext( $this->list->getContext() );
+               $formatter->setAudience( LogFormatter::FOR_THIS_USER );
 
                // Log link for this page
-               $loglink = $this->special->skin->link(
+               $loglink = Linker::link(
                        SpecialPage::getTitleFor( 'Log' ),
-                       wfMsgHtml( 'log' ),
+                       $this->list->msg( 'log' )->escaped(),
                        array(),
                        array( 'page' => $title->getPrefixedText() )
                );
-               // Action text
-               if( !$this->canView() ) {
-                       $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
-               } else {
-                       $action = LogPage::actionText( $this->row->log_type, $this->row->log_action, $title,
-                               $this->special->skin, $paramArray, true, true );
-                       if( $this->row->log_deleted & LogPage::DELETED_ACTION )
-                               $action = '<span class="history-deleted">' . $action . '</span>';
-               }
-               // User links
-               $userLink = $this->special->skin->userLink( $this->row->log_user,
-                       User::WhoIs( $this->row->log_user ) );
-               if( LogEventsList::isDeleted($this->row,LogPage::DELETED_USER) ) {
-                       $userLink = '<span class="history-deleted">' . $userLink . '</span>';
-               }
+               // User links and action text
+               $action = $formatter->getActionText();
                // Comment
-               $comment = $wgLang->getDirMark() . $this->special->skin->commentBlock( $this->row->log_comment );
+               $comment = $this->list->getLanguage()->getDirMark() . Linker::commentBlock( $this->row->log_comment );
                if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) {
                        $comment = '<span class="history-deleted">' . $comment . '</span>';
                }
-               return "<li>($loglink) $date $userLink $action $comment</li>";
+
+               return "<li>($loglink) $date $action $comment</li>";
        }
 }