Index: trunk/extensions/FileAttach/FileAttach.php |
— | — | @@ -8,8 +8,8 @@ |
9 | 9 | * @licence GNU General Public Licence 2.0 or later |
10 | 10 | * |
11 | 11 | */ |
12 | | -if ( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' ); |
13 | | -define( 'FILEATTCH_VERSION', '1.0.2, 2010-04-24' ); |
| 12 | +if( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' ); |
| 13 | +define( 'FILEATTACH_VERSION', '1.0.3, 2012-03-07' ); |
14 | 14 | |
15 | 15 | $wgAttachmentHeading = 'Attachments'; |
16 | 16 | |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | 'author' => '[http://www.mediawiki.org/wiki/User:Milan Milan Holzapfel]', |
23 | 23 | 'descriptionmsg' => 'fileattach-desc', |
24 | 24 | 'url' => 'https://www.mediawiki.org/wiki/Extension:FileAttach', |
25 | | - 'version' => FILEATTCH_VERSION |
| 25 | + 'version' => FILEATTACH_VERSION |
26 | 26 | ); |
27 | 27 | |
28 | 28 | class FileAttach { |
— | — | @@ -36,10 +36,10 @@ |
37 | 37 | public static function onBeforePageDisplay( $out, $skin ) { |
38 | 38 | global $wgParser, $wgAttachmentHeading; |
39 | 39 | |
40 | | - # Bail if page inappropriate for attachments |
41 | | - if( !is_object( $wgParser ) || !is_object( $wgParser->mOutput )|| !isset( $wgParser->mOutput->mSections ) ) return true; |
| 40 | + // Bail if page inappropriate for attachments |
| 41 | + if( !is_object( $wgParser ) || !is_object( $wgParser->mOutput ) || !isset( $wgParser->mOutput->mSections ) ) return true; |
42 | 42 | |
43 | | - # If the last section in the article is level 2 and "Attachments" then convert to file icons |
| 43 | + // If the last section in the article is level 2 and "Attachments" then convert to file icons |
44 | 44 | $sections = $wgParser->mOutput->mSections; |
45 | 45 | if( is_array( $sections ) && count( $sections ) > 0 ) { |
46 | 46 | $last = $sections[count( $sections ) - 1]; |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | | - # Modify the upload form |
| 71 | + // Modify the upload form |
72 | 72 | if( self::$uploadForm ) { |
73 | 73 | global $wgRequest; |
74 | 74 | $attachto = $wgRequest->getText( 'attachto' ); |
— | — | @@ -104,8 +104,7 @@ |
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | | - * Change the redirection after upload to the page the file attached to, |
109 | | - * and attach the file to the article |
| 108 | + * Change the redirection after upload to the page the file attached to, and attach the file to the article |
110 | 109 | */ |
111 | 110 | public static function onSpecialUploadComplete( $upload ) { |
112 | 111 | global $wgOut, $wgRequest, $wgAttachmentHeading; |
— | — | @@ -130,19 +129,27 @@ |
131 | 130 | } |
132 | 131 | |
133 | 132 | public static function onSkinTemplateTabs( $skin, &$actions ) { |
134 | | - $attachto = $skin->getTitle()->getPrefixedText(); |
135 | | - $url = SpecialPage::getTitleFor( 'Upload' )->getLocalURL( array( 'attachto' => $attachto ) ); |
| 133 | + $url = self::actionUrl( $skin ); |
136 | 134 | $actions['attach'] = array( 'text' => wfMsg( 'fileattach-attachfile' ), 'class' => false, 'href' => $url ); |
137 | 135 | return true; |
138 | 136 | } |
139 | 137 | |
140 | 138 | public static function onSkinTemplateNavigation( $skin, &$actions ) { |
141 | | - $attachto = $skin->getTitle()->getPrefixedText(); |
142 | | - $url = SpecialPage::getTitleFor( 'Upload' )->getLocalURL( array( 'attachto' => $attachto ) ); |
| 139 | + $url = self::actionUrl( $skin ); |
143 | 140 | $actions['views']['attach'] = array( 'text' => wfMsg( 'fileattach-attachfile' ), 'class' => false, 'href' => $url ); |
144 | 141 | return true; |
145 | 142 | } |
146 | 143 | |
| 144 | + /** |
| 145 | + * Get the name of the title to attach to, if it's a talk page, use the content page instead |
| 146 | + */ |
| 147 | + public static function actionUrl( $skin ) { |
| 148 | + $title = $skin->getTitle(); |
| 149 | + if( $title->isTalkPage() ) $title = Title::newFromText( $title->getText(), $title->getNamespace() - 1 ); |
| 150 | + $url = SpecialPage::getTitleFor( 'Upload' )->getLocalURL( array( 'attachto' => $title->getPrefixedText() ) ); |
| 151 | + return $url; |
| 152 | + } |
| 153 | + |
147 | 154 | } |
148 | 155 | |
149 | 156 | /** |