From ef985d1362532a5d9a730d002c56d2b5175c302d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 25 Nov 2004 13:47:17 +0000 Subject: [PATCH] Split recentchanges and image history list formatters from Skin, where they never really belonged. No skin overrides these things, and they just waste server time loading and parsing the code for every page hit where they're not needed. --- includes/ChangesList.php | 559 +++++++++++++++++++++ includes/ImagePage.php | 83 +++- includes/Skin.php | 616 +----------------------- includes/SpecialRecentchanges.php | 8 +- includes/SpecialRecentchangeslinked.php | 7 +- includes/SpecialWatchlist.php | 7 +- 6 files changed, 652 insertions(+), 628 deletions(-) create mode 100644 includes/ChangesList.php diff --git a/includes/ChangesList.php b/includes/ChangesList.php new file mode 100644 index 0000000000..5f6425d5d4 --- /dev/null +++ b/includes/ChangesList.php @@ -0,0 +1,559 @@ +skin =& $skin; + } + + # Returns text for the start of the tabular part of RC + function beginRecentChangesList() { + $this->rc_cache = array() ; + $this->rcMoveIndex = 0; + $this->rcCacheIndex = 0 ; + $this->lastdate = ''; + $this->rclistOpen = false; + return ''; + } + + /** + * Returns text for the end of RC + * If enhanced RC is in use, returns pretty much all the text + */ + function endRecentChangesList() { + $s = $this->recentChangesBlock() ; + if( $this->rclistOpen ) { + $s .= "\n"; + } + return $s; + } + + /** + * Enhanced RC ungrouped line + */ + function recentChangesBlockLine ( $rcObj ) { + global $wgStylePath, $wgContLang ; + + # Get rc_xxxx variables + extract( $rcObj->mAttribs ) ; + $curIdEq = 'curid='.$rc_cur_id; + + # Spacer image + $r = '' ; + + $r .= '' ; + $r .= '' ; + + if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { + $r .= '  '; + } else { + # M, N and ! + $M = wfMsg( 'minoreditletter' ); + $N = wfMsg( 'newpageletter' ); + + if ( $rc_type == RC_NEW ) { + $r .= $N ; + } else { + $r .= ' ' ; + } + if ( $rc_minor ) { + $r .= $M ; + } else { + $r .= ' ' ; + } + if ( $rcObj->unpatrolled ) { + $r .= '!'; + } else { + $r .= ' '; + } + } + + # Timestamp + $r .= ' '.$rcObj->timestamp.' ' ; + $r .= '' ; + + # Article link + $link = $rcObj->link ; + if ( $rcObj->watched ) $link = ''.$link.'' ; + $r .= $link ; + + # Diff + $r .= ' (' ; + $r .= $rcObj->difflink ; + $r .= '; ' ; + + # Hist + $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ); + + # User/talk + $r .= ') . . '.$rcObj->userlink ; + $r .= $rcObj->usertalklink ; + + # Comment + if ( $rc_comment != '' && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) { + $rc_comment=$this->skin->formatComment($rc_comment, $rcObj->getTitle()); + $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' ); + } + + $r .= "
\n" ; + return $r ; + } + + /** + * Enhanced RC group + */ + function recentChangesBlockGroup ( $block ) { + global $wgStylePath, $wgContLang ; + + $r = '' ; + $M = wfMsg( 'minoreditletter' ); + $N = wfMsg( 'newpageletter' ); + + # Collate list of users + $isnew = false ; + $unpatrolled = false; + $userlinks = array () ; + foreach ( $block AS $rcObj ) { + $oldid = $rcObj->mAttribs['rc_last_oldid']; + if ( $rcObj->mAttribs['rc_new'] ) { + $isnew = true ; + } + $u = $rcObj->userlink ; + if ( !isset ( $userlinks[$u] ) ) { + $userlinks[$u] = 0 ; + } + if ( $rcObj->unpatrolled ) { + $unpatrolled = true; + } + $userlinks[$u]++ ; + } + + # Sort the list and convert to text + krsort ( $userlinks ) ; + asort ( $userlinks ) ; + $users = array () ; + foreach ( $userlinks as $userlink => $count) { + $text = $userlink ; + if ( $count > 1 ) $text .= " ({$count}×)" ; + array_push ( $users , $text ) ; + } + $users = ' ['.implode('; ',$users).']' ; + + # Arrow + $rci = 'RCI'.$this->rcCacheIndex ; + $rcl = 'RCL'.$this->rcCacheIndex ; + $rcm = 'RCM'.$this->rcCacheIndex ; + $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ; + $arrowdir = $wgContLang->isRTL() ? 'l' : 'r'; + $tl = '+' ; + $tl .= '' ; + $r .= $tl ; + + # Main line + # M/N + $r .= '' ; + if ( $isnew ) $r .= $N ; + else $r .= ' ' ; + $r .= ' ' ; # Minor + if ( $unpatrolled ) { + $r .= "!"; + } else { + $r .= " "; + } + + # Timestamp + $r .= ' '.$block[0]->timestamp.' ' ; + $r .= '' ; + + # Article link + $link = $block[0]->link ; + if ( $block[0]->watched ) $link = ''.$link.'' ; + $r .= $link ; + + $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id']; + if ( $block[0]->mAttribs['rc_type'] != RC_LOG ) { + # Changes + $r .= ' ('.count($block).' ' ; + if ( $isnew ) $r .= wfMsg('changes'); + else $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle() , wfMsg('changes') , + $curIdEq.'&diff=0&oldid='.$oldid ) ; + $r .= '; ' ; + + # History + $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' ); + $r .= ')' ; + } + + $r .= $users ; + $r .= "
\n" ; + + # Sub-entries + $r .= '\n" ; + + $this->rcCacheIndex++ ; + return $r ; + } + + /** + * If enhanced RC is in use, this function takes the previously cached + * RC lines, arranges them, and outputs the HTML + */ + function recentChangesBlock () { + global $wgStylePath ; + if ( count ( $this->rc_cache ) == 0 ) return '' ; + $blockOut = ''; + foreach ( $this->rc_cache AS $secureName => $block ) { + if ( count ( $block ) < 2 ) { + $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ; + } else { + $blockOut .= $this->recentChangesBlockGroup ( $block ) ; + } + } + + return '
'.$blockOut.'
' ; + } + + /** + * Called in a loop over all displayed RC entries + * Either returns the line, or caches it for later use + */ + function recentChangesLine( &$rc, $watched = false ) { + global $wgUser ; + $usenew = $wgUser->getOption( 'usenewrc' ); + if ( $usenew ) + $line = $this->recentChangesLineNew ( $rc, $watched ) ; + else + $line = $this->recentChangesLineOld ( $rc, $watched ) ; + return $line ; + } + + function recentChangesLineOld( &$rc, $watched = false ) { + $fname = 'Skin::recentChangesLineOld'; + wfProfileIn( $fname ); + + global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds, $wgUseRCPatrol, $wgOnlySysopsCanPatrol; + + static $message; + if( !isset( $message ) ) { + foreach( explode(' ', 'diff hist minoreditletter newpageletter blocklink' ) as $msg ) { + $message[$msg] = wfMsg( $msg ); + } + } + + # Extract DB fields into local scope + extract( $rc->mAttribs ); + $curIdEq = 'curid=' . $rc_cur_id; + + # Should patrol-related stuff be shown? + $unpatrolled = $wgUseRCPatrol && $wgUser->getID() != 0 && + ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') ) && $rc_patrolled == 0; + + # Make date header if necessary + $date = $wgLang->date( $rc_timestamp, true); + $s = ''; + if ( $date != $this->lastdate ) { + if ( '' != $this->lastdate ) { $s .= "\n"; } + $s .= "

{$date}

\n\n"; } - $s .= "

{$date}

\n\n"; - return $s; - } /** * This function is called by all recent changes variants, by the page history, @@ -2550,63 +1992,7 @@ class Skin { wfProfileOut( $fname ); return $comment; } - - function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) { - global $wgUser, $wgLang, $wgContLang, $wgTitle; - - $datetime = $wgLang->timeanddate( $timestamp, true ); - $del = wfMsg( 'deleteimg' ); - $delall = wfMsg( 'deleteimgcompletely' ); - $cur = wfMsg( 'cur' ); - - if ( $iscur ) { - $url = Image::wfImageUrl( $img ); - $rlink = $cur; - if ( $wgUser->isAllowed('delete') ) { - $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() . - '&action=delete' ); - $style = $this->getInternalLinkAttributes( $link, $delall ); - - $dlink = ''.$delall.''; - } else { - $dlink = $del; - } - } else { - $url = htmlspecialchars( wfImageArchiveUrl( $img ) ); - if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) { - $rlink = $this->makeKnownLink( $wgTitle->getPrefixedText(), - wfMsg( 'revertimg' ), 'action=revert&oldimage=' . - urlencode( $img ) ); - $dlink = $this->makeKnownLink( $wgTitle->getPrefixedText(), - $del, 'action=delete&oldimage=' . urlencode( $img ) ); - } else { - # Having live active links for non-logged in users - # means that bots and spiders crawling our site can - # inadvertently change content. Baaaad idea. - $rlink = wfMsg( 'revertimg' ); - $dlink = $del; - } - } - if ( 0 == $user ) { - $userlink = $usertext; - } else { - $userlink = $this->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . - ':'.$usertext, $usertext ); - } - $nbytes = wfMsg( 'nbytes', $size ); - $style = $this->getInternalLinkAttributes( $url, $datetime ); - - $s = "
  • ({$dlink}) ({$rlink}) {$datetime}" - . " . . {$userlink} ({$nbytes})"; - - if ( '' != $description && '*' != $description ) { - $sk=$wgUser->getSkin(); - $s .= $wgContLang->emphasize(' (' . $sk->formatComment($description,$wgTitle) . ')'); - } - $s .= "
  • \n"; - return $s; - } - + function tocIndent($level) { return str_repeat( '
    '."\n", $level>0 ? $level : 0 ); } diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index d58ae0c149..6671645b08 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -9,6 +9,7 @@ * */ require_once( 'Feed.php' ); +require_once( 'ChangesList.php' ); /** * Constructor @@ -170,7 +171,8 @@ function wfSpecialRecentchanges( $par ) { $feed->outFooter(); } else { $wgOut->setSyndicated( true ); - $s = $sk->beginRecentChangesList(); + $list =& new ChangesList( $sk ); + $s = $list->beginRecentChangesList(); $counter = 1; foreach( $rows as $obj ){ if( $limit == 0) { @@ -181,11 +183,11 @@ function wfSpecialRecentchanges( $par ) { ! ( $hidepatrolled && $obj->rc_patrolled ) ) { $rc = RecentChange::newFromRow( $obj ); $rc->counter = $counter++; - $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user ) ); + $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) ); --$limit; } } - $s .= $sk->endRecentChangesList(); + $s .= $list->endRecentChangesList(); $wgOut->addHTML( $s ); } } diff --git a/includes/SpecialRecentchangeslinked.php b/includes/SpecialRecentchangeslinked.php index 6f82b35400..6a86012d8c 100644 --- a/includes/SpecialRecentchangeslinked.php +++ b/includes/SpecialRecentchangeslinked.php @@ -84,7 +84,8 @@ function wfSpecialRecentchangeslinked( $par = NULL ) { $wgOut->addHTML( $note."\n" ); - $s = $sk->beginRecentChangesList(); + $list =& new ChangesList( $sk ); + $s = $list->beginRecentChangesList(); $count = $dbr->numRows( $res ); $counter = 1; @@ -95,10 +96,10 @@ function wfSpecialRecentchangeslinked( $par = NULL ) { $rc = RecentChange::newFromCurRow( $obj ); $rc->counter = $counter++; - $s .= $sk->recentChangesLine( $rc ); + $s .= $list->recentChangesLine( $rc ); --$limit; } - $s .= $sk->endRecentChangesList(); + $s .= $list->endRecentChangesList(); $dbr->freeResult( $res ); $wgOut->addHTML( $s ); diff --git a/includes/SpecialWatchlist.php b/includes/SpecialWatchlist.php index be82afed5e..0e9ac0c45f 100644 --- a/includes/SpecialWatchlist.php +++ b/includes/SpecialWatchlist.php @@ -187,15 +187,16 @@ function wfSpecialWatchlist() { } $sk = $wgUser->getSkin(); - $s = $sk->beginRecentChangesList(); + $list =& new ChangesList( $sk ); + $s = $list->beginRecentChangesList(); $counter = 1; while ( $obj = $dbr->fetchObject( $res ) ) { # Make fake RC entry $rc = RecentChange::newFromCurRow( $obj ); $rc->counter = $counter++; - $s .= $sk->recentChangesLine( $rc, true ); + $s .= $list->recentChangesLine( $rc, true ); } - $s .= $sk->endRecentChangesList(); + $s .= $list->endRecentChangesList(); $dbr->freeResult( $res ); $wgOut->addHTML( $s ); -- 2.20.1