r103035 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103034‎ | r103035 | r103036 >
Date:21:22, 14 November 2011
Author:yuvipanda
Status:ok (Comments)
Tags:
Comment:
Fixed (most) issues with Extension:ShortURL pointed out in CR

Comprehensive CR URL: http://www.mediawiki.org/wiki/User:Catrope/Extension_review/ShortUrl
Modified paths:
  • /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/ShortUrl.utils.php (modified) (history)
  • /trunk/extensions/ShortUrl/SpecialShortUrl.php (modified) (history)
  • /trunk/extensions/ShortUrl/css/ext.shortUrl.css (modified) (history)
  • /trunk/extensions/ShortUrl/js/ext.shortUrl.js (modified) (history)
  • /trunk/extensions/ShortUrl/schemas/shorturls.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ShortUrl/ShortUrl.hooks.php
@@ -21,8 +21,8 @@
2222 public static function addToolboxLink( &$tpl ) {
2323 global $wgOut, $wgShortUrlPrefix;
2424
25 - if ( $wgShortUrlPrefix == null ) {
26 - $urlPrefix = SpecialPage::getTitleFor( 'ShortUrl' )->getFullURL() . '/';
 25+ if ( $wgShortUrlPrefix === null ) {
 26+ $urlPrefix = SpecialPage::getTitleFor( 'ShortUrl' )->getCanonicalUrl() . '/';
2727 } else {
2828 $urlPrefix = $wgShortUrlPrefix;
2929 }
Index: trunk/extensions/ShortUrl/js/ext.shortUrl.js
@@ -1,6 +1,6 @@
22 jQuery( function( $ ) {
33 if( $( '#t-shorturl' ).length ) {
44 var url = $( '#t-shorturl a' ).attr( 'href' );
5 - $( '#firstHeading' ).append( '<a class="title-shortlink" href="' + url + '">' + url + '</a>' );
 5+ $( '#firstHeading' ).append( $( '<div class="title-shortlink-container"></div>').append( $( '<a>' ).addClass( 'title-shortlink' ).attr( 'href', url ).text( url ) ) );
66 }
77 });
Index: trunk/extensions/ShortUrl/schemas/shorturls.sql
@@ -2,9 +2,9 @@
33 -- Replace /*$wgDBTableOptions*/ with the correct options
44
55 CREATE TABLE IF NOT EXISTS /*_*/shorturls (
6 - su_id integer NOT NULL AUTO_INCREMENT,
 6+ su_id integer NOT NULL PRIMARY KEY AUTO_INCREMENT,
77 su_namespace integer NOT NULL,
8 - su_title varchar(255) NOT NULL,
9 - PRIMARY KEY (su_id),
10 - UNIQUE KEY (su_namespace, su_title)
 8+ su_title varchar(255) NOT NULL
119 ) /*$wgDBTableOptions*/;
 10+
 11+CREATE UNIQUE INDEX /*i*/shorturls_ns_title ON /*_*/shorturls (su_namespace, su_title);
Index: trunk/extensions/ShortUrl/ShortUrl.i18n.php
@@ -17,7 +17,8 @@
1818 $messages['en'] = array(
1919 'shorturl' => 'Short URL',
2020 'shorturl-desc' => '[[Special:ShortUrl|Short URL for redirects]]',
21 - 'shorturl-not-found' => 'Sorry, the URL you are looking for is not found (No Short URL with ID $1 exists)',
 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)',
2223 'shorturl-toolbox-title' => 'Copy this short link for sharing',
2324 'shorturl-toolbox-text' => 'Short URL'
2425 );
@@ -28,7 +29,7 @@
2930 $messages['ast'] = array(
3031 'shorturl' => 'URL curtia',
3132 'shorturl-desc' => '[[Special:ShortUrl|URL curtia pa redireiciones]]',
32 - 'shorturl-not-found' => "Lo sentimos, nun s'alcontró la URL que tas buscando (Nun esiste denguna URL curtia con ID $1)",
 33+ 'shorturl-not-found-message' => "Lo sentimos, nun s'alcontró la URL que tas buscando (Nun esiste denguna URL curtia con ID $1)",
3334 'shorturl-toolbox-title' => 'Copia esti enllaz curtiu pa compartir',
3435 'shorturl-toolbox-text' => 'URL curtia',
3536 );
@@ -40,7 +41,7 @@
4142 $messages['be-tarask'] = array(
4243 'shorturl' => 'Кароткія спасылкі',
4344 'shorturl-desc' => '[[Special:ShortUrl|Кароткія спасылкі для перанакіраваньняў]]',
44 - 'shorturl-not-found' => 'На жаль, пазначаны URL-адрас ня знойдзены (кароткая спасылка з ідэнтыфікатарам $1 не існуе)',
 45+ 'shorturl-not-found-message' => 'На жаль, пазначаны URL-адрас ня знойдзены (кароткая спасылка з ідэнтыфікатарам $1 не існуе)',
4546 'shorturl-toolbox-title' => 'Скапіюйце гэтую кароткую спасылку',
4647 'shorturl-toolbox-text' => 'Кароткая спасылка',
4748 );
@@ -51,7 +52,7 @@
5253 $messages['br'] = array(
5354 'shorturl' => 'URL berr',
5455 'shorturl-desc' => '[[Special:ShortUrl|URL berr evit adkasoù]]',
55 - 'shorturl-not-found' => "Digarezit, n'eo ket bet kavet an URL emaoc'h o klask (N'eus URL berr ebet gant an ID $1)",
 56+ '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)",
5657 'shorturl-toolbox-title' => 'Kopiit al liamm berr-mañ evit e rannañ',
5758 'shorturl-toolbox-text' => 'URL berr',
5859 );
@@ -62,7 +63,7 @@
6364 $messages['de'] = array(
6465 'shorturl' => 'Kurz-URL',
6566 'shorturl-desc' => 'Ergänzt eine [[Special:ShortUrl|Spezialseite]] zum Erstellen von Kurz-URLs für Weiterleitungen',
66 - 'shorturl-not-found' => 'Die gesuchte Kurz-URL wurde leider nicht gefunden (Es ist keine Kurz-URL mit der Kennung $1 vorhanden)',
 67+ 'shorturl-not-found-message' => 'Die gesuchte Kurz-URL wurde leider nicht gefunden (Es ist keine Kurz-URL mit der Kennung $1 vorhanden)',
6768 'shorturl-toolbox-title' => 'Kurz-URL kopieren, um sie zu nutzen',
6869 'shorturl-toolbox-text' => 'Kurz-URL',
6970 );
@@ -74,7 +75,7 @@
7576 $messages['fr'] = array(
7677 'shorturl' => 'URL courte',
7778 'shorturl-desc' => '[[Special:ShortUrl|URL courte pour les redirections]]',
78 - 'shorturl-not-found' => 'Désolé, l’URL que vous recherchez est introuvable (aucune URL courte avec l’ID $1)',
 79+ 'shorturl-not-found-message' => 'Désolé, l’URL que vous recherchez est introuvable (aucune URL courte avec l’ID $1)',
7980 'shorturl-toolbox-title' => 'Copiez ce court lien pour le partager',
8081 'shorturl-toolbox-text' => 'URL courte',
8182 );
@@ -94,7 +95,7 @@
9596 $messages['gl'] = array(
9697 'shorturl' => 'Enderezo URL curto',
9798 'shorturl-desc' => '[[Special:ShortUrl|Enderezo URL curto para as redireccións]]',
98 - 'shorturl-not-found' => 'Sentímolo, non se atopou o enderezo URL que está a buscar (non existe ningún enderezo URL curto co ID $1)',
 99+ '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)',
99100 'shorturl-toolbox-title' => 'Copie esta ligazón curta para compartir',
100101 'shorturl-toolbox-text' => 'Enderezo URL curto',
101102 );
@@ -105,7 +106,7 @@
106107 $messages['he'] = array(
107108 'shorturl' => 'כתובת קצרה',
108109 'shorturl-desc' => '[[Special:ShortUrl|כתובת קצרה להפניות]]',
109 - 'shorturl-not-found' => 'סליחה, הכתובת שאתם מחפשים אינה נמצאת (אין כתובת קצרה עם המזהה $1)',
 110+ 'shorturl-not-found-message' => 'סליחה, הכתובת שאתם מחפשים אינה נמצאת (אין כתובת קצרה עם המזהה $1)',
110111 'shorturl-toolbox-title' => 'העתיקו את הקישור הקצר הזה בשביל שיתוף',
111112 'shorturl-toolbox-text' => 'כתובת קצרה',
112113 );
@@ -123,7 +124,7 @@
124125 $messages['ia'] = array(
125126 'shorturl' => 'URL curte',
126127 'shorturl-desc' => '[[Special:ShortUrl|URL curte pro redirectiones]]',
127 - 'shorturl-not-found' => 'Le URL que tu cerca non ha essite trovate (nulle URL curte con le ID $1 existe).',
 128+ 'shorturl-not-found-message' => 'Le URL que tu cerca non ha essite trovate (nulle URL curte con le ID $1 existe).',
128129 'shorturl-toolbox-title' => 'Copiar iste ligamine curte pro divulgation',
129130 'shorturl-toolbox-text' => 'URL curte',
130131 );
@@ -134,7 +135,7 @@
135136 $messages['lb'] = array(
136137 'shorturl' => 'Kuerz URL',
137138 'shorturl-desc' => '[[Special:ShortUrl|Kuerz URL fir Viruleedungen]]',
138 - 'shorturl-not-found' => "Pardon, d'URL no där Dir sicht gouf net fonnt (Et gëtt keng Kuerz-URL mat der ID $1)",
 139+ '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)",
139140 'shorturl-toolbox-title' => 'Kopéiert dës Kuerz-URL fir se ze notzen',
140141 'shorturl-toolbox-text' => 'Kuerz URL',
141142 );
@@ -145,7 +146,7 @@
146147 $messages['mk'] = array(
147148 'shorturl' => 'Кратка URL-адреса',
148149 'shorturl-desc' => '[[Special:ShortUrl|Кратка URL-адреса за пренасочувања]]',
149 - 'shorturl-not-found' => 'Нажалост, не ја најдов URL-адресата што ја барате (не постои кратка URL-адреса со назнаката $1)',
 150+ 'shorturl-not-found-message' => 'Нажалост, не ја најдов URL-адресата што ја барате (не постои кратка URL-адреса со назнаката $1)',
150151 'shorturl-toolbox-title' => 'Ископирајте ја оваа кратка врска за да ја споделите',
151152 'shorturl-toolbox-text' => 'Кратка URL-адреса',
152153 );
@@ -156,7 +157,7 @@
157158 $messages['ms'] = array(
158159 'shorturl' => 'URL Ringkas',
159160 'shorturl-desc' => '[[Special:ShortUrl|URL Ringkas untuk lencongan]]',
160 - 'shorturl-not-found' => 'Maaf, URL yang anda cari itu tidak dijumpai (Tidak wujudnya URL yang ber-ID $1)',
 161+ 'shorturl-not-found-message' => 'Maaf, URL yang anda cari itu tidak dijumpai (Tidak wujudnya URL yang ber-ID $1)',
161162 'shorturl-toolbox-title' => 'Salin pautan ringkas ini untuk dikongsi',
162163 'shorturl-toolbox-text' => 'URL Ringkas',
163164 );
@@ -168,7 +169,7 @@
169170 $messages['nl'] = array(
170171 'shorturl' => 'Korte URL',
171172 'shorturl-desc' => '[[Special:ShortUrl|Korte URL voor doorverwijzingen]]',
172 - 'shorturl-not-found' => 'De URL waarnaar u zoekt is niet gevonden. Er bestaat geen korte URL met ID $1',
 173+ 'shorturl-not-found-message' => 'De URL waarnaar u zoekt is niet gevonden. Er bestaat geen korte URL met ID $1',
173174 'shorturl-toolbox-title' => 'Deze korte verwijzing kopiëren om te delen',
174175 'shorturl-toolbox-text' => 'Korte URL',
175176 );
@@ -179,7 +180,7 @@
180181 $messages['or'] = array(
181182 'shorturl' => 'ଛୋଟ URL',
182183 'shorturl-desc' => '[[Special:ShortUrl|ଆଉଥରେ ଫେରନ୍ତା ଲିଙ୍କପାଇଁ ଛୋଟ URL]]',
183 - 'shorturl-not-found' => 'କ୍ଷମା କରିବେ, ଆପଣ ଦେଇଥିବା URLଟି ମିଳିଲା ନାହିଁ ($1 ନାଆଁରେ କିଛି ଛୋଟ URL ମିଳିଲା ନାହିଁ)',
 184+ 'shorturl-not-found-message' => 'କ୍ଷମା କରିବେ, ଆପଣ ଦେଇଥିବା URLଟି ମିଳିଲା ନାହିଁ ($1 ନାଆଁରେ କିଛି ଛୋଟ URL ମିଳିଲା ନାହିଁ)',
184185 'shorturl-toolbox-title' => 'ଏହି ଛୋଟ ଲିଙ୍କଟି ବାଣ୍ଟିବା ପାଇଁ ନକଲ କରନ୍ତୁ',
185186 'shorturl-toolbox-text' => 'ଛୋଟ URL',
186187 );
@@ -190,7 +191,7 @@
191192 $messages['pt'] = array(
192193 'shorturl' => 'URL Curta',
193194 'shorturl-desc' => '[[Special:ShortUrl|URL Curta para redireccionamentos]]',
194 - 'shorturl-not-found' => 'A URL que pretende não foi encontrada (não existe nenhuma URL Curta com a identificação $1)',
 195+ 'shorturl-not-found-message' => 'A URL que pretende não foi encontrada (não existe nenhuma URL Curta com a identificação $1)',
195196 'shorturl-toolbox-title' => 'Copie este link curto para partilhar',
196197 'shorturl-toolbox-text' => 'URL Curta',
197198 );
@@ -201,7 +202,7 @@
202203 $messages['ru'] = array(
203204 'shorturl' => 'Короткая ссылка',
204205 'shorturl-desc' => '[[Special:ShortUrl|Короткая ссылка для перенаправлений]]',
205 - 'shorturl-not-found' => 'К сожалению, указанный URL-адрес не найден (нет короткой ссылки с идентификатором $1)',
 206+ 'shorturl-not-found-message' => 'К сожалению, указанный URL-адрес не найден (нет короткой ссылки с идентификатором $1)',
206207 'shorturl-toolbox-title' => 'Скопируйте эту короткую ссылку',
207208 'shorturl-toolbox-text' => 'Короткая ссылка',
208209 );
@@ -221,7 +222,7 @@
222223 $messages['ta'] = array(
223224 'shorturl' => 'குறுந்தொடுப்பு',
224225 'shorturl-desc' => '[[Special:ShortUrl|வழிமாற்றுகளுக்கான குறுந்தொடுப்பு]]',
225 - 'shorturl-not-found' => 'மன்னிக்கவும், நீங்கள் எதிர்பார்க்கும் உரலி கிடைக்கவில்லை ($1 என்ற அடையாளத்துடன் கூடிய குறுந்தொடுப்பு ஏதுமில்லை)',
 226+ 'shorturl-not-found-message' => 'மன்னிக்கவும், நீங்கள் எதிர்பார்க்கும் உரலி கிடைக்கவில்லை ($1 என்ற அடையாளத்துடன் கூடிய குறுந்தொடுப்பு ஏதுமில்லை)',
226227 'shorturl-toolbox-title' => 'பகிர்வதற்காக இக்குறுந்தொடுப்பை நகலெடுக்கவும்',
227228 'shorturl-toolbox-text' => 'குறுந்தொடுப்பு',
228229 );
Index: trunk/extensions/ShortUrl/ShortUrl.utils.php
@@ -25,11 +25,11 @@
2626 public static function encodeTitle( $title ) {
2727 global $wgMemc;
2828
29 - $memcKey = wfMemcKey( 'shorturls', 'title', $title->getFullText() );
 29+ $memcKey = wfMemcKey( 'shorturls', 'title', $title->getPrefixedText() );
3030 $id = $wgMemc->get( $memcKey );
3131 if ( !$id ) {
3232 $dbr = wfGetDB( DB_SLAVE );
33 - $query = $dbr->select(
 33+ $entry = $dbr->selectRow(
3434 'shorturls',
3535 array( 'su_id' ),
3636 array(
@@ -38,8 +38,7 @@
3939 ),
4040 __METHOD__
4141 );
42 - if ( $dbr->numRows( $query ) > 0 ) {
43 - $entry = $dbr->fetchObject( $query );
 42+ if ( $entry !== false ) {
4443 $id = $entry->su_id;
4544 } else {
4645 $dbw = wfGetDB( DB_MASTER );
@@ -68,17 +67,19 @@
6968 $entry = $wgMemc->get( $memcKey );
7069 if ( !$entry ) {
7170 $dbr = wfGetDB( DB_SLAVE );
72 - $query = $dbr->select(
 71+ $entry = $dbr->selectRow(
7372 'shorturls',
7473 array( 'su_namespace', 'su_title' ),
7574 array( 'su_id' => $id ),
7675 __METHOD__
7776 );
7877
79 - $entry = $dbr->fetchRow( $query ); // Less overhead on memcaching
 78+ if ( $entry === false ) {
 79+ return false; // No such shorturl exists
 80+ }
8081 $wgMemc->set( $memcKey, $entry, 0 );
8182 }
82 - return Title::makeTitle( $entry['su_namespace'], $entry['su_title'] );
 83+ return Title::makeTitle( $entry->su_namespace, $entry->su_title );
8384 }
8485
8586 /**
Index: trunk/extensions/ShortUrl/ShortUrl.php
@@ -15,6 +15,13 @@
1616 die( 1 );
1717 }
1818
 19+// Configuration variables
 20+// Prefix to use for the shortened URL. mod_rewrite (or equivalent) needs to be setup
 21+// to produce a shorter URL
 22+// Default is 'null' which just uses the (not so short) URL that all Special Pages get
 23+// Eg: http://en.wikipedia.org/wiki/Special:ShortUrl/5234
 24+$wgShortUrlPrefix = null;
 25+
1926 // Extension credits that will show up on Special:Version
2027 $wgExtensionCredits['specialpage'][] = array(
2128 'path' => __FILE__,
@@ -42,10 +49,7 @@
4350 $wgResourceModules['ext.shortUrl'] = array(
4451 'scripts' => 'js/ext.shortUrl.js',
4552 'styles' => 'css/ext.shortUrl.css',
46 - 'dependencies' => array( 'jquery' ),
4753 'localBasePath' => dirname( __FILE__ ),
4854 'remoteExtPath' => 'ShortUrl'
4955 );
5056
51 -// Configuration
52 -$wgShortUrlPrefix = null;
Index: trunk/extensions/ShortUrl/css/ext.shortUrl.css
@@ -1,5 +1,4 @@
22 .title-shortlink {
33 font-size: small;
4 - display: Block;
54 margin: 0px;
65 }
Index: trunk/extensions/ShortUrl/SpecialShortUrl.php
@@ -36,12 +36,10 @@
3737 global $wgOut;
3838
3939 $title = ShortUrlUtils::decodeURL( $par );
40 - if ( $title ) {
 40+ if ( $title !== false ) {
4141 $wgOut->redirect( $title->getFullURL(), '301' );
42 - return;
 42+ } else {
 43+ $wgOut->showErrorPage( 'shorturl-not-found-title', 'shorturl-not-found-message', array( $par ) );
4344 }
44 - // Wrong ID
45 - $notFound = Html::element( 'p', array(), wfMsg( 'shorturl-not-found', $par ) );
46 - $wgOut->addHTML( $notFound );
4745 }
4846 }

Comments

#Comment by Nikerabbit (talk | contribs)   11:03, 15 November 2011

Looks good. In ShortUrl.php I'd use this commenting style

/**
 * This does something
 */
 $wgBunnies = 4;

Status & tagging log