Advertisement
Guest User

media wiki api

a guest
Feb 19th, 2023
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.95 KB | None | 0 0
  1. #mediawiki
  2. ---------
  3.  
  4. #!/bin/bash
  5.  
  6. # Set the variables
  7. WIKI_URL="https://example.com/w/api.php"
  8. PAGE_TITLE="Page_title"
  9. TOKEN=$(curl -s "$WIKI_URL?action=query&meta=tokens&type=csrf&format=json" | jq -r '.query.tokens.csrftoken')
  10. SUMMARY="Edit summary"
  11. CONTENT="New page content"
  12.  
  13. # Make the API call to edit the page
  14. curl -s -X POST "$WIKI_URL" \
  15. -d "action=edit" \
  16. -d "title=$PAGE_TITLE" \
  17. -d "format=json" \
  18. -d "summary=$SUMMARY" \
  19. -d "text=$CONTENT" \
  20. -d "token=$TOKEN"
  21.  
  22. # Verify that the edit was successful
  23. if [ $? -eq 0 ]; then
  24.     echo "Page $PAGE_TITLE edited successfully"
  25. else
  26.     echo "Edit failed"
  27. fi
  28. --------------------
  29. #!/bin/bash
  30.  
  31. # Set the variables
  32. DATE=$(date +%Y%m%d)
  33. DB_NAME="mediawiki"
  34. DB_USER="root"
  35. DB_PASSWORD="your_password"
  36. BACKUP_DIR="/path/to/backup/directory"
  37. BACKUP_FILE="$BACKUP_DIR/$DB_NAME-$DATE.sql.gz"
  38.  
  39. # Create the backup directory if it doesn't exist
  40. if [ ! -d "$BACKUP_DIR" ]; then
  41.     mkdir -p "$BACKUP_DIR"
  42. fi
  43.  
  44. # Create the backup
  45. docker exec -i mediawiki /usr/bin/mysqldump -u $DB_USER --password=$DB_PASSWORD $DB_NAME | gzip > $BACKUP_FILE
  46.  
  47. # Verify that the backup was created
  48. if [ -f "$BACKUP_FILE" ]; then
  49.     echo "Backup of database $DB_NAME created at $BACKUP_FILE"
  50. else
  51.     echo "Backup failed"
  52. fi
  53. --------------------
  54. #!/bin/bash
  55.  
  56. # Set the variables
  57. DB_NAME="mediawiki"
  58. DB_USER="root"
  59. DB_PASSWORD="your_password"
  60. BACKUP_FILE="/path/to/backup/file.sql.gz"
  61.  
  62. # Check if the backup file exists
  63. if [ ! -f "$BACKUP_FILE" ]; then
  64.     echo "Backup file not found"
  65.     exit 1
  66. fi
  67.  
  68. # Restore the backup to the database
  69. gunzip -c "$BACKUP_FILE" | docker exec -i mediawiki /usr/bin/mysql -u $DB_USER --password=$DB_PASSWORD $DB_NAME
  70.  
  71. # Verify that the restore was successful
  72. if [ $? -eq 0 ]; then
  73.     echo "Database $DB_NAME restored from $BACKUP_FILE"
  74. else
  75.     echo "Restore failed"
  76. fi
  77. --------------------
  78. #!/bin/bash
  79.  
  80. # Set the MediaWiki version and port number
  81. MEDIAWIKI_VERSION="1.36.1"
  82. PORT="8080"
  83. # Create a directory to hold the MediaWiki files
  84. mkdir mediawiki
  85. cd mediawiki
  86. # Download the MediaWiki Docker image
  87. docker pull mediawiki:$MEDIAWIKI_VERSION
  88. # Create a Docker container and start it
  89. docker run --name mediawiki -p $PORT:80 -v $(pwd):/var/www/data -d mediawiki:$MEDIAWIKI_VERSION
  90. # Wait for the container to start up
  91. sleep 5
  92. # Get the initial login credentials
  93. docker logs mediawiki 2>&1 | grep "Admin username" -A 1
  94. echo "MediaWiki is now running at http://localhost:$PORT"
  95.  
  96. #This script sets the MediaWiki version and port number, creates a directory to hold the MediaWiki files, downloads the MediaWiki #Docker image, creates a Docker container using the downloaded image, and starts the container. It then waits for the container to #start up and retrieves the initial login credentials from the container logs.
  97. #You can save this script to a file (e.g., install_mediawiki.sh) and run it from the command line using bash install_mediawiki.sh. #Note that you may need to modify the script to fit your specific needs (e.g., setting different port numbers or MediaWiki versions).
  98.  
  99.  
  100. ----------------------
  101. #This script uses the requests library to make an API request to the MediaWiki site, passing in the necessary parameters to create a new #page (action, title, text, summary, format, and token). The get_edit_token function is a separate function that retrieves an edit token #required for making API edits. Note that this script is just an example, and may need to be modified to fit the specific MediaWiki site #and login credentials that you are using. Also, be sure to handle any errors that may occur during the API request.
  102.  
  103. import requests
  104.  
  105. # Set the API endpoint and login credentials
  106. api_endpoint = "https://example.com/api.php"
  107. api_username = "your_username"
  108. api_password = "your_password"
  109.  
  110. # Set the page title and content
  111. page_title = "New_Page_Title"
  112. page_content = "This is the content of the new page."
  113.  
  114. # Set the edit summary
  115. edit_summary = "Created a new page using the API"
  116.  
  117. # Make the API request to create the new page
  118. api_request = requests.post(api_endpoint, data={
  119.     "action": "edit",
  120.     "title": page_title,
  121.     "text": page_content,
  122.     "summary": edit_summary,
  123.     "format": "json",
  124.     "token": get_edit_token(api_endpoint, api_username, api_password)
  125. })
  126.  
  127. # Check the API response to see if the page was created successfully
  128. if api_request.json()["edit"]["result"] == "Success":
  129.     print(f"Page '{page_title}' was created successfully!")
  130. else:
  131.     print("There was an error creating the page.")
  132. --------------------
  133. Perl: This script uses the LWP::UserAgent module to make an API request to the MediaWiki site, passing in the necessary parameters to create a new page (action, title, text, summary, format, and token). The get_edit_token function is a separate function that retrieves an edit token required for making API edits.
  134.  
  135. Note that this script is just an example, and may need to be modified to fit the specific MediaWiki site and login credentials that you are using. Also, be sure to handle any errors that may occur during the API request.
  136.  
  137. use LWP::UserAgent;
  138. use JSON;
  139.  
  140. # Set the API endpoint and login credentials
  141. my $api_endpoint = "https://example.com/api.php";
  142. my $api_username = "your_username";
  143. my $api_password = "your_password";
  144.  
  145. # Set the page title and content
  146. my $page_title = "New_Page_Title";
  147. my $page_content = "This is the content of the new page.";
  148.  
  149. # Set the edit summary
  150. my $edit_summary = "Created a new page using the API";
  151.  
  152. # Make the API request to create the new page
  153. my $ua = LWP::UserAgent->new;
  154. my $api_request = $ua->post($api_endpoint, [
  155.     action => 'edit',
  156.     title => $page_title,
  157.     text => $page_content,
  158.     summary => $edit_summary,
  159.     format => 'json',
  160.     token => get_edit_token($api_endpoint, $api_username, $api_password),
  161. ]);
  162.  
  163. # Decode the JSON response
  164. my $api_response = decode_json($api_request->content);
  165.  
  166. # Check the API response to see if the page was created successfully
  167. if ($api_response->{'edit'}{'result'} eq 'Success') {
  168.     print "Page '$page_title' was created successfully!\n";
  169. } else {
  170.     print "There was an error creating the page.\n";
  171. }
  172.  
  173. # Get the edit token required for making API edits
  174. sub get_edit_token {
  175.     my ($api_endpoint, $api_username, $api_password) = @_;
  176.  
  177.     my $ua = LWP::UserAgent->new;
  178.     my $api_request = $ua->post($api_endpoint, [
  179.         action => 'query',
  180.         meta => 'tokens',
  181.         type => 'login',
  182.         format => 'json',
  183.     ]);
  184.  
  185.     my $api_response = decode_json($api_request->content);
  186.     my $login_token = $api_response->{'query'}{'tokens'}{'logintoken'};
  187.  
  188.     $api_request = $ua->post($api_endpoint, [
  189.         action => 'login',
  190.         lgname => $api_username,
  191.         lgpassword => $api_password,
  192.         lgtoken => $login_token,
  193.         format => 'json',
  194.     ]);
  195.  
  196.     $api_request = $ua->post($api_endpoint, [
  197.         action => 'query',
  198.         meta => 'tokens',
  199.         type => 'edit',
  200.         format => 'json',
  201.     ]);
  202.  
  203.     $api_response = decode_json($api_request->content);
  204.     my $edit_token = $api_response->{'query'}{'tokens'}{'edittoken'};
  205.  
  206.     return $edit_token;
  207. }
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement