Tell regexp parser to use extra analysis on external link regexp;
[lhc/web/wiklou.git] / includes / SpecialContributions.php
index aa1da78..0088532 100644 (file)
@@ -34,13 +34,19 @@ function wfSpecialContributions( $par = '' ) {
        $sk = $wgUser->getSkin();
        $dbr =& wfGetDB( DB_SLAVE );
        $userCond = "";
+       $namespace = $wgRequest->getVal( 'namespace', '' );
+       if( $namespace != '' ) {
+               $namespace = IntVal( $namespace );
+       } else {
+               $namespace = NULL;
+       }
 
        $nt = Title::newFromURL( $target );
        if ( !$nt ) {
                $wgOut->errorpage( 'notargettitle', 'notargettext' );
                return;
        }
-       $nt->setNamespace( Namespace::getUser() );
+       $nt =& Title::makeTitle( NS_USER, $nt->getDBkey() );
 
        $id = User::idFromName( $nt->getText() );
 
@@ -71,43 +77,56 @@ function wfSpecialContributions( $par = '' ) {
                $omq = 'AND old_minor_edit=0';
                $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
                  WfMsg( 'show' ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
-                 "&offset={$offset}&limit={$limit}&hideminor=0" );
+                 "&offset={$offset}&limit={$limit}&hideminor=0&namespace={$namespace}" );
        } else {
                $cmq = $omq = '';
                $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
                  WfMsg( 'hide' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
-                 "&offset={$offset}&limit={$limit}&hideminor=1" );
+                 "&offset={$offset}&limit={$limit}&hideminor=1&namespace={$namespace}" );
        }
-
+       
+       if( !is_null($namespace) ) {
+               $cmq .= " AND cur_namespace = {$namespace}";
+               $omq .= " AND old_namespace = {$namespace}";
+       }
+       
+       # We may have to force the index, as some options will cause
+       # MySQL to incorrectly pick eg the namespace index.
+       list( $useIndex, $tailOpts ) = $dbr->makeSelectOptions( array(
+               'USE INDEX' => 'usertext_timestamp',
+               'LIMIT' => $querylimit ) );
+       
        extract( $dbr->tableNames( 'old', 'cur' ) );
        if ( $userCond == '' ) {
-               $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur " .
+               $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur $useIndex " .
                  "WHERE cur_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$cmq} " .
-                 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
+                 "ORDER BY inverse_timestamp $tailOpts";
                $res1 = $dbr->query( $sql, $fname );
 
-               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
+               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old $useIndex " .
                  "WHERE old_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$omq} " .
-                 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
+                 "ORDER BY inverse_timestamp $tailOpts";
                $res2 = $dbr->query( $sql, $fname );
        } else {
-               $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur " .
-                 "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
+               $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur $useIndex " .
+                 "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp $tailOpts";
                $res1 = $dbr->query( $sql, $fname );
 
-               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
-                 "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
+               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old $useIndex " .
+                 "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp $tailOpts";
                $res2 = $dbr->query( $sql, $fname );
        }
        $nCur = $dbr->numRows( $res1 );
        $nOld = $dbr->numRows( $res2 );
 
+       $wgOut->addHTML( namespaceForm( $target, $hideminor, $namespace ) );
+
        $top = wfShowingResults( $offset, $limit );
        $wgOut->addHTML( "<p>{$top}\n" );
 
        $sl = wfViewPrevNext( $offset, $limit,
          $wgContLang->specialpage( 'Contributions' ),
-         "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
+         "hideminor={$hideminor}&namespace={$namespace}&target=" . wfUrlEncode( $target ),
          ($nCur + $nOld) <= $offlimit);
 
         $shm = wfMsg( 'showhideminor', $mlink );
@@ -189,46 +208,55 @@ function wfSpecialContributions( $par = '' ) {
  * @todo This would probably look a lot nicer in a table.
  */
 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
+       $fname = 'ucListEdit';
+       wfProfileIn( $fname );
+       
        global $wgLang, $wgOut, $wgUser, $wgRequest;
-       $page = Title::makeName( $ns, $t );
-       $link = $sk->makeKnownLink( $page, '' );
+       static $messages;
+       if( !isset( $messages ) ) {
+               foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
+                       $messages[$msg] = wfMsg( $msg );
+               }
+       }
+       
+       $page =& Title::makeTitle( $ns, $t );
+       $link = $sk->makeKnownLinkObj( $page, '' );
        $difftext = $topmarktext = '';
        if($topmark) {
-               $topmarktext .= '<strong>' . wfMsg('uctop') . '</strong>';
+               $topmarktext .= '<strong>' . $messages['uctop'] . '</strong>';
                if(!$isnew) {
-                       $difftext .= $sk->makeKnownLink( $page, '(' . wfMsg('diff') . ')', 'diff=0' );
+                       $difftext .= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'] . ')', 'diff=0' );
                } else {
-                       $difftext .= wfMsg('newarticle');
+                       $difftext .= $messages['newarticle'];
                }
                
                if( $wgUser->isAllowed('rollback') ) {
                        $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
                        # $target = $wgRequest->getText( 'target' );
-                       $topmarktext .= ' ['. $sk->makeKnownLink( $page,
-                       wfMsg( 'rollbacklink' ),
-                       'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
+                       $topmarktext .= ' ['. $sk->makeKnownLinkObj( $page,
+                               $messages['rollbacklink'],
+                               'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
                }
 
        }
        if ( $oldid ) {
-               $difftext= $sk->makeKnownLink( $page, '('.wfMsg('diff').')', 'diff=prev&oldid='.$oldid );
+               $difftext= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'].')', 'diff=prev&oldid='.$oldid );
        } 
-       $histlink='('.$sk->makeKnownLink($page,wfMsg('hist'),'action=history').')';
-
-       if($comment) {
-
-               $comment='<em>('. $sk->formatComment($comment, Title::newFromText($t) ) .')</em> ';
+       $histlink='('.$sk->makeKnownLinkObj( $page, $messages['hist'], 'action=history' ) . ')';
 
+       if( $comment ) {
+               $comment = '<em>(' . $sk->formatComment( $comment, $page ) . ')</em> ';
        }
        $d = $wgLang->timeanddate( $ts, true );
 
        if ($isminor) {
-               $mflag = '<span class="minor">'.wfMsg( 'minoreditletter' ).'</span> ';
+               $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
        } else {
                $mflag = '';
        }
 
        $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
+       wfProfileOut( $fname );
 }
 
 /**
@@ -256,4 +284,41 @@ function ucDaysLink( $lim, $d ) {
          "{$d}", "target={$target}&days={$d}&limit={$lim}" );
        return $s;
 }
+
+/**
+ * Generates a form used to restrict display of contributions
+ * to a specific namespace
+ *
+ * @return     none
+ * @param      string  $target target user to show contributions for
+ * @param      string  $hideminor whether minor contributions are hidden
+ * @param      string  $namespace currently selected namespace, NULL for show all
+ */
+function namespaceForm ( $target, $hideminor, $namespace ) {
+       global $wgContLang, $wgScript;
+
+       $namespaceselect = '<form><select name="namespace">';
+       $namespaceselect .= '<option value="" '.(is_null($namespace) ? ' selected="selected"' : '').'>'.wfMsg( 'all' ).'</option>';
+       $arr = $wgContLang->getNamespaces();
+       foreach( array_keys( $arr ) as $i ) {
+               if( $i < 0 ) {
+                       continue;
+               }
+               $namespacename = str_replace ( "_", " ", $arr[$i] );
+               $n = ($i == 0) ? wfMsg ( 'articlenamespace' ) : $namespacename;
+               $sel = ($i === $namespace) ? ' selected="selected"' : '';
+               $namespaceselect .= "<option value='{$i}'{$sel}>{$n}</option>";
+       }
+       $namespaceselect .= '</select>';
+
+       $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
+
+       $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
+       $out .= '<input type="hidden" name="title" value="'.$wgContLang->specialpage( 'Contributions' ).'" />';
+       $out .= '<input type="hidden" name="target" value="'.htmlspecialchars( $target ).'" />';
+       $out .= '<input type="hidden" name="hideminor" value="'.$hideminor.'" />';      
+       $out .= wfMsg ( 'allpagesformtext2', $namespaceselect, $submitbutton );
+       $out .= '</form></div>';
+       return $out;
+}
 ?>