Index: trunk/extensions/FilePageMasking/FilePageMasking.i18n.php |
— | — | @@ -0,0 +1,12 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation file for FilePageMasking extension. |
| 5 | + * |
| 6 | + * @addtogroup Extensions |
| 7 | +*/ |
| 8 | + |
| 9 | +$messages = array(); |
| 10 | + |
| 11 | +$messages['en'] = array( |
| 12 | + 'file_masking_desc' => 'Rewrites ".xxx" into "_xxx" in image description page links', |
| 13 | +); |
Property changes on: trunk/extensions/FilePageMasking/FilePageMasking.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 14 | + native |
Index: trunk/extensions/FilePageMasking/FilePageMasking.php |
— | — | @@ -0,0 +1,87 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + |
| 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 |
| 16 | + variable must be a single character, and must be valid in a URL. |
| 17 | + |
| 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 |
| 21 | + file extensions will not be masked. |
| 22 | + |
| 23 | +*/ |
| 24 | + |
| 25 | +if ( ! defined( 'MEDIAWIKI' ) ) |
| 26 | + die(); |
| 27 | + |
| 28 | +$wgExtensionCredits['parserhook'][] = array( |
| 29 | + 'name' => 'FilePageMasking', |
| 30 | + 'author' => 'Robert Rohde', |
| 31 | + 'version' => '1.0', |
| 32 | + 'description' => 'Converts file extensions ".xxx" to "_xxx" on description page links', // kept for b/c |
| 33 | + 'descriptionmsg' => 'file_masking_desc', |
| 34 | + 'path' => __FILE__, |
| 35 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:FilePageMasking', |
| 36 | +); |
| 37 | + |
| 38 | +$wgFilePageMaskingCharacter = '_'; |
| 39 | + |
| 40 | +$wgExtensionMessagesFiles['FilePageMasking'] = dirname( __FILE__ ) . "/FilePageMasking.i18n.php"; |
| 41 | + |
| 42 | +$wgHooks['GetLocalURL'][] = 'wfFilePageMasking_Mask'; |
| 43 | +$wgHooks['ArticleFromTitle'][] = 'wfFilePageMasking_Unmask'; |
| 44 | + |
| 45 | + |
| 46 | +/** |
| 47 | + * This hook applies masking to file page links. |
| 48 | + **/ |
| 49 | +function wfFilePageMasking_Mask( &$title, &$url, $query ) { |
| 50 | + global $wgFileExtensions, $wgFilePageMaskingCharacter; |
| 51 | + |
| 52 | + if( $title->getNamespace() == NS_FILE ) { |
| 53 | + $lUrl = strlen($url); |
| 54 | + foreach( $wgFileExtensions as $ext ) { |
| 55 | + $lExt = strlen($ext); |
| 56 | + $p = stripos( $url, "." . $ext, $lUrl - $lExt - 1 ); |
| 57 | + if( $p == $lUrl - $lExt - 1 ) { |
| 58 | + $url[$p] = $wgFilePageMaskingCharacter; |
| 59 | + break; |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + return true; |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | +/** |
| 68 | + * This hook removes masking to file page requests. |
| 69 | + **/ |
| 70 | +function wfFilePageMasking_Unmask( &$title, &$article ) { |
| 71 | + global $wgFileExtensions, $wgFilePageMaskingCharacter; |
| 72 | + |
| 73 | + if( $title->getNamespace() == NS_FILE ) { |
| 74 | + $name = $title->getDBkey(); |
| 75 | + $lName = strlen($name); |
| 76 | + foreach( $wgFileExtensions as $ext ) { |
| 77 | + $lExt = strlen($ext); |
| 78 | + $p = stripos( $name, $wgFilePageMaskingCharacter . $ext, $lName - $lExt - 1 ); |
| 79 | + if( $p == $lName - $lExt - 1 ) { |
| 80 | + $name[$p] = "."; |
| 81 | + $title = Title::newFromText( $name, NS_FILE ); |
| 82 | + break; |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + return true; |
| 87 | +} |
| 88 | + |
Property changes on: trunk/extensions/FilePageMasking/FilePageMasking.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 89 | + native |