* Skip additional setting of include_path in commandLine.inc (for non-Wikimedia mode)
[lhc/web/wiklou.git] / includes / SpecialBrokenRedirects.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 * A special page listing redirects to non existent page. Those should be
9 * fixed to point to an existing page.
10 * @addtogroup SpecialPage
11 */
12 class BrokenRedirectsPage extends PageQueryPage {
13 var $targets = array();
14
15 function getName() {
16 return 'BrokenRedirects';
17 }
18
19 function isExpensive( ) { return true; }
20 function isSyndicated() { return false; }
21
22 function getPageHeader( ) {
23 global $wgOut;
24 return $wgOut->parse( wfMsg( 'brokenredirectstext' ) );
25 }
26
27 function getSQL() {
28 $dbr = wfGetDB( DB_SLAVE );
29 list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
30
31 $sql = "SELECT 'BrokenRedirects' AS type,
32 p1.page_namespace AS namespace,
33 p1.page_title AS title,
34 rd_namespace,
35 rd_title
36 FROM $redirect AS rd
37 JOIN $page p1 ON (rd.rd_from=p1.page_id)
38 LEFT JOIN $page AS p2 ON (rd_namespace=p2.page_namespace AND rd_title=p2.page_title )
39 WHERE p2.page_namespace IS NULL";
40 return $sql;
41 }
42
43 function getOrder() {
44 return '';
45 }
46
47 function formatResult( $skin, $result ) {
48 global $wgUser, $wgContLang;
49
50 $fromObj = Title::makeTitle( $result->namespace, $result->title );
51 if ( isset( $result->rd_title ) ) {
52 $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title );
53 } else {
54 $blinks = $fromObj->getBrokenLinksFrom();
55 if ( $blinks ) {
56 $toObj = $blinks[0];
57 } else {
58 $toObj = false;
59 }
60 }
61
62 // $toObj may very easily be false if the $result list is cached
63 if ( !is_object( $toObj ) ) {
64 return '<s>' . $skin->makeLinkObj( $fromObj ) . '</s>';
65 }
66
67 $from = $skin->makeKnownLinkObj( $fromObj ,'', 'redirect=no' );
68 $edit = $skin->makeKnownLinkObj( $fromObj, wfMsgHtml( 'brokenredirects-edit' ), 'action=edit' );
69 $to = $skin->makeBrokenLinkObj( $toObj );
70 $arr = $wgContLang->getArrow();
71
72 $out = "{$from} {$edit}";
73
74 if( $wgUser->isAllowed( 'delete' ) ) {
75 $delete = $skin->makeKnownLinkObj( $fromObj, wfMsgHtml( 'brokenredirects-delete' ), 'action=delete' );
76 $out .= " {$delete}";
77 }
78
79 $out .= " {$arr} {$to}";
80 return $out;
81 }
82 }
83
84 /**
85 * constructor
86 */
87 function wfSpecialBrokenRedirects() {
88 list( $limit, $offset ) = wfCheckLimits();
89
90 $sbr = new BrokenRedirectsPage();
91
92 return $sbr->doQuery( $offset, $limit );
93
94 }
95 ?>