r94047 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94046‎ | r94047 | r94048 >
Date:15:17, 7 August 2011
Author:ialex
Status:deferred
Tags:
Comment:
* Use SkinAfterContent hook instead of requesting admin to hack the code
* Removed usage of $wgTitle
Modified paths:
  • /trunk/extensions/Postcomment/Postcomment.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Postcomment/Postcomment.php
@@ -26,6 +26,7 @@
2727 $dir = dirname(__FILE__) . '/';
2828 $wgExtensionMessagesFiles['PostComment'] = $dir . 'Postcomment.i18n.php';
2929
 30+$wgHooks['SkinAfterContent'][] = 'wfPostcommentForm';
3031 $wgSpecialPages['Postcomment'] = 'SpecialPostcomment';
3132
3233 class SpecialPostcomment extends UnlistedSpecialPage {
@@ -122,23 +123,22 @@
123124 }
124125 }
125126
126 -function wfPostcommentForm() {
127 - global $wgUser, $wgTitle, $wgRequest;
 127+function wfPostcommentForm( &$data, $sk ) {
 128+ global $wgUser, $wgRequest;
128129
129130 $action = $wgRequest->getVal( 'action', 'view' );
 131+ $title = $sk->getTitle();
130132
131133 // just for talk pages
132 - if ( !$wgTitle->isTalkPage() || $action != 'view' ) {
133 - return;
 134+ if ( !$title->isTalkPage() || $action != 'view' ) {
 135+ return true;
134136 }
135137
136 - if ( !$wgTitle->userCan( 'edit', true ) ) {
137 - echo wfMsg( 'postcomment_discussionprotected' );
138 - return;
 138+ if ( !$title->userCan( 'edit', true ) ) {
 139+ $data .= wfMsgHtml( 'postcomment_discussionprotected' );
 140+ return true;
139141 }
140142
141 - $sk = $wgUser->getSkin();
142 -
143143 $user_str = '';
144144 if ($wgUser->getID() == 0) {
145145 $user_str = wfMsg( 'postcomment_notloggedin' );
@@ -148,15 +148,15 @@
149149 }
150150
151151 $pc = SpecialPage::getTitleFor( 'Postcomment' );
152 - if ( $wgTitle->getNamespace() == NS_USER_TALK ) {
153 - $msg = wfMsg( 'postcomment_leavemessagefor', $wgTitle->getText() );
 152+ if ( $title->getNamespace() == NS_USER_TALK ) {
 153+ $msg = wfMsg( 'postcomment_leavemessagefor', $title->getText() );
154154 } else {
155155 $msg = wfMsg( 'postcomment_addcommentdiscussionpage' );
156156 }
157157
158 - echo "<br /><br />
 158+ $data .= "<hr /><br />
159159 <form name=\"commentForm\" method=\"POST\" action=\"{$pc->getFullURL()}\">
160 -<input name=\"target\" type=\"hidden\" value=\"" . htmlspecialchars( $wgTitle->getPrefixedDBkey() ) . "\"/>
 160+<input name=\"target\" type=\"hidden\" value=\"" . htmlspecialchars( $title->getPrefixedDBkey() ) . "\"/>
161161 <table>
162162 <tr>
163163 <td colspan=\"2\" valign=\"top\">
@@ -185,4 +185,5 @@
186186 </tr>
187187 </table>
188188 </form>";
 189+ return true;
189190 }

Status & tagging log