From 861e40c6223720d5160b3821214a6bd92c987a7f Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 10 Jul 2006 08:38:48 +0000 Subject: [PATCH] * (bug 6448) Allow filtering of Special:Newpages according to username Comes with a free index upgrade. --- RELEASE-NOTES | 1 + includes/SpecialNewpages.php | 55 +++++++++---------- languages/Messages.php | 1 + .../archives/patch-recentchanges-utindex.sql | 4 ++ maintenance/mysql5/tables.sql | 3 +- maintenance/tables.sql | 3 +- maintenance/updaters.inc | 19 +++++++ 7 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 maintenance/archives/patch-recentchanges-utindex.sql diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c4959bf95e..4f1ebcde7e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -41,6 +41,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN attempts to create an account. Fixed inefficiency of Special:Ipblocklist in the presence of large numbers of blocks; added indexes and implemented an indexed pager. +* (bug 6448) Allow filtering of Special:Newpages according to username == Languages updated == diff --git a/includes/SpecialNewpages.php b/includes/SpecialNewpages.php index c0c6ba96ba..c050137393 100644 --- a/includes/SpecialNewpages.php +++ b/includes/SpecialNewpages.php @@ -11,10 +11,13 @@ * @subpackage SpecialPage */ class NewPagesPage extends QueryPage { + var $namespace; + var $username = ''; - function NewPagesPage( $namespace = NS_MAIN ) { + function NewPagesPage( $namespace = NS_MAIN, $username = '' ) { $this->namespace = $namespace; + $this->username = $username; } function getName() { @@ -26,12 +29,18 @@ class NewPagesPage extends QueryPage { return false; } + function makeUserWhere( &$dbo ) { + return $this->username ? ' AND rc_user_text = ' . $dbo->addQuotes( $this->username ) : ''; + } + function getSQL() { global $wgUser, $wgUseRCPatrol; $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ? 1 : 0; $dbr =& wfGetDB( DB_SLAVE ); extract( $dbr->tableNames( 'recentchanges', 'page', 'text' ) ); + $uwhere = $this->makeUserWhere( $dbr ); + # FIXME: text will break with compression return "SELECT 'Newpages' as type, @@ -50,7 +59,8 @@ class NewPagesPage extends QueryPage { page_latest as rev_id FROM $recentchanges,$page WHERE rc_cur_id=page_id AND rc_new=1 - AND rc_namespace=" . $this->namespace . " AND page_is_redirect=0"; + AND rc_namespace=" . $this->namespace . " AND page_is_redirect=0 + {$uwhere}"; } function preprocessResults( &$dbo, &$res ) { @@ -112,34 +122,20 @@ class NewPagesPage extends QueryPage { } /** - * Show a namespace selection form for filtering + * Show a form for filtering namespace and username * * @return string */ function getPageHeader() { - $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() ); - $form = wfOpenElement( 'form', array( - 'method' => 'post', - 'action' => $thisTitle->getLocalUrl() ) ); - $form .= wfElement( 'label', array( 'for' => 'namespace' ), - wfMsg( 'namespace' ) ) . ' '; - $form .= HtmlNamespaceSelector( $this->namespace ); - # Preserve the offset and limit - $form .= wfElement( 'input', array( - 'type' => 'hidden', - 'name' => 'offset', - 'value' => $this->offset ) ); - $form .= wfElement( 'input', array( - 'type' => 'hidden', - 'name' => 'limit', - 'value' => $this->limit ) ); - $form .= wfElement( 'input', array( - 'type' => 'submit', - 'name' => 'submit', - 'id' => 'submit', - 'value' => wfMsg( 'allpagessubmit' ) ) ); - $form .= wfCloseElement( 'form' ); - return( $form ); + $self = Title::makeTitle( NS_SPECIAL, $this->getName() ); + $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) ); + $form .= ''; + $form .= ''; + $form .= ''; + $form .= ''; + $form .= '
' . wfMsgHtml( 'namespace' ) . '' . HtmlNamespaceSelector( $this->namespace ) . '
' . wfMsgHtml( 'newpages-username' ) . '' . wfInput( 'username', 30, $this->username ) . '
' . wfSubmitButton( wfMsg( 'allpagessubmit' ) ) . '
'; + $form .= wfHidden( 'offset', $this->offset ) . wfHidden( 'limit', $this->limit ) . ''; + return $form; } /** @@ -148,7 +144,7 @@ class NewPagesPage extends QueryPage { * @return array */ function linkParameters() { - return( array( 'namespace' => $this->namespace ) ); + return( array( 'namespace' => $this->namespace, 'username' => $this->username ) ); } } @@ -161,6 +157,7 @@ function wfSpecialNewpages($par, $specialPage) { list( $limit, $offset ) = wfCheckLimits(); $namespace = NS_MAIN; + $username = ''; if ( $par ) { $bits = preg_split( '/\s*,\s*/', trim( $par ) ); @@ -184,12 +181,14 @@ function wfSpecialNewpages($par, $specialPage) { } else { if( $ns = $wgRequest->getInt( 'namespace', 0 ) ) $namespace = $ns; + if( $un = $wgRequest->getText( 'username' ) ) + $username = $un; } if ( ! isset( $shownavigation ) ) $shownavigation = ! $specialPage->including(); - $npp = new NewPagesPage( $namespace ); + $npp = new NewPagesPage( $namespace, $username ); if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) ) $npp->doQuery( $offset, $limit, $shownavigation ); diff --git a/languages/Messages.php b/languages/Messages.php index 1f02b2bb19..68efed8433 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -981,6 +981,7 @@ The [http://meta.wikimedia.org/wiki/Help:Job_queue job queue] length is '''$7''' 'recentchangeslinked' => 'Related changes', 'rclsub' => "(to pages linked from \"$1\")", 'newpages' => 'New pages', +'newpages-username' => 'Username:', 'ancientpages' => 'Oldest pages', 'intl' => 'Interlanguage links', 'move' => 'Move', diff --git a/maintenance/archives/patch-recentchanges-utindex.sql b/maintenance/archives/patch-recentchanges-utindex.sql new file mode 100644 index 0000000000..4ebe316507 --- /dev/null +++ b/maintenance/archives/patch-recentchanges-utindex.sql @@ -0,0 +1,4 @@ +--- July 2006 +--- Index on recentchanges.( rc_namespace, rc_user_text ) +--- Helps the username filtering in Special:Newpages +ALTER TABLE /*$wgDBprefix*/recentchanges ADD INDEX `rc_ns_usertext` ( `rc_namespace` , `rc_user_text` ); \ No newline at end of file diff --git a/maintenance/mysql5/tables.sql b/maintenance/mysql5/tables.sql index 0ee6e2aa71..e1ae0e67cf 100644 --- a/maintenance/mysql5/tables.sql +++ b/maintenance/mysql5/tables.sql @@ -809,7 +809,8 @@ CREATE TABLE /*$wgDBprefix*/recentchanges ( INDEX rc_namespace_title (rc_namespace, rc_title), INDEX rc_cur_id (rc_cur_id), INDEX new_name_timestamp(rc_new,rc_namespace,rc_timestamp), - INDEX rc_ip (rc_ip) + INDEX rc_ip (rc_ip), + INDEX rc_ns_usertext ( rc_namespace, rc_user_text ) ) TYPE=InnoDB, DEFAULT CHARSET=utf8; diff --git a/maintenance/tables.sql b/maintenance/tables.sql index b00115e371..67b620aed3 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -795,7 +795,8 @@ CREATE TABLE /*$wgDBprefix*/recentchanges ( INDEX rc_namespace_title (rc_namespace, rc_title), INDEX rc_cur_id (rc_cur_id), INDEX new_name_timestamp(rc_new,rc_namespace,rc_timestamp), - INDEX rc_ip (rc_ip) + INDEX rc_ip (rc_ip), + INDEX rc_ns_usertext ( rc_namespace, rc_user_text ) ) TYPE=InnoDB; diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 0174168353..9acf302b6f 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -762,6 +762,23 @@ function do_templatelinks_update() { echo "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n"; } +# July 2006 +# Add ( rc_namespace, rc_user_text ) index [R. Church] +function do_rc_indices_update() { + global $wgDatabase; + echo( "Checking for additional recent changes indices...\n" ); + # See if we can find the index we want + $info = $wgDatabase->indexInfo( 'recentchanges', 'rc_ns_usertext', __METHOD__ ); + if( !$info ) { + # None, so create + echo( "...index on ( rc_namespace, rc_user_text ) not found; creating\n" ); + dbsource( archive( 'patch-recentchanges-utindex.sql' ) ); + } else { + # Index seems to exist + echo( "...seems to be ok\n" ); + } +} + function do_all_updates( $doShared = false ) { global $wgNewTables, $wgNewFields, $wgRenamedTables, $wgSharedDB, $wgDatabase; @@ -820,6 +837,8 @@ function do_all_updates( $doShared = false ) { do_logging_timestamp_index(); flush(); do_page_random_update(); flush(); + + do_rc_indices_update(); flush(); initialiseMessages(); flush(); } -- 2.20.1