X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialWhatlinkshere.php;h=4d5bfa0564d75d98f04d0ad76a633fe522d8c5e5;hb=027030d18104525bd9c3e7b6fb68251e9ead6820;hp=d7bfa3d69f8659645554aab40ad858a965c06a63;hpb=ffd7f8d72470bf5f39c8f768a7e0ca2399494419;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/SpecialWhatlinkshere.php b/includes/SpecialWhatlinkshere.php
index d7bfa3d69f..4d5bfa0564 100644
--- a/includes/SpecialWhatlinkshere.php
+++ b/includes/SpecialWhatlinkshere.php
@@ -1,122 +1,127 @@
-
-
-function wfSpecialWhatlinkshere($par = NULL)
-{
- global $wgUser, $wgOut, $target;
- $fname = "wfSpecialWhatlinkshere";
-
- if($par) {
- $target = $par;
- } else {
- $target = wfCleanQueryVar( $_REQUEST['target'] );
- }
- if ( "" == $target ) {
- $wgOut->errorpage( "notargettitle", "notargettext" );
+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";
- if ( 0 == $id ) {
- $sql = "SELECT DISTINCT bl_from FROM brokenlinks WHERE bl_to='" .
- wfStrencode( $nt->getPrefixedDBkey() ) . "' LIMIT 500";
- $res = wfQuery( $sql, DB_READ, $fname );
+ $wgOut->addHTML('< '.$sk->makeKnownLinkObj($nt, '', 'redirect=no' )."
\n");
- if ( 0 == wfNumRows( $res ) ) {
- $wgOut->addHTML( wfMsg( "nolinkshere" ) );
- } else {
- $wgOut->addHTML( wfMsg( "linkshere" ) );
- $wgOut->addHTML( "\n
" );
-
- while ( $row = wfFetchObject( $res ) ) {
- $lid = $row->bl_from;
- $sql = "SELECT cur_namespace,cur_title,cur_is_redirect " .
- "FROM cur WHERE cur_id={$lid}";
- $res2 = wfQuery( $sql, DB_READ, $fname );
- $s = wfFetchObject( $res2 );
-
- $n = Title::makeName( $s->cur_namespace, $s->cur_title );
- $link = $sk->makeKnownLink( $n, "", "redirect=no" );
- $wgOut->addHTML( "- {$link}" );
-
- if ( 1 == $s->cur_is_redirect ) {
- $wgOut->addHTML( $isredir );
- wfShowIndirectLinks( 1, $lid );
- }
- $wgOut->addHTML( "
\n" );
- }
- $wgOut->addHTML( "
\n" );
- wfFreeResult( $res );
- }
- } else {
- wfShowIndirectLinks( 0, $id );
- }
+ wfShowIndirectLinks( 0, $nt, $limit, $offset );
}
-function wfShowIndirectLinks( $level, $lid )
-{
+/**
+ * @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";
-
- $sql = "SELECT DISTINCT l_from FROM links WHERE l_to={$lid} ORDER BY l_from LIMIT 500";
- $res = wfQuery( $sql, DB_READ, $fname );
-
- if ( 0 == wfNumRows( $res ) ) {
+ $fname = 'wfShowIndirectLinks';
+
+ $dbr =& wfGetDB( DB_READ );
+
+ // Read one extra row as an at-end check
+ $queryLimit = $limit + 1;
+ $limitSql = ( $level == 0 )
+ ? "$offset,$queryLimit"
+ : $queryLimit;
+
+ $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,
+ array( 'LIMIT' => $limitSql ) );
+
+ if ( 0 == $dbr->numRows( $res ) ) {
if ( 0 == $level ) {
- $wgOut->addHTML( wfMsg( "nolinkshere" ) );
+ $wgOut->addWikiText( wfMsg( 'nolinkshere' ) );
}
return;
}
if ( 0 == $level ) {
- $wgOut->addHTML( wfMsg( "linkshere" ) );
+ $wgOut->addWikiText( wfMsg( 'linkshere' ) );
}
$sk = $wgUser->getSkin();
- $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
-
- $wgOut->addHTML( "" );
- while ( $row = wfFetchObject( $res ) ) {
- $nt = Title::newFromDBkey( $row->l_from );
- if( !$nt ) {
- $wgOut->addHTML( "\n" );
- continue;
- }
- $ns = $nt->getNamespace();
- $t = wfStrencode( $nt->getDBkey() );
+ $isredir = ' (' . wfMsg( 'isredirect' ) . ")\n";
- # FIXME: this should be in a join above, or cached in the links table
+ if( $dbr->numRows( $res ) == 0 ) {
+ return;
+ }
+ $atend = ( $dbr->numRows( $res ) <= $limit );
+
+ if( $level == 0 ) {
+ $specialTitle = Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' );
+ $prevnext = wfViewPrevNext( $offset, $limit, $specialTitle,
+ 'target=' . urlencode( $target->getPrefixedDbKey() ),
+ $atend );
+ $wgOut->addHTML( $prevnext );
+ }
+
+ $wgOut->addHTML( '' );
+ $linksShown = 0;
+ while ( $row = $dbr->fetchObject( $res ) ) {
+ if( ++$linksShown > $limit ) {
+ // Last row is for checks only; don't display it.
+ break;
+ }
- $sql = "SELECT cur_id,cur_is_redirect FROM cur " .
- "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
- $res2 = wfQuery( $sql, DB_READ, $fname );
- $s = wfFetchObject( $res2 );
+ $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
- if ( 1 == $s->cur_is_redirect ) {
- $extra = "redirect=no";
+ if ( $row->page_is_redirect ) {
+ $extra = 'redirect=no';
} else {
- $extra = "";
+ $extra = '';
}
-
- $link = $sk->makeKnownLink( $row->l_from, "", $extra );
- $wgOut->addHTML( "- {$link}" );
-
- if ( 1 == $s->cur_is_redirect ) {
- $wgOut->addHTML( $isredir );
- if ( $level < 2 ) {
- wfShowIndirectLinks( $level + 1, $s->cur_id );
- }
+
+ $link = $sk->makeKnownLinkObj( $nt, '', $extra );
+ $wgOut->addHTML( '
- '.$link );
+
+ if ( $row->page_is_redirect ) {
+ $wgOut->addHTML( $isredir );
+ if ( $level < 2 ) {
+ wfShowIndirectLinks( $level + 1, $nt, 500 );
+ }
}
$wgOut->addHTML( "
\n" );
}
$wgOut->addHTML( "
\n" );
+
+ if( $level == 0 ) {
+ $wgOut->addHTML( $prevnext );
+ }
}
?>