|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00028 require(dirname(__FILE__) . '/../../../../config.php'); 00029 require_once('../simpletestlib.php'); 00030 00031 require_login(); 00032 $context = get_context_instance(CONTEXT_SYSTEM); 00033 require_capability('tool/unittest:execute', $context); 00034 00035 $PAGE->set_url('/admin/tool/todochecker.php'); 00036 $PAGE->set_context($context); 00037 $PAGE->set_title('To-do checker'); 00038 $PAGE->set_heading('To-do checker'); 00039 00040 $thirdparty = load_third_party_lib_list(); 00041 $extensionstotest = array('php'); 00042 $extensionsregex = '/\.(?:' . implode('|', $extensionstotest) . ')$/'; 00043 $patterntofind = 'TO' . 'DO'; // Make it not match the regex. 00044 $found = array(); 00045 00046 echo $OUTPUT->header(); 00047 echo $OUTPUT->heading('To-do checker', 2); 00048 00049 echo $OUTPUT->box_start(); 00050 echo 'Checking code ...'; 00051 flush(); 00052 recurseFolders($CFG->dirroot, 'check_to_dos', $extensionsregex, false, array_keys($thirdparty)); 00053 echo ' done.'; 00054 echo $OUTPUT->box_end(); 00055 00056 if (empty($found)) { 00057 echo '<p>No to-dos found.</p>'; 00058 } else { 00059 $total = 0; 00060 foreach ($found as $filepath => $matches) { 00061 $total += count($matches); 00062 } 00063 00064 echo '<p>' . $total . ' to-dos found:</p><dl>'; 00065 foreach ($found as $filepath => $matches) { 00066 echo '<dt>' . $filepath . ' <b>(' . count($matches) . ')</b></dt><dd><ul>'; 00067 foreach ($matches as $lineno => $line) { 00068 $url = 'http://cvs.moodle.org/moodle/' . $filepath . '?view=annotate#l' . $lineno; 00069 $error = ''; 00070 00071 // Make sure there is a tracker issue id mentioned 00072 $matches = array(); 00073 if (preg_match('/\bTODO\b.*?\b(MDL-\d+)/', $line, $matches)) { 00074 $issueid = $matches[1]; 00075 $issueurl = 'http://tracker.moodle.org/browse/' . $issueid; 00076 00077 // Make sure the issue is still open. 00078 list($issueopen, $issuesummary) = issue_info($issueid); 00079 if ($issueopen) { 00080 $issuename = $issueid; 00081 } else { 00082 $issuename = '<strike>' . $issueid . '</strike>'; 00083 $error = 'The associated tracker issue is Resolved.'; 00084 } 00085 00086 $line = str_replace($issueid, '<a href="' . $issueurl . '" title="' . s($issuesummary) . 00087 '">' . $issuename . '</a>', htmlspecialchars($line)); 00088 } else { 00089 $line = htmlspecialchars($line); 00090 $error = 'No associated tracker issue.'; 00091 } 00092 00093 if ($error) { 00094 $error = '<span class="error">' . $error . '</span>'; 00095 } 00096 echo '<li><a href="' . $url . '">' . $lineno . '</a>: ' . $line . $error . '</li>'; 00097 } 00098 echo '</ul></dd>'; 00099 } 00100 echo '</dl>'; 00101 } 00102 00103 echo $OUTPUT->footer(); 00104 00105 function check_to_dos($filepath) { 00106 global $CFG, $found, $thirdparty; 00107 if (isset($thirdparty[$filepath])) { 00108 return; // Skip this file. 00109 } 00110 $lines = file($filepath); 00111 $matchesinfile = array(); 00112 foreach ($lines as $lineno => $line) { 00113 if (preg_match('/(?<!->|\$)\bTODO\b/i', $line)) { 00114 $matchesinfile[$lineno] = $line; 00115 } 00116 } 00117 if (!empty($matchesinfile)) { 00118 $shortpath = str_replace($CFG->dirroot . '/', '', $filepath); 00119 $found[$shortpath] = $matchesinfile; 00120 } 00121 } 00122 00123 function issue_info($issueid) { 00124 static $cache = array(); 00125 if (array_key_exists($issueid, $cache)) { 00126 return $cache[$issueid]; 00127 } 00128 00129 $xmlurl = 'http://tracker.moodle.org/si/jira.issueviews:issue-xml/' . $issueid . '/' . $issueid . '.xml'; 00130 $content = download_file_content($xmlurl); 00131 00132 // Get the status. 00133 $open = preg_match('/Unresolved<\/resolution>/', $content); 00134 00135 // Get the summary. 00136 $matches = array(); 00137 preg_match('/<title>\[' . $issueid . '\]\s+(.*?)<\/title>/', $content, $matches); 00138 $summary = $matches[1]; 00139 preg_match('/<assignee[^>]*>(.*?)<\/assignee>/', $content, $matches); 00140 $summary .= ' - Assignee: ' . $matches[1]; 00141 00142 $cache[$issueid] = array($open, $summary); 00143 return $cache[$issueid]; 00144 } 00145 00146 function load_third_party_lib_list() { 00147 global $CFG; 00148 $libs = array(); 00149 $xml = simplexml_load_file($CFG->libdir . '/thirdpartylibs.xml'); 00150 foreach ($xml->library as $libobject) { 00151 $libs[$CFG->libdir . '/' . $libobject->location] = 1; 00152 } 00153 return $libs; 00154 }