Benutzer:Quarz/X/Schraubstock 3

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Originaldateien (old): Phabricator Repository

qrpedia.org – index.html

[Bearbeiten | Quelltext bearbeiten]

Hier konnte statt der Repository-Version nur das HTML-Output (Seitenquelltext) der Seite zum Vergleich genutzt werden. Im Repository ist die neueste Version eine index.html, die nicht mit dem Seitenquelltext übereinstimmt. Auf qrpedia.org läuft tatsächlich keine index.html, sondern eine index.php

  • Wikipedia-pageID statt Artikeltitel als Merkmal verwenden
  • Verarbeitung auf qrwp.org steuern durch Übergabe der pageID als Key-Value-Paar: id=<pageID>
  • Überflüssiges aufräumen
--- old/index.html	HTML output qrpdia.org
+++ new/index.html	Sat Feb 01 21:58:01 2020
@@ -90,25 +90,16 @@
 					var original_URL = $(this).val();
 					if (original_URL.indexOf('wikipedia.org/wiki/') > 0)	//	Lazy way to see if it's a Wikipedia URL
 					{
-						// Form a qrwp URL
-						var new_URL = original_URL.replace('wikipedia.org/wiki/','qrwp.org/');
-						var new_URL = new_URL.replace('https://','http://');
-						
 						//	Get the URL path
 						var url = document.createElement('a');
-						url.href = new_URL;
-						var path = url.pathname.replace('/','');
+						url.href = original_URL;
+						var path = url.pathname.replace('/wiki/','');
 						
 						//	Get the language of the article
-						var language = url.hostname.replace('.qrwp.org','');
+						var language = url.hostname.replace('.wikipedia.org','');
 													
 						//	Add some text saying how many languages the article has
 						//	Call the Wikipedia API	
-						///
-						console.log(new_URL);
-						console.log(language);
-						console.log(path);
-
 						$.getJSON(
 							'https://'+language+'.wikipedia.org/w/api.php?format=json&callback=?',
 							{ 
@@ -138,8 +129,7 @@
 											}
 										}
 
-										///
-										console.log(encodeURIComponent(new_URL));
+										var new_URL = 'https://' + language + '.qrwp.org/id=' + pageId;
 
 										//	Add the image to the page
 										$('.qr').attr('src','https://qrpedia.org/qr/php/qr.php?size=345&e=L&d='+encodeURIComponent(new_URL));

qrwp.org – .htaccess

[Bearbeiten | Quelltext bearbeiten]
  • URL-Path in Querystring wandeln, ohne ein Key-Value-Paar zu bilden. Zweck:
    • Artikeltitel nicht per $_GET[] importieren, um automatisches urdecode zu verhindern
    • pageID per $_GET[] importieren.
--- old/.htaccess	Fri Sep 09 18:32:00 2011
+++ new/.htaccess	Sat Feb 01 22:16:13 2020
@@ -5,7 +5,7 @@
 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
-RewriteRule ^(.*)$ index.php?title=$1 [L,QSA]
+RewriteRule ^(.*)$ index.php?$1 [L,QSA]
 
 #RewriteEngine on
 #Options +FollowSymLinks

qrwp.org – index.php

[Bearbeiten | Quelltext bearbeiten]
  • urldecode des Artikeltitels vollständig im Skript steuern
  • Artikeltitel oder pageID auswerten, je nach Input
  • Im API-Aufruf llurl (deprecated) durch llprop=url ersetzen
--- old/index.php	Wed Sep 02 21:51:00 2015
+++ new/index.php	Mon Feb 03 20:21:58 2020
@@ -42,12 +42,22 @@
 		}
 	}
 
-	// An .htaccess file changes example.com/Foo to example.com/?title=foo
+	// An .htaccess file changes example.com/foo to example.com/?foo
 	// Remove any escaped characters. Eg \'
-	$request = stripslashes( $_GET['title'] );
+	$request = stripslashes( $_SERVER['QUERY_STRING'] );
 
 	// If a request has been sent - redirect the user	
 	if ( $request != null ) {
+		if (@$_GET['id']) {
+			$pid = $_GET['id'];
+			$search = 'pageids=' . $pid;
+		} else {
+			// Correct double urlencoded string
+			$request = str_replace('%25','%',$request);
+			$request = urldecode($request);
+			$search = 'titles=' . $request . '&redirects=';
+		}
+
 		// Gets the phone user's primary language - based on the headers of the phone's browser
 		// Code modified from http://www.php.net/manual/en/reserved.variables.server.php#94237
 		// RFC 2616 compatible Accept Language Parser
@@ -62,7 +72,7 @@
 			$splits = array();
 
 			if ( preg_match( $pattern, $lang, $splits ) ) {
-				$phone_language = $splits[primarytag];
+				$phone_language = $splits['primarytag'];
 				// Once the language has been found - no need to continue the loop.
 				break;
 			}
@@ -71,9 +81,9 @@
 		// Get the language requested. For example fr.qrwp.org/foo assumes that /foo is French
 		$requested_server = $_SERVER['SERVER_NAME'];
 
-		if ( $requested_server != $server_name ) // If this has a subdomain
-		{
 			$pieces = explode( ".", $requested_server );
+		if ( count($pieces)>2 ) // If this has a subdomain
+		{
 			$requested_language = $pieces[0]; // Assume that only one sub domain has been chosen. "fr.en.de.qrwp.org" will return "fr"
 		} else //	If there is no sub domain, use the default language set in config.php
 		{
@@ -93,7 +103,9 @@
 
 		//	If the phone's language is the same as the requested language (eg en-gb & en.qrwp) do the redirection without a call to Wikipedia 
 		if ( $phone_language == $requested_language ) {
-			$mobile_url = "https://$requested_language.m.wikipedia.org/wiki/" . $request;
+			$mobile_url = "https://$requested_language.m.wikipedia.org/";
+			if($pid) $mobile_url .= 'w/index.php?curid=' . $pid;
+			else $mobile_url .= 'wiki/' . $request;
 			writeLog( urldecode( $mobile_url ) );
 			header( "Location: $mobile_url" );
 			exit;
@@ -105,14 +117,14 @@
 		https://en.wikipedia.org/w/api.php?action=query&
 				prop=info|langlinks&		//	Get page info and alternate languages
 				lllimit=200&				//	Max number of languages to return
-				llurl&						//	Get the URLs of alternate languages
+				llprop=url&					//	Get the URLs of alternate languages
 				titles=Rossetta_Stone&	//	Title of the page
 				redirects=&					//	Page may redirect - so get the final page
 				format=json					//	Other formats are available. Leave off for human readable XML
 		*/
 
 		// Construct the API call - this is to the $requested_language Wikipedia
-		$api_call = "https://$requested_language.wikipedia.org/w/api.php?action=query&prop=info|langlinks&lllimit=200&llurl&titles=$request&redirects=&format=json";
+		$api_call = "https://$requested_language.wikipedia.org/w/api.php?action=query&prop=info|langlinks&lllimit=200&llprop=url&$search&format=json";
 
 		// Use CURL to retrieve the information
 		$curl_handle = curl_init();