Files now list what pages use them
authorDan
Fri, 30 Jul 2010 15:49:11 -0400
changeset 1277 4264ace0855f
parent 1276 dac5fad7ad6a
child 1278 9a4b0c3056ac
Files now list what pages use them
includes/namespaces/file.php
language/english/core.json
--- a/includes/namespaces/file.php	Fri Jul 30 15:01:06 2010 -0400
+++ b/includes/namespaces/file.php	Fri Jul 30 15:49:11 2010 -0400
@@ -188,6 +188,34 @@
 			$html .= '</p>';
 		}
 		$db->free_result();
+		$html .= '<h3>' . $lang->get('onpage_filebox_lbl_pagesusing') . '</h3>';
+		$q = $db->sql_query('SELECT t.page_id, t.namespace, p.name FROM ' . table_prefix . "page_text AS t\n"
+			              . "  LEFT JOIN enano_pages AS p\n"
+			              . "    ON ( t.page_id = p.urlname AND t.namespace = p.namespace )\n"
+			              . "  WHERE t.page_text REGEXP '\\\\[\\\\[:" .
+							  addslashes(preg_quote($paths->nslist[$this->namespace])) .
+							  addslashes(preg_quote($this->page_id)) .
+							  "(\\\\||\\\\])';");
+		if ( !$q )
+			$db->_die();
+		
+		if ( $db->numrows() < 1 )
+		{
+			$html .= '<p>' . $lang->get('onpage_filebox_msg_no_inlinks') . '</p>';
+		}
+		else
+		{
+			$html .= '<p>' . $lang->get('onpage_filebox_msg_pagesusing') . '</p>';
+			$html .= '<ul>';
+			while ( $row = $db->fetchrow() )
+			{
+				$html .= '<li><a href="' . makeUrlNS($row['namespace'], $row['page_id']) . '">' .
+							htmlspecialchars($row['name']) .
+							'</a></li>';
+			}
+			$html .= '</ul>';
+		}
+		$db->free_result();
 		$html .= '</div><br />';
 		return $html;
 	}
--- a/language/english/core.json	Fri Jul 30 15:01:06 2010 -0400
+++ b/language/english/core.json	Fri Jul 30 15:49:11 2010 -0400
@@ -333,6 +333,9 @@
 			filebox_btn_this_version: 'this ver',
 			filebox_btn_revert: 'restore',
 			filebox_btn_current: 'current',
+			filebox_lbl_pagesusing: 'Pages using this file',
+			filebox_msg_pagesusing: 'The following pages embed this file:',
+			filebox_msg_no_inlinks: 'There are no pages that embed this file.',
 			
 			protect_heading: 'Protect page',
 			protect_msg_select_level: 'Select a protection level:',