2010 June, 30 (Guerric)

    Table of contents
    No headers

      

    Index: deki/core/deki_plug.php
    ===================================================================
    --- deki/core/deki_plug.php    (revision 20234)
    +++ deki/core/deki_plug.php    (working copy)
    @@ -179,11 +179,11 @@
                 // auto-double encode, check for '=' sign
                 if (strncmp($path, '=', 1) == 0)
                 {
    -                $result->path .= '='.urlencode(urlencode(substr($path, 1)));        
    +                $result->path .= '='.self::urlencode(substr($path, 1), 2);        
                 }
                 else
                 {
    -                $result->path .= urlencode(urlencode($path));
    +                $result->path .= self::urlencode($path, 2);
                 }
             }
             return $result;
    Index: deki/core/dream_plug.php
    ===================================================================
    --- deki/core/dream_plug.php    (revision 20234)
    +++ deki/core/dream_plug.php    (working copy)
    @@ -66,6 +66,24 @@
         protected $timeout = 300;
         protected $headers = array();
     
    +    /**
    +     * Urlencoding to RFC 3986 also bugfix #7500
    +     * @param string $string
    +     * @param int $repeat - number of times to encode the string
    +     * @return string
    +     */
    +    public static function urlencode($string, $repeat = 1)
    +    {
    +        $searches = array('.');
    +        $replaces = array('%2E');
    +        
    +        for ($i = 0; $i < $repeat; $i++)
    +        {
    +            $string = str_replace($searches, $replaces, urlencode($string));
    +        }
    +        
    +        return $string;
    +    }
     
         /**
          * Constructor
    Index: includes/Article.php
    ===================================================================
    --- includes/Article.php    (revision 20234)
    +++ includes/Article.php    (working copy)
    @@ -1517,60 +1517,73 @@
          * @param string $section - the section to return to
          * @return boolean
          */
    -    function save( $text, $section = null, $editsummary = null) {
    -        global $wgOut, $wgUser, $wgDekiPlug, $wgRequest;
    +    function save($text, $section = null, $editsummary = null)
    +    {
    +        global $wgOut, $wgUser, $wgRequest;
    +        
    +        // get a plug instance
    +        $Plug = DekiPlug::getInstance();
     
    -        $isNew = $this->getId() == 0;
    -
    -        if ($isNew) {
    -            $this->mTitle = Title::newFromText( Title::normalizeParentName( $this->mTitle->getPrefixedText()));
    -            $r = $wgDekiPlug->At('pages', '='.urlencode(urlencode($this->mTitle->getPrefixedDBkey())), 'contents')->With('abort', 'exists');
    +        $isNew = $this->getId() == 0;        
    +        if ($isNew)
    +        {
    +            $this->mTitle = Title::newFromText(Title::normalizeParentName($this->mTitle->getPrefixedText()));
    +            $Plug = $Plug->At('pages', '='.$this->mTitle->getPrefixedDBkey(), 'contents')->With('abort', 'exists');
             }
    -        else {
    -            $r = $wgDekiPlug->At('pages', $this->getID(), 'contents');
    +        else
    +        {
    +            $Plug = $Plug->At('pages', $this->getID(), 'contents');
             }
     
             if ($wgRequest->getVal('redirect') == 'no' || $isNew) {
    -            $r = $r->With('redirects', 0);
    +            $Plug = $Plug->With('redirects', 0);
             }
             if ($this->mSection != '') {
    -            $r = $r->With('section', $this->mSection);
    +            $Plug = $Plug->With('section', $this->mSection);
             }
     
    -        if (!empty($this->mTitleText) && strcmp($this->mTitleText, $this->mTitle->getPathlessText()) != 0) {
    -            $r = $r->With('title', $this->mTitleText);    
    +        if (!empty($this->mTitleText) && strcmp($this->mTitleText, $this->mTitle->getPathlessText()) != 0)
    +        {
    +            $Plug = $Plug->With('title', $this->mTitleText);    
             }
            
             if (!empty($editsummary)) {
    -            $r = $r->With('comment', $editsummary);    
    +            $Plug = $Plug->With('comment', $editsummary);    
             }
            
    -        //post contents to API
    -        $r = $r->With('edittime', $this->getTimestamp())->Post($text);
    +        // post contents to API
    +        /* @var $Result DekiResult */
    +        $Result = $Plug->With('edittime', $this->getTimestamp())->Post($text);
     
             //fail cases
    -        if (!MTMessage::HandleFromDream($r, array(409))) {
    -            if ($r['status'] == 409) {
    +        if (!$Result->handleResponse(array(409)))
    +        {
    +            if ($Result->is(409))
    +            {
                     wfMessagePush('general', wfMsg('Article.Error.page-already-exists'));
                 }
    -            else {
    +            else
    +            {
                     wfMessagePush('general', wfMsg('Article.Error.page-save-failed'));
                 }
                 return false;
             }
     
             //if the API returns a conflict error, output the error
    -        if (wfArrayVal($r, 'body/edit/@status') == 'conflict') {
    -            $newid = wfArrayVal($r, 'body/edit/page.overwritten/@revision');
    +        if ($Result->getVal('body/edit/@status') == 'conflict')
    +        {
    +            $newid = $Result->getVal('body/edit/page.overwritten/@revision');
     
    -            if (!is_null(wfArrayVal($r, 'body/edit/page.base/@revision'))) {
    +            if (!is_null($Result->getVal('body/edit/page.base/@revision')))
    +            {
                     $oldid = $newid;
                     wfMessagePush('general', wfMsg('Article.Common.page-created-with-conflict',
                                                    '<a href="'. $this->mTitle->getLocalUrl('diff=0&revision='.$oldid) .'">'.
                                                    wfMsg('Article.Common.page-created-with-conflict-link') .'</a>'), 'conflict');
                 }
    -            else {
    -                $oldid = wfArrayVal($r, 'body/edit/page.overwritten/@revision') - 1;
    +            else
    +            {
    +                $oldid = $Result->getVal('body/edit/page.overwritten/@revision') - 1;
                     wfMessagePush('general', wfMsg('Article.Common.page-saved-with-conflict',
                                                    '<a href="'. $this->mTitle->getLocalUrl('diff=0&revision='.$oldid) .'">'.
                                                    wfMsg('Article.Common.page-saved-with-conflict-link') .'</a>'), 'conflict');
    @@ -1578,8 +1591,9 @@
             }
     
             //reload the title object so we can redirect to the proper location
    -        if ($isNew) {
    -            $newid = $r['body']['edit']['page']['@id'];
    +        if ($isNew)
    +        {
    +            $newid = $Result->getVal('body/edit/page/@id');
                 $this->mTitle = Title::newFromID( $newid );
                 $this->mTitle->mArticleID = $newid;
             }
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by