3 function wfSpecialWhatlinkshere($par = NULL)
5 global $wgUser, $wgOut, $wgRequest;
6 $fname = "wfSpecialWhatlinkshere";
8 $target = $wgRequest->getVal( 'target' );
9 $limit = $wgRequest->getInt( 'limit', 500 );
13 } else if ( is_null( $target ) ) {
14 $wgOut->errorpage( "notargettitle", "notargettext" );
18 $nt = Title
::newFromURL( $target );
20 $wgOut->errorpage( "notargettitle", "notargettext" );
23 $wgOut->setPagetitle( $nt->getPrefixedText() );
24 $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
26 $id = $nt->getArticleID();
27 $sk = $wgUser->getSkin();
28 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
30 $wgOut->addHTML("< ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
31 $dbr =& wfGetDB( DB_SLAVE
);
32 extract( $dbr->tableNames( 'cur', 'brokenlinks', 'links' ) );
35 $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM $brokenlinks,$cur WHERE bl_to='" .
36 $dbr->strencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT $limit";
37 $res = $dbr->query( $sql, $fname );
39 if ( 0 == $dbr->numRows( $res ) ) {
40 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
42 $wgOut->addHTML( wfMsg( "linkshere" ) );
43 $wgOut->addHTML( "\n<ul>" );
45 while ( $row = $dbr->fetchObject( $res ) ) {
46 $nt = Title
::makeTitle( $row->cur_namespace
, $row->cur_title
);
50 $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
51 $wgOut->addHTML( "<li>{$link}" );
53 if ( $row->cur_is_redirect
) {
54 $wgOut->addHTML( $isredir );
55 wfShowIndirectLinks( 1, $row->cur_id
, $limit );
57 $wgOut->addHTML( "</li>\n" );
59 $wgOut->addHTML( "</ul>\n" );
60 $dbr->freeResult( $res );
63 wfShowIndirectLinks( 0, $id, $limit );
67 function wfShowIndirectLinks( $level, $lid, $limit )
69 global $wgOut, $wgUser;
70 $fname = "wfShowIndirectLinks";
72 $dbr =& wfGetDB( DB_READ
);
73 extract( $dbr->tableNames( 'links','cur' ) );
75 $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";
76 $res = $dbr->query( $sql, $fname );
78 if ( 0 == $dbr->numRows( $res ) ) {
80 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
85 $wgOut->addHTML( wfMsg( "linkshere" ) );
87 $sk = $wgUser->getSkin();
88 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
90 $wgOut->addHTML( "<ul>" );
91 while ( $row = $dbr->fetchObject( $res ) ) {
92 $nt = Title
::makeTitle( $row->cur_namespace
, $row->cur_title
);
94 $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from
) . " -->\n" );
98 if ( $row->cur_is_redirect
) {
99 $extra = "redirect=no";
104 $link = $sk->makeKnownLinkObj( $nt, "", $extra );
105 $wgOut->addHTML( "<li>{$link}" );
107 if ( $row->cur_is_redirect
) {
108 $wgOut->addHTML( $isredir );
110 wfShowIndirectLinks( $level +
1, $row->cur_id
, $limit );
113 $wgOut->addHTML( "</li>\n" );
115 $wgOut->addHTML( "</ul>\n" );