<?php
-
-function wfSpecialWhatlinkshere($par = NULL)
-{
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ * Entry point
+ * @param string $par An article name ??
+ */
+function wfSpecialWhatlinkshere($par = NULL) {
global $wgUser, $wgOut, $wgRequest;
- $fname = "wfSpecialWhatlinkshere";
+ $fname = 'wfSpecialWhatlinkshere';
- $target = $wgRequest->getVal( 'target' );
- $limit = $wgRequest->getInt( 'limit', 500 );
-
- if(!empty($par)) {
- $target = $par;
- } else if ( is_null( $target ) ) {
- $wgOut->errorpage( "notargettitle", "notargettext" );
+ $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
+ list( $limit, $offset ) = $wgRequest->getLimitOffset();
+
+ if (is_null($target)) {
+ $wgOut->errorpage( 'notargettitle', 'notargettext' );
return;
}
$nt = Title::newFromURL( $target );
if( !$nt ) {
- $wgOut->errorpage( "notargettitle", "notargettext" );
+ $wgOut->errorpage( 'notargettitle', 'notargettext' );
return;
}
$wgOut->setPagetitle( $nt->getPrefixedText() );
- $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
+ $wgOut->setSubtitle( wfMsg( 'linklistsub' ) );
- $id = $nt->getArticleID();
$sk = $wgUser->getSkin();
- $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
+ $isredir = ' (' . wfMsg( 'isredirect' ) . ")\n";
- $wgOut->addHTML("< ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
- $dbr =& wfGetDB( DB_SLAVE );
- extract( $dbr->tableNames( 'cur', 'brokenlinks', 'links' ) );
+ $wgOut->addHTML('< '.$sk->makeKnownLinkObj($nt, '', 'redirect=no' )."<br />\n");
- if ( 0 == $id ) {
- $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM $brokenlinks,$cur WHERE bl_to='" .
- $dbr->strencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT $limit";
- $res = $dbr->query( $sql, $fname );
+ $specialTitle = Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' );
+ $wgOut->addHTML( wfViewPrevNext( $offset, $limit, $specialTitle, 'target=' . urlencode( $target ) ) );
- if ( 0 == $dbr->numRows( $res ) ) {
- $wgOut->addHTML( wfMsg( "nolinkshere" ) );
- } else {
- $wgOut->addHTML( wfMsg( "linkshere" ) );
- $wgOut->addHTML( "\n<ul>" );
-
- while ( $row = $dbr->fetchObject( $res ) ) {
- $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
- if( !$nt ) {
- continue;
- }
- $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
- $wgOut->addHTML( "<li>{$link}" );
-
- if ( $row->cur_is_redirect ) {
- $wgOut->addHTML( $isredir );
- wfShowIndirectLinks( 1, $row->cur_id, $limit );
- }
- $wgOut->addHTML( "</li>\n" );
- }
- $wgOut->addHTML( "</ul>\n" );
- $dbr->freeResult( $res );
- }
- } else {
- wfShowIndirectLinks( 0, $id, $limit );
- }
+ wfShowIndirectLinks( 0, $nt, $limit, $offset );
+ $wgOut->addHTML( wfViewPrevNext( $offset, $limit, $specialTitle, 'target=' . urlencode( $target ) ) );
}
-function wfShowIndirectLinks( $level, $lid, $limit )
-{
+/**
+ * @param int $level
+ * @param Title $target
+ * @param int $limit
+ * @param int $offset
+ * @access private
+ */
+function wfShowIndirectLinks( $level, $target, $limit, $offset = 0 ) {
global $wgOut, $wgUser;
- $fname = "wfShowIndirectLinks";
+ $fname = 'wfShowIndirectLinks';
$dbr =& wfGetDB( DB_READ );
- extract( $dbr->tableNames( 'links','cur' ) );
+
+ if ( $level == 0 ) {
+ $limitSql = $dbr->limitResult( $limit, $offset );
+ } else {
+ $limitSql = "LIMIT $limit";
+ }
- $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM $links,$cur WHERE l_to={$lid} AND l_from=cur_id LIMIT $limit";
- $res = $dbr->query( $sql, $fname );
+ $res = $dbr->select( array( 'pagelinks', 'page' ),
+ array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ),
+ array(
+ 'pl_from=page_id',
+ 'pl_namespace' => $target->getNamespace(),
+ 'pl_title' => $target->getDbKey() ),
+ $fname,
+ $limitSql );
if ( 0 == $dbr->numRows( $res ) ) {
if ( 0 == $level ) {
- $wgOut->addHTML( wfMsg( "nolinkshere" ) );
+ $wgOut->addHTML( wfMsg( 'nolinkshere' ) );
}
return;
}
if ( 0 == $level ) {
- $wgOut->addHTML( wfMsg( "linkshere" ) );
+ $wgOut->addHTML( wfMsg( 'linkshere' ) );
}
$sk = $wgUser->getSkin();
- $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
+ $isredir = ' (' . wfMsg( 'isredirect' ) . ")\n";
- $wgOut->addHTML( "<ul>" );
+ $wgOut->addHTML( '<ul>' );
while ( $row = $dbr->fetchObject( $res ) ) {
- $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
- if( !$nt ) {
- $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
- continue;
- }
+ $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
- if ( $row->cur_is_redirect ) {
- $extra = "redirect=no";
+ if ( $row->page_is_redirect ) {
+ $extra = 'redirect=no';
} else {
- $extra = "";
+ $extra = '';
}
- $link = $sk->makeKnownLinkObj( $nt, "", $extra );
- $wgOut->addHTML( "<li>{$link}" );
+ $link = $sk->makeKnownLinkObj( $nt, '', $extra );
+ $wgOut->addHTML( '<li>'.$link );
- if ( $row->cur_is_redirect ) {
+ if ( $row->page_is_redirect ) {
$wgOut->addHTML( $isredir );
if ( $level < 2 ) {
- wfShowIndirectLinks( $level + 1, $row->cur_id, $limit );
+ wfShowIndirectLinks( $level + 1, $nt, 500 );
}
}
$wgOut->addHTML( "</li>\n" );