Some changes to the link tables. They now all use a key on cur_id for the *_from...
[mediawiki.git] / includes / SpecialWhatlinkshere.php
blobaf4e8a0710ea59ae0999ac97d6da7c7c934f5c4f
1 <?php
3 function wfSpecialWhatlinkshere($par = NULL)
5 global $wgUser, $wgOut, $target;
6 $fname = "wfSpecialWhatlinkshere";
8 if($par) {
9 $target = $par;
10 } else {
11 $target = $_REQUEST['target'] ;
13 if ( "" == $target ) {
14 $wgOut->errorpage( "notargettitle", "notargettext" );
15 return;
17 $nt = Title::newFromURL( $target );
18 if( !$nt ) {
19 $wgOut->errorpage( "notargettitle", "notargettext" );
20 return;
22 $wgOut->setPagetitle( $nt->getPrefixedText() );
23 $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
25 $id = $nt->getArticleID();
26 $sk = $wgUser->getSkin();
27 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
29 if ( 0 == $id ) {
30 $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM brokenlinks,cur WHERE bl_to='" .
31 wfStrencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT 500";
32 $res = wfQuery( $sql, DB_READ, $fname );
34 if ( 0 == wfNumRows( $res ) ) {
35 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
36 } else {
37 $wgOut->addHTML( wfMsg( "linkshere" ) );
38 $wgOut->addHTML( "\n<ul>" );
40 while ( $row = wfFetchObject( $res ) ) {
41 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
42 if( !$nt ) {
43 continue;
45 $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
46 $wgOut->addHTML( "<li>{$link}" );
48 if ( $row->cur_is_redirect ) {
49 $wgOut->addHTML( $isredir );
50 wfShowIndirectLinks( 1, $row->cur_id );
52 $wgOut->addHTML( "</li>\n" );
54 $wgOut->addHTML( "</ul>\n" );
55 wfFreeResult( $res );
57 } else {
58 wfShowIndirectLinks( 0, $id );
62 function wfShowIndirectLinks( $level, $lid )
64 global $wgOut, $wgUser;
65 $fname = "wfShowIndirectLinks";
67 $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";
68 $res = wfQuery( $sql, DB_READ, $fname );
70 if ( 0 == wfNumRows( $res ) ) {
71 if ( 0 == $level ) {
72 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
74 return;
76 if ( 0 == $level ) {
77 $wgOut->addHTML( wfMsg( "linkshere" ) );
79 $sk = $wgUser->getSkin();
80 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
82 $wgOut->addHTML( "<ul>" );
83 while ( $row = wfFetchObject( $res ) ) {
84 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
85 if( !$nt ) {
86 $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
87 continue;
90 if ( $row->cur_is_redirect ) {
91 $extra = "redirect=no";
92 } else {
93 $extra = "";
96 $link = $sk->makeKnownLinkObj( $nt, "", $extra );
97 $wgOut->addHTML( "<li>{$link}" );
99 if ( $row->cur_is_redirect ) {
100 $wgOut->addHTML( $isredir );
101 if ( $level < 2 ) {
102 wfShowIndirectLinks( $level + 1, $row->cur_id );
105 $wgOut->addHTML( "</li>\n" );
107 $wgOut->addHTML( "</ul>\n" );