MediaWiki
REL1_22
|
00001 <?php 00026 abstract class RevisionListBase extends ContextSource { 00030 var $title; 00031 00032 var $ids, $res, $current; 00033 00039 function __construct( IContextSource $context, Title $title ) { 00040 $this->setContext( $context ); 00041 $this->title = $title; 00042 } 00043 00048 function filterByIds( array $ids ) { 00049 $this->ids = $ids; 00050 } 00051 00057 public function getType() { 00058 return null; 00059 } 00060 00064 protected function initCurrent() { 00065 $row = $this->res->current(); 00066 if ( $row ) { 00067 $this->current = $this->newItem( $row ); 00068 } else { 00069 $this->current = false; 00070 } 00071 } 00072 00077 public function reset() { 00078 if ( !$this->res ) { 00079 $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) ); 00080 } else { 00081 $this->res->rewind(); 00082 } 00083 $this->initCurrent(); 00084 return $this->current; 00085 } 00086 00090 public function current() { 00091 return $this->current; 00092 } 00093 00097 public function next() { 00098 $this->res->next(); 00099 $this->initCurrent(); 00100 return $this->current; 00101 } 00102 00107 public function length() { 00108 if ( !$this->res ) { 00109 return 0; 00110 } else { 00111 return $this->res->numRows(); 00112 } 00113 } 00114 00119 abstract public function doQuery( $db ); 00120 00125 abstract public function newItem( $row ); 00126 } 00127 00131 abstract class RevisionItemBase { 00133 var $list; 00134 00136 var $row; 00137 00142 public function __construct( $list, $row ) { 00143 $this->list = $list; 00144 $this->row = $row; 00145 } 00146 00152 public function getIdField() { 00153 return null; 00154 } 00155 00161 public function getTimestampField() { 00162 return false; 00163 } 00164 00170 public function getAuthorIdField() { 00171 return false; 00172 } 00173 00179 public function getAuthorNameField() { 00180 return false; 00181 } 00182 00187 public function getId() { 00188 $field = $this->getIdField(); 00189 return $this->row->$field; 00190 } 00191 00196 public function formatDate() { 00197 return $this->list->getLanguage()->userDate( $this->getTimestamp(), 00198 $this->list->getUser() ); 00199 } 00200 00205 public function formatTime() { 00206 return $this->list->getLanguage()->userTime( $this->getTimestamp(), 00207 $this->list->getUser() ); 00208 } 00209 00214 public function getTimestamp() { 00215 $field = $this->getTimestampField(); 00216 return wfTimestamp( TS_MW, $this->row->$field ); 00217 } 00218 00223 public function getAuthorId() { 00224 $field = $this->getAuthorIdField(); 00225 return intval( $this->row->$field ); 00226 } 00227 00232 public function getAuthorName() { 00233 $field = $this->getAuthorNameField(); 00234 return strval( $this->row->$field ); 00235 } 00236 00240 abstract public function canView(); 00241 00245 abstract public function canViewContent(); 00246 00251 abstract public function getHTML(); 00252 } 00253 00254 class RevisionList extends RevisionListBase { 00255 public function getType() { 00256 return 'revision'; 00257 } 00258 00263 public function doQuery( $db ) { 00264 $conds = array( 'rev_page' => $this->title->getArticleID() ); 00265 if ( $this->ids !== null ) { 00266 $conds['rev_id'] = array_map( 'intval', $this->ids ); 00267 } 00268 return $db->select( 00269 array( 'revision', 'page', 'user' ), 00270 array_merge( Revision::selectFields(), Revision::selectUserFields() ), 00271 $conds, 00272 __METHOD__, 00273 array( 'ORDER BY' => 'rev_id DESC' ), 00274 array( 00275 'page' => Revision::pageJoinCond(), 00276 'user' => Revision::userJoinCond() ) 00277 ); 00278 } 00279 00280 public function newItem( $row ) { 00281 return new RevisionItem( $this, $row ); 00282 } 00283 } 00284 00288 class RevisionItem extends RevisionItemBase { 00289 var $revision, $context; 00290 00291 public function __construct( $list, $row ) { 00292 parent::__construct( $list, $row ); 00293 $this->revision = new Revision( $row ); 00294 $this->context = $list->getContext(); 00295 } 00296 00297 public function getIdField() { 00298 return 'rev_id'; 00299 } 00300 00301 public function getTimestampField() { 00302 return 'rev_timestamp'; 00303 } 00304 00305 public function getAuthorIdField() { 00306 return 'rev_user'; 00307 } 00308 00309 public function getAuthorNameField() { 00310 return 'user_name'; // see Revision::selectUserFields() 00311 } 00312 00313 public function canView() { 00314 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() ); 00315 } 00316 00317 public function canViewContent() { 00318 return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() ); 00319 } 00320 00321 public function isDeleted() { 00322 return $this->revision->isDeleted( Revision::DELETED_TEXT ); 00323 } 00324 00330 protected function getRevisionLink() { 00331 $date = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true ); 00332 if ( $this->isDeleted() && !$this->canViewContent() ) { 00333 return $date; 00334 } 00335 return Linker::link( 00336 $this->list->title, 00337 $date, 00338 array(), 00339 array( 00340 'oldid' => $this->revision->getId(), 00341 'unhide' => 1 00342 ) 00343 ); 00344 } 00345 00351 protected function getDiffLink() { 00352 if ( $this->isDeleted() && !$this->canViewContent() ) { 00353 return $this->context->msg( 'diff' )->escaped(); 00354 } else { 00355 return Linker::link( 00356 $this->list->title, 00357 $this->context->msg( 'diff' )->escaped(), 00358 array(), 00359 array( 00360 'diff' => $this->revision->getId(), 00361 'oldid' => 'prev', 00362 'unhide' => 1 00363 ), 00364 array( 00365 'known', 00366 'noclasses' 00367 ) 00368 ); 00369 } 00370 } 00371 00372 public function getHTML() { 00373 $difflink = $this->context->msg( 'parentheses' ) 00374 ->rawParams( $this->getDiffLink() )->escaped(); 00375 $revlink = $this->getRevisionLink(); 00376 $userlink = Linker::revUserLink( $this->revision ); 00377 $comment = Linker::revComment( $this->revision ); 00378 if ( $this->isDeleted() ) { 00379 $revlink = "<span class=\"history-deleted\">$revlink</span>"; 00380 } 00381 return "<li>$difflink $revlink $userlink $comment</li>"; 00382 } 00383 }