r40502 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40501‎ | r40502 | r40503 >
Date:17:34, 5 September 2008
Author:aaron
Status:old
Tags:
Comment:
*Add history link to protect log items
*Made typeAction() more general
*Tweaked code for less tab whitespace
Modified paths:
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LogEventsList.php
@@ -38,7 +38,7 @@
3939 private function preCacheMessages() {
4040 // Precache various messages
4141 if( !isset( $this->message ) ) {
42 - $messages = 'revertmerge protect_change unblocklink revertmove undeletelink revdel-restore rev-delundel';
 42+ $messages = 'revertmerge protect_change unblocklink revertmove undeletelink revdel-restore rev-delundel hist';
4343 foreach( explode(' ', $messages ) as $msg ) {
4444 $this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
4545 }
@@ -216,69 +216,73 @@
217217 $del = $this->showhideLinks( $row ) . ' ';
218218 }
219219 // Add review links and such...
220 - if( !($this->flags & self::NO_ACTION_LINK) && !($row->log_deleted & LogPage::DELETED_ACTION) ) {
221 - if( self::typeAction($row,'move','move') && isset( $paramArray[0] ) && $wgUser->isAllowed( 'move' ) ) {
222 - $destTitle = Title::newFromText( $paramArray[0] );
223 - if( $destTitle ) {
224 - $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
225 - $this->message['revertmove'],
226 - 'wpOldTitle=' . urlencode( $destTitle->getPrefixedDBkey() ) .
227 - '&wpNewTitle=' . urlencode( $title->getPrefixedDBkey() ) .
228 - '&wpReason=' . urlencode( wfMsgForContent( 'revertmove' ) ) .
229 - '&wpMovetalk=0' ) . ')';
 220+ if( ($this->flags & self::NO_ACTION_LINK) || ($row->log_deleted & LogPage::DELETED_ACTION) ) {
 221+ // Action text is suppressed...
 222+ } else if( self::typeAction($row,'move','move') && !empty($paramArray[0]) && $wgUser->isAllowed( 'move' ) ) {
 223+ $destTitle = Title::newFromText( $paramArray[0] );
 224+ if( $destTitle ) {
 225+ $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
 226+ $this->message['revertmove'],
 227+ 'wpOldTitle=' . urlencode( $destTitle->getPrefixedDBkey() ) .
 228+ '&wpNewTitle=' . urlencode( $title->getPrefixedDBkey() ) .
 229+ '&wpReason=' . urlencode( wfMsgForContent( 'revertmove' ) ) .
 230+ '&wpMovetalk=0' ) . ')';
 231+ }
 232+ // Show undelete link
 233+ } else if( self::typeAction($row,array('delete','suppress'),'delete') && $wgUser->isAllowed( 'delete' ) ) {
 234+ $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
 235+ $this->message['undeletelink'], 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
 236+ // Show unblock link
 237+ } else if( self::typeAction($row,array('block','suppress'),'block') && $wgUser->isAllowed( 'block' ) ) {
 238+ $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Ipblocklist' ),
 239+ $this->message['unblocklink'],
 240+ 'action=unblock&ip=' . urlencode( $row->log_title ) ) . ')';
 241+ // Show change protection link
 242+ } else if( self::typeAction($row,'protect',array('modify','protect','unprotect')) ) {
 243+ $revert = '(' . $this->skin->makeKnownLinkObj( $title, $this->message['hist'],
 244+ 'action=history&offset=' . urlencode($row->log_timestamp) ) . ')';
 245+ if( self::typeAction($row,'protect','modify') && $wgUser->isAllowed('protect') ) {
 246+ $revert .= ' (' . $this->skin->makeKnownLinkObj( $title, $this->message['protect_change'],
 247+ 'action=unprotect' ) . ')';
 248+ }
 249+ // Show unmerge link
 250+ } else if ( self::typeAction($row,'merge','merge') ) {
 251+ $merge = SpecialPage::getTitleFor( 'Mergehistory' );
 252+ $revert = '(' . $this->skin->makeKnownLinkObj( $merge, $this->message['revertmerge'],
 253+ wfArrayToCGI( array('target' => $paramArray[0], 'dest' => $title->getPrefixedDBkey(),
 254+ 'mergepoint' => $paramArray[1] ) ) ) . ')';
 255+ // If an edit was hidden from a page give a review link to the history
 256+ } else if( self::typeAction($row,array('delete','suppress'),'revision') && $wgUser->isAllowed( 'deleterevision' ) ) {
 257+ if( count($paramArray) == 2 ) {
 258+ $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
 259+ // Different revision types use different URL params...
 260+ $key = $paramArray[0];
 261+ // Link to each hidden object ID, $paramArray[1] is the url param
 262+ $Ids = explode( ',', $paramArray[1] );
 263+ $revParams = '';
 264+ foreach( $Ids as $n => $id ) {
 265+ $revParams .= '&' . urlencode($key) . '[]=' . urlencode($id);
230266 }
231 - // Show undelete link
232 - } else if( self::typeAction($row,array('delete','suppress'),'delete') && $wgUser->isAllowed( 'delete' ) ) {
233 - $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
234 - $this->message['undeletelink'], 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
235 - // Show unblock link
236 - } else if( self::typeAction($row,array('block','suppress'),'block') && $wgUser->isAllowed( 'block' ) ) {
237 - $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Ipblocklist' ),
238 - $this->message['unblocklink'],
239 - 'action=unblock&ip=' . urlencode( $row->log_title ) ) . ')';
240 - // Show change protection link
241 - } else if( self::typeAction($row,'protect','modify') && $wgUser->isAllowed( 'protect' ) ) {
242 - $revert = '(' . $this->skin->makeKnownLinkObj( $title, $this->message['protect_change'], 'action=unprotect' ) . ')';
243 - // Show unmerge link
244 - } else if ( self::typeAction($row,'merge','merge') ) {
245 - $merge = SpecialPage::getTitleFor( 'Mergehistory' );
246 - $revert = '(' . $this->skin->makeKnownLinkObj( $merge, $this->message['revertmerge'],
247 - wfArrayToCGI( array('target' => $paramArray[0], 'dest' => $title->getPrefixedDBkey(),
248 - 'mergepoint' => $paramArray[1] ) ) ) . ')';
249 - // If an edit was hidden from a page give a review link to the history
250 - } else if( self::typeAction($row,array('delete','suppress'),'revision') && $wgUser->isAllowed( 'deleterevision' ) ) {
251 - if( count($paramArray) == 2 ) {
252 - $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
253 - // Different revision types use different URL params...
254 - $key = $paramArray[0];
255 - // Link to each hidden object ID, $paramArray[1] is the url param
256 - $Ids = explode( ',', $paramArray[1] );
257 - $revParams = '';
258 - foreach( $Ids as $n => $id ) {
259 - $revParams .= '&' . urlencode($key) . '[]=' . urlencode($id);
260 - }
261 - $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
262 - 'target=' . $title->getPrefixedUrl() . $revParams ) . ')';
 267+ $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
 268+ 'target=' . $title->getPrefixedUrl() . $revParams ) . ')';
 269+ }
 270+ // Hidden log items, give review link
 271+ } else if( self::typeAction($row,array('delete','suppress'),'event') && $wgUser->isAllowed( 'deleterevision' ) ) {
 272+ if( count($paramArray) == 1 ) {
 273+ $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
 274+ $Ids = explode( ',', $paramArray[0] );
 275+ // Link to each hidden object ID, $paramArray[1] is the url param
 276+ $logParams = '';
 277+ foreach( $Ids as $n => $id ) {
 278+ $logParams .= '&logid[]=' . intval($id);
263279 }
264 - // Hidden log items, give review link
265 - } else if( self::typeAction($row,array('delete','suppress'),'event') && $wgUser->isAllowed( 'deleterevision' ) ) {
266 - if( count($paramArray) == 1 ) {
267 - $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
268 - $Ids = explode( ',', $paramArray[0] );
269 - // Link to each hidden object ID, $paramArray[1] is the url param
270 - $logParams = '';
271 - foreach( $Ids as $n => $id ) {
272 - $logParams .= '&logid[]=' . intval($id);
273 - }
274 - $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
275 - 'target=' . $title->getPrefixedUrl() . $logParams ) . ')';
276 - }
277 - } else {
278 - wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
279 - &$comment, &$revert, $row->log_timestamp ) );
280 - // wfDebug( "Invoked LogLine hook for " $row->log_type . ", " . $row->log_action . "\n" );
281 - // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
 280+ $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
 281+ 'target=' . $title->getPrefixedUrl() . $logParams ) . ')';
282282 }
 283+ } else {
 284+ wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
 285+ &$comment, &$revert, $row->log_timestamp ) );
 286+ // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
283287 }
284288 // Event description
285289 if( self::isDeleted($row,LogPage::DELETED_ACTION) ) {
@@ -316,15 +320,15 @@
317321 /**
318322 * @param Row $row
319323 * @param mixed $type (string/array)
320 - * @param string $action
 324+ * @param mixed $action (string/array)
321325 * @return bool
322326 */
323327 public static function typeAction( $row, $type, $action ) {
324 - if( is_array($type) ) {
325 - return ( in_array($row->log_type,$type) && $row->log_action == $action );
326 - } else {
327 - return ( $row->log_type == $type && $row->log_action == $action );
 328+ $match = is_array($type) ? in_array($row->log_type,$type) : $row->log_type == $type;
 329+ if( $match ) {
 330+ $match = is_array($action) ? in_array($row->log_action,$action) : $row->log_action == $action;
328331 }
 332+ return $match;
329333 }
330334
331335 /**