New global config setting $wgMaxTocLevel: Maximum indent level of toc.
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
1 <?php
2
3 function wfSpecialWhatlinkshere($par = NULL)
4 {
5 global $wgUser, $wgOut, $wgRequest;
6 $fname = "wfSpecialWhatlinkshere";
7
8 $target = $wgRequest->getVal( 'target' );
9 $limit = $wgRequest->getInt( 'limit', 500 );
10
11 if(!empty($par)) {
12 $target = $par;
13 } else if ( is_null( $target ) ) {
14 $wgOut->errorpage( "notargettitle", "notargettext" );
15 return;
16 }
17
18 $nt = Title::newFromURL( $target );
19 if( !$nt ) {
20 $wgOut->errorpage( "notargettitle", "notargettext" );
21 return;
22 }
23 $wgOut->setPagetitle( $nt->getPrefixedText() );
24 $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
25
26 $id = $nt->getArticleID();
27 $sk = $wgUser->getSkin();
28 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
29
30 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
31 $dbr =& wfGetDB( DB_SLAVE );
32 extract( $dbr->tableNames( 'cur', 'brokenlinks', 'links' ) );
33
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 );
38
39 if ( 0 == $dbr->numRows( $res ) ) {
40 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
41 } else {
42 $wgOut->addHTML( wfMsg( "linkshere" ) );
43 $wgOut->addHTML( "\n<ul>" );
44
45 while ( $row = $dbr->fetchObject( $res ) ) {
46 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
47 if( !$nt ) {
48 continue;
49 }
50 $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
51 $wgOut->addHTML( "<li>{$link}" );
52
53 if ( $row->cur_is_redirect ) {
54 $wgOut->addHTML( $isredir );
55 wfShowIndirectLinks( 1, $row->cur_id, $limit );
56 }
57 $wgOut->addHTML( "</li>\n" );
58 }
59 $wgOut->addHTML( "</ul>\n" );
60 $dbr->freeResult( $res );
61 }
62 } else {
63 wfShowIndirectLinks( 0, $id, $limit );
64 }
65 }
66
67 function wfShowIndirectLinks( $level, $lid, $limit )
68 {
69 global $wgOut, $wgUser;
70 $fname = "wfShowIndirectLinks";
71
72 $dbr =& wfGetDB( DB_READ );
73 extract( $dbr->tableNames( 'links','cur' ) );
74
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 );
77
78 if ( 0 == $dbr->numRows( $res ) ) {
79 if ( 0 == $level ) {
80 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
81 }
82 return;
83 }
84 if ( 0 == $level ) {
85 $wgOut->addHTML( wfMsg( "linkshere" ) );
86 }
87 $sk = $wgUser->getSkin();
88 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
89
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;
96 }
97
98 if ( $row->cur_is_redirect ) {
99 $extra = "redirect=no";
100 } else {
101 $extra = "";
102 }
103
104 $link = $sk->makeKnownLinkObj( $nt, "", $extra );
105 $wgOut->addHTML( "<li>{$link}" );
106
107 if ( $row->cur_is_redirect ) {
108 $wgOut->addHTML( $isredir );
109 if ( $level < 2 ) {
110 wfShowIndirectLinks( $level + 1, $row->cur_id, $limit );
111 }
112 }
113 $wgOut->addHTML( "</li>\n" );
114 }
115 $wgOut->addHTML( "</ul>\n" );
116 }
117
118 ?>