r88838 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88837‎ | r88838 | r88839 >
Date:21:11, 25 May 2011
Author:yuvipanda
Status:ok
Tags:
Comment:
Moved to base36
Modified paths:
  • /trunk/extensions/ShortUrl/ShortUrl.functions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ShortUrl/ShortUrl.functions.php
@@ -14,31 +14,6 @@
1515 }
1616
1717 /**
18 - * stolen from http://www.php.net/manual/en/function.base64-encode.php#63543
19 - *
20 - * @param $string string
21 - */
22 -function urlsafe_b64encode( $string ) {
23 - $data = base64_encode( $string );
24 - $data = str_replace( array( '+', '/', '=' ), array( '-', '_', '' ), $data );
25 - return $data;
26 -}
27 -
28 -/**
29 - * stolen from http://www.php.net/manual/en/function.base64-encode.php#63543
30 - *
31 - * @param $string string
32 - */
33 -function urlsafe_b64decode( $string ) {
34 - $data = str_replace( array( '-', '_' ), array( '+', '/' ), $string );
35 - $mod4 = strlen( $data ) % 4;
36 - if ( $mod4 ) {
37 - $data .= substr( '====', $mod4 );
38 - }
39 - return base64_decode( $data );
40 -}
41 -
42 -/**
4318 * @param $title Title
4419 * @return mixed|string
4520 */
@@ -68,7 +43,7 @@
6944 }
7045 $wgMemc->set( wfMemcKey( 'shorturls', 'title', $title->getFullText() ), $id, 0 );
7146 }
72 - return urlsafe_b64encode( $id );
 47+ return base_convert( $id, 10, 36 );
7348 }
7449
7550 /**
@@ -78,7 +53,7 @@
7954 function shorturlDecode ( $data ) {
8055 global $wgMemc;
8156
82 - $id = intval( urlsafe_b64decode ( $data ) );
 57+ $id = intval( base_convert ( $data, 36, 10 ) );
8358 $entry = $wgMemc->get( wfMemcKey( 'shorturls', 'id', $id ) );
8459 if ( !$entry ) {
8560 $dbr = wfGetDB( DB_SLAVE );

Status & tagging log