r110893 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110892‎ | r110893 | r110894 >
Date:23:12, 7 February 2012
Author:aaron
Status:ok
Tags:core 
Comment:
In LogFormatter:
* Changed LogFormatter to support displaying redacting log items if the context user can see them. The default mode is still "show only public items".
* Fixed static calls to non-static getRestrictedElement() function.
* Cleaned up LogFormatter that build up vars only to then throw them away and replace them with rev-deleted placeholders.
In RevDel_LogItem:
* Use LogFormatter instead of raw LogPage::actionText call as such calls are broken and just displayed things like the string "move" (the log action name) instead of "x moved a to b: reason" and such. Fixes r96546.
Modified paths:
  • /trunk/phase3/includes/logging/LogFormatter.php (modified) (history)
  • /trunk/phase3/includes/revisiondelete/RevisionDelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/revisiondelete/RevisionDelete.php
@@ -848,8 +848,9 @@
849849
850850 public function getHTML() {
851851 $date = htmlspecialchars( $this->list->getLanguage()->timeanddate( $this->row->log_timestamp ) );
852 - $paramArray = LogPage::extractParams( $this->row->log_params );
853852 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
 853+ $formatter = LogFormatter::newFromRow( $this->row );
 854+ $formatter->setAudience( LogFormatter::FOR_THIS_USER );
854855
855856 // Log link for this page
856857 $loglink = Linker::link(
@@ -858,27 +859,14 @@
859860 array(),
860861 array( 'page' => $title->getPrefixedText() )
861862 );
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();
878865 // Comment
879866 $comment = $this->list->getLanguage()->getDirMark() . Linker::commentBlock( $this->row->log_comment );
880867 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) {
881868 $comment = '<span class="history-deleted">' . $comment . '</span>';
882869 }
883 - return "<li>($loglink) $date $userLink $action $comment</li>";
 870+
 871+ return "<li>($loglink) $date $action $comment</li>";
884872 }
885873 }
Index: trunk/phase3/includes/logging/LogFormatter.php
@@ -16,6 +16,9 @@
1717 * @since 1.19
1818 */
1919 class LogFormatter {
 20+ // Audience options for viewing usernames, comments, and actions
 21+ const FOR_PUBLIC = 1;
 22+ const FOR_THIS_USER = 2;
2023
2124 // Static->
2225
@@ -59,6 +62,9 @@
6063 /// @var LogEntry
6164 protected $entry;
6265
 66+ /// Integer constant for handling log_deleted
 67+ protected $audience = self::FOR_PUBLIC;
 68+
6369 /// Whether to output user tool links
6470 protected $linkFlood = false;
6571
@@ -85,6 +91,32 @@
8692 }
8793
8894 /**
 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+ /**
89121 * If set to true, will produce user tool links after
90122 * the user name. This should be replaced with generic
91123 * CSS/JS solution.
@@ -113,14 +145,17 @@
114146 * @return string HTML
115147 */
116148 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 {
123158 $performer = $this->getPerformerElement() . $this->msg( 'word-separator' )->text();
124 - $element = $performer . self::getRestrictedElement( 'rev-deleted-event' );
 159+ $element = $performer . $this->getRestrictedElement( 'rev-deleted-event' );
125160 }
126161
127162 return $element;
@@ -239,11 +274,14 @@
240275 * which parts of the log entry has been hidden.
241276 */
242277 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' );
248286 }
249287
250288 return $element;
@@ -254,12 +292,15 @@
255293 * @return string HTML
256294 */
257295 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' );
264305 }
265306
266307 return $element;
@@ -268,7 +309,7 @@
269310 /**
270311 * Helper method for displaying restricted element.
271312 * @param $message string
272 - * @return string HTML
 313+ * @return string HTML or wikitext
273314 */
274315 protected function getRestrictedElement( $message ) {
275316 if ( $this->plaintext ) {
@@ -281,6 +322,19 @@
282323 }
283324
284325 /**
 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+ /**
285339 * Shortcut for wfMessage which honors local context.
286340 * @todo Would it be better to require replacing the global context instead?
287341 * @param $key string

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96546Enabled MoveLogFormatter...nikerabbit09:09, 8 September 2011

Status & tagging log