User:Jrincayc/Infopage

From Wikipedia, the free encyclopedia

This feature creates an info page with information about a page. Currently, it is the number of people watching the page, the number of edits, and the number of talk edits, the number of authors of the article and the number of authors on the talk page.

Patch against 1.3.0beta4:

--- mediawiki-1.3.0beta4_orig/includes/Article.php	2004-06-26 18:05:26.000000000 -0600
+++ mediawiki-1.3.0beta4/includes/Article.php	2004-07-07 20:47:13.000000000 -0600
@@ -1833,6 +1833,62 @@
 	/* static */ function onArticleEdit($title_obj){
 		LinkCache::linksccClearPage( $title_obj->getArticleID() );
 	}
+
+	# Info about this page
+
+	function info()
+	{
+		global $wgUser, $wgTitle, $wgOut, $wgLang;
+
+		$basenamespace = $wgTitle->getNamespace() & (~1);
+		$fullTitle = $wgTitle->makeName($basenamespace,
+			$wgTitle->getDBKey());
+		$wgOut->setPagetitle(  $fullTitle );
+		$wgOut->setSubtitle( wfMsg( "infosubtitle" ));
+		$sql = "SELECT COUNT(*) FROM watchlist WHERE wl_title = '" .
+			$wgTitle->getDBkey() . "' AND wl_namespace = " .
+			$basenamespace;
+		$wgOut->addHTML( wfMsg("numwatchers") . wfSingleQuery( $sql, DB_READ ) . "<br />" );
+		$sql = "SELECT COUNT(*) FROM old WHERE old_title = '" .
+			$wgTitle->getDBkey() . "' AND old_namespace = " .
+			$basenamespace;
+		$old = wfSingleQuery( $sql, DB_READ );
+		$sql = "SELECT COUNT(*) FROM cur WHERE cur_title = '" .
+			$wgTitle->getDBkey() . "' AND cur_namespace = " .
+			$basenamespace;
+		$new = wfSingleQuery( $sql , DB_READ );
+		$wgOut->addHTML( wfMsg("numedits") . ($old + $new) . "<br />");
+		$sql = "SELECT old_user FROM old WHERE old_title = '" .
+			$wgTitle->getDBkey() . "' AND old_namespace = " .
+			$basenamespace .
+			 " UNION SELECT cur_user FROM cur WHERE cur_title = '" .
+			$wgTitle->getDBkey() . "' AND cur_namespace = " .
+			$basenamespace;
+		$res = wfQuery( $sql,  DB_READ);
+		$authors = wfNumRows( $res );
+		wfFreeResult($res);
+		$wgOut->addHTML( wfMsg("numauthors") . $authors . "<br />" );
+		$sql = "SELECT COUNT(*) from old where old_title = '" .
+			$wgTitle->getDBkey() . "' AND old_namespace = " .
+			($basenamespace+1);
+		$old = wfSingleQuery( $sql , DB_READ);
+		$sql = "SELECT COUNT(*) from cur where cur_title = '" .
+			$wgTitle->getDBkey() . "' AND cur_namespace = " .
+			($basenamespace+1);
+		$new = wfSingleQuery( $sql, DB_READ );
+		$wgOut->addHTML( wfMsg("numtalkedits") . ($old + $new) . "<br />");
+		$sql = "SELECT old_user FROM old WHERE old_title = '" .
+			$wgTitle->getDBkey() . "' AND old_namespace = " .
+			($basenamespace + 1).
+			 " UNION SELECT cur_user FROM cur WHERE cur_title = '" .
+			$wgTitle->getDBkey() . "' AND cur_namespace = " .
+			($basenamespace + 1);
+		$res = wfQuery( $sql ,DB_READ );
+		$authors = wfNumRows( $res );
+		wfFreeResult($res);
+		$wgOut->addHTML( wfMsg("numtalkauthors") . $authors  );
+
+	}
 }
 
 ?>
diff -ur mediawiki-1.3.0beta4_orig/includes/DatabaseFunctions.php mediawiki-1.3.0beta4/includes/DatabaseFunctions.php
--- mediawiki-1.3.0beta4_orig/includes/DatabaseFunctions.php	2004-06-26 18:05:26.000000000 -0600
+++ mediawiki-1.3.0beta4/includes/DatabaseFunctions.php	2004-07-07 20:53:44.000000000 -0600
@@ -39,6 +39,15 @@
 	}
 }
 
+function wfSingleQuery( $sql, $db, $fname = "" )
+{
+	$res = wfQuery($sql, $db, $fname );
+	$row = wfFetchRow( $res );
+	$ret = $row[0];
+	wfFreeResult( $res );
+	return $ret;
+}
+
 function &wfGetDB( $db = DB_LAST )
 {
 	global $wgLoadBalancer;
diff -ur mediawiki-1.3.0beta4_orig/index.php mediawiki-1.3.0beta4/index.php
--- mediawiki-1.3.0beta4_orig/index.php	2004-06-26 18:05:24.000000000 -0600
+++ mediawiki-1.3.0beta4/index.php	2004-07-07 20:40:48.000000000 -0600
@@ -108,6 +108,7 @@
 		case "rollback":
 		case "protect":
 		case "unprotect":
+		case "info":
 			$wgArticle->$action();
 			break;
 		case "print":
diff -ur mediawiki-1.3.0beta4_orig/languages/Language.php mediawiki-1.3.0beta4/languages/Language.php
--- mediawiki-1.3.0beta4_orig/languages/Language.php	2004-06-26 18:05:28.000000000 -0600
+++ mediawiki-1.3.0beta4/languages/Language.php	2004-07-07 20:54:58.000000000 -0600
@@ -1300,6 +1300,14 @@
 'categoryarticlecount' => "There are $1 articles in this category.",
 'usenewcategorypage' => "1\n\nSet first character to \"0\" to disable the new category page layout.",
 
+# Info page
+"infosubtitle" => "Information for page",
+"numedits" => "Number of Article Edits: ",
+"numtalkedits" => "Number of Talk Edits: ",
+"numwatchers" => "Number of Watchers: ",
+"numauthors" => "Number of Article Authors: ",
+"numtalkauthors" => "Number of Talk Authors: ",
+
 # Monobook.js: tooltips and access keys for monobook
 'Monobook.js' => '/* tooltips and access keys */
 ta = new Object();

Further work required:

  • Add link to info page from Views
  • Code review (This is the first thing I have written in PHP)
  • Some method of active user selection for watchlist might be nice