From e80c925a8701574df996c14817eee0702b754505 Mon Sep 17 00:00:00 2001 From: Raimond Spekking Date: Thu, 22 Mar 2007 09:22:24 +0000 Subject: [PATCH] * (bug 4624) Namespace selection for Special:Whatlinkshere Based on a patch of Suisui Found another bug: scrolling backwards at Special:Whatlinkshere was broken since ? 'previous' shows always the first page in reversed order but not the real previous page. Fixed now by changing backwards scrolling mechanism. * (bug 4777) Separate prev/next messages for Special:Whatlinkshere --- RELEASE-NOTES | 7 +- includes/SpecialWhatlinkshere.php | 145 ++++++++++++++++++------------ languages/messages/MessagesDe.php | 7 +- languages/messages/MessagesEn.php | 21 +++-- maintenance/language/messages.inc | 3 + 5 files changed, 112 insertions(+), 71 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 551221443d..fce8e9f65f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -30,10 +30,9 @@ lighter making things easier to read. == Changes since 1.9 == -* (bug 5142) Fixed call of hook ArticleViewHeader * (bug 7292) Fix site statistics when moving pages in/out of content namespaces * (bug 6937) Introduce "statistics-footer" message, appended to Special:Statistics -* (bug 8531) Correct local name of Lingála (patch by Raymond) +* (bug 8531) Correct local name of Lingála * (bug 6638) List block flags in block log entries * New script maintenance/language/checkExtensioni18n.php used to check i18n progress in the extension repository. @@ -284,6 +283,10 @@ lighter making things easier to read. Warning on upload of images with uppercase extension if image with lowercase extension exists * (bug 9363) Fix Postgres error on Recentchangeslinked +* (bug 5142) Fixed call of hook ArticleViewHeader +* (bug 4624) Namespace selection for Special:Whatlinkshere + Scrolling backwards at Special:Whatlinkshere fixed +* (bug 4777) Separate prev/next messages for Special:Whatlinkshere == Languages updated == diff --git a/includes/SpecialWhatlinkshere.php b/includes/SpecialWhatlinkshere.php index c131c00655..fecb1802b0 100644 --- a/includes/SpecialWhatlinkshere.php +++ b/includes/SpecialWhatlinkshere.php @@ -16,7 +16,7 @@ function wfSpecialWhatlinkshere($par = NULL) { class WhatLinksHerePage { var $request, $par; - var $limit, $from, $dir, $target; + var $limit, $from, $back, $target, $namespace; var $selfTitle, $skin; function WhatLinksHerePage( &$request, $par = null ) { @@ -34,10 +34,7 @@ class WhatLinksHerePage { $this->limit = 50; } $this->from = $this->request->getInt( 'from' ); - $this->dir = $this->request->getText( 'dir', 'next' ); - if ( $this->dir != 'prev' ) { - $this->dir = 'next'; - } + $this->back = $this->request->getInt( 'back' ); $targetString = isset($this->par) ? $this->par : $this->request->getVal( 'target' ); @@ -58,7 +55,7 @@ class WhatLinksHerePage { $wgOut->addHTML( wfMsg( 'whatlinkshere-barrow' ) . ' ' .$this->skin->makeLinkObj($this->target, '', 'redirect=no' )."
\n"); - $this->showIndirectLinks( 0, $this->target, $this->limit, $this->from, $this->dir ); + $this->showIndirectLinks( 0, $this->target, $this->limit, $this->from, $this->back ); } /** @@ -66,20 +63,20 @@ class WhatLinksHerePage { * @param Title $target Target title * @param int $limit Number of entries to display * @param Title $from Display from this article ID - * @param string $dir 'next' or 'prev', whether $fromTitle is the start or end of the list + * @param Title $back Display from this article ID at backwards scrolling * @private */ - function showIndirectLinks( $level, $target, $limit, $from = 0, $dir = 'next' ) { + function showIndirectLinks( $level, $target, $limit, $from = 0, $back = 0 ) { global $wgOut; $fname = 'WhatLinksHerePage::showIndirectLinks'; $dbr = wfGetDB( DB_READ ); - // Some extra validation - $from = intval( $from ); - if ( !$from && $dir == 'prev' ) { - // Before start? No make sense - $dir = 'next'; + if ( ( $ns = $this->request->getVal( 'namespace', null )) !== null && $ns !== '' ) { + $options['namespace'] = intval( $ns ); + $this->setNamespace( $options['namespace'] ); + } else { + $options['namespace'] = ''; } // Make the query @@ -95,14 +92,14 @@ class WhatLinksHerePage { 'tl_title' => $target->getDBkey(), ); + if ( $this->namespace !== null ){ + $plConds['page_namespace'] = (int)$this->namespace; + $tlConds['page_namespace'] = (int)$this->namespace; + } + if ( $from ) { - if ( 'prev' == $dir ) { - $offsetCond = "page_id < $from"; - $options = array( 'ORDER BY page_id DESC' ); - } else { - $offsetCond = "page_id >= $from"; - $options = array( 'ORDER BY page_id' ); - } + $offsetCond = "page_id >= $from"; + $options = array( 'ORDER BY page_id' ); } else { $offsetCond = false; $options = array( 'ORDER BY page_id,is_template DESC' ); @@ -120,14 +117,37 @@ class WhatLinksHerePage { $plConds, $fname, $options ); $tlRes = $dbr->select( array( 'templatelinks', 'page' ), $fields, $tlConds, $fname, $options ); - if ( !$dbr->numRows( $plRes ) && !$dbr->numRows( $tlRes ) ) { - if ( 0 == $level ) { + if ( 0 == $level && !isset( $this->namespace ) ) { + // really no links to here $wgOut->addWikiText( wfMsg( 'nolinkshere', $this->target->getPrefixedText() ) ); + } elseif ( 0 == $level && isset( $this->namespace ) ) { + // no links from requested namespace to here + $options = array(); // reinitialize for a further namespace search + $options['namespace'] = $this->namespace; + $options['target'] = $this->target->getPrefixedText(); + list( $options['limit'], $options['offset']) = wfCheckLimits(); + $wgOut->addHTML( $this->whatlinkshereForm( $options ) ); + $wgOut->addWikiText( wfMsg( 'nolinkshere-ns', $this->target->getPrefixedText(), $this->namespace ) ); } return; } + $options = array(); + list( $options['limit'], $options['offset']) = wfCheckLimits(); + if ( ( $ns = $this->request->getVal( 'namespace', null ) ) !== null && $ns !== '' && ctype_digit($ns) ) { + $options['namespace'] = intval( $ns ); + $this->setNamespace( $options['namespace'] ); + } else { + $options['namespace'] = ''; + $this->setNamespace( null ); + } + $options['offset'] = $this->request->getVal( 'offset' ); + /* Offset must be an integral. */ + if ( !strlen( $options['offset'] ) || !preg_match( '/^[0-9]+$/', $options['offset'] ) ) + $options['offset'] = ''; + $options['target'] = $this->target->getPrefixedDBkey(); + // Read the rows into an array and remove duplicates // templatelinks comes second so that the templatelinks row overwrites the // pagelinks row, so we get (inclusion) rather than nothing @@ -149,46 +169,27 @@ class WhatLinksHerePage { $numRows = count( $rows ); // Work out the start and end IDs, for prev/next links - if ( $dir == 'prev' ) { - // Descending order - if ( $numRows > $limit ) { - // More rows available before these ones - // Get the ID from the next row past the end of the displayed set - $prevId = $rows[$limit]->page_id; - // Remove undisplayed rows - $rows = array_slice( $rows, 0, $limit ); - } else { - // No more rows available before - $prevId = 0; - } - // Assume that the ID specified in $from exists, so there must be another page - $nextId = $from; - - // Reverse order ready for display - $rows = array_reverse( $rows ); + if ( $numRows > $limit ) { + // More rows available after these ones + // Get the ID from the last row in the result set + $nextId = $rows[$limit]->page_id; + // Remove undisplayed rows + $rows = array_slice( $rows, 0, $limit ); } else { - // Ascending - if ( $numRows > $limit ) { - // More rows available after these ones - // Get the ID from the last row in the result set - $nextId = $rows[$limit]->page_id; - // Remove undisplayed rows - $rows = array_slice( $rows, 0, $limit ); - } else { - // No more rows after - $nextId = false; - } - $prevId = $from; + // No more rows after + $nextId = false; } + $prevId = $from; - if ( 0 == $level ) { + if ( $level == 0 ) { + $wgOut->addHTML( $this->whatlinkshereForm( $options ) ); $wgOut->addWikiText( wfMsg( 'linkshere', $this->target->getPrefixedText() ) ); } $isredir = wfMsg( 'isredirect' ); $istemplate = wfMsg( 'istemplate' ); if( $level == 0 ) { - $prevnext = $this->getPrevNext( $limit, $prevId, $nextId ); + $prevnext = $this->getPrevNext( $limit, $prevId, $nextId, $options['namespace'] ); $wgOut->addHTML( $prevnext ); } @@ -236,19 +237,19 @@ class WhatLinksHerePage { return $this->skin->makeKnownLinkObj( $this->selfTitle, $text, $query ); } - function getPrevNext( $limit, $prevId, $nextId ) { + function getPrevNext( $limit, $prevId, $nextId, $namespace ) { global $wgLang; $fmtLimit = $wgLang->formatNum( $limit ); - $prev = wfMsg( 'prevn', $fmtLimit ); - $next = wfMsg( 'nextn', $fmtLimit ); + $prev = wfMsg( 'whatlinkshere-prev', $fmtLimit ); + $next = wfMsg( 'whatlinkshere-next', $fmtLimit ); if ( 0 != $prevId ) { - $prevLink = $this->makeSelfLink( $prev, "limit={$limit}&from={$prevId}&dir=prev" ); + $prevLink = $this->makeSelfLink( $prev, "limit={$limit}&from={$this->back}&back={$fromId}&namespace={$namespace}" ); } else { $prevLink = $prev; } if ( 0 != $nextId ) { - $nextLink = $this->makeSelfLink( $next, "limit={$limit}&from={$nextId}" ); + $nextLink = $this->makeSelfLink( $next, "limit={$limit}&from={$nextId}&back={$prevId}&namespace={$namespace}" ); } else { $nextLink = $next; } @@ -267,6 +268,34 @@ class WhatLinksHerePage { $fmtLimit = $wgLang->formatNum( $limit ); return $this->makeSelfLink( $fmtLimit, $query ); } + + function whatlinkshereForm( $options ) { + global $wgScript, $wgTitle; + + $options['title'] = $wgTitle->getPrefixedText(); + + $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => "$wgScript" ) ) . + '
' . + Xml::element( 'legend', array(), wfMsg( 'whatlinkshere' ) ); + + foreach ( $options as $name => $value ) { + if( $name === 'namespace') continue; + $f .= "\t" . Xml::hidden( $name, $value ). "\n"; + } + + $f .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' . + Xml::namespaceSelector( $options['namespace'], '' ) . + Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . + '
' . + Xml::closeElement( 'form' ) . "\n"; + + return $f; + } + + function setNamespace( $ns ) { + $this->namespace = $ns; + } + } ?> diff --git a/languages/messages/MessagesDe.php b/languages/messages/MessagesDe.php index e0a7e03261..26b166984e 100644 --- a/languages/messages/MessagesDe.php +++ b/languages/messages/MessagesDe.php @@ -1479,10 +1479,13 @@ Im [[Special:Log/delete|Lösch-Logbuch]] finden Sie eine Übersicht der kürzlic 'notargettitle' => 'Keine Seite angegeben', 'notargettext' => 'Sie haben nicht angegeben, auf welche Seite diese Funktion angewendet werden soll.', 'linklistsub' => '(Liste der Verweise)', -'linkshere' => "Die folgenden Seiten verweisen auf '''[[:$1]]''':", -'nolinkshere' => "Keine Seite verweist auf '''[[:$1]]'''.", +'linkshere' => "Die folgenden Seiten verweisen auf '''„[[:$1]]“''':", +'nolinkshere' => "Keine Seite verweist auf '''„[[:$1]]“'''.", +'nolinkshere-ns' => "Keine Seite verweist auf '''„[[:$1]]“''' im Namensraum „{{ns:$2}}“.", 'isredirect' => 'Weiterleitungsseite', 'istemplate' => 'Vorlageneinbindung', +'whatlinkshere-prev' => 'vorherige $1', +'whatlinkshere-next' => 'nächste $1', # Block/unblock 'blockip' => 'IP-Adresse/Benutzer sperren', diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index dd074257c7..be3b103170 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1897,17 +1897,20 @@ Consult the [[Special:Log/delete|deletion log]] for a record of recent deletions # What links here # -'whatlinkshere' => 'What links here', +'whatlinkshere' => 'What links here', 'whatlinkshere-summary' => '', -'whatlinkshere-barrow' => '<', -'notargettitle' => 'No target', -'notargettext' => 'You have not specified a target page or user +'whatlinkshere-barrow' => '<', +'notargettitle' => 'No target', +'notargettext' => 'You have not specified a target page or user to perform this function on.', -'linklistsub' => '(List of links)', -'linkshere' => "The following pages link to '''[[:$1]]''':", -'nolinkshere' => "No pages link to '''[[:$1]]'''.", -'isredirect' => 'redirect page', -'istemplate' => 'inclusion', +'linklistsub' => '(List of links)', +'linkshere' => "The following pages link to '''[[:$1]]''':", +'nolinkshere' => "No pages link to '''[[:$1]]'''.", +'nolinkshere-ns' => "No pages link to '''[[:$1]]''' at namespace {{ns:$2}}.", +'isredirect' => 'redirect page', +'istemplate' => 'inclusion', +'whatlinkshere-prev' => 'previous $1', +'whatlinkshere-next' => 'next $1', # Block/unblock IP # diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index b7ef9b7dec..3e554d9030 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1233,8 +1233,11 @@ $wgMessageStructure = array( 'linklistsub', 'linkshere', 'nolinkshere', + 'nolinkshere-ns', 'isredirect', 'istemplate', + 'whatlinkshere-prev', + 'whatlinkshere-next', ), 'block' => array( 'blockip', -- 2.20.1