r113239 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113238‎ | r113239 | r113240 >
Date:15:58, 7 March 2012
Author:nad
Status:deferred
Tags:
Comment:
if attaching a file when on a talk page, attach to the content page instead
Modified paths:
  • /trunk/extensions/FileAttach/FileAttach.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FileAttach/FileAttach.php
@@ -8,8 +8,8 @@
99 * @licence GNU General Public Licence 2.0 or later
1010 *
1111 */
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' );
1414
1515 $wgAttachmentHeading = 'Attachments';
1616
@@ -21,7 +21,7 @@
2222 'author' => '[http://www.mediawiki.org/wiki/User:Milan Milan Holzapfel]',
2323 'descriptionmsg' => 'fileattach-desc',
2424 'url' => 'https://www.mediawiki.org/wiki/Extension:FileAttach',
25 - 'version' => FILEATTCH_VERSION
 25+ 'version' => FILEATTACH_VERSION
2626 );
2727
2828 class FileAttach {
@@ -36,10 +36,10 @@
3737 public static function onBeforePageDisplay( $out, $skin ) {
3838 global $wgParser, $wgAttachmentHeading;
3939
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;
4242
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
4444 $sections = $wgParser->mOutput->mSections;
4545 if( is_array( $sections ) && count( $sections ) > 0 ) {
4646 $last = $sections[count( $sections ) - 1];
@@ -67,7 +67,7 @@
6868 }
6969 }
7070
71 - # Modify the upload form
 71+ // Modify the upload form
7272 if( self::$uploadForm ) {
7373 global $wgRequest;
7474 $attachto = $wgRequest->getText( 'attachto' );
@@ -104,8 +104,7 @@
105105 }
106106
107107 /**
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
110109 */
111110 public static function onSpecialUploadComplete( $upload ) {
112111 global $wgOut, $wgRequest, $wgAttachmentHeading;
@@ -130,19 +129,27 @@
131130 }
132131
133132 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 );
136134 $actions['attach'] = array( 'text' => wfMsg( 'fileattach-attachfile' ), 'class' => false, 'href' => $url );
137135 return true;
138136 }
139137
140138 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 );
143140 $actions['views']['attach'] = array( 'text' => wfMsg( 'fileattach-attachfile' ), 'class' => false, 'href' => $url );
144141 return true;
145142 }
146143
 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+
147154 }
148155
149156 /**

Status & tagging log