r56926 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56925‎ | r56926 | r56927 >
Date:18:39, 25 September 2009
Author:siebrand
Status:ok
Tags:
Comment:
* update extension description
* stylize.php, break introduction to 80 characters per line, remove trailing whitespace
Modified paths:
  • /trunk/extensions/FilePageMasking/FilePageMasking.i18n.php (modified) (history)
  • /trunk/extensions/FilePageMasking/FilePageMasking.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FilePageMasking/FilePageMasking.i18n.php
@@ -8,5 +8,5 @@
99 $messages = array();
1010
1111 $messages['en'] = array(
12 - 'file_masking_desc' => 'Rewrites ".xxx" into "_xxx" in image description page links',
 12+ 'file_masking_desc' => 'Rewrites ".xxx" into "_xxx" in file description page links',
1313 );
Index: trunk/extensions/FilePageMasking/FilePageMasking.php
@@ -1,24 +1,24 @@
22 <?php
3 -
43 /*
 4+ This extension masks local links for file description pages by modifying the
 5+ file extension at the end of the description page URL so it does not also look
 6+ like a file. This makes it easier for search engines and other programs to
 7+ recognize the file description page as HTML rather than assuming it is also a
 8+ file based on its extension.
59
6 - This extension masks local links for file description pages by modifying the file extension
7 - at the end of the description page URL so it does not also look like a file. This makes it
8 - easier for search engines and other programs to recognize the file description page as HTML
9 - rather than assuming it is also a file based on its extension.
10 -
11 - By default, extensions of the form ".xxx" are translated to "_xxx". This only occurs
12 - for internal links that should target the file description page. When a file description page
13 - of the form "_xxx" is requested, this extension automatically translates it back to ".xxx"
14 - so that Mediawiki will retrieve the correct page. The choice of masking character can be
15 - set by changing $wgFilePageMaskingCharacter, which defaults to "_". The setting of this
 10+ By default, extensions of the form ".xxx" are translated to "_xxx". This only
 11+ occurs for internal links that should target the file description page. When
 12+ a file description page of the form "_xxx" is requested, this extension
 13+ automatically translates it back to ".xxx" so that Mediawiki will retrieve the
 14+ correct page. The choice of masking character can be set by changing
 15+ $wgFilePageMaskingCharacter, which defaults to "_". The setting of this
1616 variable must be a single character, and must be valid in a URL.
1717
18 - This extension relies on $wgFileExtensions to determine the list of case insensitive file
19 - extensions to translate. On sites where $wgStrictFileExtensions is set to false, the user may
20 - upload files with extensions not considered by $wgFileExtensions. If this is the case, those
 18+ This extension relies on $wgFileExtensions to determine the list of case
 19+ insensitive file extensions to translate. On sites where
 20+ $wgStrictFileExtensions is set to false, the user may upload files with
 21+ extensions not considered by $wgFileExtensions. If this is the case, those
2122 file extensions will not be masked.
22 -
2323 */
2424
2525 if ( ! defined( 'MEDIAWIKI' ) )
@@ -30,7 +30,7 @@
3131 'version' => '1.0',
3232 'description' => 'Converts file extensions ".xxx" to "_xxx" on description page links', // kept for b/c
3333 'descriptionmsg' => 'file_masking_desc',
34 - 'path' => __FILE__,
 34+ 'path' => __FILE__,
3535 'url' => 'http://www.mediawiki.org/wiki/Extension:FilePageMasking',
3636 );
3737
@@ -41,19 +41,18 @@
4242 $wgHooks['GetLocalURL'][] = 'wfFilePageMasking_Mask';
4343 $wgHooks['ArticleFromTitle'][] = 'wfFilePageMasking_Unmask';
4444
45 -
4645 /**
4746 * This hook applies masking to file page links.
48 - **/
 47+ **/
4948 function wfFilePageMasking_Mask( &$title, &$url, $query ) {
5049 global $wgFileExtensions, $wgFilePageMaskingCharacter;
5150
52 - if( $title->getNamespace() == NS_FILE ) {
53 - $lUrl = strlen($url);
54 - foreach( $wgFileExtensions as $ext ) {
55 - $lExt = strlen($ext);
 51+ if ( $title->getNamespace() == NS_FILE ) {
 52+ $lUrl = strlen( $url );
 53+ foreach ( $wgFileExtensions as $ext ) {
 54+ $lExt = strlen( $ext );
5655 $p = stripos( $url, "." . $ext, $lUrl - $lExt - 1 );
57 - if( $p == $lUrl - $lExt - 1 ) {
 56+ if ( $p == $lUrl - $lExt - 1 ) {
5857 $url[$p] = $wgFilePageMaskingCharacter;
5958 break;
6059 }
@@ -62,20 +61,19 @@
6362 return true;
6463 }
6564
66 -
6765 /**
6866 * This hook removes masking to file page requests.
69 - **/
 67+ **/
7068 function wfFilePageMasking_Unmask( &$title, &$article ) {
7169 global $wgFileExtensions, $wgFilePageMaskingCharacter;
7270
73 - if( $title->getNamespace() == NS_FILE ) {
 71+ if ( $title->getNamespace() == NS_FILE ) {
7472 $name = $title->getDBkey();
75 - $lName = strlen($name);
76 - foreach( $wgFileExtensions as $ext ) {
77 - $lExt = strlen($ext);
 73+ $lName = strlen( $name );
 74+ foreach ( $wgFileExtensions as $ext ) {
 75+ $lExt = strlen( $ext );
7876 $p = stripos( $name, $wgFilePageMaskingCharacter . $ext, $lName - $lExt - 1 );
79 - if( $p == $lName - $lExt - 1 ) {
 77+ if ( $p == $lName - $lExt - 1 ) {
8078 $name[$p] = ".";
8179 $title = Title::newFromText( $name, NS_FILE );
8280 break;
@@ -84,4 +82,3 @@
8583 }
8684 return true;
8785 }
88 -

Status & tagging log