Merge "[FileRepo] Made getDescription() respect *_deleted fields."
authorDemon <chadh@wikimedia.org>
Mon, 4 Jun 2012 20:41:52 +0000 (20:41 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 4 Jun 2012 20:41:52 +0000 (20:41 +0000)
1  2 
includes/Export.php
includes/ImagePage.php
includes/Revision.php
includes/filerepo/file/LocalFile.php

diff --combined includes/Export.php
@@@ -468,7 -468,7 +468,7 @@@ class XmlDumpWriter 
         * @return string
         */
        function schemaVersion() {
 -              return "0.6";
 +              return "0.7";
        }
  
        /**
                        $out .= "      " . Xml::elementClean( 'comment', array(), strval( $row->rev_comment ) ) . "\n";
                }
  
 +              if ( $row->rev_sha1 && !( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
 +                      $out .= "      " . Xml::element('sha1', null, strval( $row->rev_sha1 ) ) . "\n";
 +              } else {
 +                      $out .= "      <sha1/>\n";
 +              }
 +
                $text = '';
                if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
                        $out .= "      " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
                                "" ) . "\n";
                }
  
 -              if ( $row->rev_sha1 && !( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
 -                      $out .= "      " . Xml::element('sha1', null, strval( $row->rev_sha1 ) ) . "\n";
 -              } else {
 -                      $out .= "      <sha1/>\n";
 -              }
 -
                wfRunHooks( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
  
                $out .= "    </revision>\n";
        function writeLogItem( $row ) {
                wfProfileIn( __METHOD__ );
  
 -              $out  = "    <logitem>\n";
 -              $out .= "      " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
 +              $out  = "  <logitem>\n";
 +              $out .= "    " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
  
 -              $out .= $this->writeTimestamp( $row->log_timestamp );
 +              $out .= $this->writeTimestamp( $row->log_timestamp, "    " );
  
                if ( $row->log_deleted & LogPage::DELETED_USER ) {
 -                      $out .= "      " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
 +                      $out .= "    " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
                } else {
 -                      $out .= $this->writeContributor( $row->log_user, $row->user_name );
 +                      $out .= $this->writeContributor( $row->log_user, $row->user_name, "    " );
                }
  
                if ( $row->log_deleted & LogPage::DELETED_COMMENT ) {
 -                      $out .= "      " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
 +                      $out .= "    " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
                } elseif ( $row->log_comment != '' ) {
 -                      $out .= "      " . Xml::elementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
 +                      $out .= "    " . Xml::elementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
                }
  
 -              $out .= "      " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
 -              $out .= "      " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
 +              $out .= "    " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
 +              $out .= "    " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
  
                if ( $row->log_deleted & LogPage::DELETED_ACTION ) {
 -                      $out .= "      " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
 +                      $out .= "    " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
                } else {
                        $title = Title::makeTitle( $row->log_namespace, $row->log_title );
 -                      $out .= "      " . Xml::elementClean( 'logtitle', null, self::canonicalTitle( $title ) ) . "\n";
 -                      $out .= "      " . Xml::elementClean( 'params',
 +                      $out .= "    " . Xml::elementClean( 'logtitle', null, self::canonicalTitle( $title ) ) . "\n";
 +                      $out .= "    " . Xml::elementClean( 'params',
                                array( 'xml:space' => 'preserve' ),
                                strval( $row->log_params ) ) . "\n";
                }
  
 -              $out .= "    </logitem>\n";
 +              $out .= "  </logitem>\n";
  
                wfProfileOut( __METHOD__ );
                return $out;
         * @param $timestamp string
         * @return string
         */
 -      function writeTimestamp( $timestamp ) {
 +      function writeTimestamp( $timestamp, $indent = "      " ) {
                $ts = wfTimestamp( TS_ISO_8601, $timestamp );
 -              return "      " . Xml::element( 'timestamp', null, $ts ) . "\n";
 +              return $indent . Xml::element( 'timestamp', null, $ts ) . "\n";
        }
  
        /**
         * @param $text string
         * @return string
         */
 -      function writeContributor( $id, $text ) {
 -              $out = "      <contributor>\n";
 +      function writeContributor( $id, $text, $indent = "      " ) {
 +              $out = $indent . "<contributor>\n";
                if ( $id || !IP::isValid( $text ) ) {
 -                      $out .= "        " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
 -                      $out .= "        " . Xml::element( 'id', null, strval( $id ) ) . "\n";
 +                      $out .= $indent . "  " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
 +                      $out .= $indent . "  " . Xml::element( 'id', null, strval( $id ) ) . "\n";
                } else {
 -                      $out .= "        " . Xml::elementClean( 'ip', null, strval( $text ) ) . "\n";
 +                      $out .= $indent . "  " . Xml::elementClean( 'ip', null, strval( $text ) ) . "\n";
                }
 -              $out .= "      </contributor>\n";
 +              $out .= $indent . "</contributor>\n";
                return $out;
        }
  
                } else {
                        $contents = '';
                }
+               if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
+                       $comment = Xml::element( 'comment', array( 'deleted' => 'deleted' ) );
+               } else {
+                       $comment = Xml::elementClean( 'comment', null, $file->getDescription() );
+               }
                return "    <upload>\n" .
                        $this->writeTimestamp( $file->getTimestamp() ) .
                        $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
-                       "      " . Xml::elementClean( 'comment', null, $file->getDescription() ) . "\n" .
+                       "      " . $comment . "\n" .
                        "      " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
                        $archiveName .
                        "      " . Xml::element( 'src', null, $file->getCanonicalUrl() ) . "\n" .
diff --combined includes/ImagePage.php
@@@ -990,7 -990,7 +990,7 @@@ class ImageHistoryList extends ContextS
                $img = $iscur ? $file->getName() : $file->getArchiveName();
                $userId = $file->getUser( 'id' );
                $userText = $file->getUser( 'text' );
-               $description = $file->getDescription();
+               $description = $file->getDescription( File::FOR_THIS_USER, $user );
  
                $local = $this->current->isLocal();
                $row = $selected = '';
                $row .= '<td>';
                if ( $iscur ) {
                        $row .= wfMsgHtml( 'filehist-current' );
 -              } elseif ( $local && $user->isLoggedIn() && $this->title->userCan( 'edit' ) ) {
 +              } elseif ( $local && $this->title->quickUserCan( 'edit' )
 +                      && $this->title->quickUserCan( 'upload' )
 +              ) {
                        if ( $file->isDeleted( File::DELETED_FILE ) ) {
                                $row .= wfMsgHtml( 'filehist-revert' );
                        } else {
                // Image dimensions + size
                $row .= '<td>';
                $row .= htmlspecialchars( $file->getDimensionsString() );
 -              $row .= ' <span style="white-space: nowrap;">(' . Linker::formatSize( $file->getSize() ) . ')</span>';
 +              $row .= $this->getContext()->msg( 'word-separator' )->plain();
 +              $row .= '<span style="white-space: nowrap;">';
 +              $row .= $this->getContext()->msg( 'parentheses' )->rawParams( Linker::formatSize( $file->getSize() ) )->plain();
 +              $row .= '</span>';
                $row .= '</td>';
  
                // Uploading user
diff --combined includes/Revision.php
@@@ -381,9 -381,7 +381,9 @@@ class Revision 
                        'page_namespace',
                        'page_title',
                        'page_id',
 -                      'page_latest'
 +                      'page_latest',
 +                      'page_is_redirect',
 +                      'page_len',
                );
        }
  
        /**
         * Get revision ID
         *
 -       * @return Integer
 +       * @return Integer|null
         */
        public function getId() {
                return $this->mId;
        /**
         * Get text row ID
         *
 -       * @return Integer
 +       * @return Integer|null
         */
        public function getTextId() {
                return $this->mTextId;
        /**
         * Returns the length of the text in this revision, or null if unknown.
         *
 -       * @return Integer
 +       * @return Integer|null
         */
        public function getSize() {
                return $this->mSize;
        /**
         * Returns the base36 sha1 of the text in this revision, or null if unknown.
         *
 -       * @return String
 +       * @return String|null
         */
        public function getSha1() {
                return $this->mSha1;
        }
  
        /**
 -       * Returns the title of the page associated with this entry.
 +       * Returns the title of the page associated with this entry or null.
         *
 -       * @return Title
 +       * Will do a query, when title is not set and id is given.
 +       *
 +       * @return Title|null
         */
        public function getTitle() {
                if( isset( $this->mTitle ) ) {
                        return $this->mTitle;
                }
 -              $dbr = wfGetDB( DB_SLAVE );
 -              $row = $dbr->selectRow(
 -                      array( 'page', 'revision' ),
 -                      self::selectPageFields(),
 -                      array( 'page_id=rev_page',
 -                                 'rev_id' => $this->mId ),
 -                      __METHOD__ );
 -              if ( $row ) {
 -                      $this->mTitle = Title::newFromRow( $row );
 +              if( !is_null( $this->mId ) ) { //rev_id is defined as NOT NULL
 +                      $dbr = wfGetDB( DB_SLAVE );
 +                      $row = $dbr->selectRow(
 +                              array( 'page', 'revision' ),
 +                              self::selectPageFields(),
 +                              array( 'page_id=rev_page',
 +                                         'rev_id' => $this->mId ),
 +                              __METHOD__ );
 +                      if ( $row ) {
 +                              $this->mTitle = Title::newFromRow( $row );
 +                      }
                }
                return $this->mTitle;
        }
        /**
         * Get the page ID
         *
 -       * @return Integer
 +       * @return Integer|null
         */
        public function getPage() {
                return $this->mPage;
         *
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the ID regardless of permissions
         * @param $user User object to check for, only if FOR_THIS_USER is passed
         *              to the $audience parameter
         *
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
         * @param $user User object to check for, only if FOR_THIS_USER is passed
         *              to the $audience parameter
         *
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
         * @param $user User object to check for, only if FOR_THIS_USER is passed
         *              to the $audience parameter
         *
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
         * @param $user User object to check for, only if FOR_THIS_USER is passed
         *              to the $audience parameter
  
                $current = $dbw->selectRow(
                        array( 'page', 'revision' ),
 -                      array( 'page_latest', 'rev_text_id', 'rev_len', 'rev_sha1' ),
 +                      array( 'page_latest', 'page_namespace', 'page_title',
 +                              'rev_text_id', 'rev_len', 'rev_sha1' ),
                        array(
                                'page_id' => $pageId,
                                'page_latest=rev_id',
                                'len'        => $current->rev_len,
                                'sha1'       => $current->rev_sha1
                                ) );
 +                      $revision->setTitle( Title::makeTitle( $current->page_namespace, $current->page_title ) );
                } else {
                        $revision = null;
                }
@@@ -1467,9 -1467,17 +1467,17 @@@ class LocalFile extends File 
        /**
         * @return string
         */
-       function getDescription() {
+       function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
                $this->load();
-               return $this->description;
+               if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_COMMENT ) ) {
+                       return '';
+               } elseif ( $audience == self::FOR_THIS_USER
+                       && !$this->userCan( self::DELETED_COMMENT, $user ) )
+               {
+                       return '';
+               } else {
+                       return $this->description;
+               }
        }
  
        /**
@@@ -1806,6 -1814,7 +1814,6 @@@ class LocalFileDeleteBatch 
         * @return FileRepoStatus
         */
        function execute() {
 -              global $wgUseSquid;
                wfProfileIn( __METHOD__ );
  
                $this->file->lock();