* Using a white background instead of a gray one
[lhc/web/wiklou.git] / includes / SpecialDoubleRedirects.php
index 41091ce..9c0563e 100644 (file)
@@ -26,19 +26,23 @@ class DoubleRedirectsPage extends PageQueryPage {
 
        function getPageHeader( ) {
                #FIXME : probably need to add a backlink to the maintenance page.
-               return '<p>'.wfMsg("doubleredirectstext")."</p><br>\n";
+               return '<p>'.wfMsg("doubleredirectstext")."</p><br />\n";
        }
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'cur', 'links' ) );
+               extract( $dbr->tableNames( 'page', 'links' ) );
 
-               $sql = "SELECT ca.cur_namespace as ns_a, ca.cur_title as title_a," . 
-                          "  cb.cur_namespace as ns_b, cb.cur_title as title_b," .
-                          "  cb.cur_text AS rt " . 
-                          "FROM $links,$cur AS ca,$cur AS cb ". 
-                          "WHERE ca.cur_is_redirect=1 AND cb.cur_is_redirect=1 AND l_to=cb.cur_id " .
-                          "  AND l_from=ca.cur_id " ;
+               $sql = "SELECT 'DoubleRedirects' as type," .
+                        " pa.page_namespace as namespace, pa.page_title as title," .
+                            " pb.page_namespace as nsb, pb.page_title as tb," .
+                                " pc.page_namespace as nsc, pc.page_title as tc" .
+                          " FROM $links AS la, $links AS lb, $page AS pa, $page AS pb, $page AS pc" .
+                          " WHERE pa.page_is_redirect=1 AND pb.page_is_redirect=1" .
+                            " AND la.l_from=pa.page_id" .
+                                " AND la.l_to=pb.page_id" .
+                                " AND lb.l_from=pb.page_id" .
+                                " AND lb.l_to=pc.page_id";
                return $sql;
        }
 
@@ -47,14 +51,43 @@ class DoubleRedirectsPage extends PageQueryPage {
        }
        
        function formatResult( $skin, $result ) {
-               global $wgContLang ;
-               $ns = $wgContLang->getNamespaces() ;
-               $from = $skin->makeKnownLink( $ns[$result->ns_a].':'.$result->title_a ,'', 'redirect=no' );
-               $edit = $skin->makeBrokenLink( $ns[$result->ns_a].':'.$result->title_a , "(".wfMsg("qbedit").")" , 'redirect=no');
-               $to   = $skin->makeKnownLink( $ns[$result->ns_b].':'.$result->title_b ,'');
-               $content = $result->rt;
+               $fname = 'DoubleRedirectsPage::formatResult';
+               $titleA = Title::makeTitle( $result->namespace, $result->title );
+
+               if ( $result && !isset( $result->nsb ) ) {
+                       $dbr =& wfGetDB( DB_SLAVE );
+                       extract( $dbr->tableNames( 'page', 'links' ) );
+                       $encTitle = $dbr->addQuotes( $result->title );
+
+                       $sql = "SELECT pa.page_namespace as namespace, pa.page_title as title," .
+                                        " pb.page_namespace as nsb, pb.page_title as tb," .
+                                        " pc.page_namespace as nsc, pc.page_title as tc" .
+                                  " FROM $links AS la, $links AS lb, $page AS pa, $page AS pb, $page AS pc" .
+                                  " WHERE pa.page_is_redirect=1 AND pb.page_is_redirect=1" .
+                                        " AND la.l_from=pa.page_id" .
+                                        " AND la.l_to=pb.page_id" .
+                                        " AND lb.l_from=pb.page_id" .
+                                        " AND lb.l_to=pc.page_id" .
+                                        " AND pa.page_namespace={$result->namespace}" .
+                                        " AND pa.page_title=$encTitle";
+                       $res = $dbr->query( $sql, $fname );
+                       if ( $res ) {
+                               $result = $dbr->fetchObject( $res );
+                       }
+               }
+               if ( !$result ) {
+                       return '';
+               }
+               
+               $titleB = Title::makeTitle( $result->nsb, $result->tb );
+               $titleC = Title::makeTitle( $result->nsc, $result->tc );
+
+               $linkA = $skin->makeKnownLinkObj( $titleA,'', 'redirect=no' );
+               $edit = $skin->makeBrokenLinkObj( $titleA, "(".wfMsg("qbedit").")" , 'redirect=no');
+               $linkB = $skin->makeKnownLinkObj( $titleB, '', 'redirect=no' );
+               $linkC = $skin->makeKnownLinkObj( $titleC );
                
-               return "$from $edit => $to ($content)";
+               return "$linkA $edit &rarr; $linkB &rarr; $linkC";
        }
 }