MediaWikiããŒãµãŒã®ç¿»èš³ãå ¬éãããŠããŸãã
2009 , , -, , -, , Mediawiki, .
MediawikiããŒãµãŒã¯ã Mediawikiãšã³ãžã³ã³ãŒãã®åºæ¬çãªéšåã§ãã ããããªããšãWikipediaã®èšäºã«ããŸããŸãªã¿ã°ïŒã»ã¯ã·ã§ã³ããªã³ã¯ãåçïŒãæ¿å ¥ã§ããŸããã ä»ã®èšäºã®ããŒã¯ã¢ããã衚瀺ãããããã°ããå€æŽããããšããã§ããŸããã§ããã WikiããŒã¯ã¢ããã¯ãåå¿è ã§ãHTMLã®å°é家ã§ãç°¡åã«æžãããšãã§ããã»ã©æè»ã§ãã ãã®ãããããŒãµãŒã®ã³ãŒãã¯ããè€éã§ãããé·å¹Žã«ããã£ãŠãããæ¹åããããã®å€ãã®è©Šã¿ãè¡ãããŠããŸããã ãã ããä»æ¥ã§ããäžçæ倧ã®ãŠã§ããµã€ãã®1ã€ã§ãããŠã£ãããã£ã¢ã«ãšã£ãŠã¯ååã«é«éã§ãã ãã®è²ŽéãªïŒãããå°ãé£è§£ãªïŒã³ãŒãã®å éšãèŠãŠã¿ãŸãããã
ç°¡åãªæŽå²
å 責äºé ç§ãç解ããŠããããã«ããã®ç©èªã¯äž»ã«ãŠã£ãã¡ãã£ã¢ã®ã¡ãŒãªã³ã°ãªã¹ãã«é·å¹Žåå ããŠããè°è«ãããŠã£ãããã¢äŒè°2006ã®è°è«ããéããããŸããã2008幎ãŸã§ãMediawikiããŒãµãŒã¯ã ïŒé«éåã®ããïŒ1ã€ã®ãã¹å ã«ç¶æããã ãã§ãªããåžžã«æ°ããã«ãŒã«ãæ¢åã®ã³ãŒãã«è¿œå ããããšããäºå®ã®ããã§ãã æéãçµã€ã«ã€ããŠãããŒãµãŒã³ãŒãã¯å®éã®ã¹ãã²ããã£ã³ãŒãã«ãªãããããã°ããã®ãéåžžã«é£ãããæ¹åããã®ãããã«é£ãããªããŸããã æžãæããããšã¯ã»ãšãã©äžå¯èœã§ããããªããªã ãšã³ãžã³ã®ã³ã¢ãæããŸãã æ°ããã³ãŒãã®ã©ããã§ãšã©ãŒãçºçããå Žåãæ°çŸäžã®ãŠã£ãããã£ã¢ããŒãžãäžç¬ã§é£ãã§ããå¯èœæ§ããããŸãã
ã©ããã
ãã®åé¡ã解決ããæ¹æ³ã«ã€ããŠå€ãã®è°è«ãå§ãŸããŸããã 誰ããããŒãµãŒãCã§æžãçŽãããšãææ¡ããŸãããããã«ãããããŒãµãŒã¯é«éã«ãªãã1ã€ã®ãã¹ã§ã¯ãªãã«ãŒãã§ããã¹ãã解æã§ããããã«ãªããŸããããã¯ãWikipediaããŒãžã«å«ãŸãããã³ãã¬ãŒããšãµããã¿ãŒã³ã®æ°ãå¢ããããã«å¿ èŠã«ãªããŸããã ãŸããMediawikiã®æ§æãå€æŽããŠãäžéšã®æ§é ã®åæã®ãããŸãããæé€ããææ¡ããããŸããïŒããšãã°ããã ''倪åãŸãã¯æäœïŒ ''倪åãŸãã¯æäœïŒ '' ''ãŸãã¯ããªãã«ãšäžæ¬åŒ§ã®é¢ä¿ãã³ãã¬ãŒãïŒã
æçµçã«ãããŒãµãŒãPHPã«æ®ãïŒCã§æžãçŽããšMediawikiéçºè ã2ã€ã®ã¯ã©ã¹ã«åå²ãããããïŒãããŒã·ã³ã°ãååŠçãšè§£æã® 2段éã«åå²ããããšã決å®ãããŸããã ããªããã»ããµã®ä»äºã¯ãwikitextãXML DOMãšããŠè¡šçŸããããšã§ããã 解æã®æ®µéã§ãDOMããªãŒã¯ãæå¹ãªéçHTMLãååŸããããã«ãå¿ èŠãªæ°ã®å埩ãµã€ã¯ã«ã§åŠçãããŸããïŒããšãã°ããã³ãã¬ãŒãã眮ãæããããïŒã DOMã®ã«ãŒãåŠçã¯éåžžã«é«éã§ãXHTMLã®èŠ³ç¹ãããéåžžã«èªç¶ã§ãã PHPã§ã¯ããã®ãããªåŠçãéåžžã«ãããµããŒããããŠããŸãã
ããªããã»ããµ
MediawikiãœãŒã¹ãã©ã«ããŒã«ã¯ã2ã€ã®ããŒãžã§ã³ã®ããªããã»ããµãHashãšDOMã®ããŒãžã§ã³ãããããããã/includes/parser/Preprocessor_Hash.phpãš/includes/parser/Preprocessor_DOM.phpã«ãããŸãã
DOMããŒãžã§ã³ã¯HashããŒãžã§ã³ãšã»ãŒåãã§ãããããDOMããŒãžã§ã³ã«éäžããŸããããªãã·ã§ã³ã®PHPã³ã³ããŒãã³ãã§ããPHP XMLãµããŒãã䜿çšãããããããé«éã«åäœããŸãã ããªããã»ããµã¯ã©ã¹ã§æãéèŠãªé¢æ°ã¯preprocessToObjïŒïŒãšåŒã°ããŸãã Preprocessor_DOM.phpãã¡ã€ã«å ã«ã¯ãããªããã»ããµã䜿çšããä»ã®ããã€ãã®éèŠãªã¯ã©ã¹ããããŸãïŒPPDStackãPPDStackElementãPPDPartãPPFrame_DOMãããã³PPNode_DOMã
ããªããã»ããµã¯ããªããèãããããå°ãªã
Mediawiki XMLã¯ã©ã®ãããªãã®ã§ããïŒ ä»¥äžã¯ããŠã£ãããã¹ãã{{MySpattern}} this [[test]]ããXMLè¡šçŸã§ã©ã®ããã«èŠãããã®äŸã§ãã
<root> <template> <title>mytemplate</title> </template> this is a [[test]] </root>
泚ã å éšãªã³ã¯ããŸã£ããåŠçãããªãããšã ããªããã»ããµã³ãŒãã¯ãåŸã®æ®µéã§å®è¡ã§ããäœæ¥ãåé¿ããŸãïŒãããŠãããã«ã¯çç±ããããŸãïŒããããã£ãŠãããªããã»ããµã®å¯äžã®å®éã®äœæ¥ã¯ããã³ãã¬ãŒãããã³ä»ã®ããã€ãã®ããšã®ããã®XMLèŠçŽ ãäœæããããšã§ãã ãããã®ããšãããªãã¡ ããŒã¹ããŒãïŒå®å šãªãªã¹ãïŒïŒãã³ãã¬ãŒããtplargãã³ã¡ã³ããextãignoreãh
Wikitextã䜿çšããããšãããå Žåã¯ããããã®åºæ¬ããŒãã«å¯Ÿå¿ããããŒã¯ã¢ãããæ¢ã«ããã£ãŠããŸãã 念ã®ãããããã«ãããŸãïŒ
- ãã³ãã¬ãŒã =äºéäžæ¬åŒ§{{...}}
- tplarg =ããªãã«äžæ¬åŒ§{{{...}}}
- comment =ä»»æã®ã¿ã€ãã®HTMLã³ã¡ã³ã
- ext =å¥ã®æ¡åŒµåã§ç解ããå¿ èŠããããã¹ãŠã®ãã®
- ignore = noincludeã¿ã°ãããã³includeonlyã¿ã°ãšãã®äžã®ã³ã³ãã³ã
- h =ã»ã¯ã·ã§ã³
以äžã§ãã ãã以å€ã¯ãã¹ãŠç¡èŠãããå ã®ãŠã£ãããã¹ããšããŠããŒãµãŒã«è¿ãããŸãã
ããªããã»ããµã¯ã©ã®ããã«æ©èœããŸããïŒ
ããã§ã¯ç¹å¥ãªããšã¯äœããããŸããããããã€ãã®èšèã¯èšã䟡å€ããããŸãã å¿ èŠãªXMLè¡šçŸãååŸããããã«ãããªããã»ããµã¯ããã®ããã¹ãã«å«ãŸããæåæ°ã ããã«ãŒãå ã§WikitextãééããŸãã æ§æã®ãããã§ãããã¹ãå ã®äœã§ãè¡šçŸã§ããååž°ãã¿ãŒã³ãæ£ããåŠçããä»ã®æ¹æ³ã¯ãããŸããã ãããã£ãŠããŠã£ãããã£ã¢ã®èšäºã«40,000æåãå«ãŸããŠããå Žåããµã€ã¯ã«ã¯40,000åã®å埩ã§æ§æãããå¯èœæ§ããããŸãã ããã§ãããŒãµãŒã«ãšã£ãŠé床ãéåžžã«éèŠã§ããçç±ãæããã«ãªããŸããã
èªèº«ã®è§£æ
XMLã³ãŒãã®çæã«äœ¿çšãããæ®ãã®ããªããã»ããµãšè¿œå ã®ã¯ã©ã¹ãã¹ãããããŸãã ããŒãµãŒèªäœã«æ³šç®ããWikipediaã®èšäºãã¯ãªãã¯ãããšãã®ããŒãµãŒã®å žåçãªã±ãŒã¹ãèŠãŠã¿ãŸãããã ãã ããããã§ã¯ããŠã£ããå¯èœãªæ段ã§ãã£ãã·ã¥ãããããšãå¿ããŠã¯ãªããŸããããããã£ãŠãããŒãžãã¯ãªãã¯ãããã³ã«ããŒãžã®è§£æãçºçããããšã¯ã»ãšãã©ãããŸããã
Articleãªããžã§ã¯ãããå§ãŸããçŸåšã®ããŒãžã§ã³ã®ããŒãžã®å žåçãªããŒãµãŒåŒã³åºãããªãŒã次ã«ç€ºããŸãã
01.èšäº->ãã¥ãŒ |
02.-èšäº-> getContent |
03. ----èšäº-> loadContent |
04. ------ Article-> fetchContent->ããŒã¿ããŒã¹ããååŸãããŠã£ãããã¹ããè¿ããŸã |
05.-èšäº-> outputWikiText->解æã®æºå |
06. ----ããŒãµãŒ->解æ |
07. ------ããŒãµãŒ-> internalParse |
08. --------ããŒãµãŒ-> replaceVariables |
09. ----------ããŒãµãŒ-> preprocessToDom |
10. ------------ããªããã»ããµ-> preprocessToObj |
11. ----------ãã¬ãŒã ->å±é |
12. --------ããŒãµãŒ-> doTableStuff |
13. --------ããŒãµãŒ-> replaceInternalLinks |
14. --------ããŒãµãŒ-> replaceExternalLinks |
15. ------ããŒãµãŒ-> doBlockLevels |
16. ------ããŒãµãŒ-> replaceLinkHolders |
ãããã®æ©èœãèŠãŠã¿ãŸãããã ç¹°ãè¿ããŸããããããã¯äž»ãªé¢æ°ã§ããããã®äŸã§åŒã³åºããããã¹ãŠã®é¢æ°ã§ã¯ãããŸããã é ç®2ã4ã¯ãããŒã¿ããŒã¹ããèšäºã®ãŠã£ãããã¹ããååŸããŠè¿ããŸãã ãã®ããã¹ãã¯outputWikiTextãªããžã§ã¯ãã«æž¡ãããParser :: parseïŒïŒé¢æ°ã«æž¡ãããã«æºåãããŸãã
ãã®åŸããã€ã³ã8ã11ã§åã³èå³æ·±ããã®ã«ãªããŸãã replaceVariablesé¢æ°å ã§ãããã¹ãã¯DOMè¡šçŸã«å€ãããèšäºå ã®åæåã®ã«ãŒãã§ãäžèšã®ãã³ãã¬ãŒãããµããã¿ãŒã³ãããã³ä»ã®ããŒãã®éå§ã©ãã«ãšçµäºã©ãã«ãæ€çŽ¢ãããŸãã
ãã€ã³ãçªå·11ã¯ãPreprocessor_DOM.phpãã¡ã€ã«ïŒäžèšïŒã®ä»ã®ã¯ã©ã¹ã®ç¥èãå¿ èŠãšãããããããã§ã¹ãããããèå³æ·±ãã¹ãããã§ãã ãšãã¹ãã³ãã¯éåžžã«éèŠãªæ©èœã§ãããå€ãã®ããšïŒååž°åŒã³åºããå«ãïŒãè¡ããŸãããDOMããŒãããããã¹ããå®éã«æœåºããä»äºããããšèšãã ãã§ååã§ãïŒãã³ãã¬ãŒãã¯ãã¹ãã§ããã®ã§ãåžžã«ãã«ããã¹ããååŸããããã§ã¯ãããŸããïŒ 3ã€ã®ã¿ã€ããé€ããŠããã¹ãŠã®wikiã¿ã°ãæããã«ããå転ãããæå¹ãªHTMLããã¹ãïŒå«ãŸããŠããåèšäºããïŒã:ããŒãã«ããªã³ã¯ãããã³ãªã¹ãã ãããã£ãŠãäžèšã®äŸã§ã¯ãã{{MyTemplate}} this [[test]]ãexpandïŒïŒã¯ãã©ãŒã ã®ããã¹ããè¿ããŸãã
ã[[text]]ããã³ãã¬ãŒãããã€ã³ã¯ã«ãŒãããŸãããããã¯[[test]]ã§ãã
ãã®ç°¡åãªäŸãããããããã«ãããŒãã«ããªã³ã¯ããªã¹ããé€ãããã¹ãŠããã®æ®µéã§æŽçãããŠããŸãã
ãªã³ã¯ã¯ç¹å¥ãªå Žåã§ã
ã¯ãããªã³ã¯ã«ã¯ç¬èªã®ã»ã¯ã·ã§ã³ããããŸãã ãããŠãããããããããïŒç·šéã«å ããŠïŒwikièªäœãäœããã®ã®æãéèŠãªéšåã ããã§ãã ãã ããããŒãµãŒã³ãŒãã®æ®ãã®ããŒã¯ã¢ããããéåžžã«ç¹å¥ãªæ¹æ³ã§ç解ããŠããããã§ãã ç¹å¥ãªã®ã¯ã2ã€ã®æ®µéã§åŠçãããããšã§ããæåã®æ®µéã§ã¯ãåãªã³ã¯ã«äžæã®IDãå²ãåœãŠããã2çªç®ã®æ®µéã§ã¯ããã®æå¹ãªHTMLãããªã³ã¯ãã«ããŒãã®å Žæã«æ¿å ¥ãããŸãã ãã®äŸã§ã¯ãæåã®æ®µéã®åŸã«åŸãããçµæã以äžã«ç€ºããŸãã
ããã³ãã¬ãŒãã«<ïŒ-LINK 0->ãå«ããŸãããããã¯<ïŒ-LINK 1->ã§ããã
ãæ³åã®ãšããããªã³ã¯ã®ããã¹ããšãã©ãŒã LINK #IDã®IDãäžèŽãããé åããããŸããããã¯mLinkHoldersãšããååã®Parserã¯ã©ã¹ã®å€æ°ã§ãã ãããã³ã°ã«å ããŠããã®å€æ°ã¯åãªã³ã¯ã®Titleãªããžã§ã¯ããä¿åããŸãã
ãããã£ãŠããªã³ã¯ã解æãã2çªç®ã®ã¹ãããã§ã¯ããã®é åã䜿çšããŠæ€çŽ¢ãšçœ®æãç°¡åã«ããŸãã ä»ãã¹ãŠïŒ å®æããããã¹ãããã¢ã®å€ã«éããŸãïŒ
次ã®ã¹ããŒãž
次ã®æçš¿ã§ã¯ãããªããã»ããµãšPreprocessor__DOM.phpãã¡ã€ã«ã®ã¯ã©ã¹ã®è©³çŽ°ãã€ãŸãåæDOM XMLããªãŒãæ§ç¯ããããã«ã©ã®ããã«äœ¿çšããããã«éäžããŸãã Unboxæ¡åŒµæ©èœã§æ å ±ããã¯ã¹ããã£ãã·ã¥ããããã«ã©ã®ããã«äœ¿çšãããã«ã€ããŠã説æããŸãã