확장기능:변수

From mediawiki.org
This page is a translated version of the page Extension:Variables and the translation is 55% complete.
Outdated translations are marked like this.
미디어위키 확장 기능 설명서
Variables
출시 상태: 안정
구현 파서 함수
설명 문서 상의 변수를 더욱 활용할 수 있는 파서 기능을 제공합니다.
만든 이
유지 보수자 MGChecker
최신 버전 2.5.1 (2019-07-11)
MediaWiki 1.29+
PHP 5.5+
데이터베이스 변경 아니오
Composer mediawiki/variables
라이선스 ISC License
다운로드
README
RELEASE-NOTES
  • $wgVariablesAreVolatile
  • $wgVariablesDisabledFunctions
Quarterly downloads 145 (Ranked 49th)
Public wikis using 1,808 (Ranked 201st)
Variables 확장 기능 번역 (translatewiki.net에서 가능한 경우)
Vagrant 역할 variables
이슈 미해결 작업 · 버그 보고
경고 경고: This extension is incompatible with plans to parallelize parsing, as is intended by the use of Parsoid . Therefore, the future of this extension is uncertain, and it is expected to become incompatible with the standard MediaWiki parser within a few years. For further information, see 작업 T250963 and Parsoid/Extension API § No support for sequential, in-order processing of extension tags.
To avoid deprecation warning about the InternalParseBeforeSanitize hook for 미디어위키 1.35 - 미디어위키 1.38 , or missing the #var_final parser function in 미디어위키 1.39 +, please update to the latest version (master branch for now). See 작업 T276627 and 작업 T250963 for further information.

Variables 확장 기능에서는 문서 상의 변수를 정의해서 같은 문서 또는 불러들인 틀에서의 변수를 사용할 수 있습니다. 식에 따라서는 오래된 값 등을 지정된 값으로 변경할 수도 있습니다.

단 그것뿐인 기능이지만 매우 가벼운 확장기능이기에 위키로의 부하도 없으며 하나의 문서에서 많은 변수를 취급할 수 있습니다. 최상의 결과를 얻기 위해서는 확장기능:ParserFunctions 확장 기능도 갖추어서 사용하는 것도 좋을 것입니다.

This extension will not be enabled for wikis run by the Wikimedia Foundation (WMF).[1][2][3][4] See alternatives.

값 대입하기

#vardefine

  • {{#vardefine:변수 이름 | 특정 값 }}

(이미 또는 여기에 기입된) 변수 이름의 변수에 지정한 값의 값이 할당됩니다.

예시: {{#vardefine:iconwidth|25}} iconwidth = 25로 지정한다

#vardefineecho

  • {{#vardefineecho:변수 이름 | 특정 값 }}

#vardefine와 거의 마찬가지로 기능하지만 영향을 받은 값이 출력됩니다.

  • 예시: making iconwidth = {{#vardefineecho:iconwidth|25}}

값 획득하기

#var

변수 변수 이름의 값은 아래와 같이 해서 획득할 수 있습니다

  • {{#var:변수 이름}}

정의를 하지 않았을 경우에 결과는 빈 문자열이 됩니다. 경고 메시지는 표시되지 않습니다.

변수가 정의되지 않았을 경우나 비었을 경우(void)에 사용되는 값(한정값)은 아래와 같이 정의할 수 있습니다:

  • {{#var:변수 이름 | 한정값 }}

이것은 이하와 같습니다:

  • {{#if: {{#var:변수 이름 }} | {{#var:변수 이름 }} | 한정값 }}

이는 최단의 최고의 배열입니다. 하지만 버전 2.0 이전은 한정값이 상시 전개되도록 되어 있습니다. 버전 2.0부터는 실제로 사용된 경우에만 전개됩니다.

값은 파서 함수 등에서 사용할 수 있습니다.

#varexists

  • {{#varexists:변수 이름 }} 변수가 이미 정의되어 있는 경우에는 1을 반환합니다. 변수가 정의되어 있지 않은 경우에는 빈 값(void)가 반환됩니다.

It supports a second and a third parameter to replace these values.

  • {{#varexists:변수 이름 | if-value | else-value }}

이것은 이하와 같습니다:

  • {{#if: {{#varexists: 변수 이름 }} | if-value | else-value }}

but it is much shorter and better arranged. Before version 2.5 though, both were always expanded. From version 2.5 on the if and else values only get expanded when their cases are actually entered.

#var_final

Variables 2.0에서 새롭게 도입된 실험적인 함수입니다. 이 함수에서는 문서의 표시가 종료된 시점에서 변수의 값을 최종적으로 출력합니다. 파서가 모든 위키 마크업을 검증된 후에 값이 삽입되기 때문에 정확한 값이 표기될 것입니다. 단, 다른 함수와 병용할 수는 없습니다. 예시:

  • {{#var_final:변수 이름 | 한정값 }}

최종적인 문서의 표시 단계에서 변수가 존재하지 않을 경우에 또는 그 값이 빈 문자열일 경우에 default의 값이 사용됩니다. 한정으로는 함수가 어디서 사용되고 있어도 전개하기 위해서 매개변수는 그것이 필요로 하지 않아도 전개됩니다.

예제

#expr를 사용하려면 확장기능:ParserFunctions 확장 기능을 설치할 필요가 있습니다.

x = 2*a + b를 계산:

  • {{#vardefine:x|{{#expr:2*{{#var:a}}+{{#var:b}}}}}}

n에 1을 더한다:

  • {{#vardefine:n|{{#expr:{{#var:n}}+1}}}}

설치

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

Configuration

This extension provides two configuration parameters:

$egVariablesAreVolatile
Allows to disable the parser frame being marked as volatile by the extension, i.e. disable template caching.
Default: true;
$egVariablesDisabledFunctions
Allows to disable specified parser functions provided by this extension.
Default: [];
Example: [ 'var_final', 'vardefineecho' ];

Compatibility

The recommended version of the Variables extension for recent MediaWiki releases is listed below. Older versions of the extensions might work as well, but aren't tested for new MediaWiki releases.

Alternatives

As this extension will not be enabled for wikis run by the Wikimedia Foundation (WMF), here are some alternatives:[1][2][3][4]

  • If you use Variables as cache for expensive operations, you can transform the section where you need them into a template and pass the required information as template parameters instead. This will work until you reach the expansion depth limit, which can be increased if necessary.
  • If you use Variables to do more complex template operations than possible with simple 확장기능:ParserFunctions , and if you have sufficient permissions on the server, you can use Scribunto's Lua functionality instead. You may not be able to install Scribunto on shared hosting. Note that this does not add support for global Variables. However, Extension:VariablesLua adds a Scribunto interface for the Variables store.
  • Don't use variables, instead duplicate the information you need as a variable. If that information is acquired by an expensive template call, performance may suffer. This will work until you reach the node count limit.
  • If you require variables just for autonumbering, you could look into Extension:NumerAlpha .

같이 보기

References