00001 <?php
00012 class DoubleRedirectsPage extends PageQueryPage {
00013
00014 function getName() {
00015 return 'DoubleRedirects';
00016 }
00017
00018 function isExpensive( ) { return true; }
00019 function isSyndicated() { return false; }
00020
00021 function getPageHeader( ) {
00022 return wfMsgExt( 'doubleredirectstext', array( 'parse' ) );
00023 }
00024
00025 function getSQLText( &$dbr, $namespace = null, $title = null ) {
00026
00027 list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
00028
00029 $limitToTitle = !( $namespace === null && $title === null );
00030 $sql = $limitToTitle ? "SELECT" : "SELECT 'DoubleRedirects' as type," ;
00031 $sql .=
00032 " pa.page_namespace as namespace, pa.page_title as title," .
00033 " pb.page_namespace as nsb, pb.page_title as tb," .
00034 " pc.page_namespace as nsc, pc.page_title as tc" .
00035 " FROM $redirect AS ra, $redirect AS rb, $page AS pa, $page AS pb, $page AS pc" .
00036 " WHERE ra.rd_from=pa.page_id" .
00037 " AND ra.rd_namespace=pb.page_namespace" .
00038 " AND ra.rd_title=pb.page_title" .
00039 " AND rb.rd_from=pb.page_id" .
00040 " AND rb.rd_namespace=pc.page_namespace" .
00041 " AND rb.rd_title=pc.page_title";
00042
00043 if( $limitToTitle ) {
00044 $encTitle = $dbr->addQuotes( $title );
00045 $sql .= " AND pa.page_namespace=$namespace" .
00046 " AND pa.page_title=$encTitle";
00047 }
00048
00049 return $sql;
00050 }
00051
00052 function getSQL() {
00053 $dbr = wfGetDB( DB_SLAVE );
00054 return $this->getSQLText( $dbr );
00055 }
00056
00057 function getOrder() {
00058 return '';
00059 }
00060
00061 function formatResult( $skin, $result ) {
00062 global $wgContLang;
00063
00064 $fname = 'DoubleRedirectsPage::formatResult';
00065 $titleA = Title::makeTitle( $result->namespace, $result->title );
00066
00067 if ( $result && !isset( $result->nsb ) ) {
00068 $dbr = wfGetDB( DB_SLAVE );
00069 $sql = $this->getSQLText( $dbr, $result->namespace, $result->title );
00070 $res = $dbr->query( $sql, $fname );
00071 if ( $res ) {
00072 $result = $dbr->fetchObject( $res );
00073 $dbr->freeResult( $res );
00074 }
00075 }
00076 if ( !$result ) {
00077 return '<s>' . $skin->makeLinkObj( $titleA, '', 'redirect=no' ) . '</s>';
00078 }
00079
00080 $titleB = Title::makeTitle( $result->nsb, $result->tb );
00081 $titleC = Title::makeTitle( $result->nsc, $result->tc );
00082
00083 $linkA = $skin->makeKnownLinkObj( $titleA, '', 'redirect=no' );
00084 $edit = $skin->makeBrokenLinkObj( $titleA, "(".wfMsg("qbedit").")" , 'redirect=no');
00085 $linkB = $skin->makeKnownLinkObj( $titleB, '', 'redirect=no' );
00086 $linkC = $skin->makeKnownLinkObj( $titleC );
00087 $arr = $wgContLang->getArrow() . $wgContLang->getDirMark();
00088
00089 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
00090 }
00091 }
00092
00096 function wfSpecialDoubleRedirects() {
00097 list( $limit, $offset ) = wfCheckLimits();
00098
00099 $sdr = new DoubleRedirectsPage();
00100
00101 return $sdr->doQuery( $offset, $limit );
00102
00103 }