r58705 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58704‎ | r58705 | r58706 >
Date:13:47, 7 November 2009
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
File forgotten to commit in r58693: Show globalusage on the imagepage
Modified paths:
  • /trunk/extensions/GlobalUsage/SpecialGlobalUsage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalUsage/SpecialGlobalUsage.php
@@ -17,36 +17,41 @@
1818 global $wgOut, $wgRequest;
1919
2020 $target = $par ? $par : $wgRequest->getVal( 'target' );
21 - $title = Title::newFromText( $target, NS_FILE );
 21+ $this->target = Title::newFromText( $target, NS_FILE );
2222
 23+ $this->filterLocal = $wgRequest->getCheck( 'filterlocal' );
 24+
2325 $this->setHeaders();
2426
25 - $this->showForm( $title );
 27+ $this->showForm();
2628
27 - if ( is_null( $title ) )
 29+ if ( is_null( $this->target ) )
2830 {
2931 $wgOut->setPageTitle( wfMsg( 'globalusage' ) );
3032 return;
3133 }
3234
33 - $wgOut->setPageTitle( wfMsg( 'globalusage-for', $title->getPrefixedText() ) );
 35+ $wgOut->setPageTitle( wfMsg( 'globalusage-for', $this->target->getPrefixedText() ) );
3436
35 - $this->showResult( $title );
 37+ $this->showResult();
3638 }
3739
3840 /**
3941 * Shows the search form
4042 */
41 - private function showForm( $title ) {
 43+ private function showForm() {
4244 global $wgScript, $wgOut;
4345
4446 $html = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . "\n";
4547 $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() )
4750 . "\n\t" . Xml::element( 'input', array(
4851 'type' => 'submit',
4952 'value' => wfMsg( 'globalusage-ok' )
50 - ) );
 53+ ) )
 54+ . "\n\t<p>" . Xml::checkLabel( wfMsg( 'globalusage-filterlocal' ),
 55+ 'filterlocal', 'mw-filterlocal', $this->filterLocal ) . '</p>';
5156 $html .= Xml::fieldSet( wfMsg( 'globalusage-text' ), $formContent ) . "\n</form>";
5257
5358 $wgOut->addHtml( $html );
@@ -55,14 +60,15 @@
5661 /**
5762 * Creates as queryer and executes it based on $wgRequest
5863 */
59 - private function showResult( $target ) {
 64+ private function showResult() {
6065 global $wgRequest;
6166
62 - $query = new GlobalUsageQuery( $target );
 67+ $query = new GlobalUsageQuery( $this->target );
6368
6469 // Extract params from $wgRequest
6570 $query->setContinue( $wgRequest->getInt( 'offset', 0 ) );
6671 $query->setLimit( $wgRequest->getInt( 'limit', 50 ) );
 72+ $query->filterLocal( $this->filterLocal );
6773
6874 // Perform query
6975 $query->execute();
@@ -71,11 +77,12 @@
7278 global $wgOut;
7379
7480 $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();
7783
7884 $wgOut->addHtml( $navbar );
7985
 86+ $wgOut->addHtml( '<div id="mw-globalusage-result">' );
8087 foreach ( $query->getResult() as $wiki => $result ) {
8188 $wgOut->addHtml(
8289 '<h2>' . wfMsgExt(
@@ -83,9 +90,10 @@
8491 $targetName, $wiki )
8592 . "</h2><ul>\n" );
8693 foreach ( $result as $item )
87 - $wgOut->addHtml( "\t<li>" . $this->formatItem( $item ) . "</li>\n" );
 94+ $wgOut->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" );
8895 $wgOut->addHtml( "</ul>\n" );
8996 }
 97+ $wgOut->addHtml( '</div>' );
9098
9199 $wgOut->addHtml( $navbar );
92100 }
@@ -93,7 +101,7 @@
94102 * Helper to format a specific item
95103 * TODO: Make links
96104 */
97 - private function formatItem( $item ) {
 105+ private static function formatItem( $item ) {
98106 if ( !$item['namespace'] )
99107 $page = $item['title'];
100108 else
@@ -103,7 +111,36 @@
104112
105113 return WikiMap::makeForeignLink( $item['wiki'], $page );
106114 }
 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+ }
107141
 142+
 143+ return true;
 144+ }
108145 }
109146
110147
@@ -117,6 +154,7 @@
118155 private $limit = 50;
119156 private $offset = 0;
120157 private $hasMore = false;
 158+ private $filterLocal = false;
121159 private $result;
122160
123161
@@ -155,11 +193,22 @@
156194 return $this->limit;
157195 }
158196
 197+ /**
 198+ * Set whether to filter out the local usage
 199+ */
 200+ public function filterLocal( $value = true ) {
 201+ $this->filterLocal = $value;
 202+ }
159203
 204+
160205 /**
161206 * Executes the query
162207 */
163208 public function execute() {
 209+ $where = array( 'gil_to' => $this->target->getDBkey() );
 210+ if ( $this->filterLocal )
 211+ $where[] = 'gil_wiki != ' . $this->db->addQuotes( wfWikiId() );
 212+
164213 $res = $this->db->select( 'globalimagelinks',
165214 array(
166215 'gil_wiki',
@@ -167,9 +216,7 @@
168217 'gil_page_namespace',
169218 'gil_page_title'
170219 ),
171 - array(
172 - 'gil_to' => $this->target->getDBkey()
173 - ),
 220+ $where,
174221 __METHOD__,
175222 array(
176223 'ORDER BY' => 'gil_wiki, gil_page',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r58693Show globalusage on the imagepagebtongminh09:33, 7 November 2009

Comments

#Comment by Bryan (talk | contribs)   17:56, 20 November 2009

Reviewed by Werdna.

Status & tagging log