r80095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80094‎ | r80095 | r80096 >
Date:16:16, 12 January 2011
Author:ialex
Status:deferred (Comments)
Tags:
Comment:
* Use BeforePageDisplay hook to add css and js
* Removed usage of $wgArticle, not needed
* Some coding style fixes
Modified paths:
  • /trunk/extensions/TalkHere/TalkHere.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TalkHere/TalkHere.php
@@ -34,18 +34,17 @@
3535 $wgAutoloadClasses['TalkHereArticle'] = $dir . 'TalkHereArticle.php';
3636 $wgAutoloadClasses['TalkHereEditTarget'] = $dir . 'TalkHereArticle.php';
3737
38 -$wgExtensionFunctions[] = 'wfTalkHereExtension';
39 -
40 -$wgHooks['ArticleFromTitle'][] = 'wfTalkHereArticleFromTitle';
 38+$wgHooks['BeforePageDisplay'][] = 'wfTalkHereBeforePageDisplay';
 39+#$wgHooks['ArticleFromTitle'][] = 'wfTalkHereArticleFromTitle';
4140 $wgHooks['CustomEditor'][] = 'wfTalkHereCustomEditor';
4241 $wgHooks['EditPage::showEditForm:fields'][] = 'wfTalkHereShowEditFormFields';
4342
4443 $wgAjaxExportList[] = 'wfTalkHereAjaxEditor';
4544
46 -function wfTalkHereExtension( ) {
47 - global $wgOut, $wgScriptPath, $wgJsMimeType, $wgUseAjax;
 45+function wfTalkHereBeforePageDisplay( $out, $skin ) {
 46+ global $wgScriptPath, $wgJsMimeType, $wgUseAjax;
4847
49 - $wgOut->addLink(
 48+ $out->addLink(
5049 array(
5150 'rel' => 'stylesheet',
5251 'type' => 'text/css',
@@ -53,10 +52,12 @@
5453 )
5554 );
5655
57 - if ( $wgUseAjax ) $wgOut->addScript(
 56+ if ( $wgUseAjax ) $out->addScript(
5857 "<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}/extensions/TalkHere/TalkHere.js\">" .
5958 "</script>\n"
6059 );
 60+
 61+ return true;
6162 }
6263
6364 function wfTalkHereArticleFromTitle( &$title, &$article ) {
@@ -109,7 +110,7 @@
110111 $out->addHTML($html);
111112 }
112113
113 -function wfTalkHereCustomEditor( &$article, &$user ) {
 114+function wfTalkHereCustomEditor( $article, $user ) {
114115 global $wgRequest, $wgOut;
115116
116117 $action = $wgRequest->getVal( 'action' );
@@ -145,20 +146,24 @@
146147 }
147148
148149 function wfTalkHereAjaxEditor( $page, $section, $returnto ) {
149 - global $wgRequest, $wgTitle, $wgArticle, $wgOut;
 150+ global $wgRequest, $wgTitle, $wgOut;
150151
151 - $wgTitle = Title::newFromText($page);
152 - if ( !$wgTitle ) return false;
 152+ $wgTitle = Title::newFromText( $page );
 153+ if ( !$wgTitle ) {
 154+ return false;
 155+ }
153156
154157 //fake editor environment
155 - $args = array( 'wpTalkHere' => '1',
156 - 'wpReturnTo' => $returnto,
157 - 'action' => 'edit',
158 - 'section' => $section );
 158+ $args = array(
 159+ 'wpTalkHere' => '1',
 160+ 'wpReturnTo' => $returnto,
 161+ 'action' => 'edit',
 162+ 'section' => $section
 163+ );
159164
160165 $wgRequest = new FauxRequest( $args );
161 - $wgArticle = MediaWiki::articleFromTitle( $wgTitle );
162 - $editor = new EditPage( $wgArticle );
 166+ $article = MediaWiki::articleFromTitle( $wgTitle );
 167+ $editor = new EditPage( $article );
163168
164169 //generate form
165170 $editor->importFormData( $wgRequest );

Follow-up revisions

RevisionCommit summaryAuthorDate
r80165Per Jack Phoenix, follow-up r80095:...ialex13:52, 13 January 2011

Comments

#Comment by Jack Phoenix (talk | contribs)   19:06, 12 January 2011
-	$wgOut->addLink(
+	$out->addLink(
 		array(
 			'rel' => 'stylesheet',
 			'type' => 'text/css',

This could probably use $out->addExtensionStyle(), right?

-	if ( $wgUseAjax ) $wgOut->addScript(
+	if ( $wgUseAjax ) $out->addScript(
 		"<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}/extensions/TalkHere/TalkHere.js\">" .
 		"</script>\n"
 	);

This should just use $out->addScriptFile() and I really wanna see the braces there (as per our coding conventions).

Other than these two minor issues, looks good. :)

Status & tagging log