5 * @subpackage SpecialPage
11 function wfSpecialWhatlinkshere($par = NULL) {
12 global $wgUser, $wgOut, $wgRequest;
13 $fname = "wfSpecialWhatlinkshere";
15 $target = $wgRequest->getVal( 'target' );
16 $limit = $wgRequest->getInt( 'limit', 500 );
20 } else if ( is_null( $target ) ) {
21 $wgOut->errorpage( "notargettitle", "notargettext" );
25 $nt = Title
::newFromURL( $target );
27 $wgOut->errorpage( "notargettitle", "notargettext" );
30 $wgOut->setPagetitle( $nt->getPrefixedText() );
31 $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
33 $id = $nt->getArticleID();
34 $sk = $wgUser->getSkin();
35 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
37 $wgOut->addHTML("< ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
38 $dbr =& wfGetDB( DB_SLAVE
);
39 extract( $dbr->tableNames( 'cur', 'brokenlinks', 'links' ) );
42 $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM $brokenlinks,$cur WHERE bl_to='" .
43 $dbr->strencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT $limit";
44 $res = $dbr->query( $sql, $fname );
46 if ( 0 == $dbr->numRows( $res ) ) {
47 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
49 $wgOut->addHTML( wfMsg( "linkshere" ) );
50 $wgOut->addHTML( "\n<ul>" );
52 while ( $row = $dbr->fetchObject( $res ) ) {
53 $nt = Title
::makeTitle( $row->cur_namespace
, $row->cur_title
);
57 $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
58 $wgOut->addHTML( "<li>{$link}" );
60 if ( $row->cur_is_redirect
) {
61 $wgOut->addHTML( $isredir );
62 wfShowIndirectLinks( 1, $row->cur_id
, $limit );
64 $wgOut->addHTML( "</li>\n" );
66 $wgOut->addHTML( "</ul>\n" );
67 $dbr->freeResult( $res );
70 wfShowIndirectLinks( 0, $id, $limit );
77 function wfShowIndirectLinks( $level, $lid, $limit ) {
78 global $wgOut, $wgUser;
79 $fname = "wfShowIndirectLinks";
81 $dbr =& wfGetDB( DB_READ
);
82 extract( $dbr->tableNames( 'links','cur' ) );
84 $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";
85 $res = $dbr->query( $sql, $fname );
87 if ( 0 == $dbr->numRows( $res ) ) {
89 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
94 $wgOut->addHTML( wfMsg( "linkshere" ) );
96 $sk = $wgUser->getSkin();
97 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
99 $wgOut->addHTML( "<ul>" );
100 while ( $row = $dbr->fetchObject( $res ) ) {
101 $nt = Title
::makeTitle( $row->cur_namespace
, $row->cur_title
);
103 $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from
) . " -->\n" );
107 if ( $row->cur_is_redirect
) {
108 $extra = "redirect=no";
113 $link = $sk->makeKnownLinkObj( $nt, "", $extra );
114 $wgOut->addHTML( "<li>{$link}" );
116 if ( $row->cur_is_redirect
) {
117 $wgOut->addHTML( $isredir );
119 wfShowIndirectLinks( $level +
1, $row->cur_id
, $limit );
122 $wgOut->addHTML( "</li>\n" );
124 $wgOut->addHTML( "</ul>\n" );