globals.txt

来自「php 开发的内容管理系统」· 文本 代码 · 共 75 行

TXT
75
字号
globals.txtGlobals are evil. The original MediaWiki code relied onglobals for processing context far too often. MediaWikidevelopment since then has been a story of slowly movingcontext out of global variables and into objects. Storingprocessing context in object member variables allows thoseobjects to be reused in a much more flexible way. Considerthe elegance of:    # Generate the article HTML as if viewed by a web request    $article = new Article( Title::newFromText( $t ) );    $article->view();versus    # Save current globals    $oldTitle = $wgTitle;    $oldArticle = $wgArticle;    # Generate the HTML    $wgTitle = Title::newFromText( $t );    $wgArticle = new Article;    $wgArticle->view();    # Restore globals    $wgTitle = $oldTitle    $wgArticle = $oldArticleSome of the current MediaWiki developers have an idlefantasy that some day, globals will be eliminated fromMediaWiki entirely, replaced by an application object which would be passed to constructors. Whether that would be an efficient, convenient solution remains to be seen, but certainly PHP 5 makes such object-oriented programming models easier than they were in previous versions.For the time being though, MediaWiki programmers will haveto work in an environment with some global context. At the time of writing, 418 globals were initialised on startup by MediaWiki. 304 of these were configuration settings, which are documented in DefaultSettings.php. There is no comprehensive documentation for the remaining 114 globals, however some of the most important ones are listed below. They are typically initialised either in index.php or in Setup.php.$wgOut	OutputPage object for HTTP response.$wgUser	User object for the user associated with the current	request.$wgTitle	Title object created from the request URL.$wgLang	Language object selected by user preferences$wgContLang	Language object associated with the wiki being	viewed.$wgArticle	Article object corresponding to $wgTitle.$wgParser	Parser object. Parser extensions register their	hooks here.$wgLoadBalancer	A LoadBalancer object, manages database connections.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?