HTMLForm 的默认动作

HTMLForm's default action

在 Wikimedia Gerrit 上进行代码审查时,我偶然发现评论说:

$htmlForm->setAction( wfScript() );

Reviewer: not needed, wfScript() is the default for the action.

所以我查阅了有关HTMLForm::setAction(大页面)的文档。

Set the value for the action attribute of the form. When set to false (which is the default state), the set title is used.

然而,我不明白的是如何 wfScript (获取指定脚本文件的路径,尊重文件扩展名;这是 $wgScriptPath 等的包装器,除了 'index' 和 'load' 使用 $wgScript/$wgLoadScript) 可以 从标题中提取 Title 的实例?)。

这对我来说没有任何意义,因为 wfScript() return 是一个入口点,所有 Title 通常共享相同的入口点。

查找HTMLForm::getAction,我看到代码确实使用了Title。不过,只有 有条件地 。简单地说,如果 Title::getLocalURL 将 return 包含查询字符串的 URL,例如/mw/index.php?title=Special:ContributionswfScript() 已 return 编辑,并且根本未使用标题,这与 HTMLForm::setAction() 中记录的内容相反。理由很明确:这是因为浏览器可能会删除或修改这里不需要的查询字符串。

为什么不总是使用隐藏表单域方法,为什么标题必须知道它的入口点?

$this->getConfig()->get( 'ArticlePath' )$this->getTitle()->getLocalURL()有什么关系[前者用作条件,后者可能return来自HTMLForm::getAction.]

我不太确定我理解你的问题,所以如果这个答案没有真正回答你的问题,请随时发表评论,我会尝试修正我的答案:)

Why isn't the hidden form field approach always used and why does the Title have to know about its entry point?

为什么要这样做?是的,这是可能的,但使用它的唯一原因是,浏览器会删除传递给表单 action 参数的参数。其他值(如 short urls)工作正常。另一方面是,如果您配置短 url(例如 yourdomain.com/wiki/Special:UserLogin 而不是 yourdomain.com/w/index.php?title=Special:UserLogin ), HTMLForm 为什么要使用 yourdomain.com/w/index.php?title=Special:UserLogin&wpusername=test&wppassword=123(不好的例子,因为 UserLogin 不使用 HTMLForm 也不会使用 GET,但想想任何其他例子 :P)而不是(对用户来说)更好的例子 yourdomain.com/wiki/Special:UserLogin?wpusername=test&wppassword=123?所以它没有真正的技术背景,不总是使用隐藏的 title 字段,iirc.

How is $this->getConfig()->get( 'ArticlePath' ) related to $this->getTitle()->getLocalURL()

wgArticlePath configuration variable specifies the base URL for article links, which means, if you call getLocalURL on a Title object, the config var is used to build the URL/Link if no query is specified (see the code of getLocalURL 知道它是如何工作的)。这意味着,配置变量指定如何从该函数返回链接(例如 /w/index.php?title=$1 或 /wiki/$1)。所以它是这个函数的一个非常重要的部分,并且(关闭 HTMLForm 的圆圈)决定的重要条件,如果使用 wfScript() 或本地 url (来自 Title 对象),因为它是条件Title::getLocalURL() 决定是否使用问号。

我希望这对理解 HTMLForm 的作用有所帮助,如果没有,请随时发表评论:)