Remove a couple of link() calls in enhanced RC
authorAryeh Gregor <simetrical@users.mediawiki.org>
Sun, 29 Mar 2009 17:09:47 +0000 (17:09 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Sun, 29 Mar 2009 17:09:47 +0000 (17:09 +0000)
diff and cur links are now created using raw HTML instead of link(),
which they didn't really need anyway.  I didn't see any other obvious
candidates for conversion to raw HTML, since other things tend to need
fancy classes and have lots of other logic.  It's possible link() could
be made faster, too.

includes/ChangesList.php
includes/GlobalFunctions.php

index ac7ee9c..73b8a3e 100644 (file)
@@ -553,7 +553,8 @@ class EnhancedChangesList extends ChangesList {
                $rc->timestamp = $time;
                $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
 
-               # Make "cur" and "diff" links
+               # Make "cur" and "diff" links.  Don't use link(), it's too slow if
+               # called too many times (50% of CPU time on RecentChanges!).
                if( $rc->unpatrolled ) {
                        $rcIdQuery = array( 'rcid' => $rc_id );
                } else {
@@ -564,19 +565,23 @@ class EnhancedChangesList extends ChangesList {
                        $rc_last_oldid ) + $rcIdQuery;
                $attribs = array( 'tabindex' => $baseRC->counter );
 
-               # Make "diff" and "cur" links
                if( !$showdifflinks ) {
                        $curLink = $this->message['cur'];
                        $diffLink = $this->message['diff'];
                } else if( in_array( $rc_type, array(RC_NEW,RC_LOG,RC_MOVE,RC_MOVE_OVER_REDIRECT) ) ) {
-                       $curLink = ($rc_type != RC_NEW) ? $this->message['cur']
-                               : $this->skin->linkKnown( $rc->getTitle(), $this->message['cur'], $attribs, $querycur );
+                       if ( $rc_type != RC_NEW ) {
+                               $curLink = $this->message['cur'];
+                       } else {
+                               $curUrl = wfUrlencode( wfAppendQuery( $rc->getTitle()->getLinkUrl(), $querycur ) );
+                               $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
+                       }
                        $diffLink = $this->message['diff'];
                } else {
-                       $diffLink = $this->skin->linkKnown( $rc->getTitle(), $this->message['diff'], 
-                               $attribs, $querydiff );
-                       $curLink = $this->skin->linkKnown( $rc->getTitle(), $this->message['cur'],
-                               $attribs, $querycur );
+                       $url = $rc->getTitle()->getLinkUrl();
+                       $diffUrl = wfUrlencode( wfAppendQuery( $url, $querydiff ) );
+                       $curUrl = wfUrlencode( wfAppendQuery( $url, $querycur ) );
+                       $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
+                       $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
                }
 
                # Make "last" link
index 9afb3ad..f5eb274 100644 (file)
@@ -1234,10 +1234,13 @@ function wfCgiToArray( $query ) {
  * have query string parameters already. If so, they will be combined.
  *
  * @param string $url
- * @param string $query
+ * @param mixed $query String or associative array
  * @return string
  */
 function wfAppendQuery( $url, $query ) {
+       if ( is_array( $query ) ) {
+               $query = wfArrayToCGI( $query );
+       }
        if( $query != '' ) {
                if( false === strpos( $url, '?' ) ) {
                        $url .= '?';