https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114824
Revision: 114824
Author: yaron
Date: 2012-04-10 17:28:01 +0000 (Tue, 10 Apr 2012)
Log Message:
-----------
Added userCanApprove() utility function
Modified Paths:
--------------
trunk/extensions/ApprovedRevs/ApprovedRevs_body.php
Modified: trunk/extensions/ApprovedRevs/ApprovedRevs_body.php
===================================================================
--- trunk/extensions/ApprovedRevs/ApprovedRevs_body.php 2012-04-10 17:02:14 UTC
(rev 114823)
+++ trunk/extensions/ApprovedRevs/ApprovedRevs_body.php 2012-04-10 17:28:01 UTC
(rev 114824)
@@ -13,6 +13,7 @@
// Static arrays to prevent querying the database more than necessary.
static $mApprovedContentForPage = array();
static $mApprovedRevIDForPage = array();
+ static $mUserCanApprove = null;
/**
* Gets the approved revision ID for this page, or null if there isn't
@@ -132,6 +133,61 @@
return $isApprovable;
}
+ public static function userCanApprove( $title ) {
+ global $egApproveRevsSelfOwnedNamespaces;
+
+ // $mUserCanApprove is a static variable used for
+ // "caching" the result of this function, so that
+ // it only has to be called once.
+ if ( self::$mUserCanApprove ) {
+ return true;
+ } elseif ( self::$mUserCanApprove === false ) {
+ return false;
+ } elseif ( $title->userCan( 'approverevisions' ) ) {
+ self::$mUserCanApprove = true;
+ return true;
+ } else {
+ // If the user doesn't have the 'approverevisions'
+ // permission, they still might be able to approve
+ // revisions - it depends on whether the current
+ // namespace is within the admin-defined
+ // $egApproveRevsSelfOwnedNamespaces array.
+ global $wgUser;
+ $namespace = $title->getNamespace();
+ if ( in_array( $namespace,
$egApproveRevsSelfOwnedNamespaces ) ) {
+ if ( $namespace == NS_USER ) {
+ // If the page is in the 'User:'
+ // namespace, this user can approve
+ // revisions if it's their user page.
+ if ( $title->getText() ==
$wgUser->getName() ) {
+ self::$mUserCanApprove = true;
+ return true;
+ }
+ } else {
+ // Otherwise, they can approve revisions
+ // if they created the page.
+ // We get that information via a SQL
+ // query - is there an easier way?
+ $dbr = wfGetDB( DB_SLAVE );
+ $row = $dbr->selectRow(
+ array( 'revision', 'page' ),
+ 'revision.rev_user_text',
+ array( 'page.page_title' =>
$title->getDBkey() ),
+ null,
+ array( 'ORDER BY' =>
'revision.rev_id ASC' ),
+ array( 'revision' => array(
'JOIN', 'revision.rev_page = page.page_id' ) )
+ );
+ if ( $row->rev_user_text ==
$wgUser->getName() ) {
+ self::$mUserCanApprove = true;
+ return true;
+ }
+ }
+ }
+ }
+ self::$mUserCanApprove = false;
+ return false;
+ }
+
public static function saveApprovedRevIDInDB( $title, $rev_id ) {
$dbr = wfGetDB( DB_MASTER );
$page_id = $title->getArticleID();
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs