Beispiel #1
0
 /**
  * Run a dtImport job
  * @return boolean success
  */
 function run()
 {
     wfProfileIn(__METHOD__);
     if (is_null($this->title)) {
         $this->error = "dtImport: Invalid title";
         wfProfileOut(__METHOD__);
         return false;
     }
     if (method_exists('WikiPage', 'getContent')) {
         $wikiPage = new WikiPage($this->title);
         if (!$wikiPage) {
             $this->error = 'dtImport: Wiki page not found "' . $this->title->getPrefixedDBkey() . '"';
             wfProfileOut(__METHOD__);
             return false;
         }
     } else {
         $article = new Article($this->title);
         if (!$article) {
             $this->error = 'dtImport: Article not found "' . $this->title->getPrefixedDBkey() . '"';
             wfProfileOut(__METHOD__);
             return false;
         }
     }
     $for_pages_that_exist = $this->params['for_pages_that_exist'];
     if ($for_pages_that_exist == 'skip' && $this->title->exists()) {
         return true;
     }
     // Change global $wgUser variable to the one specified by
     // the job only for the extent of this import.
     global $wgUser;
     $actual_user = $wgUser;
     $wgUser = User::newFromId($this->params['user_id']);
     $text = $this->params['text'];
     if ($this->title->exists()) {
         if ($for_pages_that_exist == 'append') {
             if (method_exists('WikiPage', 'getContent')) {
                 // MW >= 1.21
                 $existingText = $wikiPage->getContent()->getNativeData();
             } else {
                 $existingText = $article->getContent();
             }
             $text = $existingText . "\n" . $text;
         } elseif ($for_pages_that_exist == 'merge') {
             $existingPageStructure = DTPageStructure::newFromTitle($this->title);
             $newPageStructure = new DTPageStructure();
             $newPageStructure->parsePageContents($text);
             $existingPageStructure->mergeInPageStructure($newPageStructure);
             $text = $existingPageStructure->toWikitext();
         }
         // otherwise, $for_pages_that_exist == 'overwrite'
     }
     $edit_summary = $this->params['edit_summary'];
     if (method_exists('WikiPage', 'getContent')) {
         $new_content = new WikitextContent($text);
         $wikiPage->doEditContent($new_content, $edit_summary);
     } else {
         $article->doEdit($text, $edit_summary);
     }
     $wgUser = $actual_user;
     wfProfileOut(__METHOD__);
     return true;
 }
Beispiel #2
0
 public static function newFromTitle($pageTitle)
 {
     $pageStructure = new DTPageStructure();
     $pageStructure->mPageTitle = $pageTitle;
     if (method_exists('WikiPage', 'getContent')) {
         $wiki_page = new WikiPage($pageTitle);
         $page_contents = $wiki_page->getContent()->getNativeData();
     } else {
         $article = new Article($pageTitle);
         $page_contents = $article->getContent();
     }
     $pageStructure->parsePageContents($page_contents);
     // Now, go through the field values and see if any of them
     // hold template calls - if any of them do, parse the value
     // as if it's the full contents of a page, and add the
     // resulting "components" to that field.
     foreach ($pageStructure->mComponents as $pageComponent) {
         if ($pageComponent->mIsTemplate) {
             foreach ($pageComponent->mFields as $fieldName => $fieldValue) {
                 if (strpos($fieldValue, '{{') !== false) {
                     $dummyPageStructure = new DTPageStructure();
                     $dummyPageStructure->parsePageContents($fieldValue);
                     $pageComponent->mFields[$fieldName] = $dummyPageStructure->mComponents;
                 }
             }
         }
     }
     return $pageStructure;
 }