From: Alexandre Emsenhuber Date: Fri, 14 Oct 2011 14:57:06 +0000 (+0000) Subject: * Moved wfViewPrevNext() to Language::viewPrevNext() so that it can be used in the... X-Git-Tag: 1.31.0-rc.0~27113 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/?a=commitdiff_plain;h=c19eee982eedf6d50ae37f69d4d1a7d3168f2398;p=lhc%2Fweb%2Fwiklou.git * Moved wfViewPrevNext() to Language::viewPrevNext() so that it can be used in the context and not always relying on $wgLang * modified the parameters order in Language::viewPrevNext() in comparaison of wfViewPrevNext() and changed it to require a Title object and extra parameter to be passed as array * Use more modern methods to genrate i18n and HTML * Removed wfNumLink(), not used anymore, only referenced in a comment in MetavidWiki extension * Inlinised wfShowingResults(); I don't see any reason why only this message should get its own function * Replaced all calls to wfViewPrevNext() and wfShowingResults() in core * Simply use OutputPage::addWikiMsg() to display 'specialpage-empty' message * Moved wfSpecialList() near wfViewPrevNext() in GlobalFunction.php --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index d0e381a40d..1219b6d613 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1575,80 +1575,38 @@ function wfShowingResults( $offset, $limit ) { * @param $query String: optional URL query parameter string * @param $atend Bool: optional param for specified if this is the last page * @return String + * @deprecated in 1.19; use Language::viewPrevNext() instead */ function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) { global $wgLang; - $fmtLimit = $wgLang->formatNum( $limit ); - // @todo FIXME: Why on earth this needs one message for the text and another one for tooltip? - # Get prev/next link display text - $prev = wfMsgExt( 'prevn', array( 'parsemag', 'escape' ), $fmtLimit ); - $next = wfMsgExt( 'nextn', array( 'parsemag', 'escape' ), $fmtLimit ); - # Get prev/next link title text - $pTitle = wfMsgExt( 'prevn-title', array( 'parsemag', 'escape' ), $fmtLimit ); - $nTitle = wfMsgExt( 'nextn-title', array( 'parsemag', 'escape' ), $fmtLimit ); - # Fetch the title object + + $query = wfCgiToArray( $query ); + if( is_object( $link ) ) { - $title =& $link; + $title = $link; } else { $title = Title::newFromText( $link ); if( is_null( $title ) ) { return false; } } - # Make 'previous' link - if( 0 != $offset ) { - $po = $offset - $limit; - $po = max( $po, 0 ); - $q = "limit={$limit}&offset={$po}"; - if( $query != '' ) { - $q .= '&' . $query; - } - $plink = '{$prev}"; - } else { - $plink = $prev; - } - # Make 'next' link - $no = $offset + $limit; - $q = "limit={$limit}&offset={$no}"; - if( $query != '' ) { - $q .= '&' . $query; - } - if( $atend ) { - $nlink = $next; - } else { - $nlink = '{$next}"; - } - # Make links to set number of items per page - $nums = $wgLang->pipeList( array( - wfNumLink( $offset, 20, $title, $query ), - wfNumLink( $offset, 50, $title, $query ), - wfNumLink( $offset, 100, $title, $query ), - wfNumLink( $offset, 250, $title, $query ), - wfNumLink( $offset, 500, $title, $query ) - ) ); - return wfMsgHtml( 'viewprevnext', $plink, $nlink, $nums ); + + return $wgLang->viewPrevNext( $title, $offset, $limit, $query, $atend ); } /** - * Generate links for (20|50|100...) items-per-page links + * Make a list item, used by various special pages * - * @param $offset String - * @param $limit Integer - * @param $title Title - * @param $query String: optional URL query parameter string + * @param $page String Page link + * @param $details String Text between brackets + * @param $oppositedm Boolean Add the direction mark opposite to your + * language, to display text properly + * @return String + * @deprecated since 1.19; use Language::specialList() instead */ -function wfNumLink( $offset, $limit, $title, $query = '' ) { +function wfSpecialList( $page, $details, $oppositedm = true ) { global $wgLang; - if( $query == '' ) { - $q = ''; - } else { - $q = $query.'&'; - } - $q .= "limit={$limit}&offset={$offset}"; - $fmtLimit = $wgLang->formatNum( $limit ); - $lTitle = wfMsgExt( 'shown-title', array( 'parsemag', 'escape' ), $limit ); - $s = '{$fmtLimit}"; - return $s; + return $wgLang->specialList( $page, $details, $oppositedm ); } /** @@ -2611,21 +2569,6 @@ function in_string( $needle, $str, $insensitive = false ) { return $func( $str, $needle ) !== false; } -/** - * Make a list item, used by various special pages - * - * @param $page String Page link - * @param $details String Text between brackets - * @param $oppositedm Boolean Add the direction mark opposite to your - * language, to display text properly - * @return String - * @deprecated since 1.19; use Language::specialList() instead - */ -function wfSpecialList( $page, $details, $oppositedm = true ) { - global $wgLang; - return $wgLang->specialList( $page, $details, $oppositedm ); -} - /** * Safety wrapper around ini_get() for boolean settings. * The values returned from ini_get() are pre-normalized for settings diff --git a/includes/QueryPage.php b/includes/QueryPage.php index c119b8541a..eac869adaa 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -502,16 +502,16 @@ abstract class QueryPage extends SpecialPage { if ( $this->shownavigation ) { $out->addHTML( $this->getPageHeader() ); if ( $this->numRows > 0 ) { - $out->addHTML( '

' . wfShowingResults( $this->offset, $this->numRows ) . '

' ); + $out->addHTML( $this->msg( 'showingresults' )->numParams( + $this->numRows, $this->offset + 1 )->parseAsBlock() ); # Disable the "next" link when we reach the end - $paging = wfViewPrevNext( $this->offset, $this->limit, - $this->getTitle( $par ), - wfArrayToCGI( $this->linkParameters() ), ( $this->numRows < $this->limit ) ); + $paging = $this->getLang()->viewPrevNext( $this->getTitle( $par ), $this->offset, + $this->limit, $this->linkParameters(), ( $this->numRows < $this->limit ) ); $out->addHTML( '

' . $paging . '

' ); } else { # No results to show, so don't bother with "showing X of Y" etc. # -- just let the user know and give up now - $out->addHTML( '

' . wfMsgHtml( 'specialpage-empty' ) . '

' ); + $out->addWikiMsg( 'specialpage-empty' ); $out->addHTML( Xml::closeElement( 'div' ) ); return; } @@ -699,7 +699,7 @@ abstract class QueryPage extends SpecialPage { } function feedDesc() { - return wfMsgExt( 'tagline', 'parsemag' ); + return $this->msg( 'tagline' )->text(); } function feedUrl() { diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 74ff8edfc2..6853ccd04b 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -344,9 +344,8 @@ class SpecialSearch extends SpecialPage { if( $num || $this->offset ) { // Show the create link ahead $this->showCreateLink( $t ); - $prevnext = wfViewPrevNext( $this->offset, $this->limit, - SpecialPage::getTitleFor( 'Search' ), - wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ), + $prevnext = $this->getLang()->viewPrevNext( $this->getTitle(), $this->offset, $this->limit, + $this->powerSearchOptions() + array( 'search' => $term ), max( $titleMatchesNum, $textMatchesNum ) < $this->limit ); //$out->addHTML( "

{$prevnext}

\n" ); @@ -1039,7 +1038,10 @@ class SpecialSearch extends SpecialPage { $lang->formatNum( $resultsShown ) ); } elseif ( $resultsShown >= $this->limit ) { - $top = wfShowingResults( $this->offset, $this->limit ); + $top = wfMsgExt( 'showingresults', array( 'parseinline' ), + $lang->formatNum( $this->limit ), + $lang->formatNum( $this->offset + 1 ) + ); } else { $top = wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $lang->formatNum( $this->limit ), diff --git a/languages/Language.php b/languages/Language.php index 1e69eda488..09e1bcb0dd 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3717,6 +3717,67 @@ class Language { return $page . $details; } + /** + * Generate (prev x| next x) (20|50|100...) type links for paging + * + * @param $title Title object to link + * @param $offset Integer offset parameter + * @param $limit Integer limit parameter + * @param $query String optional URL query parameter string + * @param $atend Bool optional param for specified if this is the last page + * @return String + */ + public function viewPrevNext( Title $title, $offset, $limit, array $query = array(), $atend = false ) { + // @todo FIXME: Why on earth this needs one message for the text and another one for tooltip? + + # Make 'previous' link + $prev = wfMessage( 'prevn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text(); + if( $offset > 0 ) { + $plink = $this->numLink( $title, max( $offset - $limit, 0 ), $limit, + $query, $prev, 'prevn-title', 'mw-prevlink' ); + } else { + $plink = htmlspecialchars( $prev ); + } + + # Make 'next' link + $next = wfMessage( 'nextn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text(); + if( $atend ) { + $nlink = htmlspecialchars( $next ); + } else { + $nlink = $this->numLink( $title, $offset + $limit, $limit, + $query, $next, 'prevn-title', 'mw-nextlink' ); + } + + # Make links to set number of items per page + $numLinks = array(); + foreach( array( 20, 50, 100, 250, 500 ) as $num ) { + $numLinks[] = $this->numLink( $title, $offset, $num, + $query, $this->formatNum( $num ), 'shown-title', 'mw-numlink' ); + } + + return wfMessage( 'viewprevnext' )->inLanguage( $this )->title( $title + )->rawParams( $plink, $nlink, $this->pipeList( $numLinks ) )->escaped(); + } + + /** + * Helper function for viewPrevNext() that generates links + * + * @param $title Title object to link + * @param $offset Integer offset parameter + * @param $limit Integer limit parameter + * @param $query Array extra query parameters + * @param $link String text to use for the link; will be escaped + * @param $tooltipMsg String name of the message to use as tooltip + * @param $class String value of the "class" attribute of the link + * @return String HTML fragment + */ + private function numLink( Title $title, $offset, $limit, array $query, $link, $tooltipMsg, $class ) { + $query = array( 'limit' => $limit, 'offset' => $offset ) + $query; + $tooltip = wfMessage( $tooltipMsg )->inLanguage( $this )->title( $title )->numParams( $limit )->text(); + return Html::element( 'a', array( 'href' => $title->getLocalURL( $query ), + 'title' => $tooltip, 'class' => $class ), $link ); + } + /** * Get the conversion rule title, if any. *