X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialNewpages.php;h=a9f58b22a73fcf1b09922beff74619b9f69117e9;hb=903732fd15bfbabf758abec8b15fd3d29df44241;hp=8fe496d59050b86aa3d313344459c3f33f254fbb;hpb=d778ac6aa7579c4ef93452f3deb583a924a63631;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialNewpages.php b/includes/SpecialNewpages.php index 8fe496d590..a9f58b22a7 100644 --- a/includes/SpecialNewpages.php +++ b/includes/SpecialNewpages.php @@ -1,135 +1,211 @@ showList( $par ); + $page->execute( $par, $sp->including() ); } /** * implements Special:Newpages - * @addtogroup SpecialPage + * @ingroup SpecialPage */ class NewPagesForm { + + // Stored objects + protected $opts, $title, $skin; + + // Some internal settings + protected $showNavigation = false; + + protected function setup( $par ) { + global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter; + + // Options + $opts = new FormOptions(); + $this->opts = $opts; // bind + $opts->add( 'hideliu', false ); + $opts->add( 'hidepatrolled', false ); + $opts->add( 'hidebots', false ); + $opts->add( 'limit', 50 ); + $opts->add( 'offset', '' ); + $opts->add( 'namespace', '0' ); + $opts->add( 'username', '' ); + $opts->add( 'feed', '' ); + + // Set values + $opts->fetchValuesFromRequest( $wgRequest ); + if ( $par ) $this->parseParams( $par ); + + // Validate + $opts->validateIntBounds( 'limit', 0, 5000 ); + if( !$wgEnableNewpagesUserFilter ) { + $opts->setValue( 'username', '' ); + } + + // Store some objects + $this->skin = $wgUser->getSkin(); + $this->title = SpecialPage::getTitleFor( 'NewPages' ); + } + + protected function parseParams( $par ) { + global $wgLang; + $bits = preg_split( '/\s*,\s*/', trim( $par ) ); + foreach ( $bits as $bit ) { + if ( 'shownav' == $bit ) + $this->showNavigation = true; + if ( 'hideliu' === $bit ) + $this->opts->setValue( 'hideliu', true ); + if ( 'hidepatrolled' == $bit ) + $this->opts->setValue( 'hidepatrolled', true ); + if ( 'hidebots' == $bit ) + $this->opts->setValue( 'hidebots', true ); + if ( is_numeric( $bit ) ) + $this->opts->setValue( 'limit', intval( $bit ) ); + + $m = array(); + if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) + $this->opts->setValue( 'limit', intval($m[1]) ); + // PG offsets not just digits! + if ( preg_match( '/^offset=([^=]+)$/', $bit, $m ) ) + $this->opts->setValue( 'offset', intval($m[1]) ); + if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) { + $ns = $wgLang->getNsIndex( $m[1] ); + if( $ns !== false ) { + $this->opts->setValue( 'namespace', $ns ); + } + } + } + } + /** * Show a form for filtering namespace and username * + * @param string $par + * @param bool $including true if the page is being included with {{Special:Newpages}} * @return string */ - public function showList() { - global $wgScript, $wgContLang, $wgGroupPermissions, $wgRequest, $wgUser, $wgOut; - $sk = $wgUser->getSkin(); - $align = $wgContLang->isRTL() ? 'left' : 'right'; - $self = SpecialPage::getTitleFor( 'NewPages' ); + public function execute( $par, $including ) { + global $wgLang, $wgGroupPermissions, $wgUser, $wgOut; - // show/hide links - $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' )); + $this->showNavigation = !$including; // Maybe changed in setup + $this->setup( $par ); - $hidelinks = array(); + if( !$including ) { + // Settings + $this->form(); - if ( $wgGroupPermissions['*']['createpage'] === true ) { - $hidelinks['hideliu'] = 'rcshowhideliu'; - } - if ( $wgUser->useNPPatrol() ) { - $hidelinks['hidepatrolled'] = 'rcshowhidepatr'; + $this->setSyndicated(); + $feedType = $this->opts->getValue( 'feed' ); + if( $feedType ) { + return $this->feed( $feedType, $options ); + } } - $hidelinks['hidebots'] = 'rcshowhidebots'; - - $defaults = array( - /* bool */ 'hideliu' => false, - /* bool */ 'hidepatrolled' => false, - /* bool */ 'hidebots' => false, - /* text */ 'namespace' => "0", - /* text */ 'username' => '', - /* int */ 'offset' => 0, - /* int */ 'limit' => 50, - ); - $options = $defaults; - - // 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] ); - } - } - - $wgOut->setSyndicated( true ); - $wgOut->setFeedAppendQuery( "namespace={$options['namespace']}&username={$options['username']}" ); - $feedType = $wgRequest->getVal( 'feed' ); - if( $feedType ) { - wfProfileOut( __METHOD__ ); - return $this->feed( $feedType, $options ); + $pager = new NewPagesPager( $this, $this->opts ); + $pager->mLimit = $this->opts->getValue( 'limit' ); + $pager->mOffset = $this->opts->getValue( 'offset' ); + + if( $pager->getNumRows() ) { + $navigation = ''; + if ( $this->showNavigation ) $navigation = $pager->getNavigationBar(); + $wgOut->addHTML( $navigation . $pager->getBody() . $navigation ); + } else { + $wgOut->addWikiMsg( 'specialpage-empty' ); } + } + + protected function filterLinks() { + global $wgGroupPermissions, $wgUser; + + // show/hide links + $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) ); - $nondefaults = array(); - foreach ( $options as $v => $t ) { - if ( $v === 'offset' ) continue; # Reset offset if parameters change - wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults ); - } + // Option value -> message mapping + $filters = array( + 'hideliu' => 'rcshowhideliu', + 'hidepatrolled' => 'rcshowhidepatr', + 'hidebots' => 'rcshowhidebots' + ); + + // Disable some if needed + if ( $wgGroupPermissions['*']['createpage'] !== true ) + unset($filters['hideliu']); + + if ( !$wgUser->useNPPatrol() ) + unset($filters['hidepatrolled']); $links = array(); - foreach ( $hidelinks as $key => $msg ) { - $reversed = 1 - $options[$key]; - $link = $sk->makeKnownLinkObj( $self, $showhide[$reversed], - wfArrayToCGI( array( $key => $reversed ), $nondefaults ) + $changed = $this->opts->getChangedValues(); + unset($changed['offset']); // Reset offset if query type changes + + foreach ( $filters as $key => $msg ) { + $onoff = 1 - $this->opts->getValue($key); + $link = $this->skin->makeKnownLinkObj( $this->title, $showhide[$onoff], + wfArrayToCGI( array( $key => $onoff ), $changed ) ); $links[$key] = wfMsgHtml( $msg, $link ); } - $hl = implode( ' | ', $links ); + return implode( ' | ', $links ); + } + + protected function form() { + global $wgOut, $wgEnableNewpagesUserFilter, $wgScript; + + // Consume values + $this->opts->consumeValue( 'offset' ); // don't carry offset, DWIW + $namespace = $this->opts->consumeValue( 'namespace' ); + $username = $this->opts->consumeValue( 'username' ); + + // Check username input validity + $ut = Title::makeTitleSafe( NS_USER, $username ); + $userText = $ut ? $ut->getText() : ''; // Store query values in hidden fields so that form submission doesn't lose them $hidden = array(); - foreach ( $nondefaults as $key => $value ) { - if ( $key === 'namespace' ) continue; - if ( $key === 'username' ) continue; + foreach ( $this->opts->getUnconsumedValues() as $key => $value ) { $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( 'fieldset' ) . - Xml::element( 'legend', null, wfMsg( 'newpages' ) ) . + $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . + Xml::hidden( 'title', $this->title->getPrefixedDBkey() ) . + Xml::fieldset( wfMsg( 'newpages' ) ) . Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) . "
' . wfMsgHtml( 'specialpage-empty' ) . '
' ); - } + protected function setSyndicated() { + global $wgOut; + $queryParams = array( + 'namespace' => $this->opts->getValue( 'namespace' ), + 'username' => $this->opts->getValue( 'username' ) + ); + $wgOut->setSyndicated( true ); + $wgOut->setFeedAppendQuery( wfArrayToCGI( $queryParams ) ); } - + /** * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment * @@ -163,24 +236,19 @@ class NewPagesForm { public function formatRow( $result ) { global $wgLang, $wgContLang, $wgUser; $dm = $wgContLang->getDirMark(); - - static $skin=null; - - if( is_null( $skin ) ) - $skin = $wgUser->getSkin(); $title = Title::makeTitleSafe( $result->rc_namespace, $result->rc_title ); $time = $wgLang->timeAndDate( $result->rc_timestamp, true ); - $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ? 'rcid=' . $result->rc_id : '' ); - $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' ); - $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), - $wgLang->formatNum( htmlspecialchars( $result->length ) ) ); - $ulink = $skin->userLink( $result->rc_user, $result->rc_user_text ) . ' ' . - $skin->userToolLinks( $result->rc_user, $result->rc_user_text ); - $comment = $skin->commentBlock( $result->rc_comment ); - $css = $this->patrollable( $result ) ? 'not-patrolled' : ''; - - return "' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' . - htmlspecialchars( $revision->getComment() ) . "
\n' . htmlspecialchars( $revision->getUserText() ) . ': ' . + htmlspecialchars( $revision->getComment() ) . + "
\n