From 39c665b46787e82a8b6748d8506b60bcb8e2865c Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Sat, 12 Apr 2008 07:25:20 +0000 Subject: [PATCH] * (bug 6934) Allow separated inclusions, links, redirects on whatlinkshere --- RELEASE-NOTES | 1 + includes/SpecialWhatlinkshere.php | 67 ++++++++++++++++++++++++------- includes/WebRequest.php | 18 +++++++++ languages/messages/MessagesEn.php | 3 ++ languages/messages/MessagesRu.php | 3 ++ 5 files changed, 77 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b2d022c6af..07dd620938 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -70,6 +70,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN ** (bug 6332) Lacking entry Mainpage-url ** (bug 8617) Separate main page url and name * Automatically add old redirects to the redirect table when needed +* (bug 6934) Allow separated inclusions, links, redirects on whatlinkshere === Bug fixes in 1.13 === diff --git a/includes/SpecialWhatlinkshere.php b/includes/SpecialWhatlinkshere.php index 56b977ea70..2871cccc24 100644 --- a/includes/SpecialWhatlinkshere.php +++ b/includes/SpecialWhatlinkshere.php @@ -22,6 +22,7 @@ class WhatLinksHerePage { var $request, $par; var $limit, $from, $back, $target; var $selfTitle, $skin; + var $hideredirs, $hidetrans, $hidelinks, $fetchlinks; private $namespace; @@ -42,6 +43,11 @@ class WhatLinksHerePage { $this->from = $this->request->getInt( 'from' ); $this->back = $this->request->getInt( 'back' ); + $this->hideredirs = $this->request->getInt( 'hideredirs' ); + $this->hidetrans = $this->request->getInt( 'hidetrans' ); + $this->hidelinks = $this->request->getInt( 'hidelinks' ); + $this->fetchlinks = !$this->hidelinks || !$this->hideredirs; + $targetString = isset($this->par) ? $this->par : $this->request->getVal( 'target' ); if ( is_null( $targetString ) ) { @@ -121,15 +127,19 @@ class WhatLinksHerePage { $options['LIMIT'] = $queryLimit; $fields = array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ); - $options['ORDER BY'] = 'pl_from'; - $plRes = $dbr->select( array( 'pagelinks', 'page' ), $fields, - $plConds, $fname, $options ); + if( $this->fetchlinks ) { + $options['ORDER BY'] = 'pl_from'; + $plRes = $dbr->select( array( 'pagelinks', 'page' ), $fields, + $plConds, $fname, $options ); + } - $options['ORDER BY'] = 'tl_from'; - $tlRes = $dbr->select( array( 'templatelinks', 'page' ), $fields, - $tlConds, $fname, $options ); + if( !$this->hidetrans ) { + $options['ORDER BY'] = 'tl_from'; + $tlRes = $dbr->select( array( 'templatelinks', 'page' ), $fields, + $tlConds, $fname, $options ); + } - if ( !$dbr->numRows( $plRes ) && !$dbr->numRows( $tlRes ) ) { + if( ( !$this->fetchlinks || !$dbr->numRows( $plRes ) ) && ( $this->hidetrans || !$dbr->numRows( $tlRes ) ) ) { if ( 0 == $level ) { $options = array(); // reinitialize for a further namespace search // really no links to here @@ -139,6 +149,9 @@ class WhatLinksHerePage { $wgOut->addHTML( $this->whatlinkshereForm( $options ) ); $errMsg = isset( $this->namespace ) ? 'nolinkshere-ns' : 'nolinkshere'; $wgOut->addWikiMsg( $errMsg, $this->target->getPrefixedText() ); + // Show filters only if there are links + if( $this->hidelinks || $this->hidetrans || $this->hideredirs ) + $wgOut->addHTML( $this->getFilterPanel() ); } return; } @@ -161,16 +174,21 @@ class WhatLinksHerePage { // 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 - while ( $row = $dbr->fetchObject( $plRes ) ) { - $row->is_template = 0; - $rows[$row->page_id] = $row; + if( $this->fetchlinks ) { + while ( $row = $dbr->fetchObject( $plRes ) ) { + $row->is_template = 0; + $rows[$row->page_id] = $row; + } + $dbr->freeResult( $plRes ); + } - $dbr->freeResult( $plRes ); - while ( $row = $dbr->fetchObject( $tlRes ) ) { - $row->is_template = 1; - $rows[$row->page_id] = $row; + if( !$this->hidetrans ) { + while ( $row = $dbr->fetchObject( $tlRes ) ) { + $row->is_template = 1; + $rows[$row->page_id] = $row; + } + $dbr->freeResult( $tlRes ); } - $dbr->freeResult( $tlRes ); // Sort by key and then change the keys to 0-based indices ksort( $rows ); @@ -193,6 +211,7 @@ class WhatLinksHerePage { if ( $level == 0 ) { $wgOut->addHTML( $this->whatlinkshereForm( $options ) ); + $wgOut->addHTML( $this->getFilterPanel() ); $wgOut->addWikiMsg( 'linkshere', $this->target->getPrefixedText() ); $prevnext = $this->getPrevNext( $limit, $prevId, $nextId, $options['namespace'] ); @@ -203,6 +222,11 @@ class WhatLinksHerePage { foreach ( $rows as $row ) { $nt = Title::makeTitle( $row->page_namespace, $row->page_title ); + if( $this->hideredirs && $row->page_is_redirect ) + continue; + if( $this->hidelinks && ( !$row->page_is_redirect && !$row->is_template ) ) + continue; + if ( $row->page_is_redirect ) { $extra = 'redirect=no'; } else { @@ -319,4 +343,17 @@ class WhatLinksHerePage { $this->namespace = $ns; } + function getFilterPanel() { + $show = wfMsg( 'show' ); + $hide = wfMsg( 'hide' ); + $links = array(); + foreach( array( 'hidetrans', 'hidelinks', 'hideredirs' ) as $type ) { + $chosen = $this->$type; + $msg = wfMsgHtml( "whatlinkshere-{$type}", $chosen ? $show : $hide ); + $url = $this->request->appendQueryValue( $type, intval( !$chosen ), true ); + $links[] = $this->makeSelfLink( $msg, $url ); + } + return '

' . implode( ' | ', $links ) . '

'; + } + } diff --git a/includes/WebRequest.php b/includes/WebRequest.php index a65e722983..398fce0815 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -490,6 +490,24 @@ class WebRequest { return htmlspecialchars( $this->appendQuery( $query ) ); } + function appendQueryValue( $key, $value, $onlyquery = false ) { + return $this->appendQueryArray( array( $key => $value ), $onlyquery ); + } + + /** + * Appends or replaces value of query variables. + * @param $array Array of values to replace/add to query + * @return string + */ + function appendQueryArray( $array, $onlyquery = false ) { + global $wgTitle; + $newquery = $_GET; + unset( $newquery['title'] ); + $newquery = array_merge( $newquery, $array ); + $query = wfArrayToCGI( $newquery ); + return $onlyquery ? $query : $wgTitle->getLocalURL( $basequery ); + } + /** * Check for limit and offset parameters on the input, and return sensible * defaults if not given. The limit must be positive and is capped at 5000. diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 16b68e628c..7f07b1ca60 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2171,6 +2171,9 @@ $1', 'whatlinkshere-prev' => '{{PLURAL:$1|previous|previous $1}}', 'whatlinkshere-next' => '{{PLURAL:$1|next|next $1}}', 'whatlinkshere-links' => '← links', +'whatlinkshere-hideredirs' => '$1 redirects', +'whatlinkshere-hidetrans' => '$1 transclusions', +'whatlinkshere-hidelinks' => '$1 links', # Block/unblock 'blockip' => 'Block user', diff --git a/languages/messages/MessagesRu.php b/languages/messages/MessagesRu.php index 1088f3598e..5e0b7fbfbc 100644 --- a/languages/messages/MessagesRu.php +++ b/languages/messages/MessagesRu.php @@ -1744,6 +1744,9 @@ $1', 'whatlinkshere-prev' => '{{PLURAL:$1|предыдущая|предыдущие|предыдущие}} $1', 'whatlinkshere-next' => '{{PLURAL:$1|следующая|следующие|следующие}} $1', 'whatlinkshere-links' => '← ссылки', +'whatlinkshere-hideredirs' => '$1 перенаправления', +'whatlinkshere-hidetrans' => '$1 включения', +'whatlinkshere-hidelinks' => '$1 ссылки', # Block/unblock 'blockip' => 'Заблокировать', -- 2.20.1