MediaWiki
REL1_24
|
00001 <?php 00026 abstract class RevisionListBase extends ContextSource { 00028 public $title; 00029 00031 protected $ids; 00032 00033 protected $res; 00034 00036 protected $current; 00037 00043 function __construct( IContextSource $context, Title $title ) { 00044 $this->setContext( $context ); 00045 $this->title = $title; 00046 } 00047 00052 function filterByIds( array $ids ) { 00053 $this->ids = $ids; 00054 } 00055 00061 public function getType() { 00062 return null; 00063 } 00064 00068 protected function initCurrent() { 00069 $row = $this->res->current(); 00070 if ( $row ) { 00071 $this->current = $this->newItem( $row ); 00072 } else { 00073 $this->current = false; 00074 } 00075 } 00076 00081 public function reset() { 00082 if ( !$this->res ) { 00083 $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) ); 00084 } else { 00085 $this->res->rewind(); 00086 } 00087 $this->initCurrent(); 00088 return $this->current; 00089 } 00090 00095 public function current() { 00096 return $this->current; 00097 } 00098 00103 public function next() { 00104 $this->res->next(); 00105 $this->initCurrent(); 00106 return $this->current; 00107 } 00108 00113 public function length() { 00114 if ( !$this->res ) { 00115 return 0; 00116 } else { 00117 return $this->res->numRows(); 00118 } 00119 } 00120 00125 abstract public function doQuery( $db ); 00126 00131 abstract public function newItem( $row ); 00132 } 00133 00137 abstract class RevisionItemBase { 00139 protected $list; 00140 00142 protected $row; 00143 00148 public function __construct( $list, $row ) { 00149 $this->list = $list; 00150 $this->row = $row; 00151 } 00152 00158 public function getIdField() { 00159 return null; 00160 } 00161 00167 public function getTimestampField() { 00168 return false; 00169 } 00170 00176 public function getAuthorIdField() { 00177 return false; 00178 } 00179 00185 public function getAuthorNameField() { 00186 return false; 00187 } 00188 00193 public function getId() { 00194 $field = $this->getIdField(); 00195 return $this->row->$field; 00196 } 00197 00202 public function formatDate() { 00203 return $this->list->getLanguage()->userDate( $this->getTimestamp(), 00204 $this->list->getUser() ); 00205 } 00206 00211 public function formatTime() { 00212 return $this->list->getLanguage()->userTime( $this->getTimestamp(), 00213 $this->list->getUser() ); 00214 } 00215 00220 public function getTimestamp() { 00221 $field = $this->getTimestampField(); 00222 return wfTimestamp( TS_MW, $this->row->$field ); 00223 } 00224 00229 public function getAuthorId() { 00230 $field = $this->getAuthorIdField(); 00231 return intval( $this->row->$field ); 00232 } 00233 00238 public function getAuthorName() { 00239 $field = $this->getAuthorNameField(); 00240 return strval( $this->row->$field ); 00241 } 00242 00246 abstract public function canView(); 00247 00251 abstract public function canViewContent(); 00252 00257 abstract public function getHTML(); 00258 } 00259 00260 class RevisionList extends RevisionListBase { 00261 public function getType() { 00262 return 'revision'; 00263 } 00264 00269 public function doQuery( $db ) { 00270 $conds = array( 'rev_page' => $this->title->getArticleID() ); 00271 if ( $this->ids !== null ) { 00272 $conds['rev_id'] = array_map( 'intval', $this->ids ); 00273 } 00274 return $db->select( 00275 array( 'revision', 'page', 'user' ), 00276 array_merge( Revision::selectFields(), Revision::selectUserFields() ), 00277 $conds, 00278 __METHOD__, 00279 array( 'ORDER BY' => 'rev_id DESC' ), 00280 array( 00281 'page' => Revision::pageJoinCond(), 00282 'user' => Revision::userJoinCond() ) 00283 ); 00284 } 00285 00286 public function newItem( $row ) { 00287 return new RevisionItem( $this, $row ); 00288 } 00289 } 00290 00294 class RevisionItem extends RevisionItemBase { 00296 protected $revision; 00297 00299 protected $context; 00300 00301 public function __construct( $list, $row ) { 00302 parent::__construct( $list, $row ); 00303 $this->revision = new Revision( $row ); 00304 $this->context = $list->getContext(); 00305 } 00306 00307 public function getIdField() { 00308 return 'rev_id'; 00309 } 00310 00311 public function getTimestampField() { 00312 return 'rev_timestamp'; 00313 } 00314 00315 public function getAuthorIdField() { 00316 return 'rev_user'; 00317 } 00318 00319 public function getAuthorNameField() { 00320 return 'user_name'; // see Revision::selectUserFields() 00321 } 00322 00323 public function canView() { 00324 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() ); 00325 } 00326 00327 public function canViewContent() { 00328 return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() ); 00329 } 00330 00331 public function isDeleted() { 00332 return $this->revision->isDeleted( Revision::DELETED_TEXT ); 00333 } 00334 00340 protected function getRevisionLink() { 00341 $date = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true ); 00342 if ( $this->isDeleted() && !$this->canViewContent() ) { 00343 return $date; 00344 } 00345 return Linker::link( 00346 $this->list->title, 00347 $date, 00348 array(), 00349 array( 00350 'oldid' => $this->revision->getId(), 00351 'unhide' => 1 00352 ) 00353 ); 00354 } 00355 00361 protected function getDiffLink() { 00362 if ( $this->isDeleted() && !$this->canViewContent() ) { 00363 return $this->context->msg( 'diff' )->escaped(); 00364 } else { 00365 return Linker::link( 00366 $this->list->title, 00367 $this->context->msg( 'diff' )->escaped(), 00368 array(), 00369 array( 00370 'diff' => $this->revision->getId(), 00371 'oldid' => 'prev', 00372 'unhide' => 1 00373 ), 00374 array( 00375 'known', 00376 'noclasses' 00377 ) 00378 ); 00379 } 00380 } 00381 00382 public function getHTML() { 00383 $difflink = $this->context->msg( 'parentheses' ) 00384 ->rawParams( $this->getDiffLink() )->escaped(); 00385 $revlink = $this->getRevisionLink(); 00386 $userlink = Linker::revUserLink( $this->revision ); 00387 $comment = Linker::revComment( $this->revision ); 00388 if ( $this->isDeleted() ) { 00389 $revlink = "<span class=\"history-deleted\">$revlink</span>"; 00390 } 00391 return "<li>$difflink $revlink $userlink $comment</li>"; 00392 } 00393 }