* Add wfRunHook calls where appropriate
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 24 May 2008 20:44:49 +0000 (20:44 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 24 May 2008 20:44:49 +0000 (20:44 +0000)
* Fix handling of file redirects in ApiDelete
* Throw an error when a file is undeleted as this is not supported

includes/api/ApiBlock.php
includes/api/ApiDelete.php
includes/api/ApiEditPage.php
includes/api/ApiLogout.php
includes/api/ApiMove.php
includes/api/ApiUndelete.php

index 3f4d0c9..f11b4b2 100644 (file)
@@ -87,6 +87,7 @@ class ApiBlock extends ApiBase {
                $form->BlockEmail = $params['noemail'];
                $form->BlockHideName = $params['hidename'];
 
+               $userID = $expiry = null;
                $retval = $form->doBlock($userID, $expiry);
                if(!empty($retval))
                        // We don't care about multiple errors, just report one of them
index 474e756..aac57f5 100644 (file)
@@ -113,6 +113,8 @@ class ApiDelete extends ApiBase {
         */
        public static function delete(&$article, $token, &$reason = NULL)
        {
+               global $wgUser;
+               
                $errors = self::getPermissionsError($article->getTitle(), $token);
                if (count($errors)) return $errors;
 
@@ -124,10 +126,15 @@ class ApiDelete extends ApiBase {
                        if($reason === false)
                                return array(array('cannotdelete'));
                }
+               
+               if (!wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason)))
+                       $this->dieUsageMsg(array('hookaborted'));
 
                // Luckily, Article.php provides a reusable delete function that does the hard work for us
-               if($article->doDeleteArticle($reason))
+               if($article->doDeleteArticle($reason)) {
+                       wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $article->getId()));
                        return array();
+               }
                return array(array('cannotdelete', $article->mTitle->getPrefixedText()));
        }
 
@@ -139,7 +146,7 @@ class ApiDelete extends ApiBase {
                if( $oldimage && !FileDeleteForm::isValidOldSpec($oldimage) )
                        return array(array('invalidoldimage'));
 
-               $file = wfFindFile($title);
+               $file = wfFindFile($title, false, FileRepo::FIND_IGNORE_REDIRECT);
                $oldfile = false;
                
                if( $oldimage )
index c80c84a..3413ee2 100644 (file)
@@ -69,6 +69,9 @@ class ApiEditPage extends ApiBase {
 
                $articleObj = new Article($titleObj);
                $ep = new EditPage($articleObj);
+               
+               if ( !wfRunHooks( 'AlternateEdit', array( &$ep ) ) )
+                       $this->dieUsageMsg(array('hookaborted'));
 
                // EditPage wants to parse its stuff from a WebRequest
                // That interface kind of sucks, but it's workable
index d0a0448..e5898a6 100644 (file)
@@ -43,6 +43,10 @@ class ApiLogout extends ApiBase {
        public function execute() {
                global $wgUser;
                $wgUser->logout();
+               
+               // Give extensions to do something after user logout
+               $injected_html = '';
+               wfRunHooks( 'UserLogoutComplete', array(&$wgUser, &$injected_html) );
        }
 
        public function getAllowedParams() {
index 4ed5af9..818f205 100644 (file)
@@ -79,6 +79,10 @@ class ApiMove extends ApiBase {
                        // We don't care about multiple errors, just report one of them
                        $this->dieUsageMsg(current($errors));
 
+               $hookErr = null;
+               if( !wfRunHooks( 'AbortMove', array( $fromTitle, $toTitle, $wgUser, &$hookErr ) ) )
+                       $this->dieUsageMsg(array('hookaborted', $hookErr));
+
                $retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']);
                if($retval !== true)
                        $this->dieUsageMsg(array($retval));
@@ -117,6 +121,10 @@ class ApiMove extends ApiBase {
                        $wgUser->removeWatch($toTitle);
                }
                $this->getResult()->addValue(null, $this->getModuleName(), $r);
+               
+               // This one is a problem as we don't have a special page, but some
+               // extensions may want to do something when the hook has succeeded.
+               //wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) )       ;
        }
 
        public function mustBePosted() { return true; }
index 9c01a66..b9f01c0 100644 (file)
@@ -59,6 +59,9 @@ class ApiUndelete extends ApiBase {
                $titleObj = Title::newFromText($params['title']);
                if(!$titleObj)
                        $this->dieUsageMsg(array('invalidtitle', $params['title']));
+                       
+               if ($titleObj->getNamespace() == NS_IMAGE)
+                       $this->dieUsage('File undeletion is not supported', 'fileundeletionunsupported');
 
                // Convert timestamps
                if(!is_array($params['timestamps']))
@@ -73,6 +76,9 @@ class ApiUndelete extends ApiBase {
                if(!is_array($retval))
                        $this->dieUsageMsg(array('cannotundelete'));
 
+               //wfRunHooks( 'FileUndeleteComplete', array(
+               //      $titleObj, $this->mFileVersions, $wgUser, $params['reason']) );
+
                $info['title'] = $titleObj->getPrefixedText();
                $info['revisions'] = $retval[0];
                $info['fileversions'] = $retval[1];