| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Static class for hooks handled by the Semantic Watchlist extension. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @file SemanticWatchlist.hooks.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @ingroup SemanticWatchlist | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @licence GNU GPL v3+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author Jeroen De Dauw < [email protected] > | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | final class SWLHooks { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * Handle the updateDataBefore hook of SMW >1.6, which gets called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * every time the value of a propery changes somewhere. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |      * @since 0.1 | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      * @param SMWStore $store | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      * @param SMWChangeSet $changes | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      * @return true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	public static function onDataUpdate( SMWStore $store, SMWSemanticData $newData ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		$subject = $newData->getSubject(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		$oldData = $store->getSemanticData( $subject ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		$title = Title::makeTitle( $subject->getNamespace(), $subject->getDBkey() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		$groups = SWLGroups::getMatchingWatchGroups( $title ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$edit = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		foreach ( $groups as /* SWLGroup */ $group ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			$changeSet = SWLChangeSet::newFromSemanticData( $oldData, $newData, $group->getProperties() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			if ( $changeSet->hasUserDefinedProperties() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 				if ( $edit === false ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 					$edit = new SWLEdit( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 						$title->getArticleID(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 						$GLOBALS['wgUser']->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 						wfTimestampNow() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 					); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 					$edit->writeToDB(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 				$changeSet->setEdit( $edit ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 				$setId = $changeSet->writeToStore( $groups, $edit->getId() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 				if ( $setId != 0 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 					$group->notifyWatchingUsers( $changeSet ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * Handles group notification. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @param SWLGroup $group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @param array $userIDs | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @param SMWChangeSet $changes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @return true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     public static function onGroupNotify( SWLGroup $group, array $userIDs, SWLChangeSet $changes ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     	global $egSWLMailPerChange, $egSWLMaxMails; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     	foreach ( $userIDs as $userID ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     		$user = User::newFromId( $userID ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     		if ( $user->getOption( 'swl_email', false ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 				if ( $user->getName() != $changes->getEdit()->getUser()->getName() || $GLOBALS['egSWLEnableSelfNotify'] ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 					if ( !method_exists( 'Sanitizer', 'validateEmail' ) || Sanitizer::validateEmail( $user->getEmail() ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 						$lastNotify = $user->getOption( 'swl_last_notify' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 						$lastWatch = $user->getOption( 'swl_last_watch' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 						if ( is_null( $lastNotify ) || is_null( $lastWatch ) || $lastNotify < $lastWatch ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 							$mailCount = $user->getOption( 'swl_mail_count', 0 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 							if ( $egSWLMailPerChange || $mailCount < $egSWLMaxMails ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 								SWLEmailer::notifyUser( $group, $user, $changes, $egSWLMailPerChange ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 								$user->setOption( 'swl_last_notify', wfTimestampNow() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 								$user->setOption( 'swl_mail_count', $mailCount + 1 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 								$user->saveSettings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 							} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 						} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	 * Adds a link to Admin Links page. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	 * @return true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	public static function addToAdminLinks( &$admin_links_tree ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	    $displaying_data_section = $admin_links_tree->getSection( wfMessage( 'adminlinks_browsesearch' )->text() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	    // Escape if SMW hasn't added links. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	    if ( is_null( $displaying_data_section ) ) return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	    $smw_docu_row = $displaying_data_section->getRow( 'smw' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	    $smw_docu_row->addItem( AlItem::newFromSpecialPage( 'WatchlistConditions' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	    return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 122 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 123 |  |  |  | 
            
                        
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.