r72119 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72118‎ | r72119 | r72120 >
Date:16:58, 1 September 2010
Author:mah
Status:resolved
Tags:
Comment:
fill out appendQuery() for FauxRequest — probably should be refactored
into the parent class, but the parent uses $_GET where we have $this->data
Modified paths:
  • /trunk/phase3/includes/WebRequest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/WebRequest.php
@@ -625,10 +625,10 @@
626626 $file = new WebRequestUpload( $this, $key );
627627 return $file->getName();
628628 }
629 -
 629+
630630 /**
631631 * Return a WebRequestUpload object corresponding to the key
632 - *
 632+ *
633633 * @param @key string
634634 * @return WebRequestUpload
635635 */
@@ -727,7 +727,7 @@
728728 $ext = substr( $pi, $dotPos );
729729 return !in_array( $ext, array( $wgScriptExtension, '.php', '.php5' ) );
730730 }
731 -
 731+
732732 /**
733733 * Parse the Accept-Language header sent by the client into an array
734734 * @return array( languageCode => q-value ) sorted by q-value in descending order
@@ -740,15 +740,15 @@
741741 if ( !$acceptLang ) {
742742 return array();
743743 }
744 -
 744+
745745 // Return the language codes in lower case
746746 $acceptLang = strtolower( $acceptLang );
747 -
 747+
748748 // Break up string into pieces (languages and q factors)
749749 $lang_parse = null;
750750 preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?|\*)\s*(;\s*q\s*=\s*(1|0(\.[0-9]+)?)?)?/',
751751 $acceptLang, $lang_parse );
752 -
 752+
753753 if ( !count( $lang_parse[1] ) ) {
754754 return array();
755755 }
@@ -777,10 +777,10 @@
778778 protected $request;
779779 protected $doesExist;
780780 protected $fileInfo;
781 -
 781+
782782 /**
783783 * Constructor. Should only be called by WebRequest
784 - *
 784+ *
785785 * @param $request WebRequest The associated request
786786 * @param $key string Key in $_FILES array (name of form field)
787787 */
@@ -791,26 +791,26 @@
792792 $this->fileInfo = $_FILES[$key];
793793 }
794794 }
795 -
 795+
796796 /**
797797 * Return whether a file with this name was uploaded.
798 - *
 798+ *
799799 * @return bool
800800 */
801801 public function exists() {
802802 return $this->doesExist;
803803 }
804 -
 804+
805805 /**
806806 * Return the original filename of the uploaded file
807 - *
 807+ *
808808 * @return mixed Filename or null if non-existent
809809 */
810810 public function getName() {
811811 if ( !$this->exists() ) {
812812 return null;
813813 }
814 -
 814+
815815 global $wgContLang;
816816 $name = $this->fileInfo['name'];
817817
@@ -821,51 +821,51 @@
822822 wfDebug( __METHOD__ . ": {$this->fileInfo['name']} normalized to '$name'\n" );
823823 return $name;
824824 }
825 -
 825+
826826 /**
827827 * Return the file size of the uploaded file
828 - *
 828+ *
829829 * @return int File size or zero if non-existent
830830 */
831831 public function getSize() {
832832 if ( !$this->exists() ) {
833833 return 0;
834834 }
835 -
 835+
836836 return $this->fileInfo['size'];
837837 }
838 -
 838+
839839 /**
840840 * Return the path to the temporary file
841 - *
 841+ *
842842 * @return mixed Path or null if non-existent
843843 */
844844 public function getTempName() {
845845 if ( !$this->exists() ) {
846846 return null;
847847 }
848 -
 848+
849849 return $this->fileInfo['tmp_name'];
850850 }
851 -
 851+
852852 /**
853853 * Return the upload error. See link for explanation
854854 * http://www.php.net/manual/en/features.file-upload.errors.php
855 - *
 855+ *
856856 * @return int One of the UPLOAD_ constants, 0 if non-existent
857857 */
858858 public function getError() {
859859 if ( !$this->exists() ) {
860860 return 0; # UPLOAD_ERR_OK
861861 }
862 -
 862+
863863 return $this->fileInfo['error'];
864864 }
865 -
 865+
866866 /**
867867 * Returns whether this upload failed because of overflow of a maximum set
868868 * in php.ini
869 - *
 869+ *
870870 * @return bool
871871 */
872872 public function isIniSizeOverflow() {
@@ -879,7 +879,7 @@
880880 # post_max_size is exceeded
881881 return true;
882882 }
883 -
 883+
884884 return false;
885885 }
886886 }
@@ -936,7 +936,23 @@
937937 }
938938
939939 public function appendQuery( $query ) {
940 - $this->notImplemented( __METHOD__ );
 940+ global $wgTitle;
 941+ $basequery = '';
 942+ foreach( $this->data as $var => $val ) {
 943+ if ( $var == 'title' )
 944+ continue;
 945+ if ( is_array( $val ) )
 946+ /* This will happen given a request like
 947+ * http://en.wikipedia.org/w/index.php?title[]=Special:Userlogin&returnto[]=Main_Page
 948+ */
 949+ continue;
 950+ $basequery .= '&' . urlencode( $var ) . '=' . urlencode( $val );
 951+ }
 952+ $basequery .= '&' . $query;
 953+
 954+ # Trim the extra &
 955+ $basequery = substr( $basequery, 1 );
 956+ return $wgTitle->getLocalURL( $basequery );
941957 }
942958
943959 public function getHeader( $name ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r79783Followup r72119, add some braces...reedy00:55, 7 January 2011

Status & tagging log