Bug 32238 - phaseout wgEnableTooltipsAndAccesskeys
[lhc/web/wiklou.git] / includes / RevisionList.php
index e64ac5a..5a9bbad 100644 (file)
@@ -2,21 +2,33 @@
 /**
  * List for revision table items for a single page
  */
-abstract class Rev_List {
+abstract class RevisionListBase {
        /**
         * @var Title
         */
        var $title;
        /**
-        * @var RequestContext
+        * @var IContextSource
         */
        var $context;
 
        var $ids, $res, $current;
 
-       function __construct( RequestContext $context, Title $title, array $ids ) {
+       /**
+        * Construct a revision list for a given title
+        * @param $context IContextSource
+        * @param $title Title
+        */
+       function __construct( IContextSource $context, Title $title ) {
                $this->context = $context;
                $this->title = $title;
+       }
+
+       /**
+        * Select items only where the ID is any of the specified values
+        * @param $ids Array
+        */
+       function filterByIds( array $ids ) {
                $this->ids = $ids;
        }
 
@@ -115,15 +127,15 @@ abstract class Rev_List {
 /**
  * Abstract base class for revision items
  */
-abstract class Rev_Item {
-       /** The parent Rev_List */
+abstract class RevisionItemBase {
+       /** The parent RevisionListBase */
        var $list;
 
        /** The DB result row */
        var $row;
 
        /**
-        * @param $list Rev_List
+        * @param $list RevisionListBase
         * @param $row DB result row
         */
        public function __construct( $list, $row ) {
@@ -172,19 +184,19 @@ abstract class Rev_Item {
        }
 
        /**
-        * Get the date, formatted with $wgLang
+        * Get the date, formatted in user's languae
         */
        public function formatDate() {
-               global $wgLang;
-               return $wgLang->date( $this->getTimestamp() );
+               return $this->list->context->getLang()->userDate( $this->getTimestamp(),
+                       $this->list->context->getUser() );
        }
 
        /**
-        * Get the time, formatted with $wgLang
+        * Get the time, formatted in user's languae
         */
        public function formatTime() {
-               global $wgLang;
-               return $wgLang->time( $this->getTimestamp() );
+               return $this->list->context->getLang()->userTime( $this->getTimestamp(),
+                       $this->list->context->getUser() );
        }
 
        /**
@@ -228,7 +240,7 @@ abstract class Rev_Item {
        abstract public function getHTML();
 }
 
-class RevisionList extends Rev_List {
+class RevisionList extends RevisionListBase {
        public function getType() {
                return 'revision';
        }
@@ -238,15 +250,19 @@ class RevisionList extends Rev_List {
         * @return mixed
         */
        public function doQuery( $db ) {
-               $ids = array_map( 'intval', $this->ids );
-               return $db->select( array('revision','page'), '*',
-                       array(
-                               'rev_page' => $this->title->getArticleID(),
-                               'rev_id'   => array_map( 'intval', $this->ids ),
-                               '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', '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() )
                );
        }
 
@@ -258,7 +274,7 @@ class RevisionList extends Rev_List {
 /**
  * Item class for a live revision table row
  */
-class RevisionItem extends Rev_Item {
+class RevisionItem extends RevisionItemBase {
        var $revision, $context;
 
        public function __construct( $list, $row ) {
@@ -280,15 +296,15 @@ class RevisionItem extends Rev_Item {
        }
 
        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() {