Page MenuHomePhabricator

SpecialWhatlinkshere.patch

Authored By
bzimport
Nov 21 2014, 9:02 PM
Size
4 KB
Referenced Files
None
Subscribers
None

SpecialWhatlinkshere.patch

--- SpecialWhatlinkshere.php 2007-02-15 22:35:35.000000000 +0900
+++ SpecialWhatlinksherenew.php 2007-02-17 09:46:36.000000000 +0900
@@ -18,6 +18,7 @@
var $request, $par;
var $limit, $from, $dir, $target;
var $selfTitle, $skin;
+ var $namespace;
function WhatLinksHerePage( &$request, $par = null ) {
global $wgUser;
@@ -75,6 +76,13 @@
$dbr = wfGetDB( DB_READ );
+ if ( ( $ns = $this->request->getVal( 'namespace', null )) !== null && $ns !== '' ) {
+ $options['namespace'] = intval( $ns );
+ $this->setNamespace( $options['namespace'] );
+ } else {
+ $options['namespace'] = '';
+ }
+
// Some extra validation
$from = intval( $from );
if ( !$from && $dir == 'prev' ) {
@@ -82,6 +90,7 @@
$dir = 'next';
}
+
// Make the query
$plConds = array(
'page_id=pl_from',
@@ -95,6 +104,11 @@
'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";
@@ -124,10 +138,26 @@
if ( !$dbr->numRows( $plRes ) && !$dbr->numRows( $tlRes ) ) {
if ( 0 == $level ) {
$wgOut->addWikiText( wfMsg( 'nolinkshere', $this->target->getPrefixedText() ) );
+ $wgOut->addHTML( $this->whatlinkshereForm( $options ) );
}
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
@@ -187,6 +217,8 @@
$isredir = wfMsg( 'isredirect' );
$istemplate = wfMsg( 'istemplate' );
+ $wgOut->addHTML( $this->whatlinkshereForm( $options ) );
+
if( $level == 0 ) {
$prevnext = $this->getPrevNext( $limit, $prevId, $nextId );
$wgOut->addHTML( $prevnext );
@@ -236,19 +268,19 @@
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 );
if ( 0 != $prevId ) {
- $prevLink = $this->makeSelfLink( $prev, "limit={$limit}&from={$prevId}&dir=prev" );
+ $prevLink = $this->makeSelfLink( $prev, "limit={$limit}&from={$prevId}&dir=prev&namespace={$namespace}" );
} else {
$prevLink = $prev;
}
if ( 0 != $nextId ) {
- $nextLink = $this->makeSelfLink( $next, "limit={$limit}&from={$nextId}" );
+ $nextLink = $this->makeSelfLink( $next, "limit={$limit}&from={$nextId}&namespace={$namespace}" );
} else {
$nextLink = $next;
}
@@ -267,6 +299,36 @@
$fmtLimit = $wgLang->formatNum( $limit );
return $this->makeSelfLink( $fmtLimit, $query );
}
+
+ function whatlinkshereForm( $options ) {
+ global $wgScript, $wgTitle;
+
+ $options['title'] = $wgTitle->getPrefixedText();
+
+ $f = "<form method='get' action=\"$wgScript\">\n";
+ foreach ( $options as $name => $value ) {
+ if( $name === 'namespace') continue;
+ $f .= "\t" . wfElement( 'input', array(
+ 'name' => $name,
+ 'type' => 'hidden',
+ 'value' => $value ) ) . "\n";
+ }
+
+ $f .= '<p>' . wfMsgHtml( 'namespace' ) . ' ' .
+ HTMLnamespaceselector( $options['namespace'], '' ) .
+ wfElement( 'input', array(
+ 'type' => 'submit',
+ 'value' => wfMsg( 'allpagessubmit' ) )
+ ) .
+ "</p></form>\n";
+
+ return $f;
+ }
+
+ function setNamespace( $ns ) {
+ $this->namespace = $ns;
+ }
+
}
?>

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2158
Default Alt Text
SpecialWhatlinkshere.patch (4 KB)

Event Timeline