MediaWiki  REL1_19
RevisionList.php
Go to the documentation of this file.
00001 <?php
00005 abstract class RevisionListBase extends ContextSource {
00009         var $title;
00010 
00011         var $ids, $res, $current;
00012 
00018         function __construct( IContextSource $context, Title $title ) {
00019                 $this->setContext( $context );
00020                 $this->title = $title;
00021         }
00022 
00027         function filterByIds( array $ids ) {
00028                 $this->ids = $ids;
00029         }
00030 
00035         public function getType() {
00036                 return null;
00037         }
00038 
00042         protected function initCurrent() {
00043                 $row = $this->res->current();
00044                 if ( $row ) {
00045                         $this->current = $this->newItem( $row );
00046                 } else {
00047                         $this->current = false;
00048                 }
00049         }
00050 
00055         public function reset() {
00056                 if ( !$this->res ) {
00057                         $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
00058                 } else {
00059                         $this->res->rewind();
00060                 }
00061                 $this->initCurrent();
00062                 return $this->current;
00063         }
00064 
00068         public function current() {
00069                 return $this->current;
00070         }
00071 
00075         public function next() {
00076                 $this->res->next();
00077                 $this->initCurrent();
00078                 return $this->current;
00079         }
00080 
00084         public function length() {
00085                 if( !$this->res ) {
00086                         return 0;
00087                 } else {
00088                         return $this->res->numRows();
00089                 }
00090         }
00091 
00096         abstract public function doQuery( $db );
00097 
00102         abstract public function newItem( $row );
00103 }
00104 
00108 abstract class RevisionItemBase {
00110         var $list;
00111 
00113         var $row;
00114 
00119         public function __construct( $list, $row ) {
00120                 $this->list = $list;
00121                 $this->row = $row;
00122         }
00123 
00128         public function getIdField() {
00129                 return null;
00130         }
00131 
00136         public function getTimestampField() {
00137                 return false;
00138         }
00139 
00144         public function getAuthorIdField() {
00145                 return false;
00146         }
00147 
00152         public function getAuthorNameField() {
00153                 return false;
00154         }
00155 
00159         public function getId() {
00160                 $field = $this->getIdField();
00161                 return $this->row->$field;
00162         }
00163 
00167         public function formatDate() {
00168                 return $this->list->getLanguage()->userDate( $this->getTimestamp(),
00169                         $this->list->getUser() );
00170         }
00171 
00175         public function formatTime() {
00176                 return $this->list->getLanguage()->userTime( $this->getTimestamp(),
00177                         $this->list->getUser() );
00178         }
00179 
00183         public function getTimestamp() {
00184                 $field = $this->getTimestampField();
00185                 return wfTimestamp( TS_MW, $this->row->$field );
00186         }
00187 
00191         public function getAuthorId() {
00192                 $field = $this->getAuthorIdField();
00193                 return intval( $this->row->$field );
00194         }
00195 
00199         public function getAuthorName() {
00200                 $field = $this->getAuthorNameField();
00201                 return strval( $this->row->$field );
00202         }
00203 
00207         abstract public function canView();
00208 
00212         abstract public function canViewContent();
00213 
00218         abstract public function getHTML();
00219 }
00220 
00221 class RevisionList extends RevisionListBase {
00222         public function getType() {
00223                 return 'revision';
00224         }
00225 
00230         public function doQuery( $db ) {
00231                 $conds = array( 'rev_page' => $this->title->getArticleID() );
00232                 if ( $this->ids !== null ) {
00233                         $conds['rev_id'] = array_map( 'intval', $this->ids );
00234                 }
00235                 return $db->select(
00236                         array( 'revision', 'page', 'user' ),
00237                         array_merge( Revision::selectFields(), Revision::selectUserFields() ),
00238                         $conds,
00239                         __METHOD__,
00240                         array( 'ORDER BY' => 'rev_id DESC' ),
00241                         array(
00242                                 'page' => Revision::pageJoinCond(),
00243                                 'user' => Revision::userJoinCond() )
00244                 );
00245         }
00246 
00247         public function newItem( $row ) {
00248                 return new RevisionItem( $this, $row );
00249         }
00250 }
00251 
00255 class RevisionItem extends RevisionItemBase {
00256         var $revision, $context;
00257 
00258         public function __construct( $list, $row ) {
00259                 parent::__construct( $list, $row );
00260                 $this->revision = new Revision( $row );
00261                 $this->context = $list->context;
00262         }
00263 
00264         public function getIdField() {
00265                 return 'rev_id';
00266         }
00267 
00268         public function getTimestampField() {
00269                 return 'rev_timestamp';
00270         }
00271 
00272         public function getAuthorIdField() {
00273                 return 'rev_user';
00274         }
00275 
00276         public function getAuthorNameField() {
00277                 return 'user_name'; // see Revision::selectUserFields()
00278         }
00279 
00280         public function canView() {
00281                 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() );
00282         }
00283 
00284         public function canViewContent() {
00285                 return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() );
00286         }
00287 
00288         public function isDeleted() {
00289                 return $this->revision->isDeleted( Revision::DELETED_TEXT );
00290         }
00291 
00296         protected function getRevisionLink() {
00297                 $date = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true );
00298                 if ( $this->isDeleted() && !$this->canViewContent() ) {
00299                         return $date;
00300                 }
00301                 return Linker::link(
00302                         $this->list->title,
00303                         $date,
00304                         array(),
00305                         array(
00306                                 'oldid' => $this->revision->getId(),
00307                                 'unhide' => 1
00308                         )
00309                 );
00310         }
00311 
00316         protected function getDiffLink() {
00317                 if ( $this->isDeleted() && !$this->canViewContent() ) {
00318                         return wfMsgHtml('diff');
00319                 } else {
00320                         return
00321                                 Linker::link(
00322                                         $this->list->title,
00323                                         wfMsgHtml('diff'),
00324                                         array(),
00325                                         array(
00326                                                 'diff' => $this->revision->getId(),
00327                                                 'oldid' => 'prev',
00328                                                 'unhide' => 1
00329                                         ),
00330                                         array(
00331                                                 'known',
00332                                                 'noclasses'
00333                                         )
00334                                 );
00335                 }
00336         }
00337 
00338         public function getHTML() {
00339                 $difflink = $this->getDiffLink();
00340                 $revlink = $this->getRevisionLink();
00341                 $userlink = Linker::revUserLink( $this->revision );
00342                 $comment = Linker::revComment( $this->revision );
00343                 if ( $this->isDeleted() ) {
00344                         $revlink = "<span class=\"history-deleted\">$revlink</span>";
00345                 }
00346                 return "<li>($difflink) $revlink $userlink $comment</li>";
00347         }
00348 }