r88581 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88580‎ | r88581 | r88582 >
Date:15:11, 22 May 2011
Author:yaron
Status:deferred
Tags:
Comment:
Improved header info and FCKeditor handling for MW >= 1.17, other improvements
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_Utils.php
@@ -98,7 +98,7 @@
9999 * - this function doubles as a function to get all categories on
100100 * the site, if no article is specified
101101 */
102 - static function getCategoriesForPage( $title = NULL ) {
 102+ static function getCategoriesForPage( $title = null ) {
103103 $categories = array();
104104 $db = wfGetDB( DB_SLAVE );
105105 $conditions = null;
@@ -147,12 +147,14 @@
148148 /**
149149 * Creates HTML linking to a wiki page
150150 */
151 - static function linkText( $namespace, $name, $text = NULL ) {
 151+ static function linkText( $namespace, $name, $text = null ) {
152152 $title = Title::makeTitleSafe( $namespace, $name );
153 - if ( $title === NULL ) {
 153+ if ( is_null( $title ) ) {
154154 return $name; // TODO maybe report an error here?
155155 }
156 - if ( NULL === $text ) $text = $title->getText();
 156+ if ( is_null( $text ) ) {
 157+ $text = $title->getText();
 158+ }
157159 $l = class_exists('DummyLinker') ? new DummyLinker : new Linker;
158160 return $l->makeLinkObj( $title, htmlspecialchars( $text ) );
159161 }
@@ -235,18 +237,54 @@
236238 }
237239
238240 /**
 241+ * Javascript files to be added regardless of the MediaWiki version
 242+ * (i.e., even if the ResourceLoader is installed).
 243+ */
 244+ static function addJavascriptFiles( $parser ) {
 245+ global $wgOut, $wgFCKEditorDir, $wgScriptPath, $wgJsMimeType;
 246+
 247+ $scripts = array();
 248+
 249+ wfRunHooks( 'sfAddJavascriptFiles', array( &$scripts ) );
 250+
 251+ // The FCKeditor extension has no defined ResourceLoader
 252+ // modules yet, so we have to call the scripts directly.
 253+ // @TODO Move this code into the FCKeditor extension.
 254+ if ( $wgFCKEditorDir && class_exists( 'FCKEditor' ) ) {
 255+ $scripts[] = "$wgScriptPath/$wgFCKEditorDir/fckeditor.js";
 256+ }
 257+
 258+ foreach ( $scripts as $js ) {
 259+ if ( $parser ) {
 260+ $script = "<script type=\"$wgJsMimeType\" src=\"$js\"></script>\n";
 261+ $parser->getOutput()->addHeadItem( $script );
 262+ } else {
 263+ $wgOut->addScriptFile( $js );
 264+ }
 265+ }
 266+ }
 267+
 268+ /**
239269 * Includes the necessary Javascript and CSS files for the form
240270 * to display and work correctly
241271 *
242272 * Accepts an optional Parser instance, or uses $wgOut if omitted.
243273 */
244 - static function addJavascriptAndCSS( $parser = NULL ) {
 274+ static function addJavascriptAndCSS( $parser = null ) {
 275+ global $wgOut;
 276+
 277+ if ( !$parser ) {
 278+ $wgOut->addMeta( 'robots', 'noindex,nofollow' );
 279+ }
 280+
 281+ self::addJavascriptFiles( $parser );
 282+
245283 // MW 1.17 +
246284 if ( class_exists( 'ResourceLoader' ) ) {
247285 self::loadJavascriptAndCSS( $parser );
248286 return;
249287 }
250 - global $wgOut, $sfgScriptPath, $smwgScriptPath, $wgScriptPath, $wgFCKEditorDir, $wgJsMimeType, $sfgUseFormEditPage;
 288+ global $sfgScriptPath, $smwgScriptPath, $wgScriptPath, $wgJsMimeType, $sfgUseFormEditPage;
251289 global $smwgJQueryIncluded, $smwgJQUIAutoIncluded;
252290 // jQuery and jQuery UI are used so often in forms, we might as
253291 // well assume they'll always be used, and include them in
@@ -305,9 +343,6 @@
306344 $scripts[] = "$sfgScriptPath/libs/jquery.fancybox.js";
307345 $scripts[] = "$sfgScriptPath/libs/SF_autogrow.js";
308346 $scripts[] = "$sfgScriptPath/libs/SF_submit.js";
309 -
310 - if ( $wgFCKEditorDir )
311 - $scripts[] = "$wgScriptPath/$wgFCKEditorDir/fckeditor.js";
312347 $scripts[] = "$sfgScriptPath/libs/SemanticForms.js";
313348
314349 global $wgOut;
@@ -319,8 +354,6 @@
320355 $wgOut->addScriptFile( $js );
321356 }
322357 }
323 - if ( !$parser )
324 - $wgOut->addMeta( 'robots', 'noindex,nofollow' );
325358 }
326359
327360 /**