Fixes bug #2632 : new image height when zooming without using "thumb" was not computed.
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * Entry point
10 * @param string $par An article name ??
11 */
12 function wfSpecialWhatlinkshere($par = NULL) {
13 global $wgUser, $wgOut, $wgRequest;
14 $fname = 'wfSpecialWhatlinkshere';
15
16 $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
17 list( $limit, $offset ) = $wgRequest->getLimitOffset();
18
19 if (is_null($target)) {
20 $wgOut->errorpage( 'notargettitle', 'notargettext' );
21 return;
22 }
23
24 $nt = Title::newFromURL( $target );
25 if( !$nt ) {
26 $wgOut->errorpage( 'notargettitle', 'notargettext' );
27 return;
28 }
29 $wgOut->setPagetitle( $nt->getPrefixedText() );
30 $wgOut->setSubtitle( wfMsg( 'linklistsub' ) );
31
32 $sk = $wgUser->getSkin();
33 $isredir = ' (' . wfMsg( 'isredirect' ) . ")\n";
34
35 $wgOut->addHTML('&lt; '.$sk->makeKnownLinkObj($nt, '', 'redirect=no' )."<br />\n");
36
37 wfShowIndirectLinks( 0, $nt, $limit, $offset );
38 }
39
40 /**
41 * @param int $level
42 * @param Title $target
43 * @param int $limit
44 * @param int $offset
45 * @access private
46 */
47 function wfShowIndirectLinks( $level, $target, $limit, $offset = 0 ) {
48 global $wgOut, $wgUser;
49 $fname = 'wfShowIndirectLinks';
50
51 $dbr =& wfGetDB( DB_READ );
52
53 // Read one extra row as an at-end check
54 $queryLimit = $limit + 1;
55 $limitSql = ( $level == 0 )
56 ? "$offset,$queryLimit"
57 : $queryLimit;
58
59 $res = $dbr->select( array( 'pagelinks', 'page' ),
60 array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ),
61 array(
62 'pl_from=page_id',
63 'pl_namespace' => $target->getNamespace(),
64 'pl_title' => $target->getDbKey() ),
65 $fname,
66 array( 'LIMIT' => $limitSql ) );
67
68 if ( 0 == $dbr->numRows( $res ) ) {
69 if ( 0 == $level ) {
70 $wgOut->addWikiText( wfMsg( 'nolinkshere' ) );
71 }
72 return;
73 }
74 if ( 0 == $level ) {
75 $wgOut->addWikiText( wfMsg( 'linkshere' ) );
76 }
77 $sk = $wgUser->getSkin();
78 $isredir = ' (' . wfMsg( 'isredirect' ) . ")\n";
79
80 if( $dbr->numRows( $res ) == 0 ) {
81 return;
82 }
83 $atend = ( $dbr->numRows( $res ) <= $limit );
84
85 if( $level == 0 ) {
86 $specialTitle = Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' );
87 $prevnext = wfViewPrevNext( $offset, $limit, $specialTitle,
88 'target=' . urlencode( $target->getPrefixedDbKey() ),
89 $atend );
90 $wgOut->addHTML( $prevnext );
91 }
92
93 $wgOut->addHTML( '<ul>' );
94 $linksShown = 0;
95 while ( $row = $dbr->fetchObject( $res ) ) {
96 if( ++$linksShown > $limit ) {
97 // Last row is for checks only; don't display it.
98 break;
99 }
100
101 $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
102
103 if ( $row->page_is_redirect ) {
104 $extra = 'redirect=no';
105 } else {
106 $extra = '';
107 }
108
109 $link = $sk->makeKnownLinkObj( $nt, '', $extra );
110 $wgOut->addHTML( '<li>'.$link );
111
112 if ( $row->page_is_redirect ) {
113 $wgOut->addHTML( $isredir );
114 if ( $level < 2 ) {
115 wfShowIndirectLinks( $level + 1, $nt, 500 );
116 }
117 }
118 $wgOut->addHTML( "</li>\n" );
119 }
120 $wgOut->addHTML( "</ul>\n" );
121
122 if( $level == 0 ) {
123 $wgOut->addHTML( $prevnext );
124 }
125 }
126
127 ?>