r85142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85141‎ | r85142 | r85143 >
Date:18:16, 1 April 2011
Author:ialex
Status:deferred
Tags:
Comment:
* Use BeforePageDisplay hook or include the script/style file directly instead of SkinTemplateSetupPageCss hook
* Also use OutputPageBodyAttributes hook to modify <body>'s class
Modified paths:
  • /trunk/extensions/uniwiki/GenericEditPage/GenericEditPage.php (modified) (history)
  • /trunk/extensions/uniwiki/Layouts/Layouts.php (modified) (history)

Diff [purge]

Index: trunk/extensions/uniwiki/GenericEditPage/GenericEditPage.php
@@ -43,11 +43,10 @@
4444 $wgAjaxExportList[] = "UW_GenericEditPage_emailSuggestion";
4545
4646 function UW_GenericEditPage_addJS( $out ) {
47 - global $wgScriptPath;
48 - $src = "$wgScriptPath/extensions/uniwiki/GenericEditPage/GenericEditPage.js";
49 - $out->addScript ( "<script type='text/javascript' src='$src'></script>" );
50 - $href = "$wgScriptPath/extensions/uniwiki/GenericEditPage/global.css";
51 - $out->addScript ( "<link rel='stylesheet' href='$href' />" );
 47+ global $wgExtensionAssetsPath;
 48+
 49+ $out->addScriptFile( "$wgExtensionAssetsPath/uniwiki/GenericEditPage/GenericEditPage.js" );
 50+ $out->addExtensionStyle( "$wgExtensionAssetsPath/uniwiki/GenericEditPage/global.css" );
5251 return true;
5352 }
5453
@@ -342,7 +341,7 @@
343342 function UW_GenericEditPage_displayEditPage ( $editor, $out ) {
344343 global $wgHooks, $wgParser, $wgTitle, $wgRequest, $wgUser, $wgCategoryBox, $wgSectionBox, $wgRequireCategory;
345344 global $wgGenericEditPageClass, $wgSwitchMode, $wgGenericEditPageWhiteList, $wgAllowSimilarTitles;
346 - global $wgAlwaysShowIntroSection;
 345+ global $wgAlwaysShowIntroSection, $wgExtensionAssetsPath;
347346
348347 // disable this whole thing on conflict and comment pages
349348 if ( $editor->section == "new" || $editor->isConflict )
@@ -358,7 +357,6 @@
359358 * checkboxes later (after the edit form) */
360359 if ( $wgCategoryBox ) {
361360 $catbox = UW_GenericEditPage_extractCategoriesIntoBox ( $text );
362 - $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'UW_GenericEditPage_addCssHookSidebar';
363361 }
364362
365363 /* break the page up into sections by splitting
@@ -366,10 +364,11 @@
367365 $nodes = preg_split( '/^(==?[^=].*)$/mi', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
368366
369367 // add css hooks only to the edit page
370 - $wgHooks['SkinTemplateSetupPageCss'][] = 'UW_GenericEditPage_editPageCss';
 368+ $out->addExtensionStyle( "$wgExtensionAssetsPath/uniwiki/GenericEditPage/style.css" );
 369+
371370 $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'UW_GenericEditPage_addCssHookGenEd';
 371+ $wgHooks['OutputPageBodyAttributes'][] = 'UW_GenericEditPage_onOutputPageBodyAttributes';
372372
373 -
374373 /* the current contents of the page we are
375374 * editing will be broken up into $page(and
376375 * combined with $layout, later on) */
@@ -676,22 +675,30 @@
677676 * special class to the <body> tag, to make targetting our css easier
678677 * (also add a hook if we just switched modes, to hide the preview) */
679678 function UW_GenericEditPage_addCssHookGenEd ( &$sktemplate, &$tpl ) {
680 - global $wgGenericEditPageClass, $wgSwitchMode;
 679+ global $wgGenericEditPageClass, $wgSwitchMode, $wgCategoryBox;
 680+
681681 $tpl->data['pageclass'] .= " edit-$wgGenericEditPageClass";
682 - if ( $wgSwitchMode ) $tpl->data['pageclass'] .= " switching-mode";
 682+ if ( $wgSwitchMode ) {
 683+ $tpl->data['pageclass'] .= ' switching-mode';
 684+ }
 685+ if ( $wgCategoryBox ) {
 686+ $tpl->data['pageclass'] .= ' with-sidebar';
 687+ }
 688+
683689 return true;
684690 }
685 -function UW_GenericEditPage_addCssHookSidebar ( &$sktemplate, &$tpl ) {
686 - global $wgGenericEditPageClass;
687 - $tpl->data['pageclass'] .= " with-sidebar";
688 - return true;
689 -}
690691
 692+function UW_GenericEditPage_onOutputPageBodyAttributes( $out, $sk, &$attr ) {
 693+ global $wgGenericEditPageClass, $wgSwitchMode, $wgCategoryBox;
691694
692 -// also attach our generic editor stylesheet
693 -function UW_GenericEditPage_editPageCss ( &$out ) {
694 - global $wgScriptPath;
695 - $out .= "@import '$wgScriptPath/extensions/uniwiki/GenericEditPage/style.css';\n";
 695+ $attr['class'] .= " edit-$wgGenericEditPageClass";
 696+ if ( $wgSwitchMode ) {
 697+ $attr['class'] .= ' switching-mode';
 698+ }
 699+ if ( $wgCategoryBox ) {
 700+ $attr['class'] .= ' with-sidebar';
 701+ }
 702+
696703 return true;
697704 }
698705
Index: trunk/extensions/uniwiki/Layouts/Layouts.php
@@ -61,7 +61,7 @@
6262 /* ---- HOOKS ---- */
6363 $wgHooks['CustomEditor'][] = "UW_Layouts_maybeRedirectToLayout";
6464 $wgHooks['UnknownAction'][] = "UW_Layouts_checkActionIsLayout";
65 -$wgHooks['SkinTemplateSetupPageCss'][] = "UW_Layouts_Css";
 65+$wgHooks['BeforePageDisplay'][] = "UW_Layouts_Css";
6666 $wgHooks['EditFormPreloadText'][] = "UW_Layouts_preFillTextBox";
6767
6868 function UW_Layouts_maybeRedirectToLayout( $article, $user ) {
@@ -232,9 +232,9 @@
233233 return false;
234234 }
235235
236 -function UW_Layouts_Css ( &$out ) {
237 - global $wgScriptPath;
238 - $out .= "@import '$wgScriptPath/extensions/uniwiki/Layouts/style.css';\n";
 236+function UW_Layouts_Css ( $out, $sk ) {
 237+ global $wgExtensionAssetsPath;
 238+ $out->addExtensionStyle( "$wgExtensionAssetsPath/uniwiki/Layouts/style.css" );
239239 return true;
240240 }
241241

Status & tagging log