r91425 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91424‎ | r91425 | r91426 >
Date:21:01, 4 July 2011
Author:hashar
Status:ok
Tags:
Comment:
HTTP status messages move: OutputPage -> HttpStatus

OutputPage::getStatusMessage() is a method to convert a numeric HTTP status
code to an english message. It does not really belong to the OutputPage were
it was for historical reason.
This patch move the basic function to a non MediaWiki dependant class in our
directory includes/libs. We could potentially enhances it, but I do not see
any use cases for us yet.
I have renamed the method to the shorter 'getMessage' since the word 'status'
is now in the class name.

Summary of changes:
* OutputPage::getStatusMessage becomes HttpStatus::getMessage
* Method moved to the new includes/libs/HttpStatus.php
* Autoloader updated
* History kept by using 'svn copy'
* No functional changes
* No input/output format changes
* Old occurences modified in phase3
* OutputPage::getStatusMessages() marked as deprecated

PHPUnit test suite is fine.
Tested manually using a redirection
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/libs/HttpStatus.php (added) (history)
  • /trunk/phase3/includes/specials/SpecialUploadStash.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -1803,58 +1803,13 @@
18041804 *
18051805 * @param $code Integer: status code
18061806 * @return String or null: message or null if $code is not in the list of
1807 - * messages
 1807+ * messages
 1808+ *
 1809+ * @deprecated since 1.19 Use HttpStatus::getMessage() instead.
18081810 */
18091811 public static function getStatusMessage( $code ) {
1810 - static $statusMessage = array(
1811 - 100 => 'Continue',
1812 - 101 => 'Switching Protocols',
1813 - 102 => 'Processing',
1814 - 200 => 'OK',
1815 - 201 => 'Created',
1816 - 202 => 'Accepted',
1817 - 203 => 'Non-Authoritative Information',
1818 - 204 => 'No Content',
1819 - 205 => 'Reset Content',
1820 - 206 => 'Partial Content',
1821 - 207 => 'Multi-Status',
1822 - 300 => 'Multiple Choices',
1823 - 301 => 'Moved Permanently',
1824 - 302 => 'Found',
1825 - 303 => 'See Other',
1826 - 304 => 'Not Modified',
1827 - 305 => 'Use Proxy',
1828 - 307 => 'Temporary Redirect',
1829 - 400 => 'Bad Request',
1830 - 401 => 'Unauthorized',
1831 - 402 => 'Payment Required',
1832 - 403 => 'Forbidden',
1833 - 404 => 'Not Found',
1834 - 405 => 'Method Not Allowed',
1835 - 406 => 'Not Acceptable',
1836 - 407 => 'Proxy Authentication Required',
1837 - 408 => 'Request Timeout',
1838 - 409 => 'Conflict',
1839 - 410 => 'Gone',
1840 - 411 => 'Length Required',
1841 - 412 => 'Precondition Failed',
1842 - 413 => 'Request Entity Too Large',
1843 - 414 => 'Request-URI Too Large',
1844 - 415 => 'Unsupported Media Type',
1845 - 416 => 'Request Range Not Satisfiable',
1846 - 417 => 'Expectation Failed',
1847 - 422 => 'Unprocessable Entity',
1848 - 423 => 'Locked',
1849 - 424 => 'Failed Dependency',
1850 - 500 => 'Internal Server Error',
1851 - 501 => 'Not Implemented',
1852 - 502 => 'Bad Gateway',
1853 - 503 => 'Service Unavailable',
1854 - 504 => 'Gateway Timeout',
1855 - 505 => 'HTTP Version Not Supported',
1856 - 507 => 'Insufficient Storage'
1857 - );
1858 - return isset( $statusMessage[$code] ) ? $statusMessage[$code] : null;
 1812+ wfDeprecated( __METHOD__ );
 1813+ return HttpStatus::getMessage( $code );
18591814 }
18601815
18611816 /**
@@ -1877,7 +1832,7 @@
18781833 $this->mRedirect = wfExpandUrl( $this->mRedirect );
18791834 if( $this->mRedirectCode == '301' || $this->mRedirectCode == '303' ) {
18801835 if( !$wgDebugRedirects ) {
1881 - $message = self::getStatusMessage( $this->mRedirectCode );
 1836+ $message = HttpStatus::getMessage( $this->mRedirectCode );
18821837 $response->header( "HTTP/1.1 {$this->mRedirectCode} $message" );
18831838 }
18841839 $this->mLastModified = wfTimestamp( TS_RFC2822 );
Index: trunk/phase3/includes/AutoLoader.php
@@ -524,6 +524,7 @@
525525 # includes/libs
526526 'CSSJanus' => 'includes/libs/CSSJanus.php',
527527 'CSSMin' => 'includes/libs/CSSMin.php',
 528+ 'HttpStatus' => 'includes/libs/HttpStatus.php',
528529 'IEContentAnalyzer' => 'includes/libs/IEContentAnalyzer.php',
529530 'IEUrlExtension' => 'includes/libs/IEUrlExtension.php',
530531 'JavaScriptMinifier' => 'includes/libs/JavaScriptMinifier.php',
Index: trunk/phase3/includes/libs/HttpStatus.php
@@ -0,0 +1,68 @@
 2+<?php
 3+/**
 4+ * @todo document
 5+ */
 6+class HttpStatus {
 7+
 8+ /**
 9+ * Get the message associed with the HTTP response code $code
 10+ *
 11+ * Replace OutputPage::getStatusMessage( $code )
 12+ *
 13+ * @param $code Integer: status code
 14+ * @return String or null: message or null if $code is not in the list of
 15+ * messages
 16+ */
 17+ public static function getMessage( $code ) {
 18+ static $statusMessage = array(
 19+ 100 => 'Continue',
 20+ 101 => 'Switching Protocols',
 21+ 102 => 'Processing',
 22+ 200 => 'OK',
 23+ 201 => 'Created',
 24+ 202 => 'Accepted',
 25+ 203 => 'Non-Authoritative Information',
 26+ 204 => 'No Content',
 27+ 205 => 'Reset Content',
 28+ 206 => 'Partial Content',
 29+ 207 => 'Multi-Status',
 30+ 300 => 'Multiple Choices',
 31+ 301 => 'Moved Permanently',
 32+ 302 => 'Found',
 33+ 303 => 'See Other',
 34+ 304 => 'Not Modified',
 35+ 305 => 'Use Proxy',
 36+ 307 => 'Temporary Redirect',
 37+ 400 => 'Bad Request',
 38+ 401 => 'Unauthorized',
 39+ 402 => 'Payment Required',
 40+ 403 => 'Forbidden',
 41+ 404 => 'Not Found',
 42+ 405 => 'Method Not Allowed',
 43+ 406 => 'Not Acceptable',
 44+ 407 => 'Proxy Authentication Required',
 45+ 408 => 'Request Timeout',
 46+ 409 => 'Conflict',
 47+ 410 => 'Gone',
 48+ 411 => 'Length Required',
 49+ 412 => 'Precondition Failed',
 50+ 413 => 'Request Entity Too Large',
 51+ 414 => 'Request-URI Too Large',
 52+ 415 => 'Unsupported Media Type',
 53+ 416 => 'Request Range Not Satisfiable',
 54+ 417 => 'Expectation Failed',
 55+ 422 => 'Unprocessable Entity',
 56+ 423 => 'Locked',
 57+ 424 => 'Failed Dependency',
 58+ 500 => 'Internal Server Error',
 59+ 501 => 'Not Implemented',
 60+ 502 => 'Bad Gateway',
 61+ 503 => 'Service Unavailable',
 62+ 504 => 'Gateway Timeout',
 63+ 505 => 'HTTP Version Not Supported',
 64+ 507 => 'Insufficient Storage'
 65+ );
 66+ return isset( $statusMessage[$code] ) ? $statusMessage[$code] : null;
 67+ }
 68+
 69+}
Property changes on: trunk/phase3/includes/libs/HttpStatus.php
___________________________________________________________________
Added: svn:mergeinfo
170 Merged /branches/wmf-deployment/includes/OutputPage.php:r53381,57468
271 Merged /branches/REL1_15/phase3/includes/OutputPage.php:r51646
372 Merged /branches/REL1_17/phase3/includes/OutputPage.php:r81445
473 Merged /branches/resourceloader/phase3/includes/OutputPage.php:r68366-69676,69678-70682,70684-71999,72001-72255,72257-72305,72307-72342
Added: svn:eol-style
574 + native
Added: svn:keywords
675 + Author Date Id Revision
Index: trunk/phase3/includes/specials/SpecialUploadStash.php
@@ -97,7 +97,7 @@
9898 $message = $e->getMessage();
9999 }
100100
101 - wfHttpError( $code, OutputPage::getStatusMessage( $code ), $message );
 101+ wfHttpError( $code, HttpStatus::getMessage( $code ), $message );
102102 return false;
103103 }
104104

Sign-offs

UserFlagDate
Hashartested21:02, 4 July 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r91459Hashar seems to have missed one occurence of OutputPage::getStatusMessage() i...ialex14:37, 5 July 2011

Status & tagging log