+ * Get an array mapping token names to their handler functions.
+ * The prototype for a token function is func($pageid, $title, $rc)
+ * it should return a token or false (permission denied)
+ * @return array array(tokenname => function)
+ */
+ protected function getTokenFunctions() {
+ // Don't call the hooks twice
+ if ( isset( $this->tokenFunctions ) ) {
+ return $this->tokenFunctions;
+ }
+
+ // If we're in JSON callback mode, no tokens can be obtained
+ if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
+ return array();
+ }
+
+ $this->tokenFunctions = array(
+ 'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' )
+ );
+ wfRunHooks( 'APIQueryRecentChangesTokens', array( &$this->tokenFunctions ) );
+ return $this->tokenFunctions;
+ }
+
+ /**
+ * @param $pageid
+ * @param $title
+ * @param $rc RecentChange (optional)
+ * @return bool|String
+ */
+ public static function getPatrolToken( $pageid, $title, $rc = null ) {
+ global $wgUser;
+
+ $validTokenUser = false;
+
+ if ( $rc ) {
+ if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) ||
+ ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW ) )
+ {
+ $validTokenUser = true;
+ }
+ } else {
+ if ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
+ $validTokenUser = true;
+ }
+ }
+
+ if ( $validTokenUser ) {
+ // The patrol token is always the same, let's exploit that
+ static $cachedPatrolToken = null;
+ if ( is_null( $cachedPatrolToken ) ) {
+ $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
+ }
+ return $cachedPatrolToken;
+ } else {
+ return false;
+ }
+
+ }
+
+ /**
+ * Sets internal state to include the desired properties in the output.
+ * @param $prop Array associative array of properties, only keys are used here