확장기능:변수

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page Extension:Variables and the translation is 32% complete.

Other languages:
Deutsch • ‎English • ‎Nederlands • ‎Tiếng Việt • ‎català • ‎dansk • ‎español • ‎français • ‎italiano • ‎polski • ‎português • ‎português do Brasil • ‎sicilianu • ‎suomi • ‎русский • ‎中文 • ‎日本語 • ‎한국어
미디어위키 확장 기능 매뉴얼
Crystal Clear action run.svg
Variables
출시 상태: 안정
구현 Parser function
설명 Introduces parser functions for dealing with page-scoped variables.
만든이
유지보수자 MGChecker
최신 버전 2.5.0 (2018-08-31)
MediaWiki 1.29+
PHP 5.5+
데이터베이스 변경 아니오
라이선스 ISC License
다운로드
README
RELEASE-NOTES
사용된 훅
ParserFirstCallInit
ParserClearState
InternalParseBeforeSanitize
Variables 확장 기능 번역 (translatewiki.net에서 가능한 경우)
사용법과 버전 매트릭스를 확인합니다.
Vagrant 역할 variables
이슈 미해결 작업 · 버그 보고

The Variables extension allows you to define a variable on a page, use it later in that same page or included templates, change its value, possibly to a value given by an expression in terms of the old value, etc.

It is much like a template, only very lightweight and scoped to only a single page, so you can use many variables on a page without slowing down the wiki with huge numbers of templates. Combine this extension with the ParserFunctions extension for best results.

값 대입하기

#vardefine

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

Assigns the value specifiedvalue to the (already existing or hereby introduced) variable variablename.

  • Example: {{#vardefine:iconwidth|25}} making iconwidth = 25

#vardefineecho

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

Works exactly as #vardefine, but the affected value is printed.

  • 예시: making iconwidth = <code>{{#vardefineecho:iconwidth|25}}</code>

Retrieving the value of a variable

#var

The value of the variable variablename is produced by

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

If undefined, this produces an empty string; it does not give an error message.

It is possible to define a value for the case that the variable is undefined or void:

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

This is equivalent to:

  • {{#if: {{#var:변수 이름}} | {{#var:변수 이름 }} | defaultvalue }}

but it is much shorter and better arranged. Before version 2.0 though, the default value always was expanded. From version 2.0 on the default only gets expanded in case it is actually used.

The value can be used in parser functions, etc.

#varexists

  • {{#varexists:변수 이름 }} returns 1 if the variable is already defined. If the variable is not defined the return value is void.

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

  • {{#varexists: variablename | if-value | else-value }}

This is equivalent to:

  • {{#if: {{#varexists: variablename }} | 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

Experimental new function introduced in Variables 2.0. This function will output the final, last value a variable has at the end of the page rendering. Naturally, the value will be inserted after the parser went over the entire wiki markup, so this function can't be used in other functions, expecting the right value is being used. Example:

  • {{#var_final:변수 이름 | defaultvalue}}

The default value will be used if the variable doesn't exist at the final page rendering stage or if its value is an empty string. The default will be expanded right where the function is used, so the parameter will be expanded, even if it won't be needed.

예제

The ParserFunctions extension must also be installed to use #expr.

Compute x = 2*a + b:

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

Add one to n:

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

설치

  • 파일을 다운로드해서, extensions/ 폴더 내의 Variables 이라는 이름의 디렉터리 내에 설치합니다.
  • 아래의 코드를 LocalSettings.php의 말미에 추가합니다:
    wfLoadExtension( 'Variables' );
    
  • Yes 완료 – 위키의 ‘Special:Version’에 이동해서, 확장기능이 올바르게 설치된 것을 확인합니다.

미디어위키 1.30 이하를 실행 중인 사용자에게:

위의 지시사항은 wfLoadExtension()을 사용하여 이 확장기능을 설치하는 새로운 방법을 기술합니다 wfLoadExtension( 'Variables' ); 대신 이 초기 버전(미디어위키 1.30 이하)에 이 확장기능을 설치하려면 다음을 사용해야 합니다:

require_once "$IP/extensions/Variables/Variables.php";

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.

Note

This extension will not be enabled for wikis run by the Wikimedia Foundation (WMF). See phab:T9865, phab:T65324, phab:T113859, and phab:T151192.

같이 보기