확장기능:CSS

This page is a translated version of the page Extension:CSS and the translation is 45% complete.
미디어위키 확장 기능 설명서
CSS
출시 상태: 안정
구현 파서 함수
설명 CSS 파일, 문서 또는 편집내에서 사용되는 규칙의 추가를 파서 함수에 제공
만든 이
최신 버전 3.5.0
MediaWiki >= 1.31.0
라이선스 GNU General Public License 2.0 or later
다운로드
예제 organicdesign.nz
  • $wgCSSPath
  • $wgCSSIdentifier
Quarterly downloads 162 (Ranked 40th)
CSS 확장 기능 번역 (translatewiki.net에서 가능한 경우)
이슈 미해결 작업 · 버그 보고

CSS 확장기능은 CSS 스타일시트를 특정 문서에 추가하는 것을 가능하게 해줍니다. CSS는 문서, 파일, 파서함수 안에서 직접적으로 정의된 규칙이 될 수 있습니다.

사용법

특정 문서에 사용될 목적으로 작성된 'MyStyles.css'라는 CSS 문서를 생성하여 파서함수 뒤에 삽입합니다.

{{#css:MyStyles.css}}

If on the other hand "MyStyles.css" was a file in the /wiki/skins directory, then it would be included as shown below. Note that the file must be an absolute path with a leading slash to distinguish it from an article title.

{{#css:/skins/MyStyles.css}}

Alternatively, CSS rules can be directly included within the parser-function (inline) as in the following example,

{{#css:
  body {
    background: yellow;
    font-size: 20pt;
    color: red;
  }
}}

설치

  • 파일을 다운로드하고 CSS 폴더를 extensions/ 디렉토리에 넣어 주세요.
    개발자와 코딩 기여자는 Git을 이용해 확장기능을 다운받는 것이 좋습니다.cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/CSS
  • 아래의 코드를 LocalSettings.php 코드의 마지막에 추가합니다.
    wfLoadExtension( 'CSS' );
    
  • 필요에 따라 설정합니다.
  •   완료 – 위키의 ‘Special:Version’에 이동해서, 확장기능이 올바르게 설치된 것을 확인합니다.

설정

경우에 따라 외부 파일에 기본 URL를 설정할 수 있습니다.

$wgCSSPath = false;  # 기본값, $wgScriptPath와 관련되어 있음
$wgCSSPath = '';  # 서버 경로
$wgCSSPath = 'https://example.org/stylesheets';  # 다른 사이트로 설정할 경우

PageCSS 대용

#css: 파서 함수가 아닌 ‎<css>‎</css>를 사용하는 Extension:PageCSS (보존)이 이전에 있었습니다. 이 확장기능은 PageCSS가 지원하는 대부분의 기능을 제공하나 호환되지 않습니다. One way to avoid breaking existing pages which still use the old ‎<css> tags is to use both this Extension:CSS and Extension:NewPageCSS on the same wiki.

An alternate solution (if you want to use only this extension, but have existing content which expects Extension:PageCSS) is to save this stub function as a PHP file and include it from your LocalSettings.php to remap <css> to #css:

<?php

// Stub to remap <css></css> tags to {{#css:}} parser function extension

// For use when installing https://www.mediawiki.org/wiki/Extension:CSS to replace Extension:NewPageCSS on existing wikis

$wgHooks['ParserFirstCallInit'][] = 'wfCSSParserStubInit';
 
// Hook our callback function into the parser
function wfCSSParserStubInit( Parser $parser ) {

        // When the parser sees the <css> tag, it executes the stub wfCSSTagRender function (below) to invoke the {{#css:}} parser
        $parser->setHook( 'css', 'wfCSSTagRender' );
        return true;
}
// Execute <css> tag
function wfCSSTagRender( $input, array $args, Parser $parser, PPFrame $frame ) {

        // Stub function, just redirect the user-provided input text blindly to the {{#css:}} parser function to re-parse it as wikitext
        $output = $parser->recursiveTagParse('{{#css:' . $input . '}}', $frame);
        return $output;
}

At this point, the prior PageCSS (or NewPageCSS) extensions may be removed from your configuration; <css> now goes to #css: and (if you have this CSS extension already up and running) will behave the way any of the other CSS extensions always have.

Problems with changing the color or background of a specific page

Using the parser function to use the CSS from another page does not work to change the color or background of the page, however, using the parser function on a single page by itself does allow the background to be changed. To overcome this problem, it is possible to load the CSS through transclusion, which does not cause the problem of failing to load the change to the page background.

Bugs

See talk page.

See also