Index: trunk/extensions/MobileFrontend/MobileFrontend.i18n.php |
— | — | @@ -69,6 +69,9 @@ |
70 | 70 | 'mobile-frontend-feedback-page' => 'Project:Mobile Extension Feedback', |
71 | 71 | 'mobile-frontend-leave-feedback-thanks' => 'Thanks, for your feedback!', |
72 | 72 | 'mobile-frontend-language' => 'Language', |
| 73 | + 'mobile-frontend-username' => 'Username:', |
| 74 | + 'mobile-frontend-password' => 'Password:', |
| 75 | + 'mobile-frontend-login' => 'Log in', |
73 | 76 | ); |
74 | 77 | |
75 | 78 | /** Message documentation (Message documentation) |
Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -170,6 +170,9 @@ |
171 | 171 | 'mobile-frontend-leave-feedback-thanks', |
172 | 172 | 'mobile-frontend-search-submit', |
173 | 173 | 'mobile-frontend-language', |
| 174 | + 'mobile-frontend-username', |
| 175 | + 'mobile-frontend-password', |
| 176 | + 'mobile-frontend-login', |
174 | 177 | ); |
175 | 178 | |
176 | 179 | public $itemsToRemove = array( |
— | — | @@ -665,7 +668,7 @@ |
666 | 669 | wfProfileIn( __METHOD__ ); |
667 | 670 | $parsedUrl = parse_url( $url ); |
668 | 671 | // Validates value as IP address |
669 | | - if ( !IP::isValid( $parsedUrl['host'] ) ) { |
| 672 | + if ( isset( $parsedUrl['host'] ) && !IP::isValid( $parsedUrl['host'] ) ) { |
670 | 673 | wfProfileOut( __METHOD__ ); |
671 | 674 | $baseUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; |
672 | 675 | $baseUrl = str_replace( $baseUrl, '', $url ); |
— | — | @@ -1005,6 +1008,7 @@ |
1006 | 1009 | |
1007 | 1010 | /** |
1008 | 1011 | * @param $html string |
| 1012 | + * @return string |
1009 | 1013 | */ |
1010 | 1014 | public function DOMParseMainPage( $html ) { |
1011 | 1015 | wfProfileIn( __METHOD__ ); |
— | — | @@ -1061,6 +1065,62 @@ |
1062 | 1066 | wfProfileOut( __METHOD__ ); |
1063 | 1067 | return $contentHtml; |
1064 | 1068 | } |
| 1069 | + |
| 1070 | + /** |
| 1071 | + * @param $token string |
| 1072 | + * @param $action string |
| 1073 | + * @return DomElement |
| 1074 | + */ |
| 1075 | + public function renderLogin( $token, $action ) { |
| 1076 | + $username = self::$messages['mobile-frontend-username']; |
| 1077 | + $password = self::$messages['mobile-frontend-password']; |
| 1078 | + $login = self::$messages['mobile-frontend-login']; |
| 1079 | + $form = <<<EOT |
| 1080 | + <form name="userlogin" method="post" action="{$action}"> |
| 1081 | + <table class="user-login"> |
| 1082 | + <tbody> |
| 1083 | + <tr> |
| 1084 | + <td class="mw-label"><label for="wpName1">{$username}</label></td> |
| 1085 | + </tr> |
| 1086 | + <tr> |
| 1087 | + <td class="mw-input"><input class="loginText" id="wpName1" tabindex="1" size="20" value="Root" name="wpName"></td> |
| 1088 | + </tr> |
| 1089 | + <tr> |
| 1090 | + <td class="mw-label"><label for="wpPassword1">{$password}</label></td> |
| 1091 | + </tr> |
| 1092 | + <tr> |
| 1093 | + <td class="mw-input"><input class="loginPassword" id="wpPassword1" tabindex="2" size="20" autofocus="" type="password" name="wpPassword"></td> |
| 1094 | + </tr> |
| 1095 | + <tr> |
| 1096 | + <td></td> |
| 1097 | + </tr> |
| 1098 | + <tr> |
| 1099 | + <td class="mw-submit"><input id="wpLoginAttempt" tabindex="9" type="submit" value="{$login}" name="wpLoginAttempt"></td> |
| 1100 | + </tr> |
| 1101 | + </tbody> |
| 1102 | + </table> |
| 1103 | + <input type="hidden" name="wpLoginToken" value="{$token}"> |
| 1104 | + </form> |
| 1105 | +EOT; |
| 1106 | + return $this->getDomDocumentNodeByTagName( $form, 'form' ); |
| 1107 | + } |
| 1108 | + |
| 1109 | + /** |
| 1110 | + * @param $html string |
| 1111 | + * @param $tagName string |
| 1112 | + * @return DomElement |
| 1113 | + */ |
| 1114 | + private function getDomDocumentNodeByTagName( $html, $tagName ) { |
| 1115 | + libxml_use_internal_errors( true ); |
| 1116 | + $dom = new DOMDocument(); |
| 1117 | + $dom->loadHTML( $html ); |
| 1118 | + libxml_use_internal_errors( false ); |
| 1119 | + $dom->preserveWhiteSpace = false; |
| 1120 | + $dom->strictErrorChecking = false; |
| 1121 | + $dom->encoding = 'UTF-8'; |
| 1122 | + $node = $dom->getElementsByTagName( $tagName )->item(0); |
| 1123 | + return $node; |
| 1124 | + } |
1065 | 1125 | |
1066 | 1126 | /** |
1067 | 1127 | * @param $html string |
— | — | @@ -1079,7 +1139,40 @@ |
1080 | 1140 | $this->doc->encoding = 'UTF-8'; |
1081 | 1141 | |
1082 | 1142 | $itemToRemoveRecords = $this->parseItemsToRemove(); |
| 1143 | + |
| 1144 | + $ptLogout = $this->doc->getElementById( 'pt-logout' ); |
| 1145 | + |
| 1146 | + if ( $ptLogout ) { |
| 1147 | + $ptLogoutLink = $ptLogout->firstChild; |
| 1148 | + $logoutHtml = $this->doc->saveXML( $ptLogoutLink, LIBXML_NOEMPTYTAG ); |
| 1149 | + } |
1083 | 1150 | |
| 1151 | + if ( self::$title == 'Special:UserLogin' ) { |
| 1152 | + $userlogin = $this->doc->getElementById( 'userloginForm' ); |
| 1153 | + |
| 1154 | + if ( $userlogin && get_class($userlogin) === 'DOMElement' ) { |
| 1155 | + $inputs = $userlogin->getElementsByTagName( 'input' ); |
| 1156 | + $forms = $userlogin->getElementsByTagName( 'form' ); |
| 1157 | + |
| 1158 | + if ( $forms ) { |
| 1159 | + foreach ( $forms as $form ) { |
| 1160 | + $action = $form->getAttribute( 'action' ); |
| 1161 | + } |
| 1162 | + } |
| 1163 | + |
| 1164 | + foreach ( $inputs as $input ) { |
| 1165 | + if ( $input->getAttribute( 'name' ) === 'wpLoginToken' ) { |
| 1166 | + $wpLoginToken = $input->getAttribute( 'value' ); |
| 1167 | + } |
| 1168 | + } |
| 1169 | + |
| 1170 | + $firstHeading = $this->doc->getElementById( 'firstHeading' ); |
| 1171 | + if ( $firstHeading ) { |
| 1172 | + $firstHeading->nodeValue = ''; |
| 1173 | + } |
| 1174 | + } |
| 1175 | + } |
| 1176 | + |
1084 | 1177 | // Tags |
1085 | 1178 | |
1086 | 1179 | // You can't remove DOMNodes from a DOMNodeList as you're iterating |
— | — | @@ -1161,6 +1254,15 @@ |
1162 | 1255 | |
1163 | 1256 | $redLink->parentNode->replaceChild( $spanNode, $redLink ); |
1164 | 1257 | } |
| 1258 | + |
| 1259 | + if ( self::$title == 'Special:UserLogin' ) { |
| 1260 | + if ( isset( $wpLoginToken ) && isset( $action ) && isset( $userlogin ) ) { |
| 1261 | + $login = $this->renderLogin( $wpLoginToken, $action ); |
| 1262 | + $loginNode = $this->doc->importNode( $login, true ); |
| 1263 | + $userlogin->appendChild( $loginNode ); |
| 1264 | + } |
| 1265 | + } |
| 1266 | + |
1165 | 1267 | $content = $this->doc->getElementById( 'content' ); |
1166 | 1268 | |
1167 | 1269 | $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG ); |