r47550 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47549‎ | r47550 | r47551 >
Date:13:56, 20 February 2009
Author:catrope
Status:deferred
Tags:
Comment:
EditOwn: Fix double-tab indentation, break some long lines and don't use assignments inside if() conditions, return statements or other assignments. No functional changes in this commit.
Modified paths:
  • /trunk/extensions/EditOwn/EditOwn.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EditOwn/EditOwn.php
@@ -28,7 +28,8 @@
2929 'author' => 'Roan Kattouw',
3030 'url' => 'http://www.mediawiki.org/wiki/Extension:EditOwn',
3131 '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',
3334 'descriptionmsg' => 'editown-desc',
3435 );
3536
@@ -38,37 +39,49 @@
3940
4041 $wgEditOwnExcludedNamespaces = array();
4142
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;
7588 }

Status & tagging log