diff --git a/lib/simpletest/todochecker.php b/lib/simpletest/todochecker.php
new file mode 100644
index 00000000000..093240a410c
--- /dev/null
+++ b/lib/simpletest/todochecker.php
@@ -0,0 +1,129 @@
+.
+
+/**
+ * Check that, as in the coding guidelines, every to-do comment links to a tracker issue.
+ *
+ * As required by http://docs.moodle.org/en/Development:Coding_style.
+ *
+ * http://docs.moodle.org/en/Development:Coding_style
+ * @package moodlecore
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+require_once(dirname(__FILE__) . '/../../config.php');
+require_once($CFG->libdir . '/simpletestlib.php');
+
+require_login();
+$context = get_context_instance(CONTEXT_SYSTEM);
+require_capability('moodle/site:config', $context);
+
+$PAGE->set_url('lib/simpletest/todochecker.php');
+$PAGE->set_context($context);
+$PAGE->set_title('To-do checker');
+$PAGE->set_heading('To-do checker');
+
+$extensionstotest = array('php');
+$extensionsregex = '/\.(?:' . implode('|', $extensionstotest) . ')$/';
+$patterntofind = 'TO' . 'DO'; // Make it not match the regex.
+$found = array();
+
+echo $OUTPUT->header();
+echo $OUTPUT->heading('To-do checker', 2);
+
+echo $OUTPUT->box_start();
+echo 'Checking code ...';
+flush();
+recurseFolders($CFG->dirroot, 'check_to_dos', $extensionsregex);
+echo ' done.';
+echo $OUTPUT->box_end();
+
+if (empty($found)) {
+ echo '
No to-dos found.
';
+} else {
+ $total = 0;
+ foreach ($found as $filepath => $matches) {
+ $total += count($matches);
+ }
+
+ echo '' . $total . ' to-dos found:
';
+ foreach ($found as $filepath => $matches) {
+ echo '- ' . $filepath . ' (' . count($matches) . ')
';
+ foreach ($matches as $lineno => $line) {
+ $url = 'http://cvs.moodle.org/moodle/' . $filepath . '?view=annotate#l' . $lineno;
+ $error = '';
+
+ // Make sure there is a tracker issue id mentioned
+ $matches = array();
+ if (preg_match('/\bTODO\b.*?\b(MDL-\d+)/', $line, $matches)) {
+ $issueid = $matches[1];
+ $issueurl = 'http://tracker.moodle.org/browse/' . $issueid;
+
+ // Make sure the issue is still open.
+ if (issue_open($issueid)) {
+ $issuename = $issueid;
+ } else {
+ $issuename = '' . $issueid . '';
+ $error = 'The associated tracker issue is Resolved.';
+ }
+
+ $line = str_replace($issueid, '' . $issuename . '', htmlspecialchars($line));
+ } else {
+ $line = htmlspecialchars($line);
+ $error = 'No associated tracker issue.';
+ }
+
+ if ($error) {
+ $error = '' . $error . '';
+ }
+ echo '- ' . $lineno . ': ' . $line . $error . '
';
+ }
+ echo '
';
+ }
+ echo '
';
+}
+
+echo $OUTPUT->footer();
+
+function check_to_dos($filepath) {
+ global $CFG, $found;
+ $lines = file($filepath);
+ $matchesinfile = array();
+ foreach ($lines as $lineno => $line) {
+ if (preg_match('/\bTODO\b/', $line)) {
+ $matchesinfile[$lineno] = $line;
+ }
+ }
+ if (!empty($matchesinfile)) {
+ $shortpath = str_replace($CFG->dirroot . '/', '', $filepath);
+ $found[$shortpath] = $matchesinfile;
+ }
+}
+
+function issue_open($issueid) {
+ static $cache = array();
+ if (array_key_exists($issueid, $cache)) {
+ return $cache[$issueid];
+ }
+
+ $xmlurl = 'http://tracker.moodle.org/si/jira.issueviews:issue-xml/' . $issueid . '/' . $issueid . '.xml';
+ $content = download_file_content($xmlurl);
+ $result = preg_match('/Unresolved<\/resolution>/', $content);
+
+ $cache[$issueid] = $result;
+ return $result;
+}