/** * * @param WpWikiplace $wikiplace */ function setWikiPlace($wikiplace) { $this->wpNameText = $wikiplace->getName(); $this->wpNameDb = Title::newFromText($this->wpNameText)->getDBkey(); }
/** * Trigger MediaWiki article creation of the wikiplace subpage. Use template "Wikiplace subpage" as content. * @param WpWikiplace $wikiplace * @param string $new_page_name * @param User $user The user who creates the subpage * @param $content The page content * @return Title/array the created Title, or an array containing i18n message key + args if an error occured * <ul> * <li><b>wp-bad-title</b> MediaWiki is unable to create this page. Title may contain bad characters.</li> * <li><b<wp-title-already-exists</b> This page already exists</li> * <li><b>sz-internal-error</b> if Mediawiki returned an error while creating the article: * <ul> * <li>The ArticleSave hook aborted the edit but didn't set the fatal flag of $status</li> * <li>In update mode, but the article didn't exist</li> * <li>In update mode, the article changed unexpectedly</li> * <li>Warning that the text was the same as before</li> * <li>In creation mode, but the article already exists</li> * </ul> * </li> * </ul> */ public static function createSubpage($wikiplace, $new_page_name, $user, $content = '-') { if ($wikiplace === null || !$wikiplace instanceof WpWikiplace || $new_page_name === null || !is_string($new_page_name)) { throw new MWException('Cannot create Wikiplace page (wrong argument)'); } $title = Title::newFromText($wikiplace->getName() . '/' . $new_page_name); // $title can be Title, or null on an error. if (!$title instanceof Title) { return array('wp-bad-title'); } if ($title->isKnown()) { return array('wp-title-already-exists'); } // as seen in EditPage->getEditPermissionErrors() ( called by EditPage->edit() ) $permErrors = $title->getUserPermissionsErrors('edit', $user); $permErrors = array_merge($permErrors, wfArrayDiff2($title->getUserPermissionsErrors('create', $user), $permErrors)); if ($permErrors) { // creation impossible return $permErrors[0]; // strange, but only key 0 seems to be used by MW when reading errors } // now store the new page in mediawiki, this will trigger the WikiplaceHook, wich will // allow the page saving $article = new Article($title); $status = $article->doEdit($content, '', EDIT_NEW, false, $user); if (!$status->isgood()) { return array('sz-internal-error'); } return $title; }