r96169 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96168‎ | r96169 | r96170 >
Date:01:48, 3 September 2011
Author:mah
Status:ok
Tags:
Comment:
add my fixme nagger
Modified paths:
  • /trunk/tools/fixme-nagger (added) (history)
  • /trunk/tools/fixme-nagger/fixme.php (added) (history)
  • /trunk/tools/fixme-nagger/template.txt (added) (history)

Diff [purge]

Index: trunk/tools/fixme-nagger/template.txt
@@ -0,0 +1,34 @@
 2+$user[name],
 3+
 4+As promised on wikitech-l (http://hexm.de/5u), I'm sending email to
 5+all MediaWiki developers with any FIXME'd revisions. I'll be sending
 6+a reminder at least twice a week from now on for any outstanding
 7+FIXMEs.
 8+
 9+Link to all your FIXMEs:
 10+http://mediawiki.org/wiki/Special:Code/MediaWiki/status/fixme?author=$author
 11+
 12+$commits
 13+
 14+Please address them as soon as possible. When you think you've
 15+addressed one, change its status field from "fixme" to "new" and make
 16+sure your new revision shows up under "Follow-up revisions"
 17+
 18+To mark a revision as follow-up to a previously committed revision
 19+right at the time of committing, just put the previously committed
 20+revision's number, prefixed by 'r', into your commit summary.
 21+
 22+If you have any questions about this, then please feel free to email
 23+me.
 24+
 25+Thanks,
 26+
 27+Mark
 28+
 29+--
 30+Mark A. Hershberger
 31+Bugmeister
 32+Wikimedia Foundation
 33+mhershberger@wikimedia.org
 34+717.271.1084
 35+
Index: trunk/tools/fixme-nagger/fixme.php
@@ -0,0 +1,148 @@
 2+#!/usr/bin/php
 3+<?php
 4+# ini file has to be read first to set $IP
 5+$dot_ini = getenv( "HOME" ) . DIRECTORY_SEPARATOR . '.mediawiki.ini';
 6+$fallback_path = dirname( dirname( dirname( realpath(__FILE__) ) ) ) . DIRECTORY_SEPARATOR . "phase3";
 7+$conf = array();
 8+$IP = "/"; /* so it is always set */
 9+if( file_exists( $dot_ini ) ) {
 10+ $conf = parse_ini_file( $dot_ini, INI_SCANNER_RAW );
 11+ if ( $conf === false ) {
 12+ exit( "Couldn't read $dot_ini!\n" );
 13+ }
 14+
 15+ if( isset( $conf['mwroot'] ) ) {
 16+ $IP = $conf['mwroot'];
 17+ } else if (file_exists( $fallback_path ) ) {
 18+ $IP = $fallback_path;
 19+ }
 20+} else if( file_exists( $fallback_path ) ) {
 21+ $IP = $fallback_path;
 22+}
 23+if ( file_exists( "$IP/LocalSettings.php" ) ) {
 24+ define( "MW_CONFIG_FILE", "$IP/LocalSettings.php" );
 25+} else {
 26+ exit( "Couldn't find LocalSettings.php in $IP\n" );
 27+}
 28+
 29+require_once( "$IP/maintenance/Maintenance.php" );
 30+
 31+class NagFixme extends Maintenance {
 32+
 33+ public $template;
 34+ public $fromAddy;
 35+
 36+ public function __construct() {
 37+ parent::__construct();
 38+ global $conf;
 39+
 40+ $this->mDescription = "Send nagging emails to everyone with FIXMEs in CR, Wikimedia Specific!";
 41+ $this->addOption( 'noemail', 'Do not send any messages, only print what would be sent' );
 42+ $this->addOption( 'template', 'The template file, defaults to template.txt or what is in the ini file' );
 43+
 44+ $this->fromAddy = $conf['from'];
 45+ }
 46+
 47+
 48+ public function execute() {
 49+ global $conf;
 50+
 51+ if( $this->hasOption( "template" ) ) {
 52+ $this->template = $this->getOption( "template" );
 53+ } else if( isset( $conf['template'] ) ) {
 54+ $this->template = $conf['template'];
 55+ } else {
 56+ $this->template = "template.txt";
 57+ }
 58+
 59+ if( file_exists( $this->template ) ) {
 60+ $this->template = addcslashes(file_get_contents( $this->template ), '"');
 61+ } else {
 62+ exit( "Please create a template file in {$this->template}.\n" );
 63+ }
 64+ foreach($this->getFixmes() as $author => $revs) {
 65+ echo "$author\n";
 66+ $this->sendMail($author, $revs);
 67+ }
 68+ }
 69+
 70+ /* Ugh, you know what would be good here? API access. */
 71+ public function getFixmes() {
 72+ global $conf;
 73+ ini_set("user_agent", isset( $conf['ua'] ) ? $conf['ua'] : "some bogus user agent");
 74+ $page = file_get_contents( $conf['fixmeUrl'] );
 75+
 76+ $fixes = explode("<tr class=\"mw-codereview-status-fixme\">\n", $page);
 77+ /* We don't care about what comes before the table of FIXMEs */
 78+ array_shift($fixes);
 79+
 80+ $bit = array();
 81+ foreach($fixes as $fix) {
 82+ $f = explode("</td>\n", $fix);
 83+ $r = array();
 84+ preg_match("/>([0-9]+)</", $f[0], $r);
 85+ $rev = $r[1];
 86+ preg_match('/class="TablePager_col_cr_message">(.*)/', $f[4], $r);
 87+ $msg = preg_replace("/<[^>]*>/", "", html_entity_decode($r[1]));
 88+ preg_match('/class="TablePager_col_cr_author.*author=([^"]+)"/', $f[5], $r);
 89+ $author = $r[1];
 90+
 91+ $bit[$author][$rev] = $msg;
 92+ }
 93+
 94+ return $bit;
 95+ }
 96+
 97+ public function getUserinfo( $author ) {
 98+ global $conf;
 99+
 100+ $ui = file_get_contents( $conf['userinfo'] . "$author" );
 101+ $ret = array();
 102+ foreach(explode("\n", $ui) as $l) {
 103+ if($l != "") {
 104+ list($name, $data) = explode(":", $l, 2);
 105+ $data = trim($data);
 106+ $name = trim($name);
 107+ if($name == "email") {
 108+ /* Obfuscate this! */
 109+ $data = preg_replace("/ .?dot.? /i", '.',
 110+ preg_replace("/ .?at.? /i", '@',
 111+ preg_replace("/ who is a user at the host called /i", '@', $data)));
 112+ }
 113+ $ret[$name] = $data;
 114+ }
 115+ }
 116+
 117+ if(!isset($ret['name'])) {
 118+ $ret['name'] = $author;
 119+ }
 120+
 121+ return $ret;
 122+ }
 123+
 124+ public function sendMail($author, $revs) {
 125+ $user = $this->getUserinfo($author);
 126+
 127+ $commits = " Rev #: Commit message\n";
 128+ foreach($revs as $r => $msg) {
 129+ $commits .= "r{$r}: $msg\n";
 130+ }
 131+
 132+ $msg = eval("\$t = \"{$this->template}\"; return \$t;");
 133+
 134+ if( !isset($user['email']) || stristr( $user['email'], '@' ) === false ) {
 135+ echo "Please send a message to $author:\n$commits";
 136+ } else {
 137+ if( $this->hasOption( 'noemail' ) ) {
 138+ echo "Would email $user[email] from " . $this->fromAddy. "\n";
 139+ echo $msg;
 140+ } else {
 141+ mail( $user['email'], "Please fix your FIXMEs", $msg, false, "-f " . $this->fromAddy );
 142+ }
 143+ }
 144+ }
 145+}
 146+
 147+$maintClass = "NagFixme";
 148+
 149+require_once( RUN_MAINTENANCE_IF_MAIN );
Property changes on: trunk/tools/fixme-nagger/fixme.php
___________________________________________________________________
Added: svn:executable
1150 + *
Added: svn:eol-syle
2151 + native

Status & tagging log