do not indent code inside the "if( defined( 'MEDIAWIKI' ) ) { }" block
[mediawiki.git] / includes / SpecialWhatlinkshere.php
blob92a4931b45ce961fc0c99319baed3ad08951271e
1 <?php
3 function wfSpecialWhatlinkshere($par = NULL)
5 global $wgUser, $wgOut, $wgRequest;
6 $fname = "wfSpecialWhatlinkshere";
8 $target = $wgRequest->getVal( 'target' );
9 $limit = $wgRequest->getInt( 'limit', 500 );
11 if(!empty($par)) {
12 $target = $par;
13 } else if ( is_null( $target ) ) {
14 $wgOut->errorpage( "notargettitle", "notargettext" );
15 return;
18 $nt = Title::newFromURL( $target );
19 if( !$nt ) {
20 $wgOut->errorpage( "notargettitle", "notargettext" );
21 return;
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("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
31 $dbr =& wfGetDB( DB_SLAVE );
32 extract( $dbr->tableNames( 'cur', 'brokenlinks', 'links' ) );
34 if ( 0 == $id ) {
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" ) );
41 } else {
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 );
47 if( !$nt ) {
48 continue;
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 );
62 } else {
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 ) ) {
79 if ( 0 == $level ) {
80 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
82 return;
84 if ( 0 == $level ) {
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 );
93 if( !$nt ) {
94 $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
95 continue;
98 if ( $row->cur_is_redirect ) {
99 $extra = "redirect=no";
100 } else {
101 $extra = "";
104 $link = $sk->makeKnownLinkObj( $nt, "", $extra );
105 $wgOut->addHTML( "<li>{$link}" );
107 if ( $row->cur_is_redirect ) {
108 $wgOut->addHTML( $isredir );
109 if ( $level < 2 ) {
110 wfShowIndirectLinks( $level + 1, $row->cur_id, $limit );
113 $wgOut->addHTML( "</li>\n" );
115 $wgOut->addHTML( "</ul>\n" );