r88818 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88817‎ | r88818 | r88819 >
Date:19:26, 25 May 2011
Author:yuvipanda
Status:resolved
Tags:
Comment:
Spacing fixes for ShortUrl
Modified paths:
  • /trunk/extensions/ShortUrl/ShortUrl.functions.php (modified) (history)
  • /trunk/extensions/ShortUrl/ShortUrl.hooks.php (modified) (history)
  • /trunk/extensions/ShortUrl/ShortUrl.i18n.php (modified) (history)
  • /trunk/extensions/ShortUrl/ShortUrl.php (modified) (history)
  • /trunk/extensions/ShortUrl/SpecialShortUrl.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ShortUrl/ShortUrl.functions.php
@@ -14,35 +14,35 @@
1515 }
1616
1717 /* stolen from http://www.php.net/manual/en/function.base64-encode.php#63543 */
18 -function urlsafe_b64encode($string) {
19 - $data = base64_encode($string);
20 - $data = str_replace(array('+','/','='),array('-','_',''),$data);
21 - return $data;
 18+function urlsafe_b64encode( $string ) {
 19+ $data = base64_encode( $string );
 20+ $data = str_replace( array( '+', '/', '=' ), array( '-', '_', '' ), $data );
 21+ return $data;
2222 }
2323
2424 /* stolen from http://www.php.net/manual/en/function.base64-encode.php#63543 */
25 -function urlsafe_b64decode($string) {
26 - $data = str_replace(array('-','_'),array('+','/'),$string);
27 - $mod4 = strlen($data) % 4;
28 - if ($mod4) {
29 - $data .= substr('====', $mod4);
30 - }
31 - return base64_decode($data);
 25+function urlsafe_b64decode( $string ) {
 26+ $data = str_replace( array( '-', '_' ), array( '+', '/' ), $string );
 27+ $mod4 = strlen( $data ) % 4;
 28+ if ( $mod4 ) {
 29+ $data .= substr( '====', $mod4 );
 30+ }
 31+ return base64_decode( $data );
3232 }
3333
3434 function shorturlEncode ( $title ) {
3535 global $wgMemc;
3636
37 - $id = null;
 37+ $id = null;
3838 $id = $wgMemc->get( wfMemcKey( 'shorturls', 'title', $title->getFullText() ) );
39 - if( !$id ) {
 39+ if ( !$id ) {
4040 $dbr = wfGetDB( DB_SLAVE );
4141 $query = $dbr->select(
4242 'shorturls',
4343 array( 'su_id' ),
4444 array( 'su_namespace' => $title->getNamespace(), 'su_title' => $title->getText() ),
45 - __METHOD__);
46 - if( $dbr->numRows( $query ) > 0 ) {
 45+ __METHOD__ );
 46+ if ( $dbr->numRows( $query ) > 0 ) {
4747 $entry = $dbr->fetchRow( $query );
4848 $id = $entry['su_id'];
4949 } else {
@@ -53,18 +53,18 @@
5454 'su_title' => $title->getText()
5555 );
5656 $dbw->insert( 'shorturls', $row_data );
57 - $id = $dbw->insertId();
 57+ $id = $dbw->insertId();
5858 }
5959 $wgMemc->set( wfMemcKey( 'shorturls', 'title', $title->getFullText() ), $id, 0 );
60 - }
 60+ }
6161 return urlsafe_b64encode( $id );
6262 }
6363
6464 function shorturlDecode ( $data ) {
6565 global $wgMemc;
6666
67 - $id = intval(urlsafe_b64decode ( $data ));
68 - $entry = $wgMemc->get( wfMemcKey( 'shorturls', 'id', $id) );
 67+ $id = intval( urlsafe_b64decode ( $data ) );
 68+ $entry = $wgMemc->get( wfMemcKey( 'shorturls', 'id', $id ) );
6969 if ( !$entry ) {
7070 $dbr = wfGetDB( DB_SLAVE );
7171 $query = $dbr->select(
@@ -74,7 +74,7 @@
7575 __METHOD__
7676 );
7777
78 - $entry = $dbr->fetchRow($query);
 78+ $entry = $dbr->fetchRow( $query );
7979 $wgMemc->set( wfMemcKey( 'shorturls', 'id', $id ), $entry, 0 );
8080 }
8181 return Title::makeTitle( $entry['su_namespace'], $entry['su_title'] );
Index: trunk/extensions/ShortUrl/ShortUrl.i18n.php
@@ -6,7 +6,7 @@
77 * @ingroup Extensions
88 * @author Yuvi Panda, yuvi.in
99 * @copyright © Yuvaraj Pandian <yuvipanda@yuvi.in>
10 - * @license Modified BSD License
 10+ * @license Modified BSD License
1111 */
1212
1313 $messages = array();
Index: trunk/extensions/ShortUrl/ShortUrl.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * Setup for ShortUrl extension, a special page that provides redirects to articles
 4+ * Setup for ShortUrl extension, a special page that provides redirects to articles
55 * via their page IDs
66 *
77 * @file
@@ -10,7 +10,7 @@
1111 * @licence Modified BSD License
1212 */
1313
14 -if( !defined( 'MEDIAWIKI' ) ) {
 14+if ( !defined( 'MEDIAWIKI' ) ) {
1515 echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
1616 die( 1 );
1717 }
Index: trunk/extensions/ShortUrl/SpecialShortUrl.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * Setup for ShortUrl extension, a special page that provides redirects to articles
 4+ * Setup for ShortUrl extension, a special page that provides redirects to articles
55 * via their page IDs
66 *
77 * @file
@@ -10,7 +10,7 @@
1111 * @licence Modified BSD License
1212 */
1313
14 -if( !defined( 'MEDIAWIKI' ) ) {
 14+if ( !defined( 'MEDIAWIKI' ) ) {
1515 echo( "not a valid entry point.\n" );
1616 die( 1 );
1717 }
@@ -37,7 +37,7 @@
3838 */
3939 public function execute( $par ) {
4040 global $wgOut, $wgRequest;
41 -
 41+
4242 $title = shorturlDecode( $par );
4343 if ( $title ) {
4444 $wgOut->redirect( $title->getFullURL(), '301' );
Index: trunk/extensions/ShortUrl/ShortUrl.hooks.php
@@ -23,7 +23,7 @@
2424 $shortId = shorturlEncode( $title );
2525 $shortURL = $wgShortUrlPrefix . $shortId;
2626 $html = Html::rawElement( 'li', array( 'id' => 't-shorturl' ),
27 - Html::Element( 'a', array( 'href' => $shortURL, 'title' => wfMsg( 'shorturl-toolbox-title') ), wfMsg ( 'shorturl-toolbox-text' ) )
 27+ Html::Element( 'a', array( 'href' => $shortURL, 'title' => wfMsg( 'shorturl-toolbox-title' ) ), wfMsg ( 'shorturl-toolbox-text' ) )
2828 );
2929
3030 echo $html;
@@ -33,7 +33,7 @@
3434
3535 public static function SetupSchema( DatabaseUpdater $du ) {
3636 $base = dirname( __FILE__ ) . '/schemas';
37 - $du->addExtensionTable( "shorturls", "$base/shorturls.sql");
 37+ $du->addExtensionTable( "shorturls", "$base/shorturls.sql" );
3838 return true;
3939 }
4040

Status & tagging log