dounong5373 2019-03-08 10:17
浏览 101

Mediawiki(1.26) - 如何从页面内访问404 HTTP状态

when calling a non-existent wiki page mediawiki delievers a 404 in the header.

Is there a way to catch this from the own page (for logging reasons)?

There is a

public function getStatusCode()

in WebResponse.php and in HttpError.php

and in OutputPage.php e.g. there is a

public function setStatusCode( $statusCode )

From within the MonoBookTemplate.php i have an instance of MonoBookTemplate.

But how do i catch from this place the 404 status?

I read about $context->getOutput() but have no clue how to access the status variable.


Part-Solution:

As a workaround i added $wgMyStatusCode to the LocalSettings.php and in WebResponse.php:

public function statusHeader( $code ) {
    HttpStatus::header( $code );

    //added
    global $wgMyStatusCode;
    $wgMyStatusCode = $code;
}

Anyway - if someone could me introduce to the secrets of object-orientation in mediawiki - thanks.

  • 写回答

1条回答 默认 最新

  • dphnn333971 2019-03-09 00:05
    关注
    !RequestContext::getTitle()->exists()
    

    is probably close enough.

    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入