| Index: trunk/phase3/includes/revisiondelete/RevisionDelete.php |
| — | — | @@ -848,8 +848,9 @@ |
| 849 | 849 | |
| 850 | 850 | public function getHTML() { |
| 851 | 851 | $date = htmlspecialchars( $this->list->getLanguage()->timeanddate( $this->row->log_timestamp ) ); |
| 852 | | - $paramArray = LogPage::extractParams( $this->row->log_params ); |
| 853 | 852 | $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title ); |
| | 853 | + $formatter = LogFormatter::newFromRow( $this->row ); |
| | 854 | + $formatter->setAudience( LogFormatter::FOR_THIS_USER ); |
| 854 | 855 | |
| 855 | 856 | // Log link for this page |
| 856 | 857 | $loglink = Linker::link( |
| — | — | @@ -858,27 +859,14 @@ |
| 859 | 860 | array(), |
| 860 | 861 | array( 'page' => $title->getPrefixedText() ) |
| 861 | 862 | ); |
| 862 | | - // Action text |
| 863 | | - if( !$this->canView() ) { |
| 864 | | - $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>'; |
| 865 | | - } else { |
| 866 | | - $skin = $this->list->getSkin(); |
| 867 | | - $action = LogPage::actionText( $this->row->log_type, $this->row->log_action, |
| 868 | | - $title, $skin, $paramArray, true, true ); |
| 869 | | - if( $this->row->log_deleted & LogPage::DELETED_ACTION ) |
| 870 | | - $action = '<span class="history-deleted">' . $action . '</span>'; |
| 871 | | - } |
| 872 | | - // User links |
| 873 | | - $userLink = Linker::userLink( $this->row->log_user, |
| 874 | | - User::WhoIs( $this->row->log_user ) ); |
| 875 | | - if( LogEventsList::isDeleted($this->row,LogPage::DELETED_USER) ) { |
| 876 | | - $userLink = '<span class="history-deleted">' . $userLink . '</span>'; |
| 877 | | - } |
| | 863 | + // User links and action text |
| | 864 | + $action = $formatter->getActionText(); |
| 878 | 865 | // Comment |
| 879 | 866 | $comment = $this->list->getLanguage()->getDirMark() . Linker::commentBlock( $this->row->log_comment ); |
| 880 | 867 | if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) { |
| 881 | 868 | $comment = '<span class="history-deleted">' . $comment . '</span>'; |
| 882 | 869 | } |
| 883 | | - return "<li>($loglink) $date $userLink $action $comment</li>"; |
| | 870 | + |
| | 871 | + return "<li>($loglink) $date $action $comment</li>"; |
| 884 | 872 | } |
| 885 | 873 | } |
| Index: trunk/phase3/includes/logging/LogFormatter.php |
| — | — | @@ -16,6 +16,9 @@ |
| 17 | 17 | * @since 1.19 |
| 18 | 18 | */ |
| 19 | 19 | class LogFormatter { |
| | 20 | + // Audience options for viewing usernames, comments, and actions |
| | 21 | + const FOR_PUBLIC = 1; |
| | 22 | + const FOR_THIS_USER = 2; |
| 20 | 23 | |
| 21 | 24 | // Static-> |
| 22 | 25 | |
| — | — | @@ -59,6 +62,9 @@ |
| 60 | 63 | /// @var LogEntry |
| 61 | 64 | protected $entry; |
| 62 | 65 | |
| | 66 | + /// Integer constant for handling log_deleted |
| | 67 | + protected $audience = self::FOR_PUBLIC; |
| | 68 | + |
| 63 | 69 | /// Whether to output user tool links |
| 64 | 70 | protected $linkFlood = false; |
| 65 | 71 | |
| — | — | @@ -85,6 +91,32 @@ |
| 86 | 92 | } |
| 87 | 93 | |
| 88 | 94 | /** |
| | 95 | + * Set the visibility restrictions for displaying content. |
| | 96 | + * If set to public, and an item is deleted, then it will be replaced |
| | 97 | + * with a placeholder even if the context user is allowed to view it. |
| | 98 | + * @param $audience integer self::FOR_THIS_USER or self::FOR_PUBLIC |
| | 99 | + */ |
| | 100 | + public function setAudience( $audience ) { |
| | 101 | + $this->audience = ( $audience == self::FOR_THIS_USER ) |
| | 102 | + ? self::FOR_THIS_USER |
| | 103 | + : self::FOR_PUBLIC; |
| | 104 | + } |
| | 105 | + |
| | 106 | + /** |
| | 107 | + * Check if a log item can be displayed |
| | 108 | + * @param $field integer LogPage::DELETED_* constant |
| | 109 | + * @return bool |
| | 110 | + */ |
| | 111 | + protected function canView( $field ) { |
| | 112 | + if ( $this->audience == self::FOR_THIS_USER ) { |
| | 113 | + return LogEventsList::userCanBitfield( |
| | 114 | + $this->entry->getDeleted(), $field, $this->context->getUser() ); |
| | 115 | + } else { |
| | 116 | + return !$this->entry->isDeleted( $field ); |
| | 117 | + } |
| | 118 | + } |
| | 119 | + |
| | 120 | + /** |
| 89 | 121 | * If set to true, will produce user tool links after |
| 90 | 122 | * the user name. This should be replaced with generic |
| 91 | 123 | * CSS/JS solution. |
| — | — | @@ -113,14 +145,17 @@ |
| 114 | 146 | * @return string HTML |
| 115 | 147 | */ |
| 116 | 148 | public function getActionText() { |
| 117 | | - $element = $this->getActionMessage(); |
| 118 | | - if ( $element instanceof Message ) { |
| 119 | | - $element = $this->plaintext ? $element->text() : $element->escaped(); |
| 120 | | - } |
| 121 | | - |
| 122 | | - if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) { |
| | 149 | + if ( $this->canView( LogPage::DELETED_ACTION ) ) { |
| | 150 | + $element = $this->getActionMessage(); |
| | 151 | + if ( $element instanceof Message ) { |
| | 152 | + $element = $this->plaintext ? $element->text() : $element->escaped(); |
| | 153 | + } |
| | 154 | + if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) { |
| | 155 | + $element = $this->styleRestricedElement( $element ); |
| | 156 | + } |
| | 157 | + } else { |
| 123 | 158 | $performer = $this->getPerformerElement() . $this->msg( 'word-separator' )->text(); |
| 124 | | - $element = $performer . self::getRestrictedElement( 'rev-deleted-event' ); |
| | 159 | + $element = $performer . $this->getRestrictedElement( 'rev-deleted-event' ); |
| 125 | 160 | } |
| 126 | 161 | |
| 127 | 162 | return $element; |
| — | — | @@ -239,11 +274,14 @@ |
| 240 | 275 | * which parts of the log entry has been hidden. |
| 241 | 276 | */ |
| 242 | 277 | public function getPerformerElement() { |
| 243 | | - $performer = $this->entry->getPerformer(); |
| 244 | | - $element = $this->makeUserLink( $performer ); |
| 245 | | - |
| 246 | | - if ( $this->entry->isDeleted( LogPage::DELETED_USER ) ) { |
| 247 | | - $element = self::getRestrictedElement( 'rev-deleted-user' ); |
| | 278 | + if ( $this->canView( LogPage::DELETED_USER ) ) { |
| | 279 | + $performer = $this->entry->getPerformer(); |
| | 280 | + $element = $this->makeUserLink( $performer ); |
| | 281 | + if ( $this->entry->isDeleted( LogPage::DELETED_USER ) ) { |
| | 282 | + $element = $this->styleRestricedElement( $element ); |
| | 283 | + } |
| | 284 | + } else { |
| | 285 | + $element = $this->getRestrictedElement( 'rev-deleted-user' ); |
| 248 | 286 | } |
| 249 | 287 | |
| 250 | 288 | return $element; |
| — | — | @@ -254,12 +292,15 @@ |
| 255 | 293 | * @return string HTML |
| 256 | 294 | */ |
| 257 | 295 | public function getComment() { |
| 258 | | - $comment = Linker::commentBlock( $this->entry->getComment() ); |
| 259 | | - // No hard coded spaces thanx |
| 260 | | - $element = ltrim( $comment ); |
| 261 | | - |
| 262 | | - if ( $this->entry->isDeleted( LogPage::DELETED_COMMENT ) ) { |
| 263 | | - $element = self::getRestrictedElement( 'rev-deleted-comment' ); |
| | 296 | + if ( $this->canView( LogPage::DELETED_COMMENT ) ) { |
| | 297 | + $comment = Linker::commentBlock( $this->entry->getComment() ); |
| | 298 | + // No hard coded spaces thanx |
| | 299 | + $element = ltrim( $comment ); |
| | 300 | + if ( $this->entry->isDeleted( LogPage::DELETED_COMMENT ) ) { |
| | 301 | + $element = $this->styleRestricedElement( $element ); |
| | 302 | + } |
| | 303 | + } else { |
| | 304 | + $element = $this->getRestrictedElement( 'rev-deleted-comment' ); |
| 264 | 305 | } |
| 265 | 306 | |
| 266 | 307 | return $element; |
| — | — | @@ -268,7 +309,7 @@ |
| 269 | 310 | /** |
| 270 | 311 | * Helper method for displaying restricted element. |
| 271 | 312 | * @param $message string |
| 272 | | - * @return string HTML |
| | 313 | + * @return string HTML or wikitext |
| 273 | 314 | */ |
| 274 | 315 | protected function getRestrictedElement( $message ) { |
| 275 | 316 | if ( $this->plaintext ) { |
| — | — | @@ -281,6 +322,19 @@ |
| 282 | 323 | } |
| 283 | 324 | |
| 284 | 325 | /** |
| | 326 | + * Helper method for styling restricted element. |
| | 327 | + * @param $content string |
| | 328 | + * @return string HTML or wikitext |
| | 329 | + */ |
| | 330 | + protected function styleRestricedElement( $content ) { |
| | 331 | + if ( $this->plaintext ) { |
| | 332 | + return $content; |
| | 333 | + } |
| | 334 | + $attribs = array( 'class' => 'history-deleted' ); |
| | 335 | + return Html::rawElement( 'span', $attribs, $content ); |
| | 336 | + } |
| | 337 | + |
| | 338 | + /** |
| 285 | 339 | * Shortcut for wfMessage which honors local context. |
| 286 | 340 | * @todo Would it be better to require replacing the global context instead? |
| 287 | 341 | * @param $key string |