Index: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.alias.php |
— | — | @@ -0,0 +1,67 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Aliases for special pages |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +$specialPageAliases = array(); |
| 9 | + |
| 10 | +/** English (English) */ |
| 11 | +$specialPageAliases['en'] = array( |
| 12 | + 'ShortUrl' => array( 'ShortUrl' ), |
| 13 | +); |
| 14 | + |
| 15 | +/** Arabic (العربية) */ |
| 16 | +$specialPageAliases['ar'] = array( |
| 17 | + 'ShortUrl' => array( 'مسار_قصير' ), |
| 18 | +); |
| 19 | + |
| 20 | +/** German (Deutsch) */ |
| 21 | +$specialPageAliases['de'] = array( |
| 22 | + 'ShortUrl' => array( 'Kurze_URL' ), |
| 23 | +); |
| 24 | + |
| 25 | +/** Persian (فارسی) */ |
| 26 | +$specialPageAliases['fa'] = array( |
| 27 | + 'ShortUrl' => array( 'نشانی_کوتاه' ), |
| 28 | +); |
| 29 | + |
| 30 | +/** Interlingua (Interlingua) */ |
| 31 | +$specialPageAliases['ia'] = array( |
| 32 | + 'ShortUrl' => array( 'URL_curte' ), |
| 33 | +); |
| 34 | + |
| 35 | +/** Indonesian (Bahasa Indonesia) */ |
| 36 | +$specialPageAliases['id'] = array( |
| 37 | + 'ShortUrl' => array( 'UrlPendek' ), |
| 38 | +); |
| 39 | + |
| 40 | +/** Japanese (日本語) */ |
| 41 | +$specialPageAliases['ja'] = array( |
| 42 | + 'ShortUrl' => array( '短縮URL' ), |
| 43 | +); |
| 44 | + |
| 45 | +/** Luxembourgish (Lëtzebuergesch) */ |
| 46 | +$specialPageAliases['lb'] = array( |
| 47 | + 'ShortUrl' => array( 'Kuerz_URL' ), |
| 48 | +); |
| 49 | + |
| 50 | +/** Macedonian (Македонски) */ |
| 51 | +$specialPageAliases['mk'] = array( |
| 52 | + 'ShortUrl' => array( 'КраткаUrl' ), |
| 53 | +); |
| 54 | + |
| 55 | +/** Nedersaksisch (Nedersaksisch) */ |
| 56 | +$specialPageAliases['nds-nl'] = array( |
| 57 | + 'ShortUrl' => array( 'Kort_webadres' ), |
| 58 | +); |
| 59 | + |
| 60 | +/** Dutch (Nederlands) */ |
| 61 | +$specialPageAliases['nl'] = array( |
| 62 | + 'ShortUrl' => array( 'KorteURL' ), |
| 63 | +); |
| 64 | + |
| 65 | +/** Traditional Chinese (中文(繁體)) */ |
| 66 | +$specialPageAliases['zh-hant'] = array( |
| 67 | + 'ShortUrl' => array( '縮寫的URL' ), |
| 68 | +); |
\ No newline at end of file |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.alias.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 69 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/schemas/shorturls.sql |
— | — | @@ -0,0 +1,10 @@ |
| 2 | +-- Replace /*_*/ with the proper prefix |
| 3 | +-- Replace /*$wgDBTableOptions*/ with the correct options |
| 4 | + |
| 5 | +CREATE TABLE IF NOT EXISTS /*_*/shorturls ( |
| 6 | + su_id integer NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 7 | + su_namespace integer NOT NULL, |
| 8 | + su_title varchar(255) NOT NULL |
| 9 | +) /*$wgDBTableOptions*/; |
| 10 | + |
| 11 | +CREATE UNIQUE INDEX /*i*/shorturls_ns_title ON /*_*/shorturls (su_namespace, su_title); |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/schemas/shorturls.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 12 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/install.settings |
— | — | @@ -0,0 +1 @@ |
| 2 | +require_once( "{{path}}/ShortUrl.php" ); |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/install.settings |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 3 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.i18n.php |
— | — | @@ -0,0 +1,254 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation file for ShortUrl extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * @author Yuvi Panda, yuvi.in |
| 9 | + * @copyright © Yuvaraj Pandian <yuvipanda@yuvi.in> |
| 10 | + * @license Modified BSD License |
| 11 | + */ |
| 12 | + |
| 13 | +$messages = array(); |
| 14 | + |
| 15 | +/** English |
| 16 | + * @author Yuvi Panda |
| 17 | + */ |
| 18 | +$messages['en'] = array( |
| 19 | + 'shorturl' => 'Short URL', |
| 20 | + 'shorturl-desc' => '[[Special:ShortUrl|Short URL for redirects]]', |
| 21 | + 'shorturl-not-found-title' => 'Short URL not found', |
| 22 | + 'shorturl-not-found-message' => 'Sorry, the URL you are looking for is not found (No short URL with ID $1 exists)', |
| 23 | + 'shorturl-toolbox-title' => 'Copy this short link for sharing', |
| 24 | + 'shorturl-toolbox-text' => 'Short URL' |
| 25 | +); |
| 26 | + |
| 27 | +/** Asturian (Asturianu) |
| 28 | + * @author Xuacu |
| 29 | + */ |
| 30 | +$messages['ast'] = array( |
| 31 | + 'shorturl' => 'URL curtia', |
| 32 | + 'shorturl-desc' => '[[Special:ShortUrl|URL curtia pa redireiciones]]', |
| 33 | + 'shorturl-not-found-title' => "Nun s'alcontró la URL curtia", |
| 34 | + 'shorturl-not-found-message' => "Lo sentimos, nun s'alcontró la URL que tas buscando (Nun esiste denguna URL curtia con ID $1)", |
| 35 | + 'shorturl-toolbox-title' => 'Copia esti enllaz curtiu pa compartir', |
| 36 | + 'shorturl-toolbox-text' => 'URL curtia', |
| 37 | +); |
| 38 | + |
| 39 | +/** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
| 40 | + * @author EugeneZelenko |
| 41 | + * @author Renessaince |
| 42 | + * @author Wizardist |
| 43 | + */ |
| 44 | +$messages['be-tarask'] = array( |
| 45 | + 'shorturl' => 'Кароткія спасылкі', |
| 46 | + 'shorturl-desc' => '[[Special:ShortUrl|Кароткія спасылкі для перанакіраваньняў]]', |
| 47 | + 'shorturl-not-found-title' => 'Кароткі URL-адрас ня знойдзены', |
| 48 | + 'shorturl-not-found-message' => 'На жаль, пазначаны URL-адрас ня знойдзены (кароткая спасылка з ідэнтыфікатарам $1 не існуе)', |
| 49 | + 'shorturl-toolbox-title' => 'Скапіюйце гэтую кароткую спасылку', |
| 50 | + 'shorturl-toolbox-text' => 'Кароткая спасылка', |
| 51 | +); |
| 52 | + |
| 53 | +/** Breton (Brezhoneg) |
| 54 | + * @author Y-M D |
| 55 | + */ |
| 56 | +$messages['br'] = array( |
| 57 | + 'shorturl' => 'URL berr', |
| 58 | + 'shorturl-desc' => '[[Special:ShortUrl|URL berr evit adkasoù]]', |
| 59 | + 'shorturl-not-found-message' => "Digarezit, n'eo ket bet kavet an URL emaoc'h o klask (N'eus URL berr ebet gant an ID $1)", |
| 60 | + 'shorturl-toolbox-title' => 'Kopiit al liamm berr-mañ evit e rannañ', |
| 61 | + 'shorturl-toolbox-text' => 'URL berr', |
| 62 | +); |
| 63 | + |
| 64 | +/** German (Deutsch) |
| 65 | + * @author Kghbln |
| 66 | + */ |
| 67 | +$messages['de'] = array( |
| 68 | + 'shorturl' => 'Kurz-URL', |
| 69 | + 'shorturl-desc' => 'Ergänzt eine [[Special:ShortUrl|Spezialseite]] zum Erstellen von Kurz-URLs für Weiterleitungen', |
| 70 | + 'shorturl-not-found-title' => 'Die Kurz-URL wurde nicht gefunden', |
| 71 | + 'shorturl-not-found-message' => 'Die gesuchte Kurz-URL wurde leider nicht gefunden (Es ist keine Kurz-URL mit der Kennung $1 vorhanden)', |
| 72 | + 'shorturl-toolbox-title' => 'Kurz-URL kopieren, um sie zu nutzen', |
| 73 | + 'shorturl-toolbox-text' => 'Kurz-URL', |
| 74 | +); |
| 75 | + |
| 76 | +/** French (Français) |
| 77 | + * @author Gomoko |
| 78 | + * @author Jean-Frédéric |
| 79 | + * @author Sherbrooke |
| 80 | + */ |
| 81 | +$messages['fr'] = array( |
| 82 | + 'shorturl' => 'URL courte', |
| 83 | + 'shorturl-desc' => '[[Special:ShortUrl|URL courte pour les redirections]]', |
| 84 | + 'shorturl-not-found-title' => 'URL courte introuvable', |
| 85 | + 'shorturl-not-found-message' => 'Désolé, l’URL que vous recherchez est introuvable (aucune URL courte avec l’ID $1)', |
| 86 | + 'shorturl-toolbox-title' => 'Copiez ce court lien pour le partager', |
| 87 | + 'shorturl-toolbox-text' => 'URL courte', |
| 88 | +); |
| 89 | + |
| 90 | +/** Franco-Provençal (Arpetan) |
| 91 | + * @author ChrisPtDe |
| 92 | + */ |
| 93 | +$messages['frp'] = array( |
| 94 | + 'shorturl' => 'URL côrta', |
| 95 | + 'shorturl-desc' => '[[Special:ShortUrl|URL côrta por les redirèccions]]', |
| 96 | + 'shorturl-toolbox-text' => 'URL côrta', |
| 97 | +); |
| 98 | + |
| 99 | +/** Galician (Galego) |
| 100 | + * @author Toliño |
| 101 | + */ |
| 102 | +$messages['gl'] = array( |
| 103 | + 'shorturl' => 'Enderezo URL curto', |
| 104 | + 'shorturl-desc' => '[[Special:ShortUrl|Enderezo URL curto para as redireccións]]', |
| 105 | + 'shorturl-not-found-title' => 'Non se atopou o enderezo URL curto', |
| 106 | + 'shorturl-not-found-message' => 'Sentímolo, non se atopou o enderezo URL que está a buscar (non existe ningún enderezo URL curto co ID $1)', |
| 107 | + 'shorturl-toolbox-title' => 'Copie esta ligazón curta para compartir', |
| 108 | + 'shorturl-toolbox-text' => 'Enderezo URL curto', |
| 109 | +); |
| 110 | + |
| 111 | +/** Hebrew (עברית) |
| 112 | + * @author Amire80 |
| 113 | + */ |
| 114 | +$messages['he'] = array( |
| 115 | + 'shorturl' => 'כתובת מקוצרת', |
| 116 | + 'shorturl-desc' => '[[Special:ShortUrl|כתובת מקוצרת להפניות]]', |
| 117 | + 'shorturl-not-found-title' => 'כתובת מקוצרת לא נמצאה', |
| 118 | + 'shorturl-not-found-message' => 'סליחה, הכתובת שאתם מחפשים אינה נמצאת (אין כתובת מקוצרת עם המזהה $1)', |
| 119 | + 'shorturl-toolbox-title' => 'העתיקו את הקישור הקצר הזה בשביל שיתוף', |
| 120 | + 'shorturl-toolbox-text' => 'כתובת מקוצרת', |
| 121 | +); |
| 122 | + |
| 123 | +/** Hindi (हिन्दी) |
| 124 | + * @author Rsrikanth05 |
| 125 | + */ |
| 126 | +$messages['hi'] = array( |
| 127 | + 'shorturl' => 'संक्षेप यूआरएल', |
| 128 | +); |
| 129 | + |
| 130 | +/** Upper Sorbian (Hornjoserbsce) |
| 131 | + * @author Michawiki |
| 132 | + */ |
| 133 | +$messages['hsb'] = array( |
| 134 | + 'shorturl' => 'Krótki URL', |
| 135 | + 'shorturl-desc' => '[[Special:ShortUrl|Krótke URL za dalesposrědkowanja]]', |
| 136 | + 'shorturl-not-found-title' => 'Krótki URL njeje so namakał', |
| 137 | + 'shorturl-not-found-message' => 'URL, kotryž sy pytał, njeje so namakał (krótki URL z ID $1 njeeksistuje)', |
| 138 | + 'shorturl-toolbox-title' => 'Tutón krótki wotkaz kopěrować, zo by so z druhimi wužiwał', |
| 139 | + 'shorturl-toolbox-text' => 'Krótki URL', |
| 140 | +); |
| 141 | + |
| 142 | +/** Interlingua (Interlingua) |
| 143 | + * @author McDutchie |
| 144 | + */ |
| 145 | +$messages['ia'] = array( |
| 146 | + 'shorturl' => 'URL curte', |
| 147 | + 'shorturl-desc' => '[[Special:ShortUrl|URL curte pro redirectiones]]', |
| 148 | + 'shorturl-not-found-title' => 'URL curte non trovate', |
| 149 | + 'shorturl-not-found-message' => 'Le URL que tu cerca non ha essite trovate (nulle URL curte con le ID $1 existe).', |
| 150 | + 'shorturl-toolbox-title' => 'Copiar iste ligamine curte pro divulgation', |
| 151 | + 'shorturl-toolbox-text' => 'URL curte', |
| 152 | +); |
| 153 | + |
| 154 | +/** Luxembourgish (Lëtzebuergesch) |
| 155 | + * @author Robby |
| 156 | + */ |
| 157 | +$messages['lb'] = array( |
| 158 | + 'shorturl' => 'Kuerz URL', |
| 159 | + 'shorturl-desc' => '[[Special:ShortUrl|Kuerz URL fir Viruleedungen]]', |
| 160 | + 'shorturl-not-found-title' => 'Kuerz URL gouf net fonnt', |
| 161 | + 'shorturl-not-found-message' => "Pardon, d'URL no där Dir sicht gouf net fonnt (Et gëtt keng Kuerz-URL mat der ID $1)", |
| 162 | + 'shorturl-toolbox-title' => 'Kopéiert dës Kuerz-URL fir se ze notzen', |
| 163 | + 'shorturl-toolbox-text' => 'Kuerz URL', |
| 164 | +); |
| 165 | + |
| 166 | +/** Macedonian (Македонски) |
| 167 | + * @author Bjankuloski06 |
| 168 | + */ |
| 169 | +$messages['mk'] = array( |
| 170 | + 'shorturl' => 'Кратка URL-адреса', |
| 171 | + 'shorturl-desc' => '[[Special:ShortUrl|Кратка URL-адреса за пренасочувања]]', |
| 172 | + 'shorturl-not-found-title' => 'Не ја пронајдов кратката URL-адреса', |
| 173 | + 'shorturl-not-found-message' => 'Нажалост, не ја најдов URL-адресата што ја барате (не постои кратка URL-адреса со назнаката $1)', |
| 174 | + 'shorturl-toolbox-title' => 'Ископирајте ја оваа кратка врска за да ја споделите', |
| 175 | + 'shorturl-toolbox-text' => 'Кратка URL-адреса', |
| 176 | +); |
| 177 | + |
| 178 | +/** Malay (Bahasa Melayu) |
| 179 | + * @author Anakmalaysia |
| 180 | + */ |
| 181 | +$messages['ms'] = array( |
| 182 | + 'shorturl' => 'URL Ringkas', |
| 183 | + 'shorturl-desc' => '[[Special:ShortUrl|URL Ringkas untuk lencongan]]', |
| 184 | + 'shorturl-not-found-title' => 'URL ringkas tidak dijumpai', |
| 185 | + 'shorturl-not-found-message' => 'Maaf, URL yang anda cari itu tidak dijumpai (Tidak wujudnya URL yang ber-ID $1)', |
| 186 | + 'shorturl-toolbox-title' => 'Salin pautan ringkas ini untuk dikongsi', |
| 187 | + 'shorturl-toolbox-text' => 'URL Ringkas', |
| 188 | +); |
| 189 | + |
| 190 | +/** Dutch (Nederlands) |
| 191 | + * @author SPQRobin |
| 192 | + * @author Siebrand |
| 193 | + */ |
| 194 | +$messages['nl'] = array( |
| 195 | + 'shorturl' => 'Korte URL', |
| 196 | + 'shorturl-desc' => '[[Special:ShortUrl|Korte URL voor doorverwijzingen]]', |
| 197 | + 'shorturl-not-found-title' => 'Korte URL niet gevonden', |
| 198 | + 'shorturl-not-found-message' => 'De URL waarnaar u zoekt is niet gevonden. Er bestaat geen korte URL met ID $1', |
| 199 | + 'shorturl-toolbox-title' => 'Deze korte verwijzing kopiëren om te delen', |
| 200 | + 'shorturl-toolbox-text' => 'Korte URL', |
| 201 | +); |
| 202 | + |
| 203 | +/** Oriya (ଓଡ଼ିଆ) |
| 204 | + * @author Psubhashish |
| 205 | + */ |
| 206 | +$messages['or'] = array( |
| 207 | + 'shorturl' => 'ଛୋଟ URL', |
| 208 | + 'shorturl-desc' => '[[Special:ShortUrl|ଆଉଥରେ ଫେରନ୍ତା ଲିଙ୍କପାଇଁ ଛୋଟ URL]]', |
| 209 | + 'shorturl-not-found-message' => 'କ୍ଷମା କରିବେ, ଆପଣ ଦେଇଥିବା URLଟି ମିଳିଲା ନାହିଁ ($1 ନାଆଁରେ କିଛି ଛୋଟ URL ମିଳିଲା ନାହିଁ)', |
| 210 | + 'shorturl-toolbox-title' => 'ଏହି ଛୋଟ ଲିଙ୍କଟି ବାଣ୍ଟିବା ପାଇଁ ନକଲ କରନ୍ତୁ', |
| 211 | + 'shorturl-toolbox-text' => 'ଛୋଟ URL', |
| 212 | +); |
| 213 | + |
| 214 | +/** Portuguese (Português) |
| 215 | + * @author Hamilton Abreu |
| 216 | + */ |
| 217 | +$messages['pt'] = array( |
| 218 | + 'shorturl' => 'URL Curta', |
| 219 | + 'shorturl-desc' => '[[Special:ShortUrl|URL Curta para redireccionamentos]]', |
| 220 | + 'shorturl-not-found-message' => 'A URL que pretende não foi encontrada (não existe nenhuma URL Curta com a identificação $1)', |
| 221 | + 'shorturl-toolbox-title' => 'Copie este link curto para partilhar', |
| 222 | + 'shorturl-toolbox-text' => 'URL Curta', |
| 223 | +); |
| 224 | + |
| 225 | +/** Russian (Русский) |
| 226 | + * @author Александр Сигачёв |
| 227 | + */ |
| 228 | +$messages['ru'] = array( |
| 229 | + 'shorturl' => 'Короткая ссылка', |
| 230 | + 'shorturl-desc' => '[[Special:ShortUrl|Короткая ссылка для перенаправлений]]', |
| 231 | + 'shorturl-not-found-message' => 'К сожалению, указанный URL-адрес не найден (нет короткой ссылки с идентификатором $1)', |
| 232 | + 'shorturl-toolbox-title' => 'Скопируйте эту короткую ссылку', |
| 233 | + 'shorturl-toolbox-text' => 'Короткая ссылка', |
| 234 | +); |
| 235 | + |
| 236 | +/** Swedish (Svenska) |
| 237 | + * @author WikiPhoenix |
| 238 | + */ |
| 239 | +$messages['sv'] = array( |
| 240 | + 'shorturl' => 'Kort URL', |
| 241 | + 'shorturl-desc' => '[[Special:ShortUrl|Kort URL för omdirigeringar]]', |
| 242 | + 'shorturl-toolbox-text' => 'Kort URL', |
| 243 | +); |
| 244 | + |
| 245 | +/** Tamil (தமிழ்) |
| 246 | + * @author Surya Prakash.S.A. |
| 247 | + */ |
| 248 | +$messages['ta'] = array( |
| 249 | + 'shorturl' => 'குறுந்தொடுப்பு', |
| 250 | + 'shorturl-desc' => '[[Special:ShortUrl|வழிமாற்றுகளுக்கான குறுந்தொடுப்பு]]', |
| 251 | + 'shorturl-not-found-message' => 'மன்னிக்கவும், நீங்கள் எதிர்பார்க்கும் உரலி கிடைக்கவில்லை ($1 என்ற அடையாளத்துடன் கூடிய குறுந்தொடுப்பு ஏதுமில்லை)', |
| 252 | + 'shorturl-toolbox-title' => 'பகிர்வதற்காக இக்குறுந்தொடுப்பை நகலெடுக்கவும்', |
| 253 | + 'shorturl-toolbox-text' => 'குறுந்தொடுப்பு', |
| 254 | +); |
| 255 | + |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 256 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.utils.php |
— | — | @@ -0,0 +1,92 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Functions used for decoding/encoding ids in ShortUrl Extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * @author Yuvi Panda, http://yuvi.in |
| 9 | + * @copyright © 2011 Yuvaraj Pandian (yuvipanda@yuvi.in) |
| 10 | + * @licence Modified BSD License |
| 11 | + */ |
| 12 | + |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + exit( 1 ); |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * Utility functions for encoding and decoding short URLs |
| 19 | + */ |
| 20 | +class ShortUrlUtils { |
| 21 | + |
| 22 | + /** |
| 23 | + * @param $title Title |
| 24 | + * @return mixed|string |
| 25 | + */ |
| 26 | + public static function encodeTitle( $title ) { |
| 27 | + global $wgMemc; |
| 28 | + |
| 29 | + $memcKey = wfMemcKey( 'shorturls', 'title', $title->getPrefixedText() ); |
| 30 | + $id = $wgMemc->get( $memcKey ); |
| 31 | + if ( !$id ) { |
| 32 | + $dbr = wfGetDB( DB_SLAVE ); |
| 33 | + $entry = $dbr->selectRow( |
| 34 | + 'shorturls', |
| 35 | + array( 'su_id' ), |
| 36 | + array( |
| 37 | + 'su_namespace' => $title->getNamespace(), |
| 38 | + 'su_title' => $title->getDBkey() |
| 39 | + ), |
| 40 | + __METHOD__ |
| 41 | + ); |
| 42 | + if ( $entry !== false ) { |
| 43 | + $id = $entry->su_id; |
| 44 | + } else { |
| 45 | + $dbw = wfGetDB( DB_MASTER ); |
| 46 | + $rowData = array( |
| 47 | + 'su_id' => $dbw->nextSequenceValue( 'shorturls_id_seq' ), |
| 48 | + 'su_namespace' => $title->getNamespace(), |
| 49 | + 'su_title' => $title->getDBkey() |
| 50 | + ); |
| 51 | + $dbw->insert( 'shorturls', $rowData, __METHOD__ ); |
| 52 | + $id = $dbw->insertId(); |
| 53 | + } |
| 54 | + $wgMemc->set( $memcKey, $id, 0 ); |
| 55 | + } |
| 56 | + return base_convert( $id, 10, 36 ); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @param $urlFragment String |
| 61 | + * @return Title |
| 62 | + */ |
| 63 | + public static function decodeURL( $urlFragment ) { |
| 64 | + global $wgMemc; |
| 65 | + |
| 66 | + $id = intval( base_convert( $urlFragment, 36, 10 ) ); |
| 67 | + $memcKey = wfMemcKey( 'shorturls', 'id', $id ); |
| 68 | + $entry = $wgMemc->get( $memcKey ); |
| 69 | + if ( !$entry ) { |
| 70 | + $dbr = wfGetDB( DB_SLAVE ); |
| 71 | + $entry = $dbr->selectRow( |
| 72 | + 'shorturls', |
| 73 | + array( 'su_namespace', 'su_title' ), |
| 74 | + array( 'su_id' => $id ), |
| 75 | + __METHOD__ |
| 76 | + ); |
| 77 | + |
| 78 | + if ( $entry === false ) { |
| 79 | + return false; // No such shorturl exists |
| 80 | + } |
| 81 | + $wgMemc->set( $memcKey, $entry, 0 ); |
| 82 | + } |
| 83 | + return Title::makeTitle( $entry->su_namespace, $entry->su_title ); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @param $title Title |
| 88 | + * @return Boolean: true if a short URL needs to be displayed |
| 89 | + */ |
| 90 | + public static function needsShortUrl( $title ) { |
| 91 | + return $title->exists() && !$title->isMainPage(); |
| 92 | + } |
| 93 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.utils.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 94 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.php |
— | — | @@ -0,0 +1,56 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Setup for ShortUrl extension, a special page that provides redirects to articles |
| 5 | + * via their page IDs |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + * @author Yuvi Panda, http://yuvi.in |
| 10 | + * @copyright © 2011 Yuvaraj Pandian (yuvipanda@yuvi.in) |
| 11 | + * @licence Modified BSD License |
| 12 | + */ |
| 13 | + |
| 14 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 15 | + echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); |
| 16 | + die( 1 ); |
| 17 | +} |
| 18 | + |
| 19 | +/** |
| 20 | + * Configuration variables |
| 21 | + * Prefix to use for the shortened URL. mod_rewrite (or equivalent) needs to be setup |
| 22 | + * to produce a shorter URL |
| 23 | + * Default is 'null' which just uses the (not so short) URL that all Special Pages get |
| 24 | + * Eg: http://en.wikipedia.org/wiki/Special:ShortUrl/5234 |
| 25 | + */ |
| 26 | +$wgShortUrlPrefix = null; |
| 27 | + |
| 28 | +// Extension credits that will show up on Special:Version |
| 29 | +$wgExtensionCredits['specialpage'][] = array( |
| 30 | + 'path' => __FILE__, |
| 31 | + 'name' => 'ShortUrl', |
| 32 | + 'version' => '1.0', |
| 33 | + 'author' => 'Yuvi Panda', |
| 34 | + 'url' => 'https://www.mediawiki.org/wiki/Extension:ShortUrl', |
| 35 | + 'descriptionmsg' => 'shorturl-desc', |
| 36 | +); |
| 37 | + |
| 38 | +// Set up the new special page |
| 39 | +$dir = dirname( __FILE__ ) . '/'; |
| 40 | +$wgExtensionMessagesFiles['ShortUrl'] = $dir . 'ShortUrl.i18n.php'; |
| 41 | +$wgExtensionMessagesFiles['ShortUrlAlias'] = $dir . 'ShortUrl.alias.php'; |
| 42 | + |
| 43 | +$wgAutoloadClasses['ShortUrlUtils'] = $dir . 'ShortUrl.utils.php'; |
| 44 | +$wgAutoloadClasses['ShortUrlHooks'] = $dir . 'ShortUrl.hooks.php'; |
| 45 | +$wgAutoloadClasses['SpecialShortUrl'] = $dir . 'SpecialShortUrl.php'; |
| 46 | +$wgSpecialPages['ShortUrl'] = 'SpecialShortUrl'; |
| 47 | + |
| 48 | +$wgHooks['SkinTemplateToolboxEnd'][] = 'ShortUrlHooks::addToolboxLink'; |
| 49 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'ShortUrlHooks::setupSchema'; |
| 50 | +$wgHooks['OutputPageBeforeHTML'][] = 'ShortUrlHooks::onOutputPageBeforeHTML'; |
| 51 | + |
| 52 | +$wgResourceModules['ext.shortUrl'] = array( |
| 53 | + 'scripts' => 'js/ext.shortUrl.js', |
| 54 | + 'styles' => 'css/ext.shortUrl.css', |
| 55 | + 'localBasePath' => dirname( __FILE__ ), |
| 56 | + 'remoteExtPath' => 'ShortUrl' |
| 57 | +); |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 58 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/css/ext.shortUrl.css |
— | — | @@ -0,0 +1,4 @@ |
| 2 | +.title-shortlink { |
| 3 | + font-size: small; |
| 4 | + margin: 0px; |
| 5 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/css/ext.shortUrl.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 6 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/SpecialShortUrl.php |
— | — | @@ -0,0 +1,45 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A special page that provides redirects to articles via their page IDs |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * @author Yuvi Panda, http://yuvi.in |
| 9 | + * @copyright © 2011 Yuvaraj Pandian (yuvipanda@yuvi.in) |
| 10 | + * @licence Modified BSD License |
| 11 | + */ |
| 12 | + |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + echo( "not a valid entry point.\n" ); |
| 15 | + die( 1 ); |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * Provides the actual redirection |
| 20 | + * @ingroup SpecialPage |
| 21 | + */ |
| 22 | +class SpecialShortUrl extends SpecialPage { |
| 23 | + |
| 24 | + /** |
| 25 | + * Constructor |
| 26 | + */ |
| 27 | + public function __construct() { |
| 28 | + parent::__construct( 'ShortUrl' ); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Main execution function |
| 33 | + * |
| 34 | + * @param $par Mixed: Parameters passed to the page |
| 35 | + */ |
| 36 | + public function execute( $par ) { |
| 37 | + global $wgOut; |
| 38 | + |
| 39 | + $title = ShortUrlUtils::decodeURL( $par ); |
| 40 | + if ( $title !== false ) { |
| 41 | + $wgOut->redirect( $title->getFullURL(), '301' ); |
| 42 | + } else { |
| 43 | + $wgOut->showErrorPage( 'shorturl-not-found-title', 'shorturl-not-found-message', array( $par ) ); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/SpecialShortUrl.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 47 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.hooks.php |
— | — | @@ -0,0 +1,72 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Hooks for ShortUrl for adding link to toolbox |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * @author Yuvi Panda, http://yuvi.in |
| 9 | + * @copyright © 2011 Yuvaraj Pandian (yuvipanda@yuvi.in) |
| 10 | + * @licence Modified BSD License |
| 11 | + */ |
| 12 | + |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + exit( 1 ); |
| 15 | +} |
| 16 | + |
| 17 | +class ShortUrlHooks { |
| 18 | + /** |
| 19 | + * @param $tpl |
| 20 | + * @return bool |
| 21 | + */ |
| 22 | + public static function addToolboxLink( &$tpl ) { |
| 23 | + global $wgOut, $wgShortUrlPrefix; |
| 24 | + |
| 25 | + if ( $wgShortUrlPrefix === null ) { |
| 26 | + $urlPrefix = SpecialPage::getTitleFor( 'ShortUrl' )->getCanonicalUrl() . '/'; |
| 27 | + } else { |
| 28 | + $urlPrefix = $wgShortUrlPrefix; |
| 29 | + } |
| 30 | + |
| 31 | + $title = $wgOut->getTitle(); |
| 32 | + if ( ShortUrlUtils::needsShortUrl( $title ) ) { |
| 33 | + $shortId = ShortUrlUtils::encodeTitle( $title ); |
| 34 | + $shortURL = $urlPrefix . $shortId; |
| 35 | + $html = Html::rawElement( 'li', array( 'id' => 't-shorturl' ), |
| 36 | + Html::Element( 'a', array( |
| 37 | + 'href' => $shortURL, |
| 38 | + 'title' => wfMsg( 'shorturl-toolbox-title' ) |
| 39 | + ), |
| 40 | + wfMsg( 'shorturl-toolbox-text' ) ) |
| 41 | + ); |
| 42 | + |
| 43 | + echo $html; |
| 44 | + } |
| 45 | + return true; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @param $out OutputPage |
| 50 | + * @param $text string the HTML text to be added |
| 51 | + * @return bool |
| 52 | + */ |
| 53 | + public static function onOutputPageBeforeHTML( &$out, &$text ) { |
| 54 | + global $wgOut; |
| 55 | + $title = $wgOut->getTitle(); |
| 56 | + if ( ShortUrlUtils::needsShortUrl( $title ) ) { |
| 57 | + $wgOut->addModules( 'ext.shortUrl' ); |
| 58 | + } |
| 59 | + return true; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @param $du DatabaseUpdater |
| 64 | + * @return bool |
| 65 | + */ |
| 66 | + public static function setupSchema( DatabaseUpdater $du ) { |
| 67 | + $base = dirname( __FILE__ ) . '/schemas'; |
| 68 | + $du->addExtensionTable( 'shorturls', "$base/shorturls.sql" ); |
| 69 | + return true; |
| 70 | + } |
| 71 | + |
| 72 | +} |
| 73 | + |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/ShortUrl.hooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 74 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/populateShortUrlTable.php |
— | — | @@ -0,0 +1,66 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$IP = getenv( 'MW_INSTALL_PATH' ); |
| 5 | +if ( $IP === false ) { |
| 6 | + $IP = dirname( __FILE__ ) . '/../..'; |
| 7 | +} |
| 8 | +require_once( "$IP/maintenance/Maintenance.php" ); |
| 9 | + |
| 10 | +class PopulateShortUrlsTable extends Maintenance { |
| 11 | + public function __construct() { |
| 12 | + parent::__construct(); |
| 13 | + $this->mDescription = 'Populates ShortUrls Table with all existing articles'; |
| 14 | + } |
| 15 | + |
| 16 | + private function insertRows( $a ) { |
| 17 | + $dbw = wfGetDB( DB_MASTER ); |
| 18 | + $dbw->insert( |
| 19 | + 'shorturls', |
| 20 | + $a, |
| 21 | + __METHOD__, |
| 22 | + array( 'IGNORE' ) |
| 23 | + ); |
| 24 | + } |
| 25 | + |
| 26 | + // @todo FIXME: Refactor out code in ShortUrl.functions.php so it can be used here |
| 27 | + public function execute() { |
| 28 | + $rowCount = 0; |
| 29 | + $dbr = wfGetDB( DB_SLAVE ); |
| 30 | + |
| 31 | + $last_processed_id = 0; |
| 32 | + |
| 33 | + while( true ) { |
| 34 | + $insertBuffer = array(); |
| 35 | + $res = $dbr->select( |
| 36 | + 'page', |
| 37 | + array( 'page_id', 'page_namespace', 'page_title' ), |
| 38 | + array( 'page_id > ' . $last_processed_id ), |
| 39 | + __METHOD__, |
| 40 | + array( 'LIMIT' => 100, 'ORDER BY' => 'page_id' ) |
| 41 | + ); |
| 42 | + if( $res->numRows() == 0 ) { |
| 43 | + break; |
| 44 | + } |
| 45 | + |
| 46 | + foreach( $res as $row ) { |
| 47 | + $rowCount++; |
| 48 | + |
| 49 | + $rowData = array( |
| 50 | + 'su_namespace' => $row->page_namespace, |
| 51 | + 'su_title' => $row->page_title |
| 52 | + ); |
| 53 | + $insertBuffer[] = $rowData; |
| 54 | + |
| 55 | + $last_processed_id = $row->page_id; |
| 56 | + } |
| 57 | + |
| 58 | + $this->insertRows( $insertBuffer ); |
| 59 | + wfWaitForSlaves(); // 'Kill' lag |
| 60 | + $this->output( $rowCount . " titles done\n" ); |
| 61 | + } |
| 62 | + $this->output( "Done\n" ); |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +$maintClass = 'PopulateShortUrlsTable'; |
| 67 | +require_once( DO_MAINTENANCE ); |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/populateShortUrlTable.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 68 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/js/ext.shortUrl.js |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +jQuery( function( $ ) { |
| 3 | + if( $( '#t-shorturl' ).length ) { |
| 4 | + var url = $( '#t-shorturl a' ).attr( 'href' ); |
| 5 | + $( '#firstHeading' ).append( $( '<div class="title-shortlink-container"></div>').append( $( '<a>' ).addClass( 'title-shortlink' ).attr( 'href', url ).text( url ) ) ); |
| 6 | + } |
| 7 | +}); |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/js/ext.shortUrl.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 8 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/README |
— | — | @@ -0,0 +1,21 @@ |
| 2 | +-------------------------------------------------------------------------- |
| 3 | +README for the ShortUrl extension |
| 4 | +Copyright © 2011 Yuvi Panda |
| 5 | +Licenses: GNU General Public Licence (GPL) |
| 6 | +-------------------------------------------------------------------------- |
| 7 | + |
| 8 | +<http://mediawiki.org/wiki/Extension:ShortUrl> |
| 9 | + |
| 10 | +== Installing == |
| 11 | + |
| 12 | +Copy the ShortUrl directory into the extensions folder of your |
| 13 | +MediaWiki installation. Then add the following lines to your |
| 14 | +LocalSettings.php file (near the end): |
| 15 | + |
| 16 | + require_once( "$IP/extensions/ShortUrl/ShortUrl.php" ); |
| 17 | + |
| 18 | +== Configuration == |
| 19 | + |
| 20 | +$wgShortUrlPrefix specifies the prefix to use before the shorturl. |
| 21 | +Defaults to using the longer form (with Special:ShortUrl). Can be |
| 22 | +condensed down to use anything else, via mod_rewrite rules |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/README |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 23 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/redirect.htaccess |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +RewriteEngine On |
| 3 | +# Needs fixing to remove extra Redirect |
| 4 | +RewriteRule ^([a-zA-Z0-9_-]+)$ /mediawiki/index.php/Special:ShortUrl/$1 [R] |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/redirect.htaccess |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 5 | + native |
Index: branches/wmf/1.18wmf1/extensions/ShortUrl/.vimrc |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +set noexpandtab |
| 3 | +set tabstop=4 |
Property changes on: branches/wmf/1.18wmf1/extensions/ShortUrl/.vimrc |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 4 | + native |