/** * @param WikiPage $article * @param $user * @param $text * @param $summary * @param $minoredit * @param $watchthis * @param $sectionanchor * @param $flags * @param $revision * @param Status $status * @param $baseRevId * @return bool */ function efSharedHelpArticleCreation(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId) { global $wgCityId, $wgHelpWikiId; // only run on help wikis if ($wgCityId !== $wgHelpWikiId) { return true; } // not likely if we got here, but... healthy paranoia ;) if (wfReadOnly()) { return true; } if ($article->mTitle->getNamespace() !== NS_HELP) { return true; } if (!$status->isOK()) { return true; } if (!($flags & EDIT_NEW)) { return true; } $talkTitle = Title::newFromText($article->mTitle->getText(), NS_HELP_TALK); if ($talkTitle->exists()) { return true; } $talkArticle = new Article($talkTitle); $redir = $article->getRedirectTarget(); if ($redir) { $target = $redir->getTalkNsText() . ':' . $redir->getText(); $talkArticle->doEdit("#REDIRECT [[{$target}]]", wfMsgForContent('sharedhelp-autotalkcreate-summary')); } else { $talkArticle->doEdit('{{talkheader}}', wfMsgForContent('sharedhelp-autotalkcreate-summary')); } return true; }
/** * * Add/update a page to wiki * @param string $pagename * @param string $text * @param boolean $hasSemanticInternal whether this text contains semanticInternal Object. * SemanticInternal Object needs some special handling. First there is a bug in current * SemanticInternal Object implemenattion: the semantic internal properties can not be * saved in the very first time. Second, if the semantic internal object saving is not from * a special page action, but a regular page saving action, the semantic internal object * is confused about the "CURRENT" page. So asynchronous saving through a task is needed. * * @param $summary */ public static function addPage($pagename, $text, $force = true, $astask = false, $hasSemanticInternal = false, $summary = "Auto generation") { global $wgUser; $title = str_replace(' ', '_', $pagename); $t = Title::makeTitleSafe(NS_MAIN, $title); $article = new Article($t); if ($article->exists() && !$force) { return false; } if (!$astask) { $e = $article->exists(); //do adding inline $article->doEdit($text, $summary); if ($hasSemanticInternal && !$e) { //one more time $article->doEdit($text, $summary); } return true; } else { //add article asynchronously. $jobs = array(); $job_params = array(); $job_params['user_id'] = $wgUser->getId(); $job_params['edit_summary'] = $summary; $job_params['text'] = $text; $jobs[] = new DTImportJob($t, $job_params); if ($hasSemanticInternal && !$article->exists()) { $jobs[] = new DTImportJob($t, $job_params); } Job::batchInsert($jobs); } }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgOut, $wgUser, $wgRequest; // Set page title and other stuff $this->setHeaders(); # Show a message if the database is in read-only mode if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } # If user is blocked, s/he doesn't need to access this page if ($wgUser->isBlocked()) { throw new UserBlockedError($this->getUser()->mBlock); } $title = $wgRequest->getVal('wpTitle'); $category = $wgRequest->getVal('wpCategory'); if (empty($title) || empty($category)) { return; } $oTitle = Title::newFromText($title); if (!is_object($oTitle)) { return; } $oArticle = new Article($oTitle); if ($oTitle->exists()) { $text = $oArticle->getContent(); } else { $text = self::getCreateplate($category); } $text .= "\n[[Category:" . $category . ']]'; $oArticle->doEdit($text, wfMsgForContent('createincategory-comment', $category)); $wgOut->redirect($oTitle->getFullUrl()); }
/** * Run a pageSchemasCreatePage job * @return boolean success */ function run() { wfProfileIn( __METHOD__ ); if ( is_null( $this->title ) ) { $this->error = "pageSchemasCreatePage: Invalid title"; wfProfileOut( __METHOD__ ); return false; } $article = new Article( $this->title ); if ( !$article ) { $this->error = 'pageSchemasCreatePage: Article not found "' . $this->title->getPrefixedDBkey() . '"'; wfProfileOut( __METHOD__ ); return false; } $page_text = $this->params['page_text']; // change global $wgUser variable to the one // specified by the job only for the extent of this // replacement global $wgUser; $actual_user = $wgUser; $wgUser = User::newFromId( $this->params['user_id'] ); $edit_summary = wfMsgForContent( 'ps-generatepages-editsummary' ); $article->doEdit( $page_text, $edit_summary ); $wgUser = $actual_user; wfProfileOut( __METHOD__ ); return true; }
/** * 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; } $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 ($for_pages_that_exist == 'append' && $this->title->exists()) { $text = $article->getContent() . "\n" . $text; } $edit_summary = $this->params['edit_summary']; $article->doEdit($text, $edit_summary); $wgUser = $actual_user; wfProfileOut(__METHOD__); return true; }
function createPost($info, $subject, $super = null) { $userName = $info['user']; if (strpos($userName, '#') !== false) { $pos = strpos($userName, '#'); $userName = substr($userName, 0, $pos); } $user = User::newFromName($userName, false); if (!$user) { throw new MWException("Username " . $info['user'] . " is invalid."); } global $article; if ($super) { $title = Threads::newReplyTitle($super, $user); } else { $title = Threads::newThreadTitle($subject, $article); } print "Creating thread {$title} as a subthread of " . ($super ? $super->title() : 'none') . "\n"; $root = new Article($title); $root->doEdit($info['content'], 'Imported from JSON', EDIT_NEW, false, $user); $t = LqtView::postEditUpdates($super ? 'reply' : 'new', $super, $root, $article, $subject, 'Imported from JSON', null); $t = Threads::withId($t->id()); // Some weirdness. return $t; }
function execute() { global $wgRequest, $wgOut, $wgUser, $wgArticle; $sitting_of = $wgRequest->getVal('sitting_of'); $session_number = $wgRequest->getVal('session_number'); $sitting_start_date_time = $wgRequest->getVal('sitting_start_date_and_time'); $sitting_end_date_time = $wgRequest->getVal('sitting_end_date_and_time'); $sitting_session_number = $wgRequest->getVal('sitting_session_number'); $wpEditToken = $wgRequest->getVal('wpEditToken'); $sitting_desc = $wgRequest->getVal('sitting_desc'); $sitting_start_date = substr($sitting_start_date_time, 0, strpos($sitting_start_date_time, ' ')); $sitting_start_time = substr($sitting_start_date_time, strpos($sitting_start_date_time, ' ') + 1); $sitting_end_date = substr($sitting_end_date_time, 0, strpos($sitting_end_date_time, ' ')); $sitting_end_time = substr($sitting_end_date_time, strpos($sitting_end_date_time, ' ') + 1); $sitting_name = $sitting_of . '-' . $sitting_start_date; //$sitting_of.'-'.$sitting_start_date_time.'-' $title = Title::newFromText($sitting_name, MV_NS_SITTING); $wgArticle = new Article($title); $wgArticle->doEdit($sitting_desc, wfMsg('mv_summary_add_sitting')); $dbkey = $title->getDBKey(); $sitting = new MV_Sitting(array('name' => $dbkey, 'start_date' => $sitting_start_date, 'start_time' => $sitting_start_time, 'end_date' => $sitting_end_date, 'end_time' => $sitting_end_time)); //$sitting->db_load_sitting(); //$sitting->db_load_streams(); if ($sitting->insertSitting()) { if ($wgArticle->exists()) { $wgOut->redirect($title->getLocalURL("action=staff")); } else { $html .= 'Article ' . $sitting_name . ' does not exist'; $wgOut->addHtml($html); } } else { $WgOut->addHTML('Error: Duplicate Sitting Name?'); } }
public static function adminPostTalkMessage($to_user, $from_user, $comment) { global $wgLang; $existing_talk = ''; //make sure we have everything we need... if (empty($to_user) || empty($from_user) || empty($comment)) { return false; } $from = $from_user->getName(); if (!$from) { return false; } //whoops $from_realname = $from_user->getRealName(); $dateStr = $wgLang->date(wfTimestampNow()); $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $from, $from_realname, $comment); $talkPage = $to_user->getUserPage()->getTalkPage(); if ($talkPage->getArticleId() > 0) { $r = Revision::newFromTitle($talkPage); $existing_talk = $r->getText() . "\n\n"; } $text = $existing_talk . $formattedComment . "\n\n"; $flags = EDIT_FORCE_BOT | EDIT_SUPPRESS_RC; $article = new Article($talkPage); $result = $article->doEdit($text, "", $flags); return $result; }
/** * A naive wrapper for \WikiPage::doEdit(). */ public function edit() { $responseData = new \StdClass(); $responseData->success = false; $responseData->title = null; $responseData->text = null; $responseData->summary = null; $responseData->user_id = 0; $responseData->user_name = null; $this->response->setFormat('json'); $this->response->setCacheValidity(\WikiaResponse::CACHE_DISABLED); if ($this->getVal('secret') != $this->wg->TheSchwartzSecretToken || !$this->request->wasPosted()) { $this->response->setVal('data', $responseData); return; } $titleText = $this->getVal('title'); $responseData->title = $titleText; $title = \Title::newFromText($titleText); \Wikia\Util\Assert::true($title instanceof \Title); $article = new \Article($title); \Wikia\Util\Assert::true($article instanceof \Article); $text = $this->getVal('text'); $responseData->text = $text; $summary = $this->getVal('summary'); $responseData->summary = $summary; if ($this->wg->User->isLoggedIn()) { $responseData->user_id = $this->wg->User->getId(); $responseData->user_name = $this->wg->User->getName(); $responseData->success = $article->doEdit($text, $summary)->isOK(); } $this->response->setVal('data', $responseData); }
/** * Create category. * * @param $category String: Name of category to create. * @param $code String: Code of language that the category is for. * @param $level String: Level that the category is for. */ public static function create($category, $code, $level = null) { $category = strip_tags($category); $title = Title::makeTitleSafe(NS_CATEGORY, $category); if ($title === null || $title->exists()) { return; } global $wgLanguageCode; $language = BabelLanguageCodes::getName($code, $wgLanguageCode); if ($level === null) { $text = wfMsgForContent('babel-autocreate-text-main', $language, $code); } else { $text = wfMsgForContent('babel-autocreate-text-levels', $level, $language, $code); } $user = self::user(); # Do not add a message if the username is invalid or if the account that adds it, is blocked if (!$user || $user->isBlocked()) { return; } if (!$title->quickUserCan('create', $user)) { return; # The Babel AutoCreate account is not allowed to create the page } /* $article->doEdit will call $wgParser->parse. * Calling Parser::parse recursively is baaaadd... (bug 29245) * @todo FIXME: surely there is a better way? */ global $wgParser, $wgParserConf; $oldParser = $wgParser; $parserClass = $wgParserConf['class']; $wgParser = new $parserClass($wgParserConf); $article = new Article($title, 0); $article->doEdit($text, wfMsgForContent('babel-autocreate-reason', wfMsgForContent('babel-url')), EDIT_FORCE_BOT, false, $user); $wgParser = $oldParser; }
/** * Run a createPage job * @return boolean success */ function run() { if (is_null($this->title)) { $this->error = "createPage: Invalid title"; return false; } $article = new Article($this->title, 0); if (!$article) { $this->error = 'createPage: Article not found "' . $this->title->getPrefixedDBkey() . '"'; return false; } $page_text = $this->params['page_text']; // change global $wgUser variable to the one // specified by the job only for the extent of this // replacement global $wgUser; $actual_user = $wgUser; $wgUser = User::newFromId($this->params['user_id']); $edit_summary = ''; if (array_key_exists('edit_summary', $this->params)) { $edit_summary = $this->params['edit_summary']; } $article->doEdit($page_text, $edit_summary); $wgUser = $actual_user; return true; }
/** * Create a new poll * @param wgRequest question * @param wgRequest answer (expects PHP array style in the form <input name=answer[]>) * Page Content should be of a different style so we have to translate * *question 1\n * *question 2\n */ public static function create() { wfProfileIn(__METHOD__); $app = F::app(); $title = $app->wg->Request->getVal('question'); $answers = $app->wg->Request->getArray('answer'); // array $title_object = Title::newFromText($title, NS_WIKIA_POLL); if (is_object($title_object) && $title_object->exists()) { $res = array('success' => false, 'error' => $app->renderView('Error', 'Index', array(wfMsg('wikiapoll-error-duplicate')))); } else { if ($title_object == null) { $res = array('success' => false, 'error' => $app->renderView('Error', 'Index', array(wfMsg('wikiapoll-error-invalid-title')))); } else { $content = ""; foreach ($answers as $answer) { $content .= "*{$answer}\n"; } /* @var $article WikiPage */ $article = new Article($title_object, NS_WIKIA_POLL); $article->doEdit($content, 'Poll Created', EDIT_NEW, false, $app->wg->User); $title_object = $article->getTitle(); // fixme: check status object $res = array('success' => true, 'pollId' => $article->getID(), 'url' => $title_object->getLocalUrl(), 'question' => $title_object->getPrefixedText()); } } wfProfileOut(__METHOD__); return $res; }
/** * Run a refreshLinks job * @return boolean success */ function run() { global $wgTitle, $wgUser, $wgLang, $wrGedcomExportDirectory; $wgTitle = $this->title; // FakeTitle (the default) generates errors when accessed, and sometimes I log wgTitle, so set it to something else $wgUser = User::newFromName('WeRelate agent'); // set the user $treeId = $this->params['tree_id']; $treeName = $this->params['name']; $treeUser = $this->params['user']; $filename = "{$wrGedcomExportDirectory}/{$treeId}.ged"; $ge = new GedcomExporter(); $error = $ge->exportGedcom($treeId, $filename); if ($error) { $this->error = $error; return false; } // leave a message for the tree requester $userTalkTitle = Title::newFromText($treeUser, NS_USER_TALK); $article = new Article($userTalkTitle, 0); if ($article->getID() != 0) { $text = $article->getContent(); } else { $text = ''; } $title = Title::makeTitle(NS_SPECIAL, 'Trees'); $msg = wfMsg('GedcomExportReady', $wgLang->date(wfTimestampNow(), true, false), $treeName, $title->getFullURL(wfArrayToCGI(array('action' => 'downloadExport', 'user' => $treeUser, 'name' => $treeName)))); $text .= "\n\n" . $msg; $success = $article->doEdit($text, 'GEDCOM export ready'); if (!$success) { $this->error = 'Unable to edit user talk page: ' . $treeUser; return false; } return true; }
public static function onUnknownAction($action, $article) { global $wgOut, $wgRequest, $wgUser, $wgParser, $wgBlikiPostGroup; if ($action == 'blog' && in_array($wgBlikiPostGroup, $wgUser->getEffectiveGroups())) { $newtitle = $wgRequest->getText('newtitle'); $title = Title::newFromText($newtitle); $error = false; if (!is_object($title)) { $wgOut->addWikitext('<div class="previewnote">Error: Bad title!</div>'); $error = true; } elseif ($title->exists()) { $wgOut->addWikitext('<div class="previewnote">Error: Title already exists!</div>'); $error = true; } if (!$error) { $summary = $wgRequest->getText('summary'); $content = $wgRequest->getText('content'); $user = $wgUser->getName(); $date = date('U'); $sig = '<div class="blog-sig">{{BlogSig|' . "{$user}|@{$date}" . '}}</div>'; $type = $wgRequest->getText('type'); switch ($type) { // Preview the item case "Full preview": $wikitext = "{$sig}\n{$summary}\n\n{$content}"; self::preview($type, $title, $wikitext); $article->view(); break; // Preview the item in news/blog format // Preview the item in news/blog format case "Summary preview": $wikitext = "{|class=\"blog\"\n|\n== [[Post a blog item|{$newtitle}]] ==\n|-\n!{$sig}\n|-\n|{$summary}\n|}__NOEDITSECTION__"; $title = Title::newFromText('Blog'); self::preview($type, $title, $wikitext); $article->view(); break; // Create the item with tags as category links // Create the item with tags as category links case "Post": $wikitext = '{{' . "Blog|1={$summary}|2={$content}" . '}}'; $wikitext .= "<noinclude>[[Category:Blog items]][[Category:Posts by {$user}]]"; foreach (array_keys($_POST) as $k) { if (preg_match("|^tag(.+)\$|", $k, $m)) { $wikitext .= '[[Category:' . str_replace('_', ' ', $m[1]) . ']]'; } } $wikitext .= "</noinclude>"; $article = new Article($title); $article->doEdit($wikitext, 'Blog item created via post form', EDIT_NEW); $wgOut->redirect($title->getFullURL()); break; } } else { $article->view(); } return false; } return true; }
function execute() { global $reportersTable, $wgOut, $wgRequest; $nameKey = 'mpnamencgsblahbladggfdsafh'; $tit = Title::newFromText($nameKey, MV_NS_MVD); $art = new Article($tit); $art->doEdit($_REQUEST['smw_Spoken_By'], '', EDIT_NEW); }
function crpage($arg1, $arg2) { $title = Title::newFromText($arg1); $article = new Article($title); $arg2 = htmlspecialchars($arg2); $article->doEdit($arg2, EDIT_UPDATE | EDIT_MINOR); return "Page {$arg1} created"; }
/** * Adds a property. * * @since 1.1 * * @param string $titleName The name of the property * @param string $propertyProperties A string of properties to assign to the propery (such as "has type") */ protected function addProperty($titleName, $propertyProperties) { $title = Title::newFromText($titleName, SMW_NS_PROPERTY); if (!$title->exists()) { $article = new Article($title, 0); $article->doEdit($article->getRawText() . $propertyProperties, ''); // TODO: add summary } }
public static function addMessageWall($userPageTitle) { wfProfileIn(__METHOD__); $botUser = User::newFromName('WikiaBot'); $article = new Article($userPageTitle); $status = $article->doEdit('', '', EDIT_NEW | EDIT_MINOR | EDIT_SUPPRESS_RC | EDIT_FORCE_BOT, false, $botUser); $title = $status->isOK() ? $article->getTitle() : false; wfProfileOut(__METHOD__); return $title; }
/** * setup function called on initialization * Create a Category:BlogListingPage so that we can purge by category when new blogs are posted * moved other setup code to ::ArticleFromTitle instead of hooking that twice [owen] * * @access public * @static */ public static function createCategory() { // make sure page "Category:BlogListingTag" exists $title = Title::newFromText('Category:BlogListingPage'); global $wgUser; if (!$title->exists() && $wgUser->isAllowed('edit')) { /** @var Article|WikiPage $article */ $article = new Article($title); $article->doEdit("__HIDDENCAT__", $title, EDIT_NEW | EDIT_FORCE_BOT | EDIT_SUPPRESS_RC); } }
public static function onUploadCompleteHook( &$file ) { global $wgExIndexMIMETypes; $localFile = $file->getLocalFile(); if ( $localFile != null && in_array( $localFile->getMimeType(), $wgExIndexMIMETypes ) ) { wfDebugLog( 'OracleTextSearch', 'Touching file page to force indexing'); $article = new Article( $localFile->getTitle() ); $article->loadContent(); $article->doEdit( $article->mContent, $article->mComment ); } return true; }
function execute($par) { $context = $this->getContext(); $request = $context->getRequest(); $out = $context->getOutput(); if ($request->getVal('ac_created_dialog', 0)) { $out->setArticleBodyOnly(true); $out->addHtml($this->getCreatedDialogHtml()); return; } $out->addCSSCode('acc'); //$out->addJSCode('ac'); $out->addJSCode('jqs'); $out->addJSCode('tmc'); $out->addModules('ext.guidedTour'); // Used for showing validation responses $out->addModules('ext.wikihow.articlecreator'); // Module to enable mw messages in javascript $t = Title::newFromText($request->getVal('t')); $out->setHTMLTitle(wfMessage('ac-html-title', $t->getText())); if ($request->wasPosted()) { $out->setArticleBodyOnly(true); $response = array(); $token = $context->getUser()->getEditToken(); if ($request->getVal('ac_token') != $token) { $response['error'] = wfMessage('ac-invalid-edit-token'); } else { if ($this->onlyEditNewArticles && $t->exists()) { $response['error'] = wfMessage('ac-title-exists', $t->getEditUrl()); } else { if (!$t->userCan('create', $context->getUser(), false)) { $response['error'] = wfMessage('ac-cannot-create', $t->getEditUrl()); } else { $a = new Article($t); $a->doEdit($request->getVal('wikitext'), wfMessage('ac-edit-summary')); // Add an author email notification $aen = new AuthorEmailNotification(); $aen->addNotification($t->getText()); $response['success'] = wfMessage('ac-successful-publish'); $response['url'] = $t->getFullUrl(); } } } $out->addHtml(json_encode($response)); } else { if ($this->onlyEditNewArticles && $t->exists()) { $out->redirect($t->getEditURL()); } else { $this->outputStartupHtml(); } } }
function testbug14404() { global $wgUser, $wgContLang, $wgLanguageCode, $wgLang; $title = Title::newFromText("Bug 14404"); $article = new Article($title); $wgUser = new User(); $wgUser->mRights = array('createpage', 'edit', 'purge'); $wgLanguageCode = 'es'; $wgContLang = Language::factory('es'); $wgLang = Language::factory('fr'); $status = $article->doEdit('{{:{{int:history}}}}', 'Test code for bug 14404', 0); $templates1 = $article->getUsedTemplates(); $wgLang = Language::factory('de'); $article->mParserOptions = null; // Let it pick the new user language $article->mPreparedEdit = false; // In order to force the rerendering of the same wikitext // We need an edit, a purge is not enough to regenerate the tables $status = $article->doEdit('{{:{{int:history}}}}', 'Test code for bug 14404', EDIT_UPDATE); $templates2 = $article->getUsedTemplates(); $this->assertEquals($templates1, $templates2); $this->assertEquals($templates1[0]->getFullText(), 'Historial'); }
function writeAnnotationProperties($newPageName, $annotatedImage, $imageURL, $coords, $createdBy) { $newTitle = Title::newFromText($newPageName); $newArticle = new Article($newTitle); $content = ''; $content .= '{{ImageAnnotation}}'; $content .= '[[SIAannotatedImage::' . $annotatedImage . '| ]]' . "\n"; $content .= '[[SIAimageURL::' . $imageURL . '| ]]' . "\n"; $content .= '[[SIArectangleCoordinates::' . $coords . '| ]]' . "\n"; $content .= '[[SIAcreatedBy::' . $createdBy . '| ]]' . "\n"; $content .= '[[Category:ImageAnnotation]]' . "\n"; $newArticle->doEdit($content, 'Created by Semantic Image Annotator'); return 'success'; }
/** * updatePages * updates infoboxes on all census enabled pages */ public function updatePages() { wfProfileIn(__METHOD__); //get all pages from category $aReturn = ApiService::call(array('action' => 'query', 'list' => 'categorymembers', 'cmtitle' => CensusDataRetrieval::getFlagCategoryTitle()->getPrefixedDBkey(), 'cmnamespace' => '0')); //perform update foreach page from category foreach ($aReturn['query']['categorymembers'] as $cm) { $oTitle = Title::newFromText($cm['title']); $oArticle = new Article($oTitle); $newText = $this->getUpdatedContent($oArticle->getContent(), $oTitle); //save updated content $oArticle->doEdit($newText, 'Updating infobox with data from Sony DB', EDIT_UPDATE); } wfProfileOut(__METHOD__); }
public function execute() { global $wgUser; $params = $this->extractRequestParams(); if (is_null($params['page'])) { $this->dieUsage('Must specify page title', 0); } if (is_null($params['tpl'])) { $this->dieUsage('Must specify template name', 1); } if (is_null($params['param'])) { $this->dieUsage('Must specify parameter name', 2); } if (is_null($params['value'])) { $this->dieUsage('Must specify value', 3); } if (is_null($params['summary'])) { $this->dieUsage('Must specify edit summary', 4); } $page = $params['page']; $template = $params['tpl']; $instance = $params['tplinstance']; $parameter = $params['param']; $value = $params['value']; $summary = $params['summary']; $articleTitle = Title::newFromText($page); if (!$articleTitle) { $this->dieUsage("Can't create title object ({$page})", 5); } $errors = $articleTitle->getUserPermissionsErrors('edit', $wgUser); if (!empty($errors)) { $this->dieUsage(wfMsg($errors[0][0], $errors[0][1]), 8); } $article = new Article($articleTitle); if (!$article->exists()) { $this->dieUsage("Article doesn't exist ({$page})", 6); } $pom = new POMPage($article->getContent()); if (array_key_exists($template, $pom->templates) && array_key_exists($instance, $pom->templates[$template])) { $pom->templates[$template][$instance]->setParameter($parameter, $value); } else { $this->dieUsage("This template ({$template}, instance #{$instance}) with this parameter ({$parameter}) doesn't exist within this page ({$page})", 7); } $success = $article->doEdit($pom->asString(), $summary); $result = array(); $result['result'] = $success ? 'Success' : 'Failure'; $this->getResult()->addValue(null, 'pomsettplparam', $result); }
/** * Run method * @return boolean success */ function run() { global $wgParser, $wgContLang; $linkCache =& LinkCache::singleton(); $linkCache->clear(); smwLog("start", "RF", "category refactoring"); $article = new Article($this->updatetitle); $latestrevision = Revision::newFromTitle($this->updatetitle); smwLog("oldtitle: " . $this->oldtitle, "RF", "category refactoring"); smwLog("newtitle: " . $this->newtitle, "RF", "category refactoring"); if (!$latestrevision) { $this->error = "SMW_UpdateCategoriesAfterMoveJob: Article not found " . $this->updatetitle->getPrefixedDBkey() . " "; wfDebug($this->error); return false; } $oldtext = $latestrevision->getRawText(); //Category X moved to Y // Links changed accordingly: $cat = $wgContLang->getNsText(NS_CATEGORY); $catlcfirst = strtolower(substr($cat, 0, 1)) . substr($cat, 1); $oldtitlelcfirst = strtolower(substr($this->oldtitle, 0, 1)) . substr($this->oldtitle, 1); // [[[C|c]ategory:[S|s]omeCategory]] -> [[[C|c]ategory:[S|s]omeOtherCategory]] $search[0] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\]\\])'; $replace[0] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}]]'; $search[1] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\]\\])'; $replace[1] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}]]'; $search[2] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\]\\])'; $replace[2] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}]]'; $search[3] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\]\\])'; $replace[3] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}]]'; // [[[C|c]ategory:[S|s]omeCategory | m]] -> [[[C|c]ategory:[S|s]omeOtherCategory | m ]] $search[4] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\|([^]]*)\\]\\])'; $replace[4] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}|${5}]]'; $search[5] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\|([^]]*)\\]\\])'; $replace[5] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}|${5}]]'; $search[6] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\|([^]]*)\\]\\])'; $replace[6] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}|${5}]]'; $search[7] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\|([^]]*)\\]\\])'; $replace[7] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}|${5}]]'; $newtext = preg_replace($search, $replace, $oldtext); $summary = 'Link(s) to ' . $this->newtitle . ' updated after page move by SMW_UpdateCategoriesAfterMoveJob. ' . $this->oldtitle . ' has been moved to ' . $this->newtitle; $article->doEdit($newtext, $summary, EDIT_FORCE_BOT); smwLog("finished editing article", "RF", "category refactoring"); $options = new ParserOptions(); $wgParser->parse($newtext, $this->updatetitle, $options, true, true, $latestrevision->getId()); smwLog("finished parsing semantic data", "RF", "category refactoring"); return true; }
function save() { global $wgUser, $wgTitle; // set username to something generic $wgUser = User::newFromName('Wikia'); $this->msg("Saving article... "); $title = Title::newFromText($this->mTitle); if ($title->exists() && !$this->overwrite) { $this->msg("Article {$this->mTitle} already exists! Giving up (because you told me to)!", true, true); exit(0); } $wgTitle = $title; $article = new Article($title); $status = $article->doEdit($this->mWikitext, "Importing content"); $this->msgStatus($status); }
private function addCoreDBData() { User::resetIdByNameCache(); //Make sysop user $user = User::newFromName('UTSysop'); if ($user->idForName() == 0) { $user->addToDatabase(); $user->setPassword('UTSysopPassword'); $user->addGroup('sysop'); $user->addGroup('bureaucrat'); $user->saveSettings(); } //Make 1 page with 1 revision $article = new Article(Title::newFromText('UTPage')); $article->doEdit('UTContent', 'UTPageSummary', EDIT_NEW, false, User::newFromName('UTSysop')); }
public function execute() { global $wgUser; $wgUser = User::newFromName($this->getOption('username', 'ScriptImporter')); $baseUrl = $this->getArg(1); $pageList = $this->fetchScriptList(); $this->output('Importing ' . count($pageList) . " pages\n"); foreach ($pageList as $page) { $this->output("Importing {$page}\n"); $url = wfAppendQuery($baseUrl, array('action' => 'raw', 'title' => "MediaWiki:{$page}")); $text = Http::get($url); $title = Title::makeTitleSafe(NS_MEDIAWIKI, $page); $article = new Article($title); $article->doEdit($text, "Importing from {$url}", 0); } }
function testTemplateCategories() { global $wgUser; $title = Title::newFromText("Categorized from template"); $article = new Article($title); $wgUser = new User(); $wgUser->mRights['*'] = array('createpage', 'edit', 'purge'); $status = $article->doEdit('{{Categorising template}}', 'Create a page with a template', 0); $this->assertEquals(array(), $title->getParentCategories()); $template = new Article(Title::newFromText('Template:Categorising template')); $status = $template->doEdit('[[Category:Solved bugs]]', 'Add a category through a template', 0); // Run the job queue $jobs = new RunJobs(); $jobs->loadParamsAndArgs(null, array('quiet' => true), null); $jobs->execute(); $this->assertEquals(array('Category:Solved_bugs' => $title->getPrefixedText()), $title->getParentCategories()); }