X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialNewpages.php;h=63e218a6effd5f93393e166c1f2f2ed5a73fcfc6;hb=5137bd84c31e39e5e26b2a25345eb0bcc7c48497;hp=220e77fdf49d35cf9f4ac1ce52518a26b224eefc;hpb=7abf88a57fe59cd105c275a5927d74cbc913d1b7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialNewpages.php b/includes/SpecialNewpages.php index 220e77fdf4..63e218a6ef 100644 --- a/includes/SpecialNewpages.php +++ b/includes/SpecialNewpages.php @@ -4,18 +4,116 @@ * @addtogroup SpecialPage */ + +/** + * Start point + */ +function wfSpecialNewPages( $par, $specialPage ) { + $page = new NewPagesPage( $specialPage ); + $page->execute( $par ); +} + /** * implements Special:Newpages * @addtogroup SpecialPage */ class NewPagesPage extends QueryPage { - var $namespace; - var $username = ''; + protected $options = array(); + protected $nondefaults = array(); + protected $specialPage; - function NewPagesPage( $namespace = NS_MAIN, $username = '' ) { - $this->namespace = $namespace; - $this->username = $username; + public function __construct( $specialPage=null ) { + $this->specialPage = $specialPage; + } + + public function execute( $par ) { + global $wgRequest, $wgLang; + + $shownavigation = is_object( $this->specialPage ) && !$this->specialPage->including(); + + $defaults = array( + /* bool */ 'hideliu' => false, + /* bool */ 'hidepatrolled' => false, + /* bool */ 'hidebots' => false, + /* text */ 'namespace' => "0", + /* text */ 'username' => '', + /* int */ 'offset' => 0, + /* int */ 'limit' => 50, + ); + + $options = $defaults; + + if ( $par ) { + $bits = preg_split( '/\s*,\s*/', trim( $par ) ); + foreach ( $bits as $bit ) { + if ( 'shownav' == $bit ) + $shownavigation = true; + if ( 'hideliu' === $bit ) + $options['hideliu'] = true; + if ( 'hidepatrolled' == $bit ) + $options['hidepatrolled'] = true; + if ( 'hidebots' == $bit ) + $options['hidebots'] = true; + if ( is_numeric( $bit ) ) + $options['limit'] = intval( $bit ); + + $m = array(); + if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) + $options['limit'] = intval($m[1]); + if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) ) + $options['offset'] = intval($m[1]); + if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) { + $ns = $wgLang->getNsIndex( $m[1] ); + if( $ns !== false ) { + $options['namespace'] = $ns; + } + } + } + } + + // Override all values from requests, if specified + foreach ( $defaults as $v => $t ) { + if ( is_bool($t) ) { + $options[$v] = $wgRequest->getBool( $v, $options[$v] ); + } elseif( is_int($t) ) { + $options[$v] = $wgRequest->getInt( $v, $options[$v] ); + } elseif( is_string($t) ) { + $options[$v] = $wgRequest->getText( $v, $options[$v] ); + } + } + + // Validate limit and offset params + if ( $options['limit'] <= 0 ) { + $options['limit'] = $defaults['limit']; + } + + if ( $options['offset'] < 0 ) { + $options['offset'] = $defaults['offset']; + } + + $nondefaults = array(); + foreach ( $options as $v => $t ) { + if ( $v === 'offset' ) continue; # Reset offset if parameters change + wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults ); + } + + # bind to class + $this->options = $options; + $this->nondefaults = $nondefaults; + + if ( !$this->doFeed( $wgRequest->getVal( 'feed' ), $options['limit'] ) ) { + $this->doQuery( $options['offset'], $options['limit'], $shownavigation ); + } + } + + function linkParameters() { + $nondefaults = $this->nondefaults; + // QueryPage seems to handle limit and offset itself + if ( isset( $nondefaults['limit'] ) ) { + unset($nondefaults['limit']); + } + return $nondefaults; } function getName() { @@ -27,29 +125,41 @@ class NewPagesPage extends QueryPage { return false; } - function makeUserWhere( &$dbo ) { - $title = Title::makeTitleSafe( NS_USER, $this->username ); - if( $title ) { - return ' AND rc_user_text = ' . $dbo->addQuotes( $title->getText() ); + function makeUserWhere( $db ) { + global $wgGroupPermissions; + $conds = array(); + if ($this->options['hidepatrolled']) { + $conds['rc_patrolled'] = 0; + } + if ($this->options['hidebots']) { + $conds['rc_bot'] = 0; + } + if ($wgGroupPermissions['*']['createpage'] == true && $this->options['hideliu']) { + $conds['rc_user'] = 0; } else { - return ''; + $title = Title::makeTitleSafe( NS_USER, $this->options['username'] ); + if( $title ) { + $conds['rc_user_text'] = $title->getText(); + } } + return $conds; } - private function makeNamespaceWhere() { - return $this->namespace !== 'all' - ? ' AND rc_namespace = ' . intval( $this->namespace ) - : ''; - } function getSQL() { - global $wgUser, $wgUseRCPatrol; - $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ? 1 : 0; + global $wgUser, $wgUseNPPatrol, $wgUseRCPatrol; + $usepatrol = ( $wgUseNPPatrol || $wgUseRCPatrol ) ? 1 : 0; $dbr = wfGetDB( DB_SLAVE ); list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' ); - $nsfilter = $this->makeNamespaceWhere(); - $uwhere = $this->makeUserWhere( $dbr ); + $conds = array(); + $conds['rc_new'] = 1; + if ( $this->options['namespace'] !== 'all' ) { + $conds['rc_namespace'] = intval( $this->options['namespace'] ); + } + $conds['page_is_redirect'] = 0; + $conds += $this->makeUserWhere( $dbr ); + $condstext = $dbr->makeList( $conds, LIST_AND ); # FIXME: text will break with compression return @@ -68,23 +178,20 @@ class NewPagesPage extends QueryPage { page_len as length, page_latest as rev_id FROM $recentchanges,$page - WHERE rc_cur_id=page_id AND rc_new=1 - {$nsfilter} - AND page_is_redirect = 0 - {$uwhere}"; + WHERE rc_cur_id=page_id AND $condstext"; } - function preprocessResults( &$dbo, &$res ) { + function preprocessResults( $db, $res ) { # Do a batch existence check on the user and talk pages $linkBatch = new LinkBatch(); - while( $row = $dbo->fetchObject( $res ) ) { - $linkBatch->addObj( Title::makeTitleSafe( NS_USER, $row->user_text ) ); - $linkBatch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_text ) ); + while( $row = $db->fetchObject( $res ) ) { + $linkBatch->add( NS_USER, $row->user_text ); + $linkBatch->add( NS_USER_TALK, $row->user_text ); } $linkBatch->execute(); # Seek to start - if( $dbo->numRows( $res ) > 0 ) - $dbo->dataSeek( $res, 0 ); + if( $db->numRows( $res ) > 0 ) + $db->dataSeek( $res, 0 ); } /** @@ -116,8 +223,10 @@ class NewPagesPage extends QueryPage { * @return bool */ function patrollable( $result ) { - global $wgUser, $wgUseRCPatrol; - return $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) && !$result->patrolled; + global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol; + return ( $wgUseRCPatrol || $wgUseNPPatrol ) + && $wgUser->isAllowed( 'patrol' ) + && !$result->patrolled; } function feedItemDesc( $row ) { @@ -138,9 +247,44 @@ class NewPagesPage extends QueryPage { * @return string */ function getPageHeader() { - global $wgScript, $wgContLang; + global $wgScript, $wgContLang, $wgGroupPermissions, $wgUser, $wgUseRCPatrol, $wgUseNPPatrol; + $sk = $wgUser->getSkin(); $align = $wgContLang->isRTL() ? 'left' : 'right'; $self = SpecialPage::getTitleFor( $this->getName() ); + + // show/hide links + $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' )); + + $hidelinks = array(); + + if ( $wgGroupPermissions['*']['createpage'] === true ) { + $hidelinks['hideliu'] = 'rcshowhideliu'; + } + if ( $wgUseNPPatrol || $wgUseRCPatrol ) { + $hidelinks['hidepatrolled'] = 'rcshowhidepatr'; + } + $hidelinks['hidebots'] = 'rcshowhidebots'; + + $links = array(); + foreach ( $hidelinks as $key => $msg ) { + $reversed = 1-$this->options[$key]; + $link = $sk->makeKnownLinkObj( $self, $showhide[$reversed], + wfArrayToCGI( array( $key => $reversed ), $this->nondefaults ) + ); + $links[$key] = wfMsgHtml( $msg, $link ); + } + + $hl = implode( ' | ', $links ); + + // Store query values in hidden fields so that form submission doesn't lose them + $hidden = array(); + foreach ( $this->nondefaults as $key => $value ) { + if ( $key === 'namespace' ) continue; + if ( $key === 'username' ) continue; + $hidden[] = Xml::hidden( $key, $value ); + } + $hidden = implode( "\n", $hidden ); + $form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . Xml::hidden( 'title', $self->getPrefixedDBkey() ) . Xml::openElement( 'table' ) . @@ -149,7 +293,7 @@ class NewPagesPage extends QueryPage { Xml::label( wfMsg( 'namespace' ), 'namespace' ) . " " . - Xml::namespaceSelector( intval( $this->namespace ), 'all' ) . + Xml::namespaceSelector( $this->options['namespace'], 'all' ) . " @@ -157,75 +301,19 @@ class NewPagesPage extends QueryPage { Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) . " " . - Xml::input( 'username', 30, $this->username, array( 'id' => 'mw-np-username' ) ) . + Xml::input( 'username', 30, $this->options['username'], array( 'id' => 'mw-np-username' ) ) . " - - + " . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . " " . + "" . $hl . "" . Xml::closeElement( 'table' ) . - Xml::hidden( 'offset', $this->offset ) . - Xml::hidden( 'limit', $this->limit ) . + $hidden . Xml::closeElement( 'form' ); return $form; } - /** - * Link parameters - * - * @return array - */ - function linkParameters() { - return( array( 'namespace' => $this->namespace, 'username' => $this->username ) ); - } - -} - -/** - * constructor - */ -function wfSpecialNewpages($par, $specialPage) { - global $wgRequest, $wgContLang; - - list( $limit, $offset ) = wfCheckLimits(); - $namespace = NS_MAIN; - $username = ''; - - if ( $par ) { - $bits = preg_split( '/\s*,\s*/', trim( $par ) ); - foreach ( $bits as $bit ) { - if ( 'shownav' == $bit ) - $shownavigation = true; - if ( is_numeric( $bit ) ) - $limit = $bit; - - $m = array(); - if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) - $limit = intval($m[1]); - if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) ) - $offset = intval($m[1]); - if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) { - $ns = $wgContLang->getNsIndex( $m[1] ); - if( $ns !== false ) { - $namespace = $ns; - } - } - } - } else { - if( $ns = $wgRequest->getText( 'namespace', NS_MAIN ) ) - $namespace = $ns; - if( $un = $wgRequest->getText( 'username' ) ) - $username = $un; - } - - if ( ! isset( $shownavigation ) ) - $shownavigation = ! $specialPage->including(); - - $npp = new NewPagesPage( $namespace, $username ); - - if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) ) - $npp->doQuery( $offset, $limit, $shownavigation ); -} +} \ No newline at end of file