X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialWhatlinkshere.php;h=4d5bfa0564d75d98f04d0ad76a633fe522d8c5e5;hb=09da7fb96c45255899fa0f4c62412d14b8575b3e;hp=083ff2a1f65ee203c60d945d0915c348f135c3eb;hpb=bc22d1c7ed7aec2eebf7c0dba0a0454c0c46b4d8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialWhatlinkshere.php b/includes/SpecialWhatlinkshere.php index 083ff2a1f6..4d5bfa0564 100644 --- a/includes/SpecialWhatlinkshere.php +++ b/includes/SpecialWhatlinkshere.php @@ -1,111 +1,127 @@ errorpage( "notargettitle", "notargettext" ); +/** + * Entry point + * @param string $par An article name ?? + */ +function wfSpecialWhatlinkshere($par = NULL) { + global $wgUser, $wgOut, $wgRequest; + $fname = 'wfSpecialWhatlinkshere'; + + $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" )."
\n"); - - if ( 0 == $id ) { - $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM brokenlinks,cur WHERE bl_to='" . - wfStrencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id 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\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"; + $fname = 'wfShowIndirectLinks'; - $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM links,cur WHERE l_to={$lid} AND l_from=cur_id LIMIT 500"; - $res = wfQuery( $sql, DB_READ, $fname ); + $dbr =& wfGetDB( DB_READ ); + + // Read one extra row as an at-end check + $queryLimit = $limit + 1; + $limitSql = ( $level == 0 ) + ? "$offset,$queryLimit" + : $queryLimit; - if ( 0 == wfNumRows( $res ) ) { + $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( "