Index: trunk/extensions/EditOwn/EditOwn.php |
— | — | @@ -28,7 +28,8 @@ |
29 | 29 | 'author' => 'Roan Kattouw', |
30 | 30 | 'url' => 'http://www.mediawiki.org/wiki/Extension:EditOwn', |
31 | 31 | 'version' => '1.0.1', |
32 | | - 'description' => 'Users without the editall right can only edit pages they\'ve created', |
| 32 | + 'description' => 'Users without the editall right can only edit ' . |
| 33 | + 'pages they\'ve created', |
33 | 34 | 'descriptionmsg' => 'editown-desc', |
34 | 35 | ); |
35 | 36 | |
— | — | @@ -38,37 +39,49 @@ |
39 | 40 | |
40 | 41 | $wgEditOwnExcludedNamespaces = array(); |
41 | 42 | |
42 | | -function EditOwn($title, $user, $action, &$result) { |
43 | | - static $cache = array(); |
44 | | - global $wgEditOwnExcludedNamespaces; |
45 | | - if(!is_array($wgEditOwnExcludedNamespaces)) |
46 | | - // Prevent PHP from whining |
47 | | - $wgEditOwnExcludedNamespaces = array(); |
48 | | - |
49 | | - if($action != 'edit' || $user->isAllowed('editall') || in_array($title->getNamespace(), $wgEditOwnExcludedNamespaces)) { |
50 | | - $result = null; |
51 | | - return true; |
52 | | - } |
53 | | - |
54 | | - if(isset($cache[$user->getName()][$title->getArticleId()])) { |
55 | | - $result = $cache[$user->getName()][$title->getArticleId()]; |
56 | | - return is_null($result); |
57 | | - } |
58 | | - |
59 | | - // Since there's no easy way to get the first revision, we'll just do a DB query |
60 | | - $dbr = wfGetDB(DB_SLAVE); |
61 | | - $res = $dbr->select('revision', Revision::selectFields(), |
62 | | - array('rev_page' => $title->getArticleId()), |
63 | | - __METHOD__, array('ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1)); |
64 | | - if(!($row = $dbr->fetchObject($res))) { |
65 | | - // Nonexistent title? Creation is allowed |
66 | | - $result = $cache[$user->getName()][$title->getArticleId()] = null; |
67 | | - return true; |
68 | | - } |
69 | | - $rev = new Revision($row); |
70 | | - if($user->getName() == $rev->getRawUserText()) { |
71 | | - $result = $cache[$user->getName()][$title->getArticleId()] = null; |
72 | | - return true; |
73 | | - } |
74 | | - return($result = $cache[$user->getName()][$title->getArticleId()] = false); |
| 43 | +function EditOwn($title, $user, $action, &$result) |
| 44 | +{ |
| 45 | + static $cache = array(); |
| 46 | + global $wgEditOwnExcludedNamespaces; |
| 47 | + if(!is_array($wgEditOwnExcludedNamespaces)) |
| 48 | + // Prevent PHP from whining |
| 49 | + $wgEditOwnExcludedNamespaces = array(); |
| 50 | + |
| 51 | + if($action != 'edit' || $user->isAllowed('editall') || |
| 52 | + in_array($title->getNamespace(), $wgEditOwnExcludedNamespaces)) |
| 53 | + { |
| 54 | + $result = null; |
| 55 | + return true; |
| 56 | + } |
| 57 | + |
| 58 | + if(isset($cache[$user->getName()][$title->getArticleId()])) |
| 59 | + { |
| 60 | + $result = $cache[$user->getName()][$title->getArticleId()]; |
| 61 | + return is_null($result); |
| 62 | + } |
| 63 | + |
| 64 | + // Since there's no easy way to get the first revision, |
| 65 | + // we'll just do a DB query |
| 66 | + $dbr = wfGetDb(DB_SLAVE); |
| 67 | + $res = $dbr->select('revision', Revision::selectFields(), |
| 68 | + array('rev_page' => $title->getArticleId()), |
| 69 | + __METHOD__, array('ORDER BY' => 'rev_timestamp ASC', |
| 70 | + 'LIMIT' => 1)); |
| 71 | + $row = $dbr->fetchObject($res); |
| 72 | + if(!$row) |
| 73 | + { |
| 74 | + // Nonexistent title? Creation is allowed |
| 75 | + $cache[$user->getName()][$title->getArticleId()] = null; |
| 76 | + $result = null; |
| 77 | + return true; |
| 78 | + } |
| 79 | + $rev = new Revision($row); |
| 80 | + if($user->getName() == $rev->getRawUserText()) { |
| 81 | + $cache[$user->getName()][$title->getArticleId()] = null; |
| 82 | + $result = null; |
| 83 | + return true; |
| 84 | + } |
| 85 | + $cache[$user->getName()][$title->getArticleId()] = false; |
| 86 | + $result = false; |
| 87 | + return false; |
75 | 88 | } |