Index: trunk/extensions/ShortUrl/ShortUrl.functions.php |
— | — | @@ -15,68 +15,66 @@ |
16 | 16 | |
17 | 17 | /* stolen from http://www.php.net/manual/en/function.base64-encode.php#63543 */ |
18 | 18 | function urlsafe_b64encode( $string ) { |
19 | | - $data = base64_encode( $string ); |
20 | | - $data = str_replace( array( '+', '/', '=' ), array( '-', '_', '' ), $data ); |
21 | | - return $data; |
| 19 | + $data = base64_encode( $string ); |
| 20 | + $data = str_replace( array( '+', '/', '=' ), array( '-', '_', '' ), $data ); |
| 21 | + return $data; |
22 | 22 | } |
23 | 23 | |
24 | 24 | /* stolen from http://www.php.net/manual/en/function.base64-encode.php#63543 */ |
25 | 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 ); |
| 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 ); |
32 | 32 | } |
33 | 33 | |
34 | 34 | function shorturlEncode ( $title ) { |
35 | | - global $wgMemc; |
| 35 | + global $wgMemc; |
36 | 36 | |
37 | | - $id = null; |
38 | | - $id = $wgMemc->get( wfMemcKey( 'shorturls', 'title', $title->getFullText() ) ); |
39 | | - if ( !$id ) { |
40 | | - $dbr = wfGetDB( DB_SLAVE ); |
41 | | - $query = $dbr->select( |
42 | | - 'shorturls', |
43 | | - array( 'su_id' ), |
44 | | - array( 'su_namespace' => $title->getNamespace(), 'su_title' => $title->getText() ), |
45 | | - __METHOD__ ); |
46 | | - if ( $dbr->numRows( $query ) > 0 ) { |
47 | | - $entry = $dbr->fetchRow( $query ); |
48 | | - $id = $entry['su_id']; |
49 | | - } else { |
50 | | - $dbw = wfGetDB( DB_MASTER ); |
51 | | - $row_data = array( |
52 | | - 'su_id' => $dbw->nextSequenceValue( 'shorturls_id_seq' ), |
53 | | - 'su_namespace' => $title->getNamespace(), |
54 | | - 'su_title' => $title->getText() |
55 | | - ); |
56 | | - $dbw->insert( 'shorturls', $row_data ); |
57 | | - $id = $dbw->insertId(); |
58 | | - } |
59 | | - $wgMemc->set( wfMemcKey( 'shorturls', 'title', $title->getFullText() ), $id, 0 ); |
60 | | - } |
| 37 | + $id = $wgMemc->get( wfMemcKey( 'shorturls', 'title', $title->getFullText() ) ); |
| 38 | + if ( !$id ) { |
| 39 | + $dbr = wfGetDB( DB_SLAVE ); |
| 40 | + $query = $dbr->select( |
| 41 | + 'shorturls', |
| 42 | + array( 'su_id' ), |
| 43 | + array( 'su_namespace' => $title->getNamespace(), 'su_title' => $title->getText() ), |
| 44 | + __METHOD__ ); |
| 45 | + if ( $dbr->numRows( $query ) > 0 ) { |
| 46 | + $entry = $dbr->fetchRow( $query ); |
| 47 | + $id = $entry['su_id']; |
| 48 | + } else { |
| 49 | + $dbw = wfGetDB( DB_MASTER ); |
| 50 | + $row_data = array( |
| 51 | + 'su_id' => $dbw->nextSequenceValue( 'shorturls_id_seq' ), |
| 52 | + 'su_namespace' => $title->getNamespace(), |
| 53 | + 'su_title' => $title->getText() |
| 54 | + ); |
| 55 | + $dbw->insert( 'shorturls', $row_data ); |
| 56 | + $id = $dbw->insertId(); |
| 57 | + } |
| 58 | + $wgMemc->set( wfMemcKey( 'shorturls', 'title', $title->getFullText() ), $id, 0 ); |
| 59 | + } |
61 | 60 | return urlsafe_b64encode( $id ); |
62 | 61 | } |
63 | 62 | |
64 | 63 | function shorturlDecode ( $data ) { |
65 | | - global $wgMemc; |
| 64 | + global $wgMemc; |
66 | 65 | |
67 | | - $id = intval( urlsafe_b64decode ( $data ) ); |
68 | | - $entry = $wgMemc->get( wfMemcKey( 'shorturls', 'id', $id ) ); |
69 | | - if ( !$entry ) { |
70 | | - $dbr = wfGetDB( DB_SLAVE ); |
71 | | - $query = $dbr->select( |
72 | | - 'shorturls', |
73 | | - array( 'su_namespace', 'su_title' ), |
74 | | - array( 'su_id' => $id ), |
75 | | - __METHOD__ |
76 | | - ); |
| 66 | + $id = intval( urlsafe_b64decode ( $data ) ); |
| 67 | + $entry = $wgMemc->get( wfMemcKey( 'shorturls', 'id', $id ) ); |
| 68 | + if ( !$entry ) { |
| 69 | + $dbr = wfGetDB( DB_SLAVE ); |
| 70 | + $query = $dbr->select( |
| 71 | + 'shorturls', |
| 72 | + array( 'su_namespace', 'su_title' ), |
| 73 | + array( 'su_id' => $id ), |
| 74 | + __METHOD__ |
| 75 | + ); |
77 | 76 | |
78 | | - $entry = $dbr->fetchRow( $query ); |
79 | | - $wgMemc->set( wfMemcKey( 'shorturls', 'id', $id ), $entry, 0 ); |
80 | | - } |
81 | | - return Title::makeTitle( $entry['su_namespace'], $entry['su_title'] ); |
82 | | - |
| 77 | + $entry = $dbr->fetchRow( $query ); |
| 78 | + $wgMemc->set( wfMemcKey( 'shorturls', 'id', $id ), $entry, 0 ); |
| 79 | + } |
| 80 | + return Title::makeTitle( $entry['su_namespace'], $entry['su_title'] ); |
83 | 81 | } |
Property changes on: trunk/extensions/ShortUrl/install.settings |
___________________________________________________________________ |
Added: svn:eol-style |
84 | 82 | + native |
Index: trunk/extensions/ShortUrl/SpecialShortUrl.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | * @param $par Mixed: Parameters passed to the page |
38 | 38 | */ |
39 | 39 | public function execute( $par ) { |
40 | | - global $wgOut, $wgRequest; |
| 40 | + global $wgOut; |
41 | 41 | |
42 | 42 | $title = shorturlDecode( $par ); |
43 | 43 | if ( $title ) { |
Property changes on: trunk/extensions/ShortUrl/README |
___________________________________________________________________ |
Added: svn:eol-style |
44 | 44 | + native |