r41671 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41670‎ | r41671 | r41672 >
Date:22:51, 4 October 2008
Author:demon
Status:old
Tags:
Comment:
Some outstanding updates to this. Add the searching back in, but with proper escaping this time :)
Modified paths:
  • /trunk/extensions/InterwikiList/InterwikiList.i18n.php (modified) (history)
  • /trunk/extensions/InterwikiList/InterwikiList.php (modified) (history)
  • /trunk/extensions/InterwikiList/InterwikiList_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/InterwikiList/InterwikiList_body.php
@@ -9,6 +9,9 @@
1010
1111 class InterwikiList extends SpecialPage {
1212
 13+ // Privates
 14+ private $mTitle; // The title for this specialpage
 15+
1316 /**
1417 * Constructor
1518 */
@@ -21,34 +24,51 @@
2225 * Execute
2326 */
2427 public function execute( $par ) {
25 - global $wgOut;
 28+ global $wgOut, $wgRequest;
2629 $wgOut->setPagetitle( wfMsg( 'interwikilist' ) );
27 - $selfTitle = Title::makeTitle( NS_SPECIAL, 'InterwikiList' );
28 - $wgOut->addHTML( $this->getInterwikis() );
 30+ $this->mTitle = SpecialPage::getTitleFor( 'InterwikiList' );
 31+ $prefix = $wgRequest->getText( 'iwsearch', $par );
 32+ $wgOut->addHTML( $this->getInterwikis( $prefix ) );
2933 }
3034
3135 /**
3236 * Get all Interwiki Links - the heart of the function
 37+ * @param $prefix string Prefix to search for in list
 38+ * @return string HTML
3339 */
34 - private function getInterwikis() {
 40+ private function getInterwikis( $prefix = null ) {
 41+ global $wgScript;
3542 $dbr = wfGetDB( DB_SLAVE );
36 -
37 - $results = $dbr->select( 'interwiki', array( 'iw_prefix', 'iw_url' ) );
38 -
39 - $text = Xml::openElement( 'table', array( 'id' => 'sv-software' ) ) . "<tr>
40 - <th>" . wfMsg( 'interwikilist-linkname' ) . "</th>
41 - <th>" . wfMsg( 'interwikilist-target' ) . "</th>
42 - </tr>\n";
43 -
 43+
 44+ $conds = array();
 45+ if ( !is_null( $prefix ) ) {
 46+ $conds[] = "iw_prefix LIKE " . $dbr->addQuotes( $dbr->escapeLike( $prefix ) . "%" );
 47+ }
 48+
 49+ $results = $dbr->select( 'interwiki', array( 'iw_prefix', 'iw_url' ), $conds );
 50+
 51+ $form = Xml::openElement( 'form', array( 'action' => $wgScript, 'method' => 'get', 'id' => 'interwikilist-search' ) ) .
 52+ Xml::hidden( 'title', $this->mTitle->getPrefixedText() ) .
 53+ Xml::inputLabel( wfMsg('interwikilist-prefix'), 'iwsearch', 'interwikilist-prefix', false, $prefix ) .
 54+ Xml::submitButton( wfMsg('search') ) .
 55+ Xml::closeElement( 'form' );
 56+ $text = Xml::fieldSet( wfMsg('interwikilist-filter'), $form );
 57+
 58+ $text .= Xml::openElement( 'table', array( 'id' => 'sv-software' ) ) .
 59+ Xml::openElement( 'tr' ) .
 60+ Xml::element( 'th', null, wfMsg( 'interwikilist-linkname' ) ) .
 61+ Xml::element( 'th', null, wfMsg( 'interwikilist-target' ) ) .
 62+ Xml::closeElement( 'tr' );;
 63+
4464 while ( $row = $dbr->fetchObject( $results ) ) {
45 - $text .= " <tr>
46 - <td>" . htmlspecialchars( $row->iw_prefix ) . "</td>
47 - <td>" . htmlspecialchars( $row->iw_url ) . "</td>
48 - </tr>\n";
 65+ $text .= Xml::openElement( 'tr' ) .
 66+ Xml::element( 'td', null, $row->iw_prefix ) .
 67+ Xml::element( 'td', null, $row->iw_url ) .
 68+ Xml::closeElement( 'tr' );
4969 }
50 - $text .= "</table>\n";
 70+ $text .= Xml::closeElement( 'table' );
5171 $dbr->freeResult( $results );
52 -
 72+
5373 return $text;
5474 }
55 -}
\ No newline at end of file
 75+}
Index: trunk/extensions/InterwikiList/InterwikiList.i18n.php
@@ -9,6 +9,8 @@
1010 'interwikilist-desc' => 'Adds a [[Special:Interwikilist|special page]] to view available interwiki links',
1111 'interwikilist-linkname' => 'Interwiki link',
1212 'interwikilist-target' => 'Target URL',
 13+ 'interwikilist-filter' => 'Filter list',
 14+ 'interwikilist-prefix' => 'Interwiki prefix:',
1315 );
1416
1517 /** Message documentation (Message documentation)
Index: trunk/extensions/InterwikiList/InterwikiList.php
@@ -13,11 +13,11 @@
1414 */
1515
1616 $wgExtensionCredits['specialpage'][] = array(
17 - 'name' => 'Interwiki List',
18 - 'version' => '0.2',
19 - 'url' => 'http://mediawiki.org/wiki/Extension:InterwikiList',
 17+ 'name' => 'Interwiki List',
 18+ 'version' => '0.3',
 19+ 'url' => 'http://mediawiki.org/wiki/Extension:InterwikiList',
2020 'description' => 'Adds a [[Special:Interwikilist|special page]] to view available interwiki links',
21 - 'author' => '[mailto:innocentkiller@gmail.com Chad Horohoe]',
 21+ 'author' => '[mailto:innocentkiller@gmail.com Chad Horohoe]',
2222 'descriptionmsg' => 'interwikilist-desc',
2323 );
2424

Status & tagging log