Merge "Localisation updates from http://translatewiki.net."
[lhc/web/wiklou.git] / includes / RevisionList.php
index 215b663..a61120e 100644 (file)
@@ -2,15 +2,11 @@
 /**
  * List for revision table items for a single page
  */
-abstract class RevisionListBase {
+abstract class RevisionListBase extends ContextSource {
        /**
         * @var Title
         */
        var $title;
-       /**
-        * @var IContextSource
-        */
-       var $context;
 
        var $ids, $res, $current;
 
@@ -20,7 +16,7 @@ abstract class RevisionListBase {
         * @param $title Title
         */
        function __construct( IContextSource $context, Title $title ) {
-               $this->context = $context;
+               $this->setContext( $context );
                $this->title = $title;
        }
 
@@ -35,6 +31,7 @@ abstract class RevisionListBase {
        /**
         * Get the internal type name of this list. Equal to the table name.
         * Override this function.
+        * @return null
         */
        public function getType() {
                return null;
@@ -84,6 +81,7 @@ abstract class RevisionListBase {
 
        /**
         * Get the number of items in the list.
+        * @return int
         */
        public function length() {
                if( !$this->res ) {
@@ -104,24 +102,6 @@ abstract class RevisionListBase {
         * @param $row stdclass
         */
        abstract public function newItem( $row );
-
-       /**
-        * Get the language of the user doing the action
-        *
-        * @return Language object
-        */
-       public function getLang() {
-               return $this->context->getLang();
-       }
-
-       /**
-        * Get the user doing the action
-        *
-        * @return User object
-        */
-       public function getUser() {
-               return $this->context->getUser();
-       }
 }
 
 /**
@@ -146,6 +126,7 @@ abstract class RevisionItemBase {
        /**
         * Get the DB field name associated with the ID list.
         * Override this function.
+        * @return null
         */
        public function getIdField() {
                return null;
@@ -154,6 +135,7 @@ abstract class RevisionItemBase {
        /**
         * Get the DB field name storing timestamps.
         * Override this function.
+        * @return bool
         */
        public function getTimestampField() {
                return false;
@@ -162,6 +144,7 @@ abstract class RevisionItemBase {
        /**
         * Get the DB field name storing user ids.
         * Override this function.
+        * @return bool
         */
        public function getAuthorIdField() {
                return false;
@@ -170,6 +153,7 @@ abstract class RevisionItemBase {
        /**
         * Get the DB field name storing user names.
         * Override this function.
+        * @return bool
         */
        public function getAuthorNameField() {
                return false;
@@ -177,6 +161,7 @@ abstract class RevisionItemBase {
 
        /**
         * Get the ID, as it would appear in the ids URL parameter
+        * @return
         */
        public function getId() {
                $field = $this->getIdField();
@@ -184,23 +169,26 @@ abstract class RevisionItemBase {
        }
 
        /**
-        * Get the date, formatted with $wgLang
+        * Get the date, formatted in user's languae
+        * @return String
         */
        public function formatDate() {
-               global $wgLang;
-               return $wgLang->date( $this->getTimestamp() );
+               return $this->list->getLanguage()->userDate( $this->getTimestamp(),
+                       $this->list->getUser() );
        }
 
        /**
-        * Get the time, formatted with $wgLang
+        * Get the time, formatted in user's languae
+        * @return String
         */
        public function formatTime() {
-               global $wgLang;
-               return $wgLang->time( $this->getTimestamp() );
+               return $this->list->getLanguage()->userTime( $this->getTimestamp(),
+                       $this->list->getUser() );
        }
 
        /**
         * Get the timestamp in MW 14-char form
+        * @return Mixed
         */
        public function getTimestamp() {
                $field = $this->getTimestampField();
@@ -209,6 +197,7 @@ abstract class RevisionItemBase {
 
        /**
         * Get the author user ID
+        * @return int
         */
        public function getAuthorId() {
                $field = $this->getAuthorIdField();
@@ -217,6 +206,7 @@ abstract class RevisionItemBase {
 
        /**
         * Get the author user name
+        * @return string
         */
        public function getAuthorName() {
                $field = $this->getAuthorNameField();
@@ -250,19 +240,19 @@ class RevisionList extends RevisionListBase {
         * @return mixed
         */
        public function doQuery( $db ) {
-               $conds = array(
-                       'rev_page' => $this->title->getArticleID(),
-                       'rev_page = page_id'
-               );
+               $conds = array( 'rev_page' => $this->title->getArticleID() );
                if ( $this->ids !== null ) {
                        $conds['rev_id'] = array_map( 'intval', $this->ids );
                }
                return $db->select(
-                       array( 'revision', 'page' ),
-                       '*',
+                       array( 'revision', 'page', 'user' ),
+                       array_merge( Revision::selectFields(), Revision::selectUserFields() ),
                        $conds,
                        __METHOD__,
-                       array( 'ORDER BY' => 'rev_id DESC' )
+                       array( 'ORDER BY' => 'rev_id DESC' ),
+                       array(
+                               'page' => Revision::pageJoinCond(),
+                               'user' => Revision::userJoinCond() )
                );
        }
 
@@ -280,7 +270,7 @@ class RevisionItem extends RevisionItemBase {
        public function __construct( $list, $row ) {
                parent::__construct( $list, $row );
                $this->revision = new Revision( $row );
-               $this->context = $list->context;
+               $this->context = $list->getContext();
        }
 
        public function getIdField() {
@@ -296,15 +286,15 @@ class RevisionItem extends RevisionItemBase {
        }
 
        public function getAuthorNameField() {
-               return 'rev_user_text';
+               return 'user_name'; // see Revision::selectUserFields()
        }
 
        public function canView() {
-               return $this->revision->userCan( Revision::DELETED_RESTRICTED );
+               return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() );
        }
 
        public function canViewContent() {
-               return $this->revision->userCan( Revision::DELETED_TEXT );
+               return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() );
        }
 
        public function isDeleted() {
@@ -314,9 +304,10 @@ class RevisionItem extends RevisionItemBase {
        /**
         * Get the HTML link to the revision text.
         * Overridden by RevDel_ArchiveItem.
+        * @return string
         */
        protected function getRevisionLink() {
-               $date = $this->list->getLang()->timeanddate( $this->revision->getTimestamp(), true );
+               $date = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true );
                if ( $this->isDeleted() && !$this->canViewContent() ) {
                        return $date;
                }
@@ -334,6 +325,7 @@ class RevisionItem extends RevisionItemBase {
        /**
         * Get the HTML link to the diff.
         * Overridden by RevDel_ArchiveItem
+        * @return string
         */
        protected function getDiffLink() {
                if ( $this->isDeleted() && !$this->canViewContent() ) {