Index: trunk/extensions/GlobalUsage/SpecialGlobalUsage.php |
— | — | @@ -17,36 +17,41 @@ |
18 | 18 | global $wgOut, $wgRequest; |
19 | 19 | |
20 | 20 | $target = $par ? $par : $wgRequest->getVal( 'target' ); |
21 | | - $title = Title::newFromText( $target, NS_FILE ); |
| 21 | + $this->target = Title::newFromText( $target, NS_FILE ); |
22 | 22 | |
| 23 | + $this->filterLocal = $wgRequest->getCheck( 'filterlocal' ); |
| 24 | + |
23 | 25 | $this->setHeaders(); |
24 | 26 | |
25 | | - $this->showForm( $title ); |
| 27 | + $this->showForm(); |
26 | 28 | |
27 | | - if ( is_null( $title ) ) |
| 29 | + if ( is_null( $this->target ) ) |
28 | 30 | { |
29 | 31 | $wgOut->setPageTitle( wfMsg( 'globalusage' ) ); |
30 | 32 | return; |
31 | 33 | } |
32 | 34 | |
33 | | - $wgOut->setPageTitle( wfMsg( 'globalusage-for', $title->getPrefixedText() ) ); |
| 35 | + $wgOut->setPageTitle( wfMsg( 'globalusage-for', $this->target->getPrefixedText() ) ); |
34 | 36 | |
35 | | - $this->showResult( $title ); |
| 37 | + $this->showResult(); |
36 | 38 | } |
37 | 39 | |
38 | 40 | /** |
39 | 41 | * Shows the search form |
40 | 42 | */ |
41 | | - private function showForm( $title ) { |
| 43 | + private function showForm() { |
42 | 44 | global $wgScript, $wgOut; |
43 | 45 | |
44 | 46 | $html = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . "\n"; |
45 | 47 | $html .= Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n"; |
46 | | - $formContent = "\t" . Xml::input( 'target', 40, is_null( $title ) ? '' : $title->getPrefixedText() ) |
| 48 | + $formContent = "\t" . Xml::input( 'target', 40, is_null( $this->target ) ? '' |
| 49 | + : $this->target->getPrefixedText() ) |
47 | 50 | . "\n\t" . Xml::element( 'input', array( |
48 | 51 | 'type' => 'submit', |
49 | 52 | 'value' => wfMsg( 'globalusage-ok' ) |
50 | | - ) ); |
| 53 | + ) ) |
| 54 | + . "\n\t<p>" . Xml::checkLabel( wfMsg( 'globalusage-filterlocal' ), |
| 55 | + 'filterlocal', 'mw-filterlocal', $this->filterLocal ) . '</p>'; |
51 | 56 | $html .= Xml::fieldSet( wfMsg( 'globalusage-text' ), $formContent ) . "\n</form>"; |
52 | 57 | |
53 | 58 | $wgOut->addHtml( $html ); |
— | — | @@ -55,14 +60,15 @@ |
56 | 61 | /** |
57 | 62 | * Creates as queryer and executes it based on $wgRequest |
58 | 63 | */ |
59 | | - private function showResult( $target ) { |
| 64 | + private function showResult() { |
60 | 65 | global $wgRequest; |
61 | 66 | |
62 | | - $query = new GlobalUsageQuery( $target ); |
| 67 | + $query = new GlobalUsageQuery( $this->target ); |
63 | 68 | |
64 | 69 | // Extract params from $wgRequest |
65 | 70 | $query->setContinue( $wgRequest->getInt( 'offset', 0 ) ); |
66 | 71 | $query->setLimit( $wgRequest->getInt( 'limit', 50 ) ); |
| 72 | + $query->filterLocal( $this->filterLocal ); |
67 | 73 | |
68 | 74 | // Perform query |
69 | 75 | $query->execute(); |
— | — | @@ -71,11 +77,12 @@ |
72 | 78 | global $wgOut; |
73 | 79 | |
74 | 80 | $navbar = wfViewPrevNext( $query->getOffset(), $query->getLimit(), $this->getTitle(), |
75 | | - 'target=' . $target->getPrefixedText(), !$query->hasMore() ); |
76 | | - $targetName = $target->getText(); |
| 81 | + 'target=' . $this->target->getPrefixedText(), !$query->hasMore() ); |
| 82 | + $targetName = $this->target->getText(); |
77 | 83 | |
78 | 84 | $wgOut->addHtml( $navbar ); |
79 | 85 | |
| 86 | + $wgOut->addHtml( '<div id="mw-globalusage-result">' ); |
80 | 87 | foreach ( $query->getResult() as $wiki => $result ) { |
81 | 88 | $wgOut->addHtml( |
82 | 89 | '<h2>' . wfMsgExt( |
— | — | @@ -83,9 +90,10 @@ |
84 | 91 | $targetName, $wiki ) |
85 | 92 | . "</h2><ul>\n" ); |
86 | 93 | foreach ( $result as $item ) |
87 | | - $wgOut->addHtml( "\t<li>" . $this->formatItem( $item ) . "</li>\n" ); |
| 94 | + $wgOut->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" ); |
88 | 95 | $wgOut->addHtml( "</ul>\n" ); |
89 | 96 | } |
| 97 | + $wgOut->addHtml( '</div>' ); |
90 | 98 | |
91 | 99 | $wgOut->addHtml( $navbar ); |
92 | 100 | } |
— | — | @@ -93,7 +101,7 @@ |
94 | 102 | * Helper to format a specific item |
95 | 103 | * TODO: Make links |
96 | 104 | */ |
97 | | - private function formatItem( $item ) { |
| 105 | + private static function formatItem( $item ) { |
98 | 106 | if ( !$item['namespace'] ) |
99 | 107 | $page = $item['title']; |
100 | 108 | else |
— | — | @@ -103,7 +111,36 @@ |
104 | 112 | |
105 | 113 | return WikiMap::makeForeignLink( $item['wiki'], $page ); |
106 | 114 | } |
| 115 | + |
| 116 | + public static function onImagePageAfterImageLinks( $imagePage, &$html ) { |
| 117 | + $title = $imagePage->getFile()->getTitle(); |
| 118 | + $targetName = $title->getText(); |
| 119 | + |
| 120 | + $query = new GlobalUsageQuery( $title ); |
| 121 | + $query->filterLocal(); |
| 122 | + $query->execute(); |
| 123 | + |
| 124 | + $guHtml = ''; |
| 125 | + foreach ( $query->getResult() as $wiki => $result ) { |
| 126 | + $guHtml .= '<li>' . wfMsgExt( |
| 127 | + 'globalusage-on-wiki', 'parseinline', |
| 128 | + $targetName, $wiki ) . "\n<ul>"; |
| 129 | + foreach ( $result as $item ) |
| 130 | + $guHtml .= "\t<li>" . self::formatItem( $item ) . "</li>\n"; |
| 131 | + $guHtml .= "</ul></li>\n"; |
| 132 | + } |
| 133 | + |
| 134 | + if ( $guHtml ) { |
| 135 | + $html .= "<h2>" . wfMsgHtml( 'globalusage' ) . "</h2>\n" |
| 136 | + . wfMsgExt( 'globalusage-of-file', 'parse' ) |
| 137 | + . "<ul>\n" . $guHtml . "</ul>\n"; |
| 138 | + if ( $query->hasMore() ) |
| 139 | + $html .= wfMsgExt( 'globalusage-more', 'parse', $targetName ); |
| 140 | + } |
107 | 141 | |
| 142 | + |
| 143 | + return true; |
| 144 | + } |
108 | 145 | } |
109 | 146 | |
110 | 147 | |
— | — | @@ -117,6 +154,7 @@ |
118 | 155 | private $limit = 50; |
119 | 156 | private $offset = 0; |
120 | 157 | private $hasMore = false; |
| 158 | + private $filterLocal = false; |
121 | 159 | private $result; |
122 | 160 | |
123 | 161 | |
— | — | @@ -155,11 +193,22 @@ |
156 | 194 | return $this->limit; |
157 | 195 | } |
158 | 196 | |
| 197 | + /** |
| 198 | + * Set whether to filter out the local usage |
| 199 | + */ |
| 200 | + public function filterLocal( $value = true ) { |
| 201 | + $this->filterLocal = $value; |
| 202 | + } |
159 | 203 | |
| 204 | + |
160 | 205 | /** |
161 | 206 | * Executes the query |
162 | 207 | */ |
163 | 208 | public function execute() { |
| 209 | + $where = array( 'gil_to' => $this->target->getDBkey() ); |
| 210 | + if ( $this->filterLocal ) |
| 211 | + $where[] = 'gil_wiki != ' . $this->db->addQuotes( wfWikiId() ); |
| 212 | + |
164 | 213 | $res = $this->db->select( 'globalimagelinks', |
165 | 214 | array( |
166 | 215 | 'gil_wiki', |
— | — | @@ -167,9 +216,7 @@ |
168 | 217 | 'gil_page_namespace', |
169 | 218 | 'gil_page_title' |
170 | 219 | ), |
171 | | - array( |
172 | | - 'gil_to' => $this->target->getDBkey() |
173 | | - ), |
| 220 | + $where, |
174 | 221 | __METHOD__, |
175 | 222 | array( |
176 | 223 | 'ORDER BY' => 'gil_wiki, gil_page', |